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 <iostream>
00029
00030 #include <qvdefines.h>
00031 #include <QRect>
00032 #include <QPoint>
00033 #include <QSize>
00034
00067 class QVGenericImage
00068 {
00069 public:
00073 QVGenericImage (): roi(0,0,0,0), anchor(QPoint(0,0)) { }
00074
00078 QVGenericImage(QVGenericImage const &img): roi(img.getROI()), anchor(img.getAnchor()) { }
00079
00081 virtual ~QVGenericImage () { };
00082
00086 virtual uInt getCols() const = 0;
00087
00091 virtual uInt getRows() const = 0;
00092
00101 virtual uInt getStep() const = 0;
00102
00111 QSize getSize() const { return QSize(getCols(), getRows()); };
00112
00119 virtual uInt getChannels() const = 0;
00120
00127 virtual uInt getTypeSize() const = 0;
00128
00135 virtual uInt getDataSize() const = 0;
00136
00143 const QRect & getROI() const { return roi; }
00144
00145
00153 void resetROI() { setROI(0,0,getCols(), getRows()); }
00154
00163 void erodeROI(uInt cols, uInt rows)
00164 { setROI(getROI().x()+cols, getROI().y()+rows, getROI().width()-2*cols, getROI().height()-2*rows); }
00165
00174 void dilateROI(uInt cols, uInt rows)
00175 { setROI(getROI().x()-cols, getROI().y()-rows, getROI().width()+2*cols, getROI().height()+2*rows); }
00176
00188 void setROI(int x, int y, uInt w, uInt h) { setROI(QRect(x,y,w,h)); }
00189
00190
00191
00192
00193
00194
00195 void setMargin(int margin)
00196 { setROI(margin, margin, getCols() - 2*margin, getRows() -2*margin); }
00197
00205 void setROI(const QRect &rect)
00206 {
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 Q_ASSERT_X(rect.x() >= 0,"QVGenericImage::setROI()","QRect.x() is less than zero");
00217 Q_ASSERT_X(rect.y() >= 0,"QVGenericImage::setROI()","QRect.y() is less than zero");
00218 Q_ASSERT_X(rect.x()+rect.width() <= (int) getCols(),"QVGenericImage::setROI()","x + width > columns");
00219 Q_ASSERT_X(rect.y()+rect.height() <= (int) getRows(),"QVGenericImage::setROI()","y + height > rows");
00220 roi = rect;
00221 }
00222
00223
00224
00230 const QPoint & getAnchor() const { return anchor; }
00231
00232
00235 void resetAnchor() { setAnchor(0,0); }
00236
00241 void setAnchor(int col, int row) { setAnchor(QPoint(col,row)); }
00242
00246 void setAnchor(const QPoint &point)
00247 {
00248 Q_ASSERT_X(point.x()>=0,"QVGenericImage::setAnchor()","horizontal value for anchor is less than zero");
00249 Q_ASSERT_X(point.y()>=0,"QVGenericImage::setAnchor()","vertical value for anchor is less than zero");
00250 Q_ASSERT_X((getCols() == 0) or (point.x() < (int) getCols()),"QVGenericImage::setAnchor()","horizontal value exceeds cols");
00251 Q_ASSERT_X((getRows() == 0) or (point.y() < (int) getRows()),"QVGenericImage::setAnchor()","vertical value exceeds rows");
00252 anchor = point;
00253 }
00254
00255
00260 virtual const char * getTypeQString() const = 0;
00261
00287 bool isCompatibleWith(const char *qvImageClassName) const
00288 {
00289 Q_ASSERT_X(qvImageClassName!= NULL,"QVGenericImage::isCompatibleWith()","class name string is NULL");
00290 return (0 == strcmp(this->getTypeQString(),qvImageClassName));
00291 }
00292
00300 bool isCompatibleWith(const QVGenericImage *image) const
00301 {
00302 Q_ASSERT_X(image!= NULL,"QVGenericImage::isCompatibleWith()","NULL pointer");
00303 return this->isCompatibleWith(image->getTypeQString());
00304 }
00305
00306 protected:
00307 QRect roi;
00308 QPoint anchor;
00309 };
00310
00311
00312 #endif // QVGENERICIMAGE_H