Developer Documentation
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 
313  DrawMeshT<Mesh>* getDrawMesh();
314 
315 
321  ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const;
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 
498  bool perFaceTextureIndexAvailable_;
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 //=============================================================================
bool enableColors_
Returns if the color array is currently activated.
Definition: MeshNode2T.hh:256
unsigned int facePickingBaseIndex_
Index of the first face in facepicking.
Definition: MeshNode2T.hh:428
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
bool enableNormals_
Flag if normals should be used.
Definition: MeshNode2T.hh:238
bool colorsEnabled()
Returns if the color array is currently activated.
Definition: MeshNode2T.hh:253
unsigned int vertexPickingBaseIndex_
Index of the first vertex in vertexpicking.
Definition: MeshNode2T.hh:386
bool updateVertexPicking_
Flag indicating if the vertex picking has to be updated.
Definition: MeshNode2T.hh:383
Vec3d bbMin_
bounding box lower left corner
Definition: MeshNode2T.hh:221
bool perFaceTextureCoordsAvailable_
This flag indicates if we have a per Face texture coordinate property.
Definition: MeshNode2T.hh:501
Kernel::Color Color
Color type.
Definition: PolyMeshT.hh:119
bool updateEdgePicking_
Flag indicating if the edge picking has to be updated.
Definition: MeshNode2T.hh:404
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:117
bool updateAnyPicking_
Flag indicating if the any picking has to be updated.
Definition: MeshNode2T.hh:446
unsigned int edgePickingBaseIndex_
Index of the first edge in edgepicking.
Definition: MeshNode2T.hh:407
unsigned int enabled_arrays_
which arrays are currently enabled?
Definition: MeshNode2T.hh:291
Vec3d bbMax_
bounding box upper right corner
Definition: MeshNode2T.hh:224
bool normalsEnabled()
Returns if the normal array is currently activated.
Definition: MeshNode2T.hh:235
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
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
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
Mesh & mesh_
The mesh this node works on.
Definition: MeshNode2T.hh:190
unsigned int anyPickingBaseIndex_
Index of the first face in anypicking.
Definition: MeshNode2T.hh:449
Mesh Drawing Class.
Definition: DrawMesh.hh:172
ArrayType
Enum controlling which array should be used for rendering.
Definition: MeshNode2T.hh:281
void set_property_map(std::map< int, std::string > *_map)
Definition: MeshNode2T.hh:511
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
std::map< int, GLuint > * textureMap_
Mapping of mesh face texture indices to gltexture id ( has to be provided externally ) ...
Definition: MeshNode2T.hh:504
bool updateFacePicking_
Flag indicating if the edge picking has to be updated.
Definition: MeshNode2T.hh:425
Interface class between scenegraph and renderer.
const Mesh & mesh() const
get the internal mesh
Definition: MeshNode2T.hh:186