Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MeshNode2T.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS MeshNodeT
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_MESHNODE_HH
61 #define ACG_MESHNODE_HH
62 
63 
64 //== INCLUDES =================================================================
65 
66 
67 
68 #include "BaseNode.hh"
69 #include <vector>
70 #include <ACG/GL/DrawMesh.hh>
71 #include <ACG/ShaderUtils/GLSLShader.hh>
72 
73 //== NAMESPACES ===============================================================
74 
75 
76 namespace ACG {
77 namespace SceneGraph {
78 
79 
80 //== CLASS DEFINITION =========================================================
81 
82 
85 class ACGDLLEXPORT MeshNodeBase : public BaseNode {
86  protected:
87  MeshNodeBase(BaseNode* _parent, std::string _name);
88 
89  void supplyDrawMesh(DrawMeshBase *drawMeshBase);
90 
91  public:
92  void updatePolyEdgeBuf();
93 
94  protected:
95 
96  DrawMeshBase *drawMeshBase_;
97 
98  // poly edge buffer used for wireframe/hiddenline rendering with barycentric interpolation in geometry shader
99  GLuint polyEdgeBuf_;
100 
101  // size in bytes of the poly edge buffer
102  int polyEdgeBufSize_;
103 
104  // texture object for polyEdgeBuf
105  GLuint polyEdgeBufTex_;
106 };
107 
108 
109 
115 template <class Mesh>
116 class MeshNodeT : public MeshNodeBase
117 {
118 public:
119  ACG_CLASSNAME(MeshNode);
120 
125  MeshNodeT(Mesh& _mesh,
126  BaseNode* _parent=0,
127  std::string _name="<MeshNode>" );
128 
130  virtual ~MeshNodeT();
131 
132 
138  void update_geometry();
139 
147  void update_topology();
148 
156  void update_color();
157 
162  void update_textures();
163 
164 private:
165 
170  typedef typename Mesh::Point Point;
171  typedef typename Point::value_type PointScalar;
172  typedef typename Mesh::Normal Normal;
173  typedef typename Normal::value_type NormalScalar;
174  typedef typename Mesh::Color Color;
175  typedef typename Color::value_type ColorScalar;
176 
177 //===========================================================================
180 //===========================================================================
181 
182 public:
183 
186  const Mesh& mesh() const { return mesh_; }
187 
188 private:
191 
194 //===========================================================================
197 //===========================================================================
198 private:
199  DrawMeshT<Mesh>* drawMesh_;
200 
205 //===========================================================================
208 //===========================================================================
209 
210 public:
211 
216  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
217 
218 private:
219 
222 
225 
228 //===========================================================================
231 //===========================================================================
232 
233 public:
235  bool normalsEnabled() { return enableNormals_; };
236 
238  void enableNormals(bool _enable) { enableNormals_ = _enable; };
239 
240 private:
241 
243  bool enableNormals_;
244 
247 //===========================================================================
250 //===========================================================================
251 public:
253  bool colorsEnabled() { return enableColors_; };
254 
256  void enableColors(bool _enable) { enableColors_ = _enable; };
257 
258 private:
259 
260  bool enableColors_;
261 
264 //===========================================================================
267 //===========================================================================
268 
269 public:
270 
276  void enable_arrays(unsigned int _arrays);
277 
278 private:
279 
282  {
283  NONE = 0,
284  PER_EDGE_VERTEX_ARRAY = 1,
285  PER_EDGE_COLOR_ARRAY = 2,
286  PER_HALFEDGE_VERTEX_ARRAY = 4,
287  PER_HALFEDGE_COLOR_ARRAY = 8
288  };
289 
291  unsigned int enabled_arrays_;
292 
293 
294 //===========================================================================
297 //===========================================================================
298 
299 public:
303  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
304 
308  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
309 
310 
314 
315 
322 
323 private:
324 
328  inline void draw_vertices();
329 
330  inline void add_point_RenderObjects(IRenderer* _renderer, const RenderObject* _baseObj);
331 
335  inline void draw_lines();
336 
337  inline void add_line_RenderObjects(IRenderer* _renderer, const RenderObject* _baseObj);
338 
339 
343  inline void draw_halfedges();
344 
345 
349  void draw_faces();
350 
351  void add_face_RenderObjects(IRenderer* _renderer, const RenderObject* _baseObj, bool _nonindexed = false);
352 
353 private:
354 
355 
358 //===========================================================================
361 //===========================================================================
362 public:
366  void pick(GLState& _state, PickTarget _target);
367 
370 //===========================================================================
373 //===========================================================================
374 
375 private:
376 
380  void pick_vertices(GLState& _state, bool _front = false);
381 
384 
387 
391 //===========================================================================
394 //===========================================================================
395 
396 
397 private:
401  void pick_edges(GLState& _state, bool _front = false);
402 
405 
407  unsigned int edgePickingBaseIndex_;
408 
409 
412 //===========================================================================
415 //===========================================================================
416 
417 
418 private:
422  void pick_faces(GLState& _state);
423 
426 
428  unsigned int facePickingBaseIndex_;
429 
430 
433 //===========================================================================
436 //===========================================================================
437 
438 private:
439 
443  void pick_any(GLState& _state);
444 
447 
449  unsigned int anyPickingBaseIndex_;
450 
454 //===========================================================================
457 //===========================================================================
458 public:
471  void setIndexPropertyName( std::string _indexPropertyName );
472 
474  const std::string& indexPropertyName() const;
475 
476 
482  void setHalfedgeTextcoordPropertyName( std::string _halfedgeTextcoordPropertyName );
483 
484  public:
485 
493  void setTextureMap( std::map< int, GLuint>* _map){ textureMap_ = _map; };
494 
495 private:
496 
499 
502 
504  std::map< int, GLuint>* textureMap_;
505 
508 
510 public:
511  void set_property_map( std::map< int, std::string>* _map){ };
512 
513 
516  unsigned int getMemoryUsage();
517 
518 private:
519  bool draw_with_offset_;
520 
521 public:
522  void set_offset(bool enable) { draw_with_offset_ = enable; }
523 };
524 
525 //=============================================================================
526 } // namespace SceneGraph
527 } // namespace ACG
528 //=============================================================================
529 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_MESHNODE_C)
530 #define ACG_MESHNODE_TEMPLATES
531 #include "MeshNode2T.cc"
532 #endif
533 //=============================================================================
534 #endif // ACG_MESHNODE_HH defined
535 //=============================================================================
Mesh Drawing Class.
Definition: DrawMesh.hh:172
void enableColors(bool _enable)
Enable or disable the use of color array.
Definition: MeshNode2T.hh:256
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
Draws the object.
bool colorsEnabled()
Returns if the color array is currently activated.
Definition: MeshNode2T.hh:253
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
DrawMeshT< Mesh > * getDrawMesh()
Get DrawMesh instance.
bool enableNormals_
Flag if normals should be used.
Definition: MeshNode2T.hh:238
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
std::map< int, GLuint > * textureMap_
Mapping of mesh face texture indices to gltexture id ( has to be provided externally ) ...
Definition: MeshNode2T.hh:504
void enableNormals(bool _enable)
Enable or disable the use of the normal array.
Definition: MeshNode2T.hh:238
void pick_any(GLState &_state)
Renders picking for all primitives.
Kernel::Color Color
Color type.
Definition: PolyMeshT.hh:119
Interface class between scenegraph and renderer.
void update_textures()
force an texture update
void draw_halfedges()
draws all halfedges of the mesh
void update_geometry()
the geometry of the mesh has changed
void setIndexPropertyName(std::string _indexPropertyName)
set the name of the property used for texture index specification
const Mesh & mesh() const
get the internal mesh
Definition: MeshNode2T.hh:186
void add_face_RenderObjects(IRenderer *_renderer, const RenderObject *_baseObj, bool _nonindexed=false)
Draws the object.
virtual ~MeshNodeT()
Destructor.
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
bool perFaceTextureCoordsAvailable_
This flag indicates if we have a per Face texture coordinate property.
Definition: MeshNode2T.hh:501
void update_color()
the colors of the mesh have changed
bool updateVertexPicking_
Flag indicating if the vertex picking has to be updated.
Definition: MeshNode2T.hh:383
const std::string & indexPropertyName() const
Get current texture index property name.
void pick_edges(GLState &_state, bool _front=false)
Renders picking for edges _front: Only render front edges (not occluded by geometry) ...
Mesh & mesh_
The mesh this node works on.
Definition: MeshNode2T.hh:190
MeshNodeT(Mesh &_mesh, BaseNode *_parent=0, std::string _name="<MeshNode>")
Default constructor.
void enable_arrays(unsigned int _arrays)
enable/disable vertex arrays according to the bits in _arrays
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const
return available draw modes
void add_line_RenderObjects(IRenderer *_renderer, const RenderObject *_baseObj)
Draws the object.
void update_topology()
the topology of the mesh has changed
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
Current bounding box.
unsigned int facePickingBaseIndex_
Index of the first face in facepicking.
Definition: MeshNode2T.hh:428
unsigned int anyPickingBaseIndex_
Index of the first face in anypicking.
Definition: MeshNode2T.hh:449
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
Draws the object deferred.
void add_point_RenderObjects(IRenderer *_renderer, const RenderObject *_baseObj)
Draws the object.
unsigned int enabled_arrays_
which arrays are currently enabled?
Definition: MeshNode2T.hh:291
void set_property_map(std::map< int, std::string > *_map)
Definition: MeshNode2T.hh:511
bool updateFacePicking_
Flag indicating if the edge picking has to be updated.
Definition: MeshNode2T.hh:425
void draw_faces()
draws all faces of the mesh
void draw_vertices()
draws all vertices of the mesh
void pick_faces(GLState &_state)
Renders picking for faces _front: Only render front faces (not occluded by geometry) ...
Vec3d bbMin_
bounding box lower left corner
Definition: MeshNode2T.hh:221
unsigned int vertexPickingBaseIndex_
Index of the first vertex in vertexpicking.
Definition: MeshNode2T.hh:386
void pick(GLState &_state, PickTarget _target)
Draws the object in picking mode.
void setTextureMap(std::map< int, GLuint > *_map)
Setup a mapping between internal texture ids on the mesh and the ids for the loaded textures in openg...
Definition: MeshNode2T.hh:493
unsigned int getMemoryUsage()
measures the size in bytes of allocated memory
bool enableColors_
Returns if the color array is currently activated.
Definition: MeshNode2T.hh:256
bool normalsEnabled()
Returns if the normal array is currently activated.
Definition: MeshNode2T.hh:235
void draw_lines()
draws all edges of the mesh
void pick_vertices(GLState &_state, bool _front=false)
Renders picking for vertices _front: Only render front vertices (not occluded by geometry) ...
void setHalfedgeTextcoordPropertyName(std::string _halfedgeTextcoordPropertyName)
Set the name of the per face texture coordinate property.
Vec3d bbMax_
bounding box upper right corner
Definition: MeshNode2T.hh:224
ArrayType
Enum controlling which array should be used for rendering.
Definition: MeshNode2T.hh:281
unsigned int edgePickingBaseIndex_
Index of the first edge in edgepicking.
Definition: MeshNode2T.hh:407
bool updateEdgePicking_
Flag indicating if the edge picking has to be updated.
Definition: MeshNode2T.hh:404
bool updateAnyPicking_
Flag indicating if the any picking has to be updated.
Definition: MeshNode2T.hh:446
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:117
bool perFaceTextureIndexAvailable_
This flag indicates if we have a per Face texture index property.
Definition: MeshNode2T.hh:493