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
00064 class QVGenericImage
00065 {
00066 public:
00070 QVGenericImage (): roi(0,0,0,0), anchor(QPoint(0,0)) { }
00071
00075 QVGenericImage(QVGenericImage const &img): roi(img.getROI()), anchor(img.getAnchor()) { }
00076
00078 virtual ~QVGenericImage () { };
00079
00083 virtual uInt getCols() const = 0;
00084
00088 virtual uInt getRows() const = 0;
00089
00098 virtual uInt getStep() const = 0;
00099
00106 virtual uInt getChannels() const = 0;
00107
00114 virtual uInt getTypeSize() const = 0;
00115
00122 virtual uInt getDataSize() const = 0;
00123
00130 const QRect & getROI() const { return roi; }
00131
00138 const QPoint & getAnchor() const { return anchor; }
00139
00140
00149 void resetROI() { setROI(0,0,getCols(), getRows()); }
00150
00160 void erodeROI(uInt cols, uInt rows)
00161 { setROI(getROI().x()+cols, getROI().y()+rows, getROI().width()-2*cols, getROI().height()-2*rows); }
00162
00172 void dilateROI(uInt cols, uInt rows)
00173 { setROI(getROI().x()-cols, getROI().y()-rows, getROI().width()+2*cols, getROI().height()+2*rows); }
00174
00187 void setROI(int x, int y, uInt w, uInt h) { setROI(QRect(x,y,w,h)); }
00188
00192 void setMarginROI(int margin)
00193 { setROI(margin, margin, getCols() - 2*margin, getRows() -2*margin); }
00194
00198 void setROI(const QRect &rect)
00199 {
00200 Q_ASSERT_X(rect.x() >= 0,"QVGenericImage::setROI()","QRect.x() is less than zero");
00201 Q_ASSERT_X(rect.y() >= 0,"QVGenericImage::setROI()","QRect.y() is less than zero");
00202 Q_ASSERT_X(rect.width() > 0,"QVGenericImage::setROI()","QRect.width() is less or equal to zero");
00203 Q_ASSERT_X(rect.height() > 0,"QVGenericImage::setROI()","QRect.height() is less or equal to zero");
00204 Q_ASSERT_X(rect.x()+rect.width() <= (int) getCols(),"QVGenericImage::setROI()","x + width > columns");
00205 Q_ASSERT_X(rect.y()+rect.height() <= (int) getRows(),"QVGenericImage::setROI()","y + height > rows");
00206 roi = rect;
00207 }
00208
00209
00212 void resetAnchor() { setAnchor(0,0); }
00213
00218 void setAnchor(int col, int row) { setAnchor(QPoint(col,row)); }
00219
00223 void setAnchor(const QPoint &point)
00224 {
00225 Q_ASSERT_X(point.x()>=0,"QVGenericImage::setAnchor()","horizontal value for anchor is less than zero");
00226 Q_ASSERT_X(point.y()>=0,"QVGenericImage::setAnchor()","vertical value for anchor is less than zero");
00227 Q_ASSERT_X(point.x() < (int) getCols(),"QVGenericImage::setAnchor()","horizontal value exceeds cols");
00228 Q_ASSERT_X(point.y() < (int) getRows(),"QVGenericImage::setAnchor()","vertical value exceeds rows");
00229 anchor = point;
00230 }
00231
00236 virtual const char * getTypeQString() const = 0;
00237
00266 bool isCompatibleWith(const char *qvImageClassName) const
00267 {
00268 Q_ASSERT_X(qvImageClassName!= NULL,"QVGenericImage::isCompatibleWith()","class name string is NULL");
00269 return (0 == strcmp(this->getTypeQString(),qvImageClassName));
00270 }
00271
00282 bool isCompatibleWith(const QVGenericImage *image) const
00283 {
00284 Q_ASSERT_X(image!= NULL,"QVGenericImage::isCompatibleWith()","NULL pointer");
00285 return this->isCompatibleWith(image->getTypeQString());
00286 }
00287
00288 protected:
00289 QRect roi;
00290 QPoint anchor;
00291 };
00292
00293
00294 #endif // QVGENERICIMAGE_H