PARP Research Group University of Murcia, Spain


src/qvgui/qv3dcanvas.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. 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 #ifndef QVGLCANVAS_H
00026 #define QVGLCANVAS_H
00027 
00028 #include <QVWorker>
00029 #include <QVMatrix>
00030 #include <QVQuaternion>
00031 
00032 #include <qvgui/qv3dmodel.h>
00033 
00034 #ifndef DOXYGEN_IGNORE_THIS
00035 
00044 class QV3DPointF
00045         {
00046         private:
00047                 double _x, _y, _z;
00048         public:
00054                 QV3DPointF(const double x = 0.0, const double y = 0.0, const double z = 0.0): _x(x), _y(y), _z(z)       { }
00055 
00057                 inline double x() const { return _x; }
00058 
00060                 inline double &x()      { return _x; }
00061 
00063                 inline double y() const { return _y; }
00064 
00066                 inline double &y()      { return _y; }
00067 
00069                 inline double z() const { return _z; }
00070 
00072                 inline double &z()      { return _z; }
00073         };
00074 
00085 class QV3DPolylineF: public QList<QV3DPointF>
00086         {};
00087 
00088 Q_DECLARE_METATYPE(QV3DPolylineF);
00089 Q_DECLARE_METATYPE(QList<QV3DPointF>);
00090 Q_DECLARE_METATYPE(QList<QV3DPolylineF>);
00091 
00104 class QV3DCanvas : public QGLWidget, public QVPropertyContainer
00105 {
00106 Q_OBJECT
00107 
00108 public:
00109         QV3DCanvas(     const QString &title, const double zoom = 0.5, bool dr_center=TRUE,
00110                         const QColor &backgroundColor = Qt::black, QWidget* parent=0);
00111 
00112         ~QV3DCanvas ();
00113 
00114         virtual void init() {};
00115         virtual void display() {};
00116         virtual void reshape(int, int) {};
00117 
00121         bool setBackgroundColor(const QColor &color)    { backgroundColor = color; return true; };
00122 
00130         bool setDisplayColor(const QString &name, const QColor &color)  { return setPropertyValue<QColor>("Color for " + name, color); }
00131         
00137         bool setDisplaySize(const QString &name, const double size)     { return setPropertyValue<double>("Size for " + name, size); }
00138 
00139 
00140         bool linkUnspecifiedInputProperty(QVPropertyContainer *sourceContainer, QString sourcePropName, LinkType linkType);
00141 
00147         void add3DModel(QV3DModel &model)
00148                 {
00149                 models.append(&model);
00150                 //QObject::connect(model.getInformer(), SIGNAL(modelUpdated()), this, SLOT(updateGL()), Qt::QueuedConnection);
00151                 }
00152 
00153 signals:
00154         void closed();
00155 
00156 protected:
00157 
00158         void draw(const QV3DPolylineF &qv3DPolyline, const QColor color = Qt::red, const double size = 1);
00159         void draw(const QList<QV3DPointF> &qv3DPointList, const QColor color = Qt::red, const double size = 1);
00160 
00161         void initializeGL();
00162         void paintGL();
00163         void resizeGL(int w, int h );
00164 
00165         void viewer();
00166 
00167         void mousePressEvent(QMouseEvent * event);
00168         void mouseReleaseEvent(QMouseEvent *event);
00169         void mouseMoveEvent(QMouseEvent *event);
00170         void wheelEvent(QWheelEvent *event);
00171         void keyPressEvent(QKeyEvent *event);
00172         
00173         void closeEvent(QCloseEvent * event);
00174 
00175 private:
00176         void draw_center_of_rotation();
00177         
00178         int beginx, beginy;
00179         QVQuaternion trackballQuat;
00180         double cx,cy,cz;
00181         bool dr_center;
00182         double zoom, fov;
00183         bool pressedleft, pressedright;
00184 
00185 
00186         const QColor    getNextColor()
00187                 {
00188                 QColor color = qvColors[colorCursor++];
00189                 colorCursor %= 10;
00190                 return color;
00191                 }
00192 
00193         int colorCursor;
00194         QColor backgroundColor;
00195         QList< QV3DModel *> models;
00196 };
00197 
00198 #endif
00199 #endif



QVision framework. PARP research group, copyright 2007, 2008.