00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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