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 <QVProcessingBlock>
00029 #include <QVMatrix>
00030 #include <QVQuaternion>
00031
00032 #include "qv3dmodel.h"
00033
00034 #ifndef DOXYGEN_IGNORE_THIS
00035
00044 class QV3DPointF: public QVVector
00045 {
00046
00047
00048 public:
00054 QV3DPointF(const double x = 0.0, const double y = 0.0, const double z = 0.0): QVVector(3)
00055 {
00056 operator[](0) = x;
00057 operator[](1) = y;
00058 operator[](2) = z;
00059 }
00060
00061 QV3DPointF(const QVVector &vector): QVVector(vector)
00062 { }
00063
00065 inline double x() const { return operator[](0); }
00066
00068 inline double &x() { return operator[](0); }
00069
00071 inline double y() const { return operator[](1); }
00072
00074 inline double &y() { return operator[](1); }
00075
00077 inline double z() const { return operator[](2); }
00078
00080 inline double &z() { return operator[](2); }
00081 };
00082
00093 class QV3DPolylineF: public QList<QV3DPointF> {};
00094
00095 Q_DECLARE_METATYPE(QV3DPolylineF);
00096 Q_DECLARE_METATYPE(QList<QV3DPointF>);
00097 Q_DECLARE_METATYPE(QList<QV3DPolylineF>);
00098
00109 class QV3DCanvas;
00110
00111 class QV3DEllipsoid: public QV3DModel
00112 {
00113 private:
00114 QColor color;
00115 double rx, ry, rz, cx, cy, cz;
00116 int lats, longs;
00117 public:
00118 QV3DEllipsoid( const QColor color = Qt::yellow,
00119 const double rx = 0.5, const double ry = 0.5, const double rz = 0.5,
00120 const double cx = 0.0, const double cy = 0.0, const double cz = 0.0,
00121 const int lats = 100, const int longs = 100):QV3DModel(),
00122 color(color), rx(rx), ry(ry), rz(rz), cx(cx), cy(cy), cz(cz),
00123 lats(lats), longs(longs)
00124 { }
00125
00126 void paint(QV3DCanvas &glWidget);
00127 };
00128
00141 class QV3DCanvas : public QGLWidget, public QVPropertyContainer
00142 {
00143 Q_OBJECT
00144
00145 public:
00146 QV3DCanvas( const QString &title, const double zoom = 0.5, bool dr_center=FALSE,
00147 const QColor &backgroundColor = Qt::black, QWidget* parent=0);
00148
00149 ~QV3DCanvas ();
00150
00151 virtual void init() {};
00152 virtual void display() {};
00153 virtual void reshape(int, int) {};
00154
00158 bool setBackgroundColor(const QColor &color) { backgroundColor = color; return true; };
00159
00163 void setAmbientLight(const double R, const double G, const double B)
00164 {
00165 ambientLightR = R;
00166 ambientLightG = G;
00167 ambientLightB = B;
00168 };
00169
00177 bool setDisplayColor(const QString &name, const QColor &color) { return setPropertyValue<QColor>("Color for " + name, color); }
00178
00184 bool setDisplaySize(const QString &name, const double size) { return setPropertyValue<double>("Size for " + name, size); }
00185
00186
00187 bool linkUnspecifiedInputProperty(QVPropertyContainer *sourceContainer, QString sourcePropName, LinkType linkType);
00188
00194 void add3DModel(QV3DModel &model)
00195 {
00196 models.append(&model);
00197
00198 }
00199
00200 signals:
00201 void closed();
00202
00203 protected:
00204
00205 void draw(const QV3DPolylineF &qv3DPolyline, const QColor color = Qt::red, const double size = 1);
00206 void draw(const QList<QV3DPointF> &qv3DPointList, const QColor color = Qt::red, const double size = 1);
00207
00208 void initializeGL();
00209 void paintGL();
00210 void resizeGL(int w, int h );
00211
00212 void viewer();
00213
00214 void mousePressEvent(QMouseEvent * event);
00215 void mouseReleaseEvent(QMouseEvent *event);
00216 void mouseMoveEvent(QMouseEvent *event);
00217 void wheelEvent(QWheelEvent *event);
00218 void keyPressEvent(QKeyEvent *event);
00219
00220 void closeEvent(QCloseEvent * event);
00221
00222 private:
00223 void draw_center_of_rotation();
00224
00225 int beginx, beginy;
00226 QVQuaternion trackballQuat;
00227 double cx,cy,cz;
00228 double ambientLightR, ambientLightG, ambientLightB;
00229 bool dr_center;
00230 double zoom, fov;
00231 bool pressedleft, pressedright;
00232
00233
00234 const QColor getNextColor()
00235 {
00236 QColor color = qvColors[colorCursor++];
00237 colorCursor %= 10;
00238 return color;
00239 }
00240
00241 int colorCursor;
00242 QColor backgroundColor;
00243 QList< QV3DModel *> models;
00244 };
00245
00246 #endif
00247
00248 #endif