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 #include <qvmath.h>
00027
00028 QVImageCanvas::QVImageCanvas(const QString name, QWidget *parent): QVCanvas(parent), QVPropertyContainer(name), _low(0.0), _high(255.0), colorCursor(0),
00029 contentLinkedBlocks(0)
00030 {
00031 qDebug() << "QVImageCanvas::QVImageCanvas()";
00032 if (qvApp == NULL)
00033 {
00034 QString str = "QVImageCanvas::QVImageCanvas(): the QVPlot cannot be created before the QVApplication instance. Aborting now.";
00035 std::cerr << qPrintable(str) << std::endl;
00036 exit(1);
00037 }
00038
00039 if (qvApp->forHelp()) return;
00040
00041 setWindowTitle("Image canvas for " + getName());
00042 addProperty<QRect>("rect select", outputFlag, QRect(), "Rectangule selected in it's image area");
00043 addProperty<QVPolyline>("poly select", outputFlag, QVPolyline(), "Poliline selected in it's image area");
00044 addProperty<QColor>("Color for selected polygon", outputFlag | internalProp, Qt::red, "Color for property poly select");
00045 addProperty<bool>("Print tags for selected polygon", outputFlag | internalProp, false, "Print tag flag poly select");
00046 addProperty<TPolyMode>("Mode for selected polygon", outputFlag | internalProp, LINE, "Polyline select mode");
00047 addProperty<QPoint>("Center for selected polygon", outputFlag | internalProp, QPoint(), "Polyline select center");
00048 addProperty<float>("Radius for selected polygon", outputFlag | internalProp, 0.0, "Polyline select radius");
00049
00050
00051 addProperty< QVImage<uChar, 3> >("Content", outputFlag);
00052
00053
00054
00055
00056 show();
00057 };
00058
00059 void QVImageCanvas::viewer()
00060 {
00061 qDebug() << "QVImageCanvas::viewer()";
00062 QMutexLocker locker(&qvApp->mutex);
00063
00064 readInputProperties();
00065
00066
00067 foreach(QString name, getPropertyList())
00068 if( (getPropertyFlags(name) & inputFlag) and not (getPropertyFlags(name) & guiInvisible) )
00069 {
00070
00071 if (isType< QVImage<uChar,1> >(name)) {
00072 QVImage<uChar, 1> imageAux = getPropertyValue<QVImage<uChar,1> >(name);
00073 getQVPainter()->drawQVImage(&imageAux);
00074 }
00075
00076 else if (isType< QVImage<uChar,3> >(name)) {
00077 QVImage<uChar,3> imageAux = getPropertyValue<QVImage<uChar,3> >(name);
00078 getQVPainter()->drawQVImage(&imageAux);
00079 }
00080
00081 else if (isType< QVImage<sFloat,1> >(name)) {
00082 QVImage<sFloat,1> imageAux = getPropertyValue<QVImage<sFloat,1> >(name);
00083 getQVPainter()->drawQVImage(&imageAux, TRUE, _low, _high);
00084 }
00085
00086 else if (isType< QVImage<sFloat,3> >(name)) {
00087 QVImage<sFloat,3> imageAux = getPropertyValue<QVImage<sFloat,3> >(name);
00088 getQVPainter()->drawQVImage(&imageAux, TRUE, _low, _high);
00089 }
00094
00095 else if (isType< QVImage<uShort,1> >(name)) {
00096 QVImage<uChar, 1> imageAux = getPropertyValue<QVImage<uShort,1> >(name);
00097 getQVPainter()->drawQVImage(&imageAux);
00098 }
00099
00100 else if (isType< QVImage<uShort,3> >(name)) {
00101 QVImage<uChar, 3> imageAux = getPropertyValue<QVImage<uShort,3> >(name);
00102 getQVPainter()->drawQVImage(&imageAux);
00103 }
00104
00105 else if (isType< QVImage<sShort,1> >(name)) {
00106 QVImage<uChar, 1> imageAux = getPropertyValue<QVImage<sShort,1> >(name);
00107 getQVPainter()->drawQVImage(&imageAux);
00108 }
00109
00110 else if (isType< QVImage<sShort,3> >(name)) {
00111 QVImage<uChar, 3> imageAux = getPropertyValue<QVImage<sShort,3> >(name);
00112 getQVPainter()->drawQVImage(&imageAux);
00113 }
00114
00115 else if (isType< QVImage<sInt,1> >(name)) {
00116 QVImage<uChar, 1> imageAux = getPropertyValue<QVImage<sInt,1> >(name);
00117 getQVPainter()->drawQVImage(&imageAux);
00118 }
00119
00120 else if (isType< QVImage<sInt,3> >(name)) {
00121 QVImage<uChar, 3> imageAux = getPropertyValue<QVImage<sInt,3> >(name);
00122 getQVPainter()->drawQVImage(&imageAux);
00123 }
00124 }
00125
00126
00127 foreach(QString name, getPropertyList())
00128 if( (getPropertyFlags(name) & inputFlag) and not (getPropertyFlags(name) & guiInvisible) )
00129 {
00130 getQVPainter()->setBrush(QBrush(Qt::NoBrush));
00131
00132
00133 if (isType< QList<QPoint> >(name))
00134 draw( getPropertyValue< QList<QPoint> >(name),
00135 getPropertyValue<QColor>("Color for " + name),
00136 getPropertyValue<bool>("Print tags for " + name),
00137 getPropertyValue<int>("Radius for " + name)
00138 );
00139
00140
00141 else if (isType< QList<QPointF> >(name))
00142 draw( getPropertyValue< QList<QPointF> >(name),
00143 getPropertyValue<QColor>("Color for " + name),
00144 getPropertyValue<bool>("Print tags for " + name),
00145 getPropertyValue<int>("Radius for " + name)
00146 );
00147
00148
00149 else if (isType< QVPolyline >(name))
00150 draw( getPropertyValue< QVPolyline >(name),
00151 getPropertyValue<QColor>("Color for " + name),
00152 getPropertyValue<bool>("Print tags for " + name)
00153 );
00154
00155
00156 else if (isType< QVPolylineF >(name))
00157 draw( getPropertyValue< QVPolylineF >(name),
00158 getPropertyValue<QColor>("Color for " + name),
00159 getPropertyValue<bool>("Print tags for " + name)
00160 );
00161
00162
00163 else if (isType< QRect >(name))
00164 draw( getPropertyValue< QRect >(name),
00165 getPropertyValue<QColor>("Color for " + name),
00166 getPropertyValue<bool>("Print tags for " + name)
00167 );
00168
00169
00170 else if (isType< QList<QVPolyline> >(name))
00171 foreach(QVPolyline polyline, getPropertyValue< QList<QVPolyline> >(name))
00172 draw( polyline,
00173 getPropertyValue<QColor>("Color for " + name),
00174 getPropertyValue<bool>("Print tags for " + name)
00175 );
00176
00177
00178 else if (isType< QList<QVPolylineF> >(name))
00179 foreach(QVPolylineF polyline, getPropertyValue< QList<QVPolylineF> >(name))
00180 draw( polyline,
00181 getPropertyValue<QColor>("Color for " + name),
00182 getPropertyValue<bool>("Print tags for " + name)
00183 );
00184
00185
00186 else if (isType< QList<QRect> >(name))
00187 foreach(QRect rectangle, getPropertyValue< QList<QRect> >(name))
00188 draw( rectangle,
00189 getPropertyValue<QColor>("Color for " + name),
00190 getPropertyValue<bool>("Print tags for " + name)
00191 );
00192
00193 else if (isType< QList<QPointFMatching> >(name))
00194 foreach(QPointFMatching matching, getPropertyValue< QList<QPointFMatching> >(name))
00195 draw( matching,
00196 getPropertyValue<double>("Radius for " + name)
00197 );
00198
00199 }
00200
00201 QVMatrix K = QVMatrix();
00202 QVCameraPose cameraPose;
00203
00204
00205 foreach(QString name, getPropertyList())
00206 if( getPropertyFlags(name) & inputFlag )
00207 {
00208 if (isType< QVCameraPose >(name))
00209 cameraPose = getPropertyValue< QVCameraPose >(name);
00210 else if (isType< QVMatrix >(name))
00211 K = getPropertyValue< QVMatrix >(name);
00212 }
00213
00214 if (K.getCols() == 3 and K.getRows() == 3)
00215 {
00216
00217 beginDrawWorldFromCamera(K(0,0), K(1,1), cameraPose);
00218
00219
00220 foreach(QString name, getPropertyList())
00221 if (getPropertyFlags(name) & inputFlag)
00222 {
00223
00224 if (isType< QV3DPolylineF >(name))
00225 draw( getPropertyValue< QV3DPolylineF >(name),
00226 getPropertyValue<QColor>("Color for " + name),
00227 getPropertyValue<double>("Size for " + name));
00228
00229 else if (isType< QList<QV3DPointF> >(name))
00230 draw( getPropertyValue< QList<QV3DPointF> >(name),
00231 getPropertyValue<QColor>("Color for " + name),
00232 getPropertyValue<double>("Size for " + name));
00233
00234 else if (isType< QList<QV3DPolylineF> >(name))
00235 foreach(QV3DPolylineF polyline, getPropertyValue< QList<QV3DPolylineF> >(name))
00236 draw( polyline,
00237 getPropertyValue<QColor>("Color for " + name));
00238 }
00239
00240
00241 foreach(QV3DModel *model, models)
00242 model->updatePaint( * (this->imageArea));
00243
00244 custom_viewer_3D();
00245
00246 endDrawWorldFromCamera();
00247 }
00248
00249 custom_viewer();
00250
00251
00252
00253
00254
00257
00258 if (contentLinkedBlocks > 0)
00259 {
00260 QVImage<uChar, 3> image = contentImage();
00261 std::cout << "Linked Blocks = " << contentLinkedBlocks << std::endl;
00262 std::cout << "\t dims(ImageCanvas) = " << image.getCols() << "x" << image.getRows() << std::endl;
00263 setPropertyValue< QVImage<uChar, 3> >("Content", image);
00264 }
00265
00266 writeOutputProperties();
00267
00268 qDebug() << "QVImageCanvas::viewer() <~ return";
00269 }
00270
00272
00273 void QVImageCanvas::draw(const QList<QPoint> &pointList, QColor color, bool printTags, int radius)
00274 {
00275 const int diameter = 2*radius;
00276 getQVPainter()->setPen(color);
00277 getQVPainter()->setBrush(QBrush(color, Qt::SolidPattern));
00278
00279
00280 for (int i = 0; i< pointList.size(); i++)
00281 {
00282 const QPoint point = pointList.at(i);
00283 if (printTags)
00284 getQVPainter()->drawText(point + QPoint(2,-2), QString("%1").arg(i));
00285
00286 getQVPainter()->drawEllipse(point.x()-radius, point.y()-radius, diameter, diameter);
00287 }
00288 }
00289
00290 void QVImageCanvas::draw(const QList<QPointF> &pointList, QColor color, bool printTags, double radius)
00291 {
00292 const double diameter = 2*radius;
00293 getQVPainter()->setPen(Qt::black);
00294 getQVPainter()->setBrush(QBrush(color, Qt::SolidPattern));
00295
00296
00297 for (int i = 0; i< pointList.size(); i++)
00298 {
00299 const QPointF point = pointList.at(i);
00300 if (printTags)
00301 getQVPainter()->drawText(point+QPointF(2,-2), QString("%1").arg(i));
00302
00303 QRectF rect(point.x() - radius, point.y() - radius, diameter, diameter);
00304 getQVPainter()->drawEllipse(rect);
00305 }
00306 }
00307
00308 void QVImageCanvas::draw(const QPointFMatching &matching, const int radius)
00309 {
00310 const int x = ABS(int(matching.first.x())),
00311 y = ABS(int(matching.first.y()));
00312
00313 const QColor color( int(123456*x + 654321*y)%255,
00314 int(162534*x + 615243*y)%255,
00315 int(342516*x + 435261*y)%255 );
00316
00317
00318
00319
00320 getQVPainter()->setPen(color);
00321 getQVPainter()->drawLine(matching.first, matching.second);
00322
00323
00324 const double diameter = 2*radius;
00325 getQVPainter()->setPen(Qt::black);
00326 getQVPainter()->setBrush(QBrush(color, Qt::SolidPattern));
00327 getQVPainter()->drawEllipse(QRectF(matching.first.x() - radius, matching.first.y() - radius, diameter, diameter));
00328 getQVPainter()->drawEllipse(QRectF(matching.second.x() - radius, matching.second.y() - radius, diameter, diameter));
00329 }
00330
00331
00332 void QVImageCanvas::draw(const QVPolyline &polyline, QColor color, bool )
00333 {
00334 getQVPainter()->setPen(color);
00335
00336 for (int i = polyline.size()-1; i>0; i--)
00337 getQVPainter()->drawLine(polyline.at(i-1)+QPointF(0.5,0.5),polyline.at(i)+QPointF(0.5,0.5));
00338
00339 if (polyline.closed)
00340 getQVPainter()->drawLine(polyline.at(0) + QPointF(0.5,0.5), polyline.at(polyline.size() -1) + QPointF(0.5,0.5));
00341
00342
00343
00344
00345
00346
00347 }
00348
00349 void QVImageCanvas::draw(const QVPolylineF &polyline, QColor color, bool )
00350 {
00351 getQVPainter()->setPen(color);
00352
00353
00354 for (int i = polyline.size()-1; i>0; i--)
00355 getQVPainter()->drawLine(polyline.at(i-1)+QPointF(0.5,0.5),polyline.at(i)+QPointF(0.5,0.5));
00356
00357 if (polyline.closed)
00358 getQVPainter()->drawLine(polyline.at(0) + QPointF(0.5,0.5), polyline.at(polyline.size() -1) + QPointF(0.5,0.5));
00359
00360
00361
00362
00363
00364
00365 }
00366
00367 void QVImageCanvas::draw(const QRect &rectangle, QColor color, bool )
00368 {
00369 getQVPainter()->setPen(color);
00370
00371 getQVPainter()->drawLine(rectangle.topLeft(), rectangle.topRight() );
00372 getQVPainter()->drawLine(rectangle.topLeft(), rectangle.bottomLeft() );
00373 getQVPainter()->drawLine(rectangle.bottomLeft(), rectangle.bottomRight() );
00374 getQVPainter()->drawLine(rectangle.topRight(), rectangle.bottomRight() );
00375 }
00376
00377 void QVImageCanvas::unlink()
00378 {
00379 std::cerr << "ERROR: QVImageCanvas::linkProperty(): global unlink not implemented" << std::endl;
00380 }
00381
00382 bool QVImageCanvas::linkUnspecifiedInputProperty(QVPropertyContainer *sourceContainer, QString sourcePropName, LinkType linkType)
00383 {
00384 if (containsProperty(sourcePropName))
00385 return false;
00386
00387 if (linkType == SynchronousLink)
00388 {
00389 std::cerr << "ERROR: QVImageCanvas::linkUnspecifiedInputProperty(): the linkType must be AsynchronousLink, the link will not be done" << std::endl;
00390 return false;
00391 }
00392
00393 QVProcessingBlock* block;
00394 if((block = dynamic_cast<QVProcessingBlock*>(sourceContainer)) != NULL)
00395 {
00396 addPropertyFromQVariant(sourcePropName, inputFlag, block->getPropertyQVariantValue(sourcePropName), block->getPropertyInfo(sourcePropName));
00397
00398 if ( block->isType< QList<QPoint> >(sourcePropName) ||
00399 block->isType< QList<QPointF> >(sourcePropName) ||
00400 block->isType< QVPolyline >(sourcePropName) ||
00401 block->isType< QVPolylineF >(sourcePropName) ||
00402 block->isType< QRect >(sourcePropName) ||
00403 block->isType< QList<QVPolyline> >(sourcePropName) ||
00404 block->isType< QList<QVPolylineF> >(sourcePropName) ||
00405 block->isType< QList<QRect> >(sourcePropName) )
00406 {
00407 std::cout << "Adding property of name " << qPrintable(sourcePropName) << " with default color " << colorCursor << std::endl;
00408 addProperty<QColor>("Color for " + sourcePropName, inputFlag, getNextColor(), QString("Color for object ") + sourcePropName);
00409 addProperty<bool>("Print tags for " + sourcePropName, inputFlag, false, QString("Print tags for object ") + sourcePropName);
00410 if ( sourceContainer->isType< QList<QPointF> >(sourcePropName)||
00411 sourceContainer->isType< QList<QPoint> >(sourcePropName) )
00412 addProperty<int>( "Radius for " + sourcePropName, inputFlag, 3,
00413 QString("Specify a radius for the points to be displayed.") + sourcePropName);
00414 }
00415 else if ( block->isType< QV3DPolylineF >(sourcePropName) ||
00416 block->isType< QList<QV3DPointF> >(sourcePropName) ||
00417 block->isType< QList<QV3DPolylineF> >(sourcePropName) )
00418 {
00419 addProperty<QColor>("Color for " + sourcePropName, inputFlag, getNextColor(), QString("Color for object ") + sourcePropName);
00420 addProperty<double>("Size for " + sourcePropName, inputFlag, 1, QString("Size for object ") + sourcePropName);
00421
00422 #ifdef DEBUG
00423 std::cout << "QV3DCanvas: Added property 'Color for " << qPrintable(sourcePropName) << "'" << std::endl;
00424 std::cout << "QV3DCanvas: Added property 'Size for " << qPrintable(sourcePropName) << "'" << std::endl;
00425 #endif // DEBUG
00426 }
00427 else if ( block->isType< QList<QPointFMatching> >(sourcePropName) )
00428 {
00429 addProperty<double>("Radius for " + sourcePropName, inputFlag, 1, QString("Radius for object ") + sourcePropName);
00430
00431 #ifdef DEBUG
00432 std::cout << "QV3DCanvas: Added property 'Radius for " << qPrintable(sourcePropName) << "'" << std::endl;
00433 #endif // DEBUG
00434 }
00435
00436 bool result = block->linkProperty(sourcePropName, this, sourcePropName ,QVProcessingBlock::AsynchronousLink);
00437 QObject::connect(block, SIGNAL(endIteration(uint, int)), this, SLOT(refreshImageArea()));
00438 return result;
00439 }
00440 else
00441 {
00442 std::cerr << "ERROR: QVImageCanvas::linkUnspecifiedInputProperty(): the sourceContainer container must be a QVProcessingBlock, the link will not be done" << std::endl;
00443 return false;
00444 }
00445 }
00446
00447 bool QVImageCanvas::linkUnspecifiedOutputProperty(QVPropertyContainer *destContainer, QString destPropName, LinkType linkType)
00448 {
00449
00450 if (linkType == SynchronousLink)
00451 std::cerr << "ERROR: QVImageCanvas::linkUnspecifiedOutputProperty(): the linkType must be AsynchronousLink, the link will not be done." << std::endl;
00452 else if (dynamic_cast<QVProcessingBlock*>(destContainer) == NULL)
00453 std::cerr << "ERROR: QVImageCanvas::linkUnspecifiedOutputProperty(): destination block is not a block." << std::endl;
00454 else if (!destContainer->isType< QVImage<uChar, 3> >(destPropName))
00455 std::cerr << "ERROR: QVImageCanvas::linkUnspecifiedOutputProperty(): destination property is not of type QVImage<uChar, 3>." << std::endl;
00456 else if (linkProperty("Content", destContainer, destPropName ,QVProcessingBlock::AsynchronousLink))
00457 {
00458
00459 contentLinkedBlocks++;
00460 return true;
00461 }
00462
00463 return false;
00464 }
00465
00466 bool QVImageCanvas::treatUnlinkInputProperty(QString destPropName, QVPropertyContainer *sourceContainer, QString sourcePropName)
00467 {
00468 if ( (destPropName != "rect select") && (destPropName != "poly select") )
00469 {
00470 removeProperty(sourcePropName);
00471
00472 if ( sourceContainer->isType< QList<QPoint> >(sourcePropName) ||
00473 sourceContainer->isType< QList<QPointF> >(sourcePropName) ||
00474 sourceContainer->isType< QVPolyline >(sourcePropName) ||
00475 sourceContainer->isType< QVPolylineF >(sourcePropName) ||
00476 sourceContainer->isType< QRect >(sourcePropName) ||
00477 sourceContainer->isType< QList<QVPolyline> >(sourcePropName) ||
00478 sourceContainer->isType< QList<QVPolylineF> >(sourcePropName) ||
00479 sourceContainer->isType< QList<QRect> >(sourcePropName) )
00480 {
00481 removeProperty("Color for " + sourcePropName);
00482 removeProperty("Print tags for " + sourcePropName);
00483 if ( sourceContainer->isType< QList<QPointF> >(sourcePropName)||
00484 sourceContainer->isType< QList<QPoint> >(sourcePropName) )
00485 removeProperty("Radius for " + sourcePropName);
00486 }
00487 else if ( sourceContainer->isType< QV3DPolylineF >(sourcePropName) ||
00488 sourceContainer->isType< QList<QV3DPointF> >(sourcePropName) ||
00489 sourceContainer->isType< QList<QV3DPolylineF> >(sourcePropName) )
00490 {
00491 removeProperty("Color for " + sourcePropName);
00492 removeProperty("Size for " + sourcePropName);
00493 }
00494 else if ( sourceContainer->isType< QList<QPointFMatching> >(sourcePropName) )
00495 removeProperty("Size for " + sourcePropName);
00496
00497 QVProcessingBlock* block;
00498 if((block = dynamic_cast<QVProcessingBlock*>(sourceContainer)) != NULL)
00499 QObject::disconnect(block, SIGNAL(endIteration(uint, int)), this, SLOT(refreshImageArea()));
00500 }
00501 return true;
00502 }
00503
00504 void QVImageCanvas::setSaturationRange(float low,float high)
00505 {
00506 _low = low;
00507 _high = high;
00508 }
00509
00510 void QVImageCanvas::rectSelectedSlot(QRect rect)
00511 {
00512 setPropertyValue<QRect>("rect select", rect);
00513 writeOutputProperties();
00514 }
00515
00516 void QVImageCanvas::polySelectedSlot(QPoint point, bool reset, TPolyMode mode)
00517 {
00518 if (reset)
00519 setPropertyValue<QVPolyline>("poly select", QVPolyline());
00520 else
00521 {
00522 QVPolyline poly = getPropertyValue<QVPolyline>("poly select");
00523 poly.append(point);
00524 setPropertyValue<QVPolyline>("poly select", poly);
00525 }
00526
00527 setPropertyValue<TPolyMode>("Mode for selected polygon", mode);
00528 writeOutputProperties();
00529 }
00530