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 <QVQuaternion>
00030 #include <QV3DPolylineF>
00031
00032 #include "qv3dmodel.h"
00033
00034 #ifndef DOXYGEN_IGNORE_THIS
00035
00046 class QV3DCanvas;
00047
00048 class QV3DEllipsoid: public QV3DModel
00049 {
00050 private:
00051 QColor color;
00052 double rx, ry, rz, cx, cy, cz;
00053 int lats, longs;
00054 public:
00055 QV3DEllipsoid( const QColor color = Qt::yellow,
00056 const double rx = 0.5, const double ry = 0.5, const double rz = 0.5,
00057 const double cx = 0.0, const double cy = 0.0, const double cz = 0.0,
00058 const int lats = 100, const int longs = 100):QV3DModel(),
00059 color(color), rx(rx), ry(ry), rz(rz), cx(cx), cy(cy), cz(cz),
00060 lats(lats), longs(longs)
00061 { }
00062
00063 void paint(QV3DCanvas &glWidget);
00064 };
00065
00078 class QV3DCanvas : public QGLWidget, public QVPropertyContainer
00079 {
00080 Q_OBJECT
00081
00082 public:
00083 QV3DCanvas( const QString &title, const double zoom = 0.5, bool dr_center=FALSE,
00084 const QColor &backgroundColor = Qt::black, QWidget* parent=0);
00085
00086 ~QV3DCanvas ();
00087
00088 virtual void init() {};
00089 virtual void display() {};
00090 virtual void reshape(int, int) {};
00091
00095 bool setBackgroundColor(const QColor &color) { backgroundColor = color; return true; };
00096
00100 void setAmbientLight(const double R, const double G, const double B)
00101 {
00102 ambientLightR = R;
00103 ambientLightG = G;
00104 ambientLightB = B;
00105 };
00106
00114 bool setDisplayColor(const QString &name, const QColor &color) { return setPropertyValue<QColor>("Color for " + name, color); }
00115
00121 bool setDisplaySize(const QString &name, const double size) { return setPropertyValue<double>("Size for " + name, size); }
00122
00123 virtual bool linkUnspecifiedInputProperty(QVPropertyContainer *sourceContainer, QString sourcePropName, LinkType linkType);
00124
00130 void add3DModel(QV3DModel &model)
00131 {
00132 models.append(&model);
00133
00134 }
00135
00136
00137 void drawQVImage(QVGenericImage *image);
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 const QColor getNextColor()
00161 {
00162 QColor color = qvColors[colorCursor++];
00163 colorCursor %= 10;
00164 return color;
00165 }
00166
00167 private:
00168
00169
00170 void draw_center_of_rotation();
00171
00172 int beginx, beginy;
00173 QVQuaternion trackballQuat;
00174 double cx,cy,cz;
00175 double ambientLightR, ambientLightG, ambientLightB;
00176 bool dr_center;
00177 double zoom, fov;
00178 bool pressedleft, pressedright;
00179
00180 int colorCursor;
00181 QColor backgroundColor;
00182 QList< QV3DModel *> models;
00183 };
00184
00185 #endif
00186
00187 #endif