00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef OPENMESHAPPS_QGLVIEWERWIDGET_HH
00044 #define OPENMESHAPPS_QGLVIEWERWIDGET_HH
00045
00046
00047
00048
00049
00050 #include <OpenMesh/Core/Geometry/VectorT.hh>
00051 #include <QtOpenGL/qgl.h>
00052 #include <string>
00053 #include <vector>
00054 #include <map>
00055
00056
00057
00058
00059 class QMenu;
00060 class QActionGroup;
00061 class QAction;
00062
00063
00064
00065
00066 class QGLViewerWidget : public QGLWidget
00067 {
00068
00069 Q_OBJECT
00070
00071 public:
00072 typedef QGLWidget Super;
00073
00074
00075 QGLViewerWidget( QWidget* _parent=0 );
00076
00077
00078 QGLViewerWidget( QGLFormat& _fmt, QWidget* _parent=0 );
00079
00080
00081 virtual ~QGLViewerWidget();
00082
00083 private:
00084
00085 void init(void);
00086
00087 public:
00088
00089
00090
00091
00092 void set_scene_pos( const OpenMesh::Vec3f& _center, float _radius );
00093
00094
00095
00096 void view_all();
00097
00099 QAction *add_draw_mode(const std::string& _s);
00100
00102 void del_draw_mode(const std::string& _s);
00103
00104 const std::string& current_draw_mode() const
00105 { return draw_mode_ ? draw_mode_names_[draw_mode_-1] : nomode_; }
00106
00107 float radius() const { return radius_; }
00108 const OpenMesh::Vec3f& center() const { return center_; }
00109
00110 const GLdouble* modelview_matrix() const { return modelview_matrix_; }
00111 const GLdouble* projection_matrix() const { return projection_matrix_; }
00112
00113 float fovy() const { return 45.0f; }
00114
00115 QAction* findAction(const char *name);
00116 void addAction(QAction* action, const char* name);
00117 void removeAction(const char* name);
00118 void removeAction(QAction* action);
00119
00120 protected:
00121
00122
00123 virtual void draw_scene(const std::string& _draw_mode);
00124
00125 double performance(void);
00126
00127 void setDefaultMaterial(void);
00128 void setDefaultLight(void);
00129
00130 private slots:
00131
00132
00133 void slotDrawMode(QAction *_mode);
00134 void slotSnapshot( void );
00135
00136
00137 private:
00138
00139
00140 void initializeGL();
00141
00142
00143 void paintGL();
00144
00145
00146 void resizeGL( int w, int h );
00147
00148 protected:
00149
00150
00151 virtual void mousePressEvent( QMouseEvent* );
00152 virtual void mouseReleaseEvent( QMouseEvent* );
00153 virtual void mouseMoveEvent( QMouseEvent* );
00154 virtual void wheelEvent( QWheelEvent* );
00155 virtual void keyPressEvent( QKeyEvent* );
00156
00157 private:
00158
00159
00160 void update_projection_matrix();
00161
00162
00163 void translate(const OpenMesh::Vec3f& _trans);
00164
00165
00166 void rotate(const OpenMesh::Vec3f& _axis, float _angle);
00167
00168 OpenMesh::Vec3f center_;
00169 float radius_;
00170
00171 GLdouble projection_matrix_[16],
00172 modelview_matrix_[16];
00173
00174
00175
00176 QMenu* popup_menu_;
00177 QActionGroup* draw_modes_group_;
00178 typedef std::map<QString,QAction*> ActionMap;
00179 ActionMap names_to_actions;
00180 unsigned int draw_mode_;
00181 unsigned int n_draw_modes_;
00182 std::vector<std::string> draw_mode_names_;
00183 static std::string nomode_;
00184
00185
00186
00187
00188 bool map_to_sphere(const QPoint& _point, OpenMesh::Vec3f& _result);
00189
00190 QPoint last_point_2D_;
00191 OpenMesh::Vec3f last_point_3D_;
00192 bool last_point_ok_;
00193
00194 };
00195
00196
00197
00198 #endif // OPENMESHAPPS_QGLVIEWERWIDGET_HH
00199
00200