00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef QVGENERICIMAGE_H
00026 #define QVGENERICIMAGE_H
00027
00028 #include <qvdefines.h>
00029 #include <QRect>
00030 #include <QPoint>
00031 #include <QSize>
00032
00065 class QVGenericImage
00066 {
00067 public:
00071 QVGenericImage (): roi(0,0,0,0), anchor(QPoint(0,0)) { }
00072
00076 QVGenericImage(QVGenericImage const &img): roi(img.getROI()), anchor(img.getAnchor()) { }
00077
00079 virtual ~QVGenericImage () { };
00080
00084 virtual uInt getCols() const = 0;
00085
00089 virtual uInt getRows() const = 0;
00090
00099 virtual uInt getStep() const = 0;
00100
00109 QSize getSize() const { return QSize(getCols(), getRows()); };
00110
00117 virtual uInt getChannels() const = 0;
00118
00125 virtual uInt getTypeSize() const = 0;
00126
00133 virtual uInt getDataSize() const = 0;
00134
00141 const QRect & getROI() const { return roi; }
00142
00143
00151 void resetROI() { setROI(0,0,getCols(), getRows()); }
00152
00161 void erodeROI(uInt cols, uInt rows)
00162 { setROI(getROI().x()+cols, getROI().y()+rows, getROI().width()-2*cols, getROI().height()-2*rows); }
00163
00172 void dilateROI(uInt cols, uInt rows)
00173 { setROI(getROI().x()-cols, getROI().y()-rows, getROI().width()+2*cols, getROI().height()+2*rows); }
00174
00186 void setROI(int x, int y, uInt w, uInt h) { setROI(QRect(x,y,w,h)); }
00187
00188
00189
00190
00191
00192
00193 #ifndef DOXYGEN_IGNORE_THIS
00194 void setMarginROI(int margin)
00195 { setROI(margin, margin, getCols() - 2*margin, getRows() -2*margin); }
00196 #endif
00197
00205 void setROI(const QRect &rect)
00206 {
00207 Q_ASSERT_X(rect.x() >= 0,"QVGenericImage::setROI()","QRect.x() is less than zero");
00208 Q_ASSERT_X(rect.y() >= 0,"QVGenericImage::setROI()","QRect.y() is less than zero");
00209 Q_ASSERT_X(rect.width() > 0,"QVGenericImage::setROI()","QRect.width() is less or equal to zero");
00210 Q_ASSERT_X(rect.height() > 0,"QVGenericImage::setROI()","QRect.height() is less or equal to zero");
00211 Q_ASSERT_X(rect.x()+rect.width() <= (int) getCols(),"QVGenericImage::setROI()","x + width > columns");
00212 Q_ASSERT_X(rect.y()+rect.height() <= (int) getRows(),"QVGenericImage::setROI()","y + height > rows");
00213 roi = rect;
00214 }
00215
00216
00217
00223 const QPoint & getAnchor() const { return anchor; }
00224
00225
00228 void resetAnchor() { setAnchor(0,0); }
00229
00234 void setAnchor(int col, int row) { setAnchor(QPoint(col,row)); }
00235
00239 void setAnchor(const QPoint &point)
00240 {
00241 Q_ASSERT_X(point.x()>=0,"QVGenericImage::setAnchor()","horizontal value for anchor is less than zero");
00242 Q_ASSERT_X(point.y()>=0,"QVGenericImage::setAnchor()","vertical value for anchor is less than zero");
00243 Q_ASSERT_X(point.x() < (int) getCols(),"QVGenericImage::setAnchor()","horizontal value exceeds cols");
00244 Q_ASSERT_X(point.y() < (int) getRows(),"QVGenericImage::setAnchor()","vertical value exceeds rows");
00245 anchor = point;
00246 }
00247
00248
00253 virtual const char * getTypeQString() const = 0;
00254
00280 bool isCompatibleWith(const char *qvImageClassName) const
00281 {
00282 Q_ASSERT_X(qvImageClassName!= NULL,"QVGenericImage::isCompatibleWith()","class name string is NULL");
00283 return (0 == strcmp(this->getTypeQString(),qvImageClassName));
00284 }
00285
00293 bool isCompatibleWith(const QVGenericImage *image) const
00294 {
00295 Q_ASSERT_X(image!= NULL,"QVGenericImage::isCompatibleWith()","NULL pointer");
00296 return this->isCompatibleWith(image->getTypeQString());
00297 }
00298
00299 protected:
00300 QRect roi;
00301 QPoint anchor;
00302 };
00303
00304
00305 #endif // QVGENERICIMAGE_H