MeshNodeT.hh
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
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef ACG_MESHNODE_HH
00053 #define ACG_MESHNODE_HH
00054
00055
00056
00057 #include "BaseNode.hh"
00058 #include <vector>
00059 #include <string>
00060 #include "../ShaderUtils/GLSLShader.hh"
00061
00062
00063
00064
00065
00066 namespace ACG {
00067 namespace SceneGraph {
00068
00069
00070
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
00161 enum FaceMode { FACE_NORMALS, FACE_COLORS, PER_VERTEX, FACE_NORMALS_COLORS, FACE_HALFEDGE_TEXTURED };
00162
00163
00164 void draw_vertices();
00165
00166 virtual void draw_faces(FaceMode _mode);
00167
00168
00169 void pick_vertices(GLState& _state, bool _front = false);
00170
00171 void pick_faces(GLState& _state);
00172
00173 void pick_edges(GLState& _state, bool _front = false);
00174
00175 void pick_any(GLState& _state);
00176
00177
00178 void update_pick_buffers ();
00179
00180
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
00193 void enable_arrays(unsigned int _arrays);
00194
00195
00196
00197 protected:
00198
00199
00200 const Mesh& mesh_;
00201
00202
00203 unsigned int enabled_arrays_;
00204
00205
00206 unsigned int face_index_buffer_, vertex_buffer_, normal_buffer_;
00207
00208
00209 std::vector<unsigned int> indices_;
00210
00211 private:
00212
00213 bool vertexBufferInitialized_;
00214 bool normalBufferInitialized_;
00215 bool faceIndexBufferInitialized_;
00216
00217
00218 std::vector< ACG::Vec3f > vertices_;
00219
00220
00221 std::vector< ACG::Vec3f > normals_;
00222
00223
00224 std::map< int, GLuint>* textureMap_;
00225
00226
00227 std::map< int, std::string>* propertyMap_;
00228
00229
00230 std::string default_halfedge_textcoord_property_;
00231
00232
00233 std::string indexPropertyName_;
00234
00235
00236 GLuint faceList_;
00237 GLuint vertexList_;
00238 GLuint edgeList_;
00239 GLuint anyList_;
00240
00241
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
00252 std::vector< ACG::Vec3f > pickVertexBuf_;
00253 std::vector< ACG::Vec4uc > pickColorBuf_;
00254
00255
00256 Vec3d bbMin_;
00257 Vec3d bbMax_;
00258 };
00259
00260
00261
00262 }
00263 }
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