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

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