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