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