OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QGLViewerWidget.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 990 $ *
38 * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05. Feb 2014) $ *
39 * *
40 \*===========================================================================*/
41
42
43 #ifndef OPENMESHAPPS_QGLVIEWERWIDGET_HH
44 #define OPENMESHAPPS_QGLVIEWERWIDGET_HH
45
46
47 //== INCLUDES =================================================================
48
49
50 #include <OpenMesh/Core/Geometry/VectorT.hh>
51 #include <QtOpenGL/qgl.h>
52 #include <string>
53 #include <vector>
54 #include <map>
55
56
57 //== FORWARD DECLARATIONS =====================================================
58
59 class QMenu;
60 class QActionGroup;
61 class QAction;
62
63 //== CLASS DEFINITION =========================================================
64
65
66 class QGLViewerWidget : public QGLWidget
67 {
68
69 Q_OBJECT
70
71 public:
72 typedef QGLWidget Super;
73
74 // Default constructor.
75 QGLViewerWidget( QWidget* _parent=0 );
76
77 //
78 QGLViewerWidget( QGLFormat& _fmt, QWidget* _parent=0 );
79
80 // Destructor.
81 virtual ~QGLViewerWidget();
82
83 private:
84
85 void init(void);
86
87 public:
88
89 /* Sets the center and size of the whole scene.
90 The _center is used as fixpoint for rotations and for adjusting
91 the camera/viewer (see view_all()). */
92 void set_scene_pos( const OpenMesh::Vec3f& _center, float _radius );
93
94 /* view the whole scene: the eye point is moved far enough from the
95 center so that the whole scene is visible. */
96 void view_all();
97
99 QAction *add_draw_mode(const std::string& _s);
100
102 void del_draw_mode(const std::string& _s);
103
104 const std::string& current_draw_mode() const
105 { return draw_mode_ ? draw_mode_names_[draw_mode_-1] : nomode_; }
106
107 float radius() const { return radius_; }
108 const OpenMesh::Vec3f& center() const { return center_; }
109
110 const GLdouble* modelview_matrix() const { return modelview_matrix_; }
111 const GLdouble* projection_matrix() const { return projection_matrix_; }
112
113 float fovy() const { return 45.0f; }
114
115 QAction* findAction(const char *name);
116 void addAction(QAction* action, const char* name);
117 void removeAction(const char* name);
118 void removeAction(QAction* action);
119
120 protected:
121
122 // draw the scene: will be called by the painGL() method.
123 virtual void draw_scene(const std::string& _draw_mode);
124
125 double performance(void);
126
127 void setDefaultMaterial(void);
128 void setDefaultLight(void);
129
130 private slots:
131
132 // popup menu clicked
133 void slotDrawMode(QAction *_mode);
134 void slotSnapshot( void );
135
136
137 private: // inherited
138
139 // initialize OpenGL states (triggered by Qt)
140 void initializeGL();
141
142 // draw the scene (triggered by Qt)
143 void paintGL();
144
145 // handle resize events (triggered by Qt)
146 void resizeGL( int w, int h );
147
148 protected:
149
150 // Qt mouse events
151 virtual void mousePressEvent( QMouseEvent* );
152 virtual void mouseReleaseEvent( QMouseEvent* );
153 virtual void mouseMoveEvent( QMouseEvent* );
154 virtual void wheelEvent( QWheelEvent* );
155 virtual void keyPressEvent( QKeyEvent* );
156
157 private:
158
159 // updates projection matrix
160 void update_projection_matrix();
161
162 // translate the scene and update modelview matrix
163 void translate(const OpenMesh::Vec3f& _trans);
164
165 // rotate the scene (around its center) and update modelview matrix
166 void rotate(const OpenMesh::Vec3f& _axis, float _angle);
167
168 OpenMesh::Vec3f center_;
169 float radius_;
170
171 GLdouble projection_matrix_[16],
172 modelview_matrix_[16];
173
174
175 // popup menu for draw mode selection
176 QMenu* popup_menu_;
177 QActionGroup* draw_modes_group_;
178 typedef std::map<QString,QAction*> ActionMap;
179 ActionMap names_to_actions;
180 unsigned int draw_mode_;
181 unsigned int n_draw_modes_;
182 std::vector<std::string> draw_mode_names_;
183 static std::string nomode_;
184
185
186
187 // virtual trackball: map 2D screen point to unit sphere
188 bool map_to_sphere(const QPoint& _point, OpenMesh::Vec3f& _result);
189
190 QPoint last_point_2D_;
191 OpenMesh::Vec3f last_point_3D_;
192 bool last_point_ok_;
193
194 };
195
196
197 //=============================================================================
198 #endif // OPENMESHAPPS_QGLVIEWERWIDGET_HH
199 //=============================================================================
200
QGLViewerWidget::add_draw_mode
QAction * add_draw_mode(const std::string &_s)
add draw mode to popup menu, and return the QAction created
Definition: QGLViewerWidget.cc:635
QGLViewerWidget::del_draw_mode
void del_draw_mode(const std::string &_s)
delete draw mode from popup menu
Definition: QGLViewerWidget.cc:702
QGLViewerWidget
Definition: QGLViewerWidget.hh:66