OpenMesh
OpenMesh/Apps/Unsupported/Streaming-qt4/Client/MeshViewerWidgetT.hh
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 362 $                                                         *
00038  *   $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00042 
00043 #ifndef OPENMESHAPPS_MESHVIEWERWIDGETT_HH
00044 #define OPENMESHAPPS_MESHVIEWERWIDGETT_HH
00045 
00046 
00047 //== INCLUDES =================================================================
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/Mesh/Attributes.hh>
00054 #include <OpenMesh/Tools/Utils/StripifierT.hh>
00055 #include <OpenMesh/Tools/Utils/Timer.hh>
00056 #include <OpenMesh/Apps/VDProgMesh/Streaming/Client/QGLViewerWidget.hh>
00057 
00058 
00059 //== FORWARDS =================================================================
00060 
00061 class QImage;
00062 
00063 
00064 //== CLASS DEFINITION =========================================================
00065 
00066               
00067 template <typename M>
00068 class MeshViewerWidgetT : public QGLViewerWidget
00069 {
00070 public:
00071   typedef M                  Mesh;
00072   typedef OpenMesh::StripifierT<Mesh>   MyStripifier;
00073 
00074 
00076   MeshViewerWidgetT(QWidget* _parent=0, const char* _name=0)
00077     : QGLViewerWidget(_parent, _name),
00078       f_strips_(false), 
00079       tex_id_(0),
00080       tex_mode_(GL_MODULATE),
00081       strips_(mesh_)
00082   {
00083     add_draw_mode("Points");
00084     add_draw_mode("Hidden-Line");
00085 #if defined(OM_USE_OSG) && OM_USE_OSG
00086     add_draw_mode("OpenSG Indices");
00087 #endif
00088   }
00089   
00090   void enable_strips() { 
00091     f_strips_ = true;  
00092     add_draw_mode("Strips'n VertexArrays");
00093     add_draw_mode("Show Strips");    
00094   }
00095   void disable_strips() { f_strips_ = false; }
00096   
00098   ~MeshViewerWidgetT() {}
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   
00108   Mesh& mesh() { return mesh_; }
00109   const Mesh& mesh() const { return mesh_; }
00110   
00111   
00112 protected:
00113   
00115   virtual void draw_scene(const std::string& _draw_mode);
00116   
00117 protected:
00118   
00120   virtual void draw_openmesh(const std::string& _drawmode);
00121   
00122   void glVertex( const typename Mesh::VertexHandle vh )
00123   { glVertex3fv( &mesh_.point( vh )[0] ); }
00124   
00125   void glNormal( const typename Mesh::VertexHandle vh )
00126   { glNormal3fv( &mesh_.normal( vh )[0] ); }
00127 
00128   void glTexCoord( const typename Mesh::VertexHandle vh )
00129   { glTexCoord2fv( &mesh_.texcoord(vh)[0] ); }
00130   
00131   void glColor( const typename Mesh::VertexHandle vh )
00132   { glColor3ubv( &mesh_.color(vh)[0] ); }
00133 
00134   void glColor( const typename Mesh::FaceHandle fh )
00135   { glColor3ubv( &mesh_.color(fh)[0] ); }
00136   
00137 
00138   
00139 protected: // Strip support
00140   
00141   void compute_strips(void)
00142   {
00143     if (f_strips_)
00144     {
00145       strips_.clear();
00146       strips_.stripify();
00147     }
00148   }    
00149 
00150 protected: // inherited
00151    
00152   virtual void keyPressEvent( QKeyEvent* _event);
00153 
00154 protected:
00155    
00156   bool                   f_strips_; // enable/disable strip usage
00157   GLuint                 tex_id_;
00158   GLint                  tex_mode_;
00159   OpenMesh::IO::Options  opt_; // mesh file contained texcoords?
00160 
00161   Mesh                   mesh_;
00162   MyStripifier           strips_;
00163 };
00164 
00165 
00166 //=============================================================================
00167 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESHAPPS_MESHVIEWERWIDGET_CC)
00168 #  define OPENMESH_MESHVIEWERWIDGET_TEMPLATES
00169 #  include "MeshViewerWidgetT.cc"
00170 #endif
00171 //=============================================================================
00172 #endif // OPENMESHAPPS_MESHVIEWERWIDGETT_HH defined
00173 //=============================================================================
00174