src/qvgui/qvimagecanvas.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. 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 #include <qvgui/qvimagecanvas.h>
00026 
00027 QVImageCanvas::QVImageCanvas(const QString name, QWidget *parent): QVPropertyContainer(name), _low(0.0), _high(255.0), circleCenter()
00028         {
00029         qDebug() << "QVImageCanvas::QVImageCanvas()";
00030         if (qvApp == NULL)
00031                 {
00032                 QString str = "QVImageCanvas::QVImageCanvas(): the QVPlot cannot be created before the QVApplication instance. Aborting now.";
00033                 std::cerr << qPrintable(str) << std::endl;
00034                 exit(1);
00035                 }
00036         // if its a --help call, do nothing
00037         if (qvApp->forHelp()) return;
00038         else QVCanvas(parent);
00039 
00040 
00041         setName("QVImageCanvas for "+name);
00042         setWindowTitle(getName());
00043         addProperty<QRect>("rect select", outputFlag | internalProp, QRect(), "Rectangule selected in it's image area");
00044         addProperty<QVPolyline>("poly select", outputFlag | internalProp, QVPolyline(), "Poliline selected in it's image area");
00045         addProperty<QColor>("poly select $$ color", outputFlag | internalProp, Qt::red, "Color for property poly select"); // to draw the polyline
00046         addProperty<bool>("poly select $$ printTags", outputFlag | internalProp, false, "Print tag flag poly select");     //
00047         addProperty<TPolyMode>("poly select $$ polyMode", outputFlag | internalProp, LINE, "Polyline select mode");         //
00048         addProperty<QPoint>("poly select $$ center", outputFlag | internalProp, QPoint(), "Polyline select center");        //
00049         addProperty<float>("poly select $$ radius", outputFlag | internalProp, 0.0, "Polyline select radius");              //
00050         show();
00051         };
00052 
00053 void QVImageCanvas::viewer()
00054         {
00055         qDebug() << "QVImageCanvas::viewer()";
00056 
00057         readInputProperties();
00058 
00059         QList<QString> imageNamesC1uChar = getPropertyListByType< QVImage<uChar,1> >();
00060         if (imageNamesC1uChar.size() == 1)
00061                 getQVPainter()->drawQVImage(&getPropertyValue<QVImage<uChar,1> >(imageNamesC1uChar.at(0)));
00062 
00063         QList<QString> imageNamesC3uChar = getPropertyListByType< QVImage<uChar,3> >();
00064         if (imageNamesC3uChar.size() == 1)
00065                 getQVPainter()->drawQVImage(&getPropertyValue<QVImage<uChar,3> >(imageNamesC3uChar.at(0)));
00066 
00068         QList<QString> imageNamesC1uShort = getPropertyListByType< QVImage<uShort,1> >();
00069         if (imageNamesC1uShort.size() == 1)
00070                 {
00071                 QVImage<uChar,1> aux = getPropertyValue<QVImage<uShort,1> >(imageNamesC1uShort.at(0));
00072                 getQVPainter()->drawQVImage(&aux);
00073 //              getQVPainter()->drawQVImage(&getPropertyValue<QVImage<uShort,1> >(imageNamesC1uShort.at(0)));
00074                 }
00075 
00077         QList<QString> imageNamesC3uShort = getPropertyListByType< QVImage<uShort,3> >();
00078         if (imageNamesC3uShort.size() == 1)
00079                 {
00080                 QVImage<uChar,3> aux = getPropertyValue<QVImage<uShort,3> >(imageNamesC1uShort.at(0));
00081                 getQVPainter()->drawQVImage(&aux);
00082 //              getQVPainter()->drawQVImage(&getPropertyValue<QVImage<uShort,3> >(imageNamesC1uShort.at(0)));
00083                 }
00084 
00085         QList<QString> imageNamesC1sShort = getPropertyListByType< QVImage<sShort,1> >();
00086         if (imageNamesC1sShort.size() == 1)
00087                 {
00088                 QVImage<uChar,1> aux = getPropertyValue<QVImage<sShort,1> >(imageNamesC1sShort.at(0));
00089                 getQVPainter()->drawQVImage(&aux);
00090 //              getQVPainter()->drawQVImage(&getPropertyValue<QVImage<sShort,1> >(imageNamesC1sShort.at(0)));
00091                 }
00092 
00093         QList<QString> imageNamesC3sShort = getPropertyListByType< QVImage<sShort,3> >();
00094         if (imageNamesC3sShort.size() == 1)
00095                 {
00096                 QVImage<uChar,3> aux = getPropertyValue<QVImage<sShort,3> >(imageNamesC1sShort.at(0));
00097                 getQVPainter()->drawQVImage(&aux);
00098 //              getQVPainter()->drawQVImage(&getPropertyValue<QVImage<sShort,3> >(imageNamesC1sShort.at(0)));
00099                 }
00100 
00101         QList<QString> imageNamesC1sInt = getPropertyListByType< QVImage<sInt,1> >();
00102         if (imageNamesC1sInt.size() == 1)
00103                 {
00104                 QVImage<uChar,1> aux = getPropertyValue<QVImage<sInt,1> >(imageNamesC1sInt.at(0));
00105                 getQVPainter()->drawQVImage(&aux);
00106 //              getQVPainter()->drawQVImage(&getPropertyValue<QVImage<sInt,1> >(imageNamesC1sInt.at(0)));
00107                 }
00108 
00109         QList<QString> imageNamesC3sInt = getPropertyListByType< QVImage<sInt,3> >();
00110         if (imageNamesC3sInt.size() == 1)
00111                 {
00112                 QVImage<uChar,3> aux = getPropertyValue<QVImage<sInt,3> >(imageNamesC1sInt.at(0));
00113                 getQVPainter()->drawQVImage(&aux);
00114 //              getQVPainter()->drawQVImage(&getPropertyValue<QVImage<sInt,3> >(imageNamesC1sInt.at(0)));
00115                 }
00116 
00117         QList<QString> imageNamesC1sFloat = getPropertyListByType< QVImage<sFloat,1> >();
00118         if (imageNamesC1sFloat.size() == 1)
00119                 getQVPainter()->drawQVImage(&getPropertyValue<QVImage<sFloat,1> >(imageNamesC1sFloat.at(0)),TRUE,_low,_high);
00120 
00121         QList<QString> imageNamesC3sFloat = getPropertyListByType< QVImage<sFloat,3> >();
00122         if (imageNamesC3sFloat.size() == 1)
00123                 getQVPainter()->drawQVImage(&getPropertyValue<QVImage<sFloat,3> >(imageNamesC3sFloat.at(0)),TRUE,_low,_high);
00124 
00125         foreach(QString name, getPropertyListByType<QVPolyline>())
00126                 {
00127                 TPolyMode mode = containsProperty(name + " $$ polyMode") ? getPropertyValue<TPolyMode>(name + " $$ polyMode") : LINE;
00128                 if (mode == CIRCLE)
00129                         draw(   getPropertyValue<QPoint>(name + " $$ center"),
00130                                 getPropertyValue<float>(name + " $$ radius"),
00131                                 getPropertyValue<QColor>(name + " $$ color"),
00132                                 getPropertyValue<bool>(name + " $$ printTags")
00133                                 );
00134                 else
00135                         draw(   getPropertyValue<QVPolyline>(name),
00136                                 getPropertyValue<QColor>(name + " $$ color"),
00137                                 getPropertyValue<bool>(name + " $$ printTags"),
00138                                 mode
00139                                 );
00140                 }
00141 
00142         foreach(QString name, getPropertyListByType< QList<QVPolyline> >())
00143                 draw(   getPropertyValue< QList<QVPolyline> >(name),
00144                         getPropertyValue<QColor>(name + " $$ color"),
00145                         getPropertyValue<bool>(name + " $$ printTags")
00146                         );
00147 
00148         foreach(QString name, getPropertyListByType< QList< QList< QPointF > > >())
00149                 draw(   getPropertyValue< QList<QList< QPointF > > >(name),
00150                         getPropertyValue<QColor>(name + " $$ color"),
00151                         getPropertyValue<bool>(name + " $$ printTags")
00152                         );
00153 
00154         foreach(QString name, getPropertyListByType< QList<QPoint> >())
00155                 draw(   getPropertyValue< QList<QPoint> >(name),
00156                         getPropertyValue<QColor>(name + " $$ color"),
00157                         getPropertyValue<bool>(name + " $$ printTags")
00158                         );
00159 
00160         foreach(QString name, getPropertyListByType< QList<QPointF> >())
00161                 draw(   getPropertyValue< QList<QPointF> >(name),
00162                         getPropertyValue<QColor>(name + " $$ color"),
00163                         getPropertyValue<bool>(name + " $$ printTags")
00164                         );
00165 
00166         custom_viewer();
00167         qDebug() << "QVImageCanvas::viewer() <~ return";
00168         }
00169 
00170 void QVImageCanvas::linkProperty(QVWorker &worker, const QString propertyName, QColor color, bool printTags)
00171         {
00172         addPropertyFromQVariant(propertyName, inputFlag, worker.getPropertyQVariantValue(propertyName), worker.getPropertyInfo(propertyName));
00173         addProperty<QColor>(propertyName + " $$ color", outputFlag, color, QString("Color for property ") + propertyName);
00174         addProperty<bool>(propertyName + " $$ printTags", outputFlag, printTags, QString("Print tag flag ") + propertyName);
00175         worker.linkProperty(propertyName, this, propertyName ,QVWorker::AsynchronousLink);
00176         QObject::connect(&worker, SIGNAL(endIteration()), this, SLOT(refreshImageArea()));
00177         }
00178 
00179 bool QVImageCanvas::linkROI(QVWorker *worker, const QString propertyName)
00180         {
00181         return QVPropertyContainer::linkProperty("rect select", worker, propertyName, QVPropertyContainer::AsynchronousLink);
00182         }
00183 
00184 bool QVImageCanvas::linkPolyline(QVWorker *worker, const QString propertyName)
00185         {
00186         return QVPropertyContainer::linkProperty("poly select", worker, propertyName, QVPropertyContainer::AsynchronousLink);
00187         }
00188 
00189 void QVImageCanvas::setLowHigh(float low,float high)
00190         {
00191         _low = low;
00192         _high = high;
00193         }
00194 
00195 void QVImageCanvas::draw(const QList<QPoint> &pointList, QColor color, bool printTags)
00196         {
00197         getQVPainter()->setPen(color);
00198 
00199         // Paint point as an asterisc.
00200         for (int i = 0; i< pointList.size(); i++)
00201                 {
00202                 const QPoint point = pointList.at(i);
00203                 if (printTags)
00204                         getQVPainter()->drawText(point + QPoint(2,-2), QString("%1").arg(i));
00205 
00206                 getQVPainter()->drawArc(QRect(point + QPoint(-2,-2), point + QPoint(+2,+2)), 0, 16*360);
00207                 }
00208         }
00209 
00210 void QVImageCanvas::draw(const QList<QPointF> &pointList, QColor color, bool printTags)
00211         {
00212         getQVPainter()->setPen(color);
00213 
00214         // Paint point as an asterisc.
00215         for (int i = 0; i< pointList.size(); i++)
00216                 {
00217                 const QPointF last = pointList.at(i);
00218                 if (printTags)
00219                         getQVPainter()->drawText(last+QPointF(2,-2), QString("%1").arg(i));
00220 
00221                 getQVPainter()->drawArc(QRectF(last+QPointF(-2,-2),last+QPointF(+2,+2)),0,16*360);
00222                 }
00223         }
00224 
00225 void QVImageCanvas::draw(const QList< QList< QPointF > > &contours, QColor color, bool printTags)
00226         {
00227         for (int i = 0; i< contours.size(); i++)
00228                 {
00229                 const QList<QPointF> polyline = contours.at(i);
00230                 
00231                 getQVPainter()->setPen(color);
00232                 getQVPainter()->drawArc(QRectF(polyline.at(0),polyline.at(0)),0,16*360);
00233                 for (int j = 0; j< polyline.size()-1; j++)
00234                         getQVPainter()->drawLine(polyline.at(j)+QPointF(0.5,0.5),polyline.at(j+1)+QPointF(0.5,0.5)); // +0.5 to paint in the center of the pixel.
00235 
00236                 // Paint last point as an asterisc.
00237                 //QPoint last = polyline.last();
00238                 const QPointF last = polyline.last();
00239                 if (printTags)
00240                         getQVPainter()->drawText(last+QPoint(2,-2), QString("%1").arg(i));
00241 
00242                 getQVPainter()->drawLine(last + QPointF(0.72500,   0.88971), last + QPointF(0.27500,   0.11029));
00243                 getQVPainter()->drawLine(last + QPointF(0.88971,   0.72500), last + QPointF(0.11029,   0.27500));
00244                 getQVPainter()->drawLine(last + QPointF(0.88971,   0.27500), last + QPointF(0.11029,   0.72500));
00245                 getQVPainter()->drawLine(last + QPointF(0.72500,   0.11029), last + QPointF(0.27500,   0.88971));
00246 
00247                 //if (polyline.closed)
00248                 //      getQVPainter()->drawLine(polyline.last()+QPointF(0.5,0.5),polyline.at(0)+QPointF(0.5,0.5));
00249                 }
00250         }
00251 
00253 void QVImageCanvas::draw(const QVPolyline &contours, QColor color, bool printTags, TPolyMode mode)
00254         {
00255         getQVPainter()->setPen(color);
00256 
00257         for (int i = 0; i< contours.size(); i++)
00258                 {
00259                 const QPoint point = contours.at(i);
00260                 if (printTags)
00261                         getQVPainter()->drawText(point + QPoint(2,-2), QString("%1").arg(i));
00262 
00263                 getQVPainter()->drawArc(QRect(point + QPoint(-2,-2), point + QPoint(+2,+2)), 0, 16*360);
00264 
00265                 if (mode == LINE)
00266                         if (i > 0)
00267                                 // +0.5 to paint in the center of the pixel.
00268                                 getQVPainter()->drawLine(contours.at(i-1)+QPointF(0.5,0.5),contours.at(i)+QPointF(0.5,0.5));
00269                         
00270                 }
00271         }
00272 
00273 void QVImageCanvas::draw(const QPoint &center, float radius, QColor color, bool printTags)
00274         {
00275         getQVPainter()->setPen(color);
00276 
00277         if (printTags)
00278                 getQVPainter()->drawText(center + QPoint(2,-2), QString("(%1, %2)").arg(center.x(), center.y()));
00279 
00280         int rad = static_cast<int>(radius);
00281         if (rad > 0) getQVPainter()->drawArc(QRect(center + QPoint(-rad,-rad), center + QPoint(rad,rad)), 0, 16*360);
00282         }
00283 
00284 void QVImageCanvas::draw(const QList<QVPolyline> &contours, QColor color, bool printTags)
00285         {
00286         //foreach(QVPolyline polyline, contours)
00287         for (int i = 0; i< contours.size(); i++)
00288                 {
00289                 const QVPolyline polyline = contours.at(i);
00290                 
00291                 getQVPainter()->setPen(color);
00292                 getQVPainter()->drawArc(QRectF(polyline.at(0),polyline.at(0)),0,16*360);
00293                 for (int j = 0; j< polyline.size()-1; j++)
00294                         getQVPainter()->drawLine(polyline.at(j)+QPointF(0.5,0.5),polyline.at(j+1)+QPointF(0.5,0.5)); // +0.5 to paint in the center of the pixel.
00295 
00296                 // Paint last point as an asterisc.
00297                 //QPoint last = polyline.last();
00298                 const QPointF last = polyline.last();
00299                 if (printTags)
00300                         getQVPainter()->drawText(last+QPointF(2,-2), QString("%1").arg(i));
00301 
00302                 getQVPainter()->drawLine(last + QPointF(0.72500,   0.88971), last + QPointF(0.27500,   0.11029));
00303                 getQVPainter()->drawLine(last + QPointF(0.88971,   0.72500), last + QPointF(0.11029,   0.27500));
00304                 getQVPainter()->drawLine(last + QPointF(0.88971,   0.27500), last + QPointF(0.11029,   0.72500));
00305                 getQVPainter()->drawLine(last + QPointF(0.72500,   0.11029), last + QPointF(0.27500,   0.88971));
00306 
00307                 if (polyline.closed)
00308                         getQVPainter()->drawLine(polyline.last()+QPointF(0.5,0.5),polyline.at(0)+QPointF(0.5,0.5));
00309                 }
00310         }
00311 
00312 void QVImageCanvas::rectSelectedSlot(QRect rect)
00313         {
00314         setPropertyValue<QRect>("rect select", rect);
00315         writeOutputProperties();
00316         }
00317 
00320 void QVImageCanvas::circleSelectedSlot(QPoint center, float radius)
00321         {
00322         if (radius < 1)
00323                 setPropertyValue<QVPolyline>("poly select", QVPolyline());
00324         else
00325                 setPropertyValue<QVPolyline>("poly select", QVPolyline::ellipse(static_cast<uInt>(2*PI*radius), center.x(), center.y(), radius, radius, 0.0));
00326 
00327         setPropertyValue<TPolyMode>("poly select $$ polyMode", CIRCLE);
00328         setPropertyValue<QPoint>("poly select $$ center", center);
00329         setPropertyValue<float>("poly select $$ radius", radius);
00330         writeOutputProperties();
00331         }
00332 
00333 void QVImageCanvas::polySelectedSlot(QPoint point, bool reset, TPolyMode mode)
00334         {
00335         if (reset)
00336                 setPropertyValue<QVPolyline>("poly select", QVPolyline());
00337         else
00338                 {
00339                 QVPolyline poly = getPropertyValue<QVPolyline>("poly select");
00340                 poly.append(point);
00341                 setPropertyValue<QVPolyline>("poly select", poly);
00342                 }
00343 
00344         setPropertyValue<TPolyMode>("poly select $$ polyMode", mode);
00345         writeOutputProperties();
00346         }
00347 

Generated on Thu Jul 17 17:23:28 2008 for QVision by  doxygen 1.5.3