00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef OPENMESHAPPS_MESHVIEWERWIDGETT_HH
00044 #define OPENMESHAPPS_MESHVIEWERWIDGETT_HH
00045
00046
00047
00048
00049 #include <string>
00050 #include <OpenMesh/Core/IO/MeshIO.hh>
00051 #include <OpenMesh/Core/IO/Options.hh>
00052 #include <OpenMesh/Core/Utils/GenProg.hh>
00053 #include <OpenMesh/Core/Utils/color_cast.hh>
00054 #include <OpenMesh/Core/Mesh/Attributes.hh>
00055 #include <OpenMesh/Tools/Utils/StripifierT.hh>
00056 #include <OpenMesh/Tools/Utils/Timer.hh>
00057 #include <OpenMesh/Apps/QtViewer/QGLViewerWidget.hh>
00058
00059
00060
00061
00062 class QImage;
00063
00064
00065
00066
00067
00068 template <typename M>
00069 class MeshViewerWidgetT : public QGLViewerWidget
00070 {
00071 public:
00072
00073 typedef M Mesh;
00074 typedef OpenMesh::StripifierT<Mesh> MyStripifier;
00075 public:
00076
00078 MeshViewerWidgetT(QWidget* _parent=0)
00079 : QGLViewerWidget(_parent),
00080 f_strips_(false),
00081 tex_id_(0),
00082 tex_mode_(GL_MODULATE),
00083 strips_(mesh_),
00084 use_color_(true),
00085 show_vnormals_(false),
00086 show_fnormals_(false)
00087 {
00088 add_draw_mode("Points");
00089 add_draw_mode("Hidden-Line");
00090 #if defined(OM_USE_OSG) && OM_USE_OSG
00091 add_draw_mode("OpenSG Indices");
00092 #endif
00093 }
00094
00096 ~MeshViewerWidgetT() {}
00097
00098 public:
00099
00101 virtual bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt);
00102
00104 virtual bool open_texture( const char *_filename );
00105 bool set_texture( QImage& _texsrc );
00106
00107 void enable_strips();
00108 void disable_strips();
00109
00110
00111 Mesh& mesh() { return mesh_; }
00112 const Mesh& mesh() const { return mesh_; }
00113
00114 protected:
00115
00117 virtual void draw_scene(const std::string& _draw_mode);
00118
00119 protected:
00120
00122 virtual void draw_openmesh(const std::string& _drawmode);
00123
00124
00125 void glVertex( const typename Mesh::VertexHandle _vh )
00126 { glVertex3fv( &mesh_.point( _vh )[0] ); }
00127
00128 void glVertex( const typename Mesh::Point& _p )
00129 { glVertex3fv( &_p[0] ); }
00130
00131 void glNormal( const typename Mesh::VertexHandle _vh )
00132 { glNormal3fv( &mesh_.normal( _vh )[0] ); }
00133
00134 void glTexCoord( const typename Mesh::VertexHandle _vh )
00135 { glTexCoord2fv( &mesh_.texcoord(_vh)[0] ); }
00136
00137 void glColor( const typename Mesh::VertexHandle _vh )
00138 { glColor3ubv( &mesh_.color(_vh)[0] ); }
00139
00140
00141
00142 void glNormal( const typename Mesh::FaceHandle _fh )
00143 { glNormal3fv( &mesh_.normal( _fh )[0] ); }
00144
00145 void glColor( const typename Mesh::FaceHandle _fh )
00146 { glColor3ubv( &mesh_.color(_fh)[0] ); }
00147
00148 void glMaterial( const typename Mesh::FaceHandle _fh,
00149 int _f=GL_FRONT_AND_BACK, int _m=GL_DIFFUSE )
00150 {
00151 OpenMesh::Vec3f c=OpenMesh::color_cast<OpenMesh::Vec3f>(mesh_.color(_fh));
00152 OpenMesh::Vec4f m( c[0], c[1], c[2], 1.0f );
00153
00154 glMaterialfv(_f, _m, &m[0]);
00155 }
00156
00157
00158 protected:
00159
00160 void compute_strips(void)
00161 {
00162 if (f_strips_)
00163 {
00164 strips_.clear();
00165 strips_.stripify();
00166 }
00167 }
00168
00169 protected:
00170
00171 virtual void keyPressEvent( QKeyEvent* _event);
00172
00173 protected:
00174
00175 bool f_strips_;
00176 GLuint tex_id_;
00177 GLint tex_mode_;
00178 OpenMesh::IO::Options opt_;
00179
00180 Mesh mesh_;
00181 MyStripifier strips_;
00182 bool use_color_;
00183 bool show_vnormals_;
00184 bool show_fnormals_;
00185 float normal_scale_;
00186 OpenMesh::FPropHandleT< typename Mesh::Point > fp_normal_base_;
00187 };
00188
00189
00190
00191 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESHAPPS_MESHVIEWERWIDGET_CC)
00192 # define OPENMESH_MESHVIEWERWIDGET_TEMPLATES
00193 # include "MeshViewerWidgetT.cc"
00194 #endif
00195
00196 #endif // OPENMESHAPPS_MESHVIEWERWIDGETT_HH defined
00197
00198