00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00024 
00025 #ifndef QVIMAGECANVAS_H
00026 #define QVIMAGECANVAS_H
00027 
00028 #include "qvcanvas.h"
00029 
00030 #include <QPointF>
00031 #include <QVProcessingBlock>
00032 #include <QVPolyline>
00033 #include <QVPolylineF>
00034 #include <QVCameraPose>
00035 #include <QV3DPolylineF>
00036 #include <qvblockprogramming/qvguiblocks/qv3dmodel.h>
00037 
00348 class QVImageCanvas: public QVCanvas, public QVPropertyContainer
00349         {
00350                 Q_OBJECT
00351 
00352         protected:
00353                 QList< QV3DModel *> models;
00354 
00355         public:
00356 
00357                 void add3DModel(QV3DModel &model)
00358                         {
00359                         models.append(&model);
00360                         
00361                         }
00362 
00363                 void draw(const QV3DPolylineF &qv3DPolyline, const QColor color = Qt::red, const double size = 1)
00364                         {
00365                         glPointSize(size);
00366                         glBegin(GL_LINES);
00367                         glColor3ub(color.red(), color.green(), color.blue());
00368                         
00369                         for (int i = 1; i < qv3DPolyline.size(); i++)
00370                                 {
00371                                 glVertex3f(qv3DPolyline[i].x(), qv3DPolyline[i].y(), qv3DPolyline[i].z());
00372                                 glVertex3f(qv3DPolyline[i-1].x(), qv3DPolyline[i-1].y(), qv3DPolyline[i-1].z());
00373                                 }
00374                         glEnd();
00375                         }
00376 
00377                 void draw(const QList<QV3DPointF> &qv3DPointList, const QColor color = Qt::red, const double size = 1)
00378                         {
00379                         glBegin(GL_POINTS);
00380                         glColor3ub(color.red(), color.green(), color.blue());
00381                         
00382                         glPointSize(size);
00383                         foreach(QV3DPointF point, qv3DPointList)
00384                             glVertex3f(point.x(), point.y(), point.z());
00385                         glEnd();
00386                         }
00387 
00388 
00393                 QVImageCanvas(const QString name = QString(), QWidget *parent=0);
00394 
00413                 bool setColor(const QString &name, const QColor &color)
00414                         { return setPropertyValue<QColor>("Color for " + name, color); }
00415 
00417                 bool setPrintTags(const QString &name, const bool &printTags)
00418                         { return setPropertyValue<bool>("Print tags for " + name, printTags); }
00419 
00427                 bool setRadius(const QString &name, const int &radius)
00428                         { return setPropertyValue<int>("Radius for " + name, radius); }
00429 
00439                 void setSaturationRange(const float low, const float high);
00440 
00443                 bool linkSelectedPolyline(QVPropertyContainer *destinationContainer, QString destinationPropName)
00444                         {
00445                         return linkProperty("poly select", destinationContainer, destinationPropName);
00446                         }
00447 
00450                 bool linkSelectedRectangle(QVPropertyContainer *destinationContainer, QString destinationPropName)
00451                         {
00452                         return linkProperty("rect select", destinationContainer, destinationPropName);
00453                         }
00454 
00459                 bool linkSelectedPolyline(QVPropertyContainer &destinationContainer, QString destinationPropName)
00460                         {
00461                         return linkSelectedPolyline(&destinationContainer, destinationPropName);
00462                         }
00463 
00468                 bool linkSelectedRectangle(QVPropertyContainer &destinationContainer, QString destinationPropName)
00469                         {
00470                         return linkSelectedRectangle(&destinationContainer, destinationPropName);
00471                         }
00472 
00511                 virtual void custom_viewer() { };
00512 
00513                 virtual void custom_viewer_3D() { };
00514 
00516                 void setLowHigh(float low,float high)
00517                         {
00518                         std::cout << "DEPRECATED, use setSaturationRange instead" << std::endl;
00519                         setSaturationRange(low, high);
00520                         }
00521 
00526                 QVPainter *getQVPainter() { return QVCanvas::getQVPainter(); };
00527 
00528 
00533                 int getZoom() const { return QVCanvas::getZoom(); };
00534 
00551                 QRect getViewport() const { return QVCanvas::getViewport(); };
00552 
00558                 QSize getSize() const { return QVCanvas::getSize(); };
00559 
00560 
00621                 void beginDrawWorldFromCamera(const double fx, const double fy, const QVCameraPose &cameraPosition)
00622                         {
00623                         return QVCanvas::beginDrawWorldFromCamera(fx,fy,cameraPosition);
00624                         };
00625 
00629                 void endDrawWorldFromCamera() { QVCanvas::endDrawWorldFromCamera(); };
00630 
00631                 
00632                 
00633 
00634                 void unlink();
00635 
00636                 #ifndef DOXYGEN_IGNORE_THIS
00637                 void viewer();
00638                 #endif
00639 
00640         public slots:
00641                 void rectSelectedSlot(QRect rect);
00642                 void polySelectedSlot(QPoint point, bool reset, TPolyMode mode);
00643 
00644         protected:
00645                 bool linkUnspecifiedInputProperty(QVPropertyContainer *sourceContainer, QString sourcePropName, LinkType linkType = AsynchronousLink);
00646                 bool linkUnspecifiedOutputProperty(QVPropertyContainer *destContainer, QString destPropName, LinkType linkType = AsynchronousLink);
00647                 bool treatUnlinkInputProperty(QString destPropName, QVPropertyContainer *sourceCont, QString sourcePropName);
00648 
00649                 void draw(const QList<QPoint> &pointList, QColor color = Qt::red, bool printTags = false, int radius = 2);
00650                 void draw(const QList<QPointF> &pointList, QColor color = Qt::red, bool printTags = false, double radius = 2);
00651                 void draw(const QVPolyline &polyline, QColor color = Qt::red, bool printTags = false);
00652                 void draw(const QVPolylineF &polylinef, QColor color = Qt::red, bool printTags = false);
00653                 void draw(const QRect &rectangle, QColor color = Qt::red, bool printTags = false);
00654                 void draw(const QPointFMatching &matching, const int radius = 2);
00655 
00656                 void closeEvent(QCloseEvent *event) { Q_UNUSED(event); emit closed(); }
00657 
00658                 const QColor    getNextColor()
00659                         {
00660                         QColor color = qvColors[colorCursor++];
00661                         colorCursor %= 10;
00662 
00663                         return color;
00664                         }
00665 
00666                 float _low,_high;
00667                 int colorCursor, contentLinkedBlocks;
00668 
00669         signals:
00670                 void closed();
00671 
00672         };
00673 
00674 Q_DECLARE_METATYPE(TPolyMode);
00675 
00676 #endif