OpenMesh
QGLViewerWidget.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2025, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43
44
45#ifndef OPENMESHAPPS_QGLVIEWERWIDGET_HH
46#define OPENMESHAPPS_QGLVIEWERWIDGET_HH
47
48
49//== INCLUDES =================================================================
50#include <OpenMesh/Core/Geometry/VectorT.hh>
51#include <string>
52#include <vector>
53#include <map>
54#if QT_VERSION_MAJOR < 6
55 #include <QGLWidget>
56#else
57 #include <QtOpenGLWidgets/QOpenGLWidget>
58#endif
59
60#ifndef __APPLE__
61 #include <GL/gl.h>
62#endif
63
64//== FORWARD DECLARATIONS =====================================================
65
66class QMenu;
67class QActionGroup;
68class QAction;
69
70//== CLASS DEFINITION =========================================================
71
72#if QT_VERSION_MAJOR < 6
73class QGLViewerWidget : public QGLWidget
74#else
75class QGLViewerWidget : public QOpenGLWidget
76#endif
77{
78 Q_OBJECT
79
80
81public:
82 #if QT_VERSION_MAJOR < 6
83 typedef QGLWidget Super;
84 #else
85 typedef QOpenGLWidget Super;
86 #endif
87
88 // Default constructor.
89 explicit QGLViewerWidget( QWidget* _parent=0 );
90
91 // Destructor.
92 virtual ~QGLViewerWidget();
93
94private:
95
96 void init(void);
97
98public:
99
100#if QT_VERSION_MAJOR > 5
101 /* Updates the gui - used to provide backwards compability */
102 void updateGL();
103#endif
104
105 /* Sets the center and size of the whole scene.
106 The _center is used as fixpoint for rotations and for adjusting
107 the camera/viewer (see view_all()). */
108 void set_scene_pos( const OpenMesh::Vec3f& _center, float _radius );
109
110 /* view the whole scene: the eye point is moved far enough from the
111 center so that the whole scene is visible. */
112 void view_all();
113
115 QAction *add_draw_mode(const std::string& _s);
116
118 void del_draw_mode(const std::string& _s);
119
120 const std::string& current_draw_mode() const
121 { return draw_mode_ ? draw_mode_names_[draw_mode_-1] : nomode_; }
122
123 float radius() const { return radius_; }
124 const OpenMesh::Vec3f& center() const { return center_; }
125
126 const GLdouble* modelview_matrix() const { return modelview_matrix_; }
127 const GLdouble* projection_matrix() const { return projection_matrix_; }
128
129 float fovy() const { return 45.0f; }
130
131 QAction* findAction(const char *name);
132 void addAction(QAction* action, const char* name);
133 void removeAction(const char* name);
134 void removeAction(QAction* action);
135
136protected:
137
138 // draw the scene: will be called by the painGL() method.
139 virtual void draw_scene(const std::string& _draw_mode);
140
141 double performance(void);
142
143 void setDefaultMaterial(void);
144 void setDefaultLight(void);
145
146private slots:
147
148 // popup menu clicked
149 void slotDrawMode(QAction *_mode);
150 void slotSnapshot( void );
151
152
153private: // inherited
154
155 // initialize OpenGL states (triggered by Qt)
156 void initializeGL();
157
158 // draw the scene (triggered by Qt)
159 void paintGL();
160
161 // handle resize events (triggered by Qt)
162 void resizeGL( int w, int h );
163
164protected:
165
166 // Qt mouse events
167 virtual void mousePressEvent( QMouseEvent* );
168 virtual void mouseReleaseEvent( QMouseEvent* );
169 virtual void mouseMoveEvent( QMouseEvent* );
170 virtual void wheelEvent( QWheelEvent* );
171 virtual void keyPressEvent( QKeyEvent* );
172
173private:
174
175 // updates projection matrix
176 void update_projection_matrix();
177
178 // translate the scene and update modelview matrix
179 void translate(const OpenMesh::Vec3f& _trans);
180
181 // rotate the scene (around its center) and update modelview matrix
182 void rotate(const OpenMesh::Vec3f& _axis, float _angle);
183
184 OpenMesh::Vec3f center_;
185 float radius_;
186
187 GLdouble projection_matrix_[16],
188 modelview_matrix_[16];
189
190
191 // popup menu for draw mode selection
192 QMenu* popup_menu_;
193 QActionGroup* draw_modes_group_;
194 typedef std::map<QString,QAction*> ActionMap;
195 ActionMap names_to_actions;
196 unsigned int draw_mode_;
197 unsigned int n_draw_modes_;
198 std::vector<std::string> draw_mode_names_;
199 static std::string nomode_;
200
201
202
203 // virtual trackball: map 2D screen point to unit sphere
204 bool map_to_sphere(const QPoint& _point, OpenMesh::Vec3f& _result);
205
206 QPoint last_point_2D_;
207 OpenMesh::Vec3f last_point_3D_;
208 bool last_point_ok_;
209
210};
211
212
213//=============================================================================
214#endif // OPENMESHAPPS_QGLVIEWERWIDGET_HH
215//=============================================================================
216
Definition: QGLViewerWidget.hh:77
QAction * add_draw_mode(const std::string &_s)
add draw mode to popup menu, and return the QAction created
Definition: QGLViewerWidget.cc:650
void del_draw_mode(const std::string &_s)
delete draw mode from popup menu
Definition: QGLViewerWidget.cc:717

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .