PARP Research Group University of Murcia, Spain


src/qvcore/qvgenericimage.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
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                 // ROI operations
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                 // Anchor operations
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



QVision framework. PARP research group, copyright 2007, 2008.