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):QVCanvas(parent), QVPropertyHolder(name), _low(0.0), _high(255.0)
00028         {
00029         setName("QVImageCanvas for "+name);
00030         setWindowTitle(getName());
00031         };
00032 
00033 void QVImageCanvas::viewer()
00034         {
00035         qDebug() << "QVImageCanvas::viewer()";
00036 
00037         readInputProperties();
00038 
00039         QList<QString> imageNamesC1uChar = getPropertyListByType< QVImage<uChar,1> >();
00040         if (imageNamesC1uChar.size() == 1)
00041                 {
00042                 QVImage<uChar,1> img = getPropertyValue<QVImage<uChar,1> >(imageNamesC1uChar.at(0));
00043                 getQVPainter()->drawQVImage(&img);
00044                 }
00045 
00046         QList<QString> imageNamesC3uChar = getPropertyListByType< QVImage<uChar,3> >();
00047         if (imageNamesC3uChar.size() == 1)
00048                 {
00049                 QVImage<uChar,3> img = getPropertyValue<QVImage<uChar,3> >(imageNamesC3uChar.at(0));
00050                 getQVPainter()->drawQVImage(&img);
00051                 }
00052 
00053         QList<QString> imageNamesC1sFloat = getPropertyListByType< QVImage<sFloat,1> >();
00054         if (imageNamesC1sFloat.size() == 1)
00055                 {
00056                 QVImage<sFloat,1> img = getPropertyValue<QVImage<sFloat,1> >(imageNamesC1sFloat.at(0));
00057                 getQVPainter()->drawQVImage(&img);
00058                 }
00059 
00060         QList<QString> polylineListNames = getPropertyListByType< QList<qvdta::QVPolyline> >();
00061         for (int i= 0; i< polylineListNames.size(); i++)
00062                 {
00063                 QList<qvdta::QVPolyline> contours = getPropertyValue< QList<qvdta::QVPolyline> >(polylineListNames.at(i));
00064                 draw(contours);
00065                 }
00066 
00067         qDebug() << "QVImageCanvas::viewer() <~ return";
00068         }
00069 
00070 void QVImageCanvas::linkProperty(QVWorker &worker, const QString propertyName)
00071         {
00072         addPropertyFromQVariant(propertyName, inputFlag, worker.getPropertyQVariantValue(propertyName), worker.getPropertyInfo(propertyName));
00073         worker.linkProperty(propertyName, this, propertyName ,QVWorker::AsynchronousLink);
00074         QObject::connect(&worker, SIGNAL(endIteration()), this, SLOT(refreshImageArea()));
00075         show();
00076         }
00077 
00078 void QVImageCanvas::setLowHigh(float low,float high)
00079         {
00080         _low = low;
00081         _high = high;
00082         }
00083 
00084 void QVImageCanvas::draw(const QList<qvdta::QVPolyline> &contours)
00085         {
00086         for (int i = 0; i< contours.size(); i++)
00087                 {
00088                 qvdta::QVPolyline polyline = contours.at(i);
00089                 getQVPainter()->setPen(QColor(polyline.direction?Qt::red:Qt::blue));
00090                 //getQVPainter()->drawText(QRect(polyline.at(0),polyline.at(0)), Qt::AlignCenter|Qt::TextDontClip, QString("%1").arg(polyline.size()));
00091                 getQVPainter()->drawArc(QRect(polyline.at(0),polyline.at(0)),0,16*360);
00092                 for (int j = 0; j< polyline.size()-1; j++)
00093                         {
00094                         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.
00095                         }
00096 
00097                 // Paint last point as an asterisc.
00098                 QPoint last = polyline.last();
00099                 getQVPainter()->drawLine(last + QPointF(0.72500,   0.88971), last + QPointF(0.27500,   0.11029));
00100                 getQVPainter()->drawLine(last + QPointF(0.88971,   0.72500), last + QPointF(0.11029,   0.27500));
00101                 getQVPainter()->drawLine(last + QPointF(0.88971,   0.27500), last + QPointF(0.11029,   0.72500));
00102                 getQVPainter()->drawLine(last + QPointF(0.72500,   0.11029), last + QPointF(0.27500,   0.88971));
00103 
00104 
00105                 if (polyline.closed) getQVPainter()->drawLine(polyline.last()+QPointF(0.5,0.5),polyline.at(0)+QPointF(0.5,0.5));
00106                 }
00107         }
00108 

Generated on Wed Jan 16 18:41:29 2008 for QVision by  doxygen 1.5.3