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 #include <QV3DPointF>
00032
00033 #include "qv3dmodel.h"
00034
00035 #ifndef DOXYGEN_IGNORE_THIS
00036
00047 class QV3DCanvas;
00048
00049 class QV3DEllipsoid: public QV3DModel
00050 {
00051 private:
00052 QColor color;
00053 double rx, ry, rz, cx, cy, cz;
00054 int lats, longs;
00055 public:
00056 QV3DEllipsoid( const QColor color = Qt::yellow,
00057 const double rx = 0.5, const double ry = 0.5, const double rz = 0.5,
00058 const double cx = 0.0, const double cy = 0.0, const double cz = 0.0,
00059 const int lats = 100, const int longs = 100):QV3DModel(),
00060 color(color), rx(rx), ry(ry), rz(rz), cx(cx), cy(cy), cz(cz),
00061 lats(lats), longs(longs)
00062 { }
00063
00064 void paint(QV3DCanvas &glWidget);
00065 };
00066
00079 class QV3DCanvas : public QGLWidget, public QVPropertyContainer
00080 {
00081 Q_OBJECT
00082
00083 public:
00084 QV3DCanvas( const QString &title, const double zoom = 0.5, bool dr_center=FALSE,
00085 const QColor &backgroundColor = Qt::black, QWidget* parent=0);
00086
00087 ~QV3DCanvas ();
00088
00089 virtual void init() {};
00090 virtual void display() {};
00091 virtual void reshape(int, int) {};
00092
00096 bool setBackgroundColor(const QColor &color) { backgroundColor = color; return true; };
00097
00101 void setAmbientLight(const double R, const double G, const double B)
00102 {
00103 ambientLightR = R;
00104 ambientLightG = G;
00105 ambientLightB = B;
00106 };
00107
00115 bool setDisplayColor(const QString &name, const QColor &color) { return setPropertyValue<QColor>("Color for " + name, color); }
00116
00122 bool setDisplaySize(const QString &name, const double size) { return setPropertyValue<double>("Size for " + name, size); }
00123
00124
00125 bool linkUnspecifiedInputProperty(QVPropertyContainer *sourceContainer, QString sourcePropName, LinkType linkType);
00126
00132 void add3DModel(QV3DModel &model)
00133 {
00134 models.append(&model);
00135
00136 }
00137
00138 signals:
00139 void closed();
00140
00141 protected:
00142
00143 void draw(const QV3DPolylineF &qv3DPolyline, const QColor color = Qt::red, const double size = 1);
00144 void draw(const QList<QV3DPointF> &qv3DPointList, const QColor color = Qt::red, const double size = 1);
00145
00146 void initializeGL();
00147 void paintGL();
00148 void resizeGL(int w, int h );
00149
00150 void viewer();
00151
00152 void mousePressEvent(QMouseEvent * event);
00153 void mouseReleaseEvent(QMouseEvent *event);
00154 void mouseMoveEvent(QMouseEvent *event);
00155 void wheelEvent(QWheelEvent *event);
00156 void keyPressEvent(QKeyEvent *event);
00157
00158 void closeEvent(QCloseEvent * event);
00159
00160 private:
00161 void draw_center_of_rotation();
00162
00163 int beginx, beginy;
00164 QVQuaternion trackballQuat;
00165 double cx,cy,cz;
00166 double ambientLightR, ambientLightG, ambientLightB;
00167 bool dr_center;
00168 double zoom, fov;
00169 bool pressedleft, pressedright;
00170
00171
00172 const QColor getNextColor()
00173 {
00174 QColor color = qvColors[colorCursor++];
00175 colorCursor %= 10;
00176 return color;
00177 }
00178
00179 int colorCursor;
00180 QColor backgroundColor;
00181 QList< QV3DModel *> models;
00182 };
00183
00184 #endif
00185
00186 #endif