OpenMesh
Loading...
Searching...
No Matches
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>
62#include <OpenMesh/Tools/Utils/StripifierT.hh>
64#include <OpenMesh/Apps/QtViewer/QGLViewerWidget.hh>
65
66
67//== FORWARDS =================================================================
68
69class QImage;
70
71
72//== CLASS DEFINITION =========================================================
73
74
75template <typename M>
77{
78public:
79
80 typedef M Mesh;
82public:
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
104
105public:
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
121protected:
122
124 virtual void draw_scene(const std::string& _draw_mode);
125
126protected:
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
165protected: // Strip support
166
167 void compute_strips(void)
168 {
169 if (f_strips_)
170 {
171 strips_.clear();
172 strips_.stripify();
173 }
174 }
175
176protected: // inherited
177
178 virtual void keyPressEvent( QKeyEvent* _event);
179
180protected:
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_;
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
A timer class.
This file provides some macros containing attribute usage.
Definition MeshViewerWidgetT.hh:77
MeshViewerWidgetT(QWidget *_parent=0)
default constructor
Definition MeshViewerWidgetT.hh:85
virtual bool open_texture(const char *_filename)
load texture
Definition MeshViewerWidgetT.cc:212
virtual bool open_mesh(const char *_filename, OpenMesh::IO::Options _opt)
open mesh
Definition MeshViewerWidgetT.cc:83
virtual void draw_openmesh(const std::string &_drawmode)
draw the mesh
Definition MeshViewerWidgetT.cc:290
virtual void draw_scene(const std::string &_draw_mode)
inherited drawing method
Definition MeshViewerWidgetT.cc:578
~MeshViewerWidgetT()
destructor
Definition MeshViewerWidgetT.hh:103
Definition QGLViewerWidget.hh:74
QAction * add_draw_mode(const std::string &_s)
add draw mode to popup menu, and return the QAction created
Definition QGLViewerWidget.cc:642
Set options for reader/writer modules.
Definition Options.hh:96
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition PolyMeshT.hh:139
Kernel::Point Point
Coordinate type.
Definition PolyMeshT.hh:115
Kernel::FaceHandle FaceHandle
Scalar type.
Definition PolyMeshT.hh:142
This class decomposes a triangle mesh into several triangle strips.
Definition StripifierT.hh:85
void clear()
delete all strips
Definition StripifierT.hh:105
size_t stripify()
Compute triangle strips, returns number of strips.
Definition StripifierT.cc:87

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .