ManifoldMusic
music visualization
 All Classes Files Functions Variables Enumerations Enumerator
MeshViewerWidgetT.h
Go to the documentation of this file.
1 
6 #ifndef OPENMESHAPPS_MESHVIEWERWIDGETT_HH
7 #define OPENMESHAPPS_MESHVIEWERWIDGETT_HH
8 
9 
10 //== INCLUDES =================================================================
11 
12 #include <string>
13 #include <OpenMesh/Core/IO/MeshIO.hh>
14 #include <OpenMesh/Core/IO/Options.hh>
15 #include <OpenMesh/Core/Utils/GenProg.hh>
16 #include <OpenMesh/Core/Utils/color_cast.hh>
17 #include <OpenMesh/Core/Mesh/Attributes.hh>
18 #include <OpenMesh/Tools/Utils/StripifierT.hh>
19 #include <OpenMesh/Tools/Utils/Timer.hh>
20 #include <QMessageBox>
21 
22 #include "QGLViewerWidget.h"
23 #include "MHMesh.h"
24 #include "audio.h"
25 #include "config.h"
26 #include <time.h>
27 
28 
29 //== FORWARDS =================================================================
30 
31 class QImage;
32 
33 
34 
40  OK,
45 };
46 
47 
48 //== CLASS DEFINITION =========================================================
49 
53 template <typename M>
55 {
56 public:
57 
58  typedef M Mesh;
59  typedef OpenMesh::StripifierT<Mesh> MyStripifier;
60 public:
61 
63  MeshViewerWidgetT(QWidget* _parent=0)
64  : QGLViewerWidget(_parent),
65  f_strips_(false),
66  tex_id_(0),
67  tex_mode_(GL_MODULATE),
68  strips_(mesh_),
69  use_color_(true),
70  show_vnormals_(false),
71  show_fnormals_(false)
72  {
73  add_draw_mode("Points");
74  add_draw_mode("Hidden-Line");
75 #if defined(OM_USE_OSG) && OM_USE_OSG
76  add_draw_mode("OpenSG Indices");
77 #endif
78  }
79 
82 
83 public:
84 
86  virtual LoadMeshErr open_mesh(const char* _filename, OpenMesh::IO::Options _opt);
88  virtual bool open_audio( const char *_filename );
90  virtual void change_color(float r, float g, float b);
91 
92  void enable_strips();
93  void disable_strips();
94 
95 
96  Mesh& mesh() { return mesh_; }
97  const Mesh& mesh() const { return mesh_; }
98 
99 protected:
100 
102  virtual void draw_scene(const std::string& _draw_mode);
103 
104 protected:
105 
107  virtual void draw_openmesh(const std::string& _drawmode);
108 
109 
110  void glVertex( const typename Mesh::VertexHandle _vh )
111  { glVertex3fv( &mesh_.point( _vh )[0] ); }
112 
113  void glVertex( const typename Mesh::Point& _p )
114  { glVertex3fv( &_p[0] ); }
115 
116  void glNormal( const typename Mesh::VertexHandle _vh )
117  { glNormal3fv( &mesh_.normal( _vh )[0] ); }
118 
119  void glTexCoord( const typename Mesh::VertexHandle _vh )
120  { glTexCoord2fv( &mesh_.texcoord(_vh)[0] ); }
121 
122  void glColor( const typename Mesh::VertexHandle _vh )
123  { glColor3ubv( &mesh_.color(_vh)[0] ); }
124 
125  // face properties
126 
127  void glNormal( const typename Mesh::FaceHandle _fh )
128  { glNormal3fv( &mesh_.normal( _fh )[0] ); }
129 
130  void glColor( const typename Mesh::FaceHandle _fh )
131  { glColor3ubv( &mesh_.color(_fh)[0] ); }
132 
133  void glMaterial( const typename Mesh::FaceHandle _fh,
134  int _f=GL_FRONT_AND_BACK, int _m=GL_DIFFUSE )
135  {
136  OpenMesh::Vec3f c=OpenMesh::color_cast<OpenMesh::Vec3f>(mesh_.color(_fh));
137  OpenMesh::Vec4f m( c[0], c[1], c[2], 1.0f );
138 
139  glMaterialfv(_f, _m, &m[0]);
140  }
141 
142 
143 protected: // Strip support
144 
145  void compute_strips(void)
146  {
147  if (f_strips_)
148  {
149  strips_.clear();
150  strips_.stripify();
151  }
152  }
153 
154 protected: // inherited
155 
156  virtual void keyPressEvent( QKeyEvent* _event);
157 
158 protected:
159 
160  bool f_strips_; // enable/disable strip usage
161  GLuint tex_id_;
162  GLint tex_mode_;
163  OpenMesh::IO::Options opt_; // mesh file contained texcoords?
164 
165  Mesh mesh_;
166  MyStripifier strips_;
167  bool use_color_;
168  bool show_vnormals_;
169  bool show_fnormals_;
170  float normal_scale_;
171  OpenMesh::FPropHandleT< typename Mesh::Point > fp_normal_base_;
172 
173 
174  //---------our stuff----------
177  Mesh testMesh;
178  clock_t t;
179 };
180 
181 
182 //=============================================================================
183 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESHAPPS_MESHVIEWERWIDGET_CC)
184 # define OPENMESH_MESHVIEWERWIDGET_TEMPLATES
185 # include "MeshViewerWidgetT.cpp"
186 #endif
187 //=============================================================================
188 #endif // OPENMESHAPPS_MESHVIEWERWIDGETT_HH defined
189 //=============================================================================
190