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

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