MeshNodeT.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper 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  *  OpenFlipper 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 OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8548 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-12 14:40:13 +0100 (Fr, 12. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS MeshNodeT
00049 //
00050 //=============================================================================
00051 
00052 #ifndef ACG_MESHNODE_HH
00053 #define ACG_MESHNODE_HH
00054 
00055 //== INCLUDES =================================================================
00056 
00057 #include "BaseNode.hh"
00058 #include <vector>
00059 #include <string>
00060 #include "../ShaderUtils/GLSLShader.hh"
00061 
00062 
00063 //== NAMESPACES ===============================================================
00064 
00065 
00066 namespace ACG {
00067 namespace SceneGraph {
00068 
00069 
00070 //== CLASS DEFINITION =========================================================
00071 
00072 
00084 template <class Mesh>
00085 class MeshNodeT : public BaseNode
00086 {
00087 
00088 public:
00089 
00093   MeshNodeT(const Mesh&  _mesh,
00094             BaseNode*    _parent=0,
00095             std::string  _name="<MeshNode>");
00096 
00098   virtual ~MeshNodeT();
00099 
00100 
00101   ACG_CLASSNAME(MeshNode);
00102 
00103 
00105   DrawModes::DrawMode  availableDrawModes() const;
00107   void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
00109   void draw(GLState& _state, DrawModes::DrawMode _drawMode);
00111   void pick(GLState& _state, PickTarget _target);
00112 
00113 
00115   const Mesh& mesh() const { return mesh_; }
00116 
00117 
00119   void update_geometry();
00122   virtual void update_topology();
00123 
00131   void setTextureMap( std::map< int, GLuint>* _map){ textureMap_ = _map; };
00132 
00138   void set_property_map( std::map< int, std::string>* _map){ propertyMap_ = _map; };
00139 
00145   void setHalfedgeTextcoordPropertyName( std::string _default_halfedge_textcoord_property )
00146     { default_halfedge_textcoord_property_ = _default_halfedge_textcoord_property; };
00147 
00155   void setIndexPropertyName( std::string _index_property_name) { indexPropertyName_ = _index_property_name; };
00156 
00157 protected:
00158 
00159 
00160   // types
00161   enum FaceMode { FACE_NORMALS, FACE_COLORS, PER_VERTEX, FACE_NORMALS_COLORS, FACE_HALFEDGE_TEXTURED };
00162 
00163   // draw vertices
00164   void draw_vertices();
00165   // draw polygons. to be overridden by TriStripNodeT
00166   virtual void draw_faces(FaceMode _mode);
00167 
00168   // pick vertices
00169   void pick_vertices(GLState& _state, bool _front = false);
00170   // pick polygons. to be overridden by TriMeshNodeT
00171   void pick_faces(GLState& _state);
00172   // pick edges
00173   void pick_edges(GLState& _state, bool _front = false);
00174   // pick anything
00175   void pick_any(GLState& _state);
00176 
00177   // update pick buffer sizes
00178   void update_pick_buffers ();
00179 
00180   // opengl vertex array stuff
00181   enum ArrayType
00182   {
00183     NONE                    = 0,
00184     VERTEX_ARRAY            = 1,
00185     NORMAL_ARRAY            = 2,
00186     COLOR_ARRAY             = 4,
00187     TEXTURE_COORD_1D_ARRAY  = 8,
00188     TEXTURE_COORD_2D_ARRAY  = 16,
00189     TEXTURE_COORD_3D_ARRAY  = 32
00190   };
00191 
00192   // enable/disable vertex arrays according to the bits in _arrays
00193   void enable_arrays(unsigned int _arrays);
00194 
00195 
00196 
00197 protected:
00198 
00199   // mesh reference
00200   const Mesh&  mesh_;
00201 
00202   // which arrays are currently enabled?
00203   unsigned int enabled_arrays_;
00204 
00205   // vertex buffer objects
00206   unsigned int  face_index_buffer_, vertex_buffer_, normal_buffer_;
00207 
00208   // index list for fast rendering (will be accessed by TriStripNodeT
00209   std::vector<unsigned int>  indices_;
00210 
00211 private:
00212 
00213   bool vertexBufferInitialized_;
00214   bool normalBufferInitialized_;
00215   bool faceIndexBufferInitialized_;
00216 
00217   // Internal buffer used when rendering non float vertex coordinates
00218   std::vector< ACG::Vec3f > vertices_;
00219 
00220   // Internal buffer used when rendering non float normals
00221   std::vector< ACG::Vec3f > normals_;
00222 
00223   // Mapping of mesh face texture indices to gltexture id ( has to be provided externally )
00224   std::map< int, GLuint>* textureMap_;
00225 
00226   // Mapping of mesh face texture indices to coordinate property names ( has to be provided externally )
00227   std::map< int, std::string>* propertyMap_;
00228 
00229   // Property name of the per face texture coordinates
00230   std::string default_halfedge_textcoord_property_;
00231 
00232   // Property name of the per face texture index.
00233   std::string indexPropertyName_;
00234 
00235   // display Lists used for picking
00236   GLuint faceList_;
00237   GLuint vertexList_;
00238   GLuint edgeList_;
00239   GLuint anyList_;
00240 
00241   // do we need to update our display lists?
00242   bool updateFaceList_;
00243   bool updateVertexList_;
00244   bool updateEdgeList_;
00245   bool updateAnyList_;
00246   unsigned int faceBaseIndex_;
00247   unsigned int vertexBaseIndex_;
00248   unsigned int edgeBaseIndex_;
00249   unsigned int anyBaseIndex_;
00250 
00251   // buffers for draw arrays during picking
00252   std::vector< ACG::Vec3f > pickVertexBuf_;
00253   std::vector< ACG::Vec4uc > pickColorBuf_;
00254 
00255   // bounding box
00256   Vec3d bbMin_;
00257   Vec3d bbMax_;
00258 };
00259 
00260 
00261 //=============================================================================
00262 } // namespace SceneGraph
00263 } // namespace ACG
00264 //=============================================================================
00265 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_MESHNODE_C)
00266 #define ACG_MESHNODE_TEMPLATES
00267 #include "MeshNodeT.cc"
00268 #endif
00269 //=============================================================================
00270 #endif // ACG_MESHNODE_HH defined
00271 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .