OpenMesh
Loading...
Searching...
No Matches
QGLViewerWidget.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2023, 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#include <GL/gl.h>
61
62//== FORWARD DECLARATIONS =====================================================
63
64class QMenu;
65class QActionGroup;
66class QAction;
67
68//== CLASS DEFINITION =========================================================
69
70#if QT_VERSION_MAJOR < 6
71class QGLViewerWidget : public QGLWidget
72#else
73class QGLViewerWidget : public QOpenGLWidget
74#endif
75{
76 Q_OBJECT
77
78
79public:
80 #if QT_VERSION_MAJOR < 6
81 typedef QGLWidget Super;
82 #else
83 typedef QOpenGLWidget Super;
84 #endif
85
86 // Default constructor.
87 explicit QGLViewerWidget( QWidget* _parent=0 );
88
89 // Destructor.
90 virtual ~QGLViewerWidget();
91
92private:
93
94 void init(void);
95
96public:
97
98#if QT_VERSION_MAJOR > 5
99 /* Updates the gui - used to provide backwards compability */
100 void updateGL();
101#endif
102
103 /* Sets the center and size of the whole scene.
104 The _center is used as fixpoint for rotations and for adjusting
105 the camera/viewer (see view_all()). */
106 void set_scene_pos( const OpenMesh::Vec3f& _center, float _radius );
107
108 /* view the whole scene: the eye point is moved far enough from the
109 center so that the whole scene is visible. */
110 void view_all();
111
113 QAction *add_draw_mode(const std::string& _s);
114
116 void del_draw_mode(const std::string& _s);
117
118 const std::string& current_draw_mode() const
119 { return draw_mode_ ? draw_mode_names_[draw_mode_-1] : nomode_; }
120
121 float radius() const { return radius_; }
122 const OpenMesh::Vec3f& center() const { return center_; }
123
124 const GLdouble* modelview_matrix() const { return modelview_matrix_; }
125 const GLdouble* projection_matrix() const { return projection_matrix_; }
126
127 float fovy() const { return 45.0f; }
128
129 QAction* findAction(const char *name);
130 void addAction(QAction* action, const char* name);
131 void removeAction(const char* name);
132 void removeAction(QAction* action);
133
134protected:
135
136 // draw the scene: will be called by the painGL() method.
137 virtual void draw_scene(const std::string& _draw_mode);
138
139 double performance(void);
140
141 void setDefaultMaterial(void);
142 void setDefaultLight(void);
143
144private slots:
145
146 // popup menu clicked
147 void slotDrawMode(QAction *_mode);
148 void slotSnapshot( void );
149
150
151private: // inherited
152
153 // initialize OpenGL states (triggered by Qt)
154 void initializeGL();
155
156 // draw the scene (triggered by Qt)
157 void paintGL();
158
159 // handle resize events (triggered by Qt)
160 void resizeGL( int w, int h );
161
162protected:
163
164 // Qt mouse events
165 virtual void mousePressEvent( QMouseEvent* );
166 virtual void mouseReleaseEvent( QMouseEvent* );
167 virtual void mouseMoveEvent( QMouseEvent* );
168 virtual void wheelEvent( QWheelEvent* );
169 virtual void keyPressEvent( QKeyEvent* );
170
171private:
172
173 // updates projection matrix
174 void update_projection_matrix();
175
176 // translate the scene and update modelview matrix
177 void translate(const OpenMesh::Vec3f& _trans);
178
179 // rotate the scene (around its center) and update modelview matrix
180 void rotate(const OpenMesh::Vec3f& _axis, float _angle);
181
182 OpenMesh::Vec3f center_;
183 float radius_;
184
185 GLdouble projection_matrix_[16],
186 modelview_matrix_[16];
187
188
189 // popup menu for draw mode selection
190 QMenu* popup_menu_;
191 QActionGroup* draw_modes_group_;
192 typedef std::map<QString,QAction*> ActionMap;
193 ActionMap names_to_actions;
194 unsigned int draw_mode_;
195 unsigned int n_draw_modes_;
196 std::vector<std::string> draw_mode_names_;
197 static std::string nomode_;
198
199
200
201 // virtual trackball: map 2D screen point to unit sphere
202 bool map_to_sphere(const QPoint& _point, OpenMesh::Vec3f& _result);
203
204 QPoint last_point_2D_;
205 OpenMesh::Vec3f last_point_3D_;
206 bool last_point_ok_;
207
208};
209
210
211//=============================================================================
212#endif // OPENMESHAPPS_QGLVIEWERWIDGET_HH
213//=============================================================================
214
Definition QGLViewerWidget.hh:75
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 .