OpenMesh: OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh Source File

| OpenMesh

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