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
MeshViewerWidgetT.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_MESHVIEWERWIDGETT_HH
44 #define OPENMESHAPPS_MESHVIEWERWIDGETT_HH
45
46
47 //== INCLUDES =================================================================
48
49 #include <string>
50 #include <OpenMesh/Core/IO/MeshIO.hh>
51 #include <OpenMesh/Core/IO/Options.hh>
52 #include <OpenMesh/Core/Utils/GenProg.hh>
53 #include <OpenMesh/Core/Utils/color_cast.hh>
54 #include <OpenMesh/Core/Mesh/Attributes.hh>
55 #include <OpenMesh/Tools/Utils/StripifierT.hh>
56 #include <OpenMesh/Tools/Utils/Timer.hh>
57 #include <OpenMesh/Apps/QtViewer/QGLViewerWidget.hh>
58
59
60 //== FORWARDS =================================================================
61
62 class QImage;
63
64
65 //== CLASS DEFINITION =========================================================
66
67
68 template <typename M>
69 class MeshViewerWidgetT : public QGLViewerWidget
70 {
71 public:
72
73 typedef M Mesh;
74 typedef OpenMesh::StripifierT<Mesh> MyStripifier;
75 public:
76
78 MeshViewerWidgetT(QWidget* _parent=0)
79 : QGLViewerWidget(_parent),
80 f_strips_(false),
81 tex_id_(0),
82 tex_mode_(GL_MODULATE),
83 strips_(mesh_),
84 use_color_(true),
85 show_vnormals_(false),
86 show_fnormals_(false)
87 {
88 add_draw_mode("Points");
89 add_draw_mode("Hidden-Line");
90 #if defined(OM_USE_OSG) && OM_USE_OSG
91 add_draw_mode("OpenSG Indices");
92 #endif
93 }
94
96 ~MeshViewerWidgetT() {}
97
98 public:
99
101 virtual bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt);
102
104 virtual bool open_texture( const char *_filename );
105 bool set_texture( QImage& _texsrc );
106
107 void enable_strips();
108 void disable_strips();
109
110
111 Mesh& mesh() { return mesh_; }
112 const Mesh& mesh() const { return mesh_; }
113
114 protected:
115
117 virtual void draw_scene(const std::string& _draw_mode);
118
119 protected:
120
122 virtual void draw_openmesh(const std::string& _drawmode);
123
124
125 void glVertex( const typename Mesh::VertexHandle _vh )
126 { glVertex3fv( &mesh_.point( _vh )[0] ); }
127
128 void glVertex( const typename Mesh::Point& _p )
129 { glVertex3fv( &_p[0] ); }
130
131 void glNormal( const typename Mesh::VertexHandle _vh )
132 { glNormal3fv( &mesh_.normal( _vh )[0] ); }
133
134 void glTexCoord( const typename Mesh::VertexHandle _vh )
135 { glTexCoord2fv( &mesh_.texcoord(_vh)[0] ); }
136
137 void glColor( const typename Mesh::VertexHandle _vh )
138 { glColor3ubv( &mesh_.color(_vh)[0] ); }
139
140 // face properties
141
142 void glNormal( const typename Mesh::FaceHandle _fh )
143 { glNormal3fv( &mesh_.normal( _fh )[0] ); }
144
145 void glColor( const typename Mesh::FaceHandle _fh )
146 { glColor3ubv( &mesh_.color(_fh)[0] ); }
147
148 void glMaterial( const typename Mesh::FaceHandle _fh,
149 int _f=GL_FRONT_AND_BACK, int _m=GL_DIFFUSE )
150 {
151 OpenMesh::Vec3f c=OpenMesh::color_cast<OpenMesh::Vec3f>(mesh_.color(_fh));
152 OpenMesh::Vec4f m( c[0], c[1], c[2], 1.0f );
153
154 glMaterialfv(_f, _m, &m[0]);
155 }
156
157
158 protected: // Strip support
159
160 void compute_strips(void)
161 {
162 if (f_strips_)
163 {
164 strips_.clear();
165 strips_.stripify();
166 }
167 }
168
169 protected: // inherited
170
171 virtual void keyPressEvent( QKeyEvent* _event);
172
173 protected:
174
175 bool f_strips_; // enable/disable strip usage
176 GLuint tex_id_;
177 GLint tex_mode_;
178 OpenMesh::IO::Options opt_; // mesh file contained texcoords?
179
180 Mesh mesh_;
181 MyStripifier strips_;
182 bool use_color_;
183 bool show_vnormals_;
184 bool show_fnormals_;
185 float normal_scale_;
186 OpenMesh::FPropHandleT< typename Mesh::Point > fp_normal_base_;
187 };
188
189
190 //=============================================================================
191 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESHAPPS_MESHVIEWERWIDGET_CC)
192 # define OPENMESH_MESHVIEWERWIDGET_TEMPLATES
193 # include "MeshViewerWidgetT.cc"
194 #endif
195 //=============================================================================
196 #endif // OPENMESHAPPS_MESHVIEWERWIDGETT_HH defined
197 //=============================================================================
198
MeshViewerWidgetT::draw_openmesh
virtual void draw_openmesh(const std::string &_drawmode)
draw the mesh
Definition: MeshViewerWidgetT.cc:283
OpenMesh::StripifierT::stripify
size_t stripify()
Compute triangle strips, returns number of strips.
Definition: StripifierT.cc:80
OpenMesh::FPropHandleT< typename Mesh::Point >
MeshViewerWidgetT::open_mesh
virtual bool open_mesh(const char *_filename, OpenMesh::IO::Options _opt)
open mesh
Definition: MeshViewerWidgetT.cc:76
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:88
MeshViewerWidgetT::~MeshViewerWidgetT
~MeshViewerWidgetT()
destructor
Definition: MeshViewerWidgetT.hh:96
OpenMesh::StripifierT::clear
void clear()
delete all strips
Definition: StripifierT.hh:98
MeshViewerWidgetT
Definition: MeshViewerWidgetT.hh:69
MeshViewerWidgetT::draw_scene
virtual void draw_scene(const std::string &_draw_mode)
inherited drawing method
Definition: MeshViewerWidgetT.cc:571
Timer.hh
A timer class.
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
OpenMesh::StripifierT
This class decomposes a triangle mesh into several triangle strips.
Definition: StripifierT.hh:77
Attributes.hh
This file provides some macros containing attribute usage.
MeshViewerWidgetT::MeshViewerWidgetT
MeshViewerWidgetT(QWidget *_parent=0)
default constructor
Definition: MeshViewerWidgetT.hh:78
MeshViewerWidgetT::open_texture
virtual bool open_texture(const char *_filename)
load texture
Definition: MeshViewerWidgetT.cc:205
QGLViewerWidget
Definition: QGLViewerWidget.hh:66