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 
45 
46 
47 //=============================================================================
48 //
49 // CLASS MeshNodeT
50 //
51 //=============================================================================
52 
53 
54 #ifndef ACG_MESHNODE_HH
55 #define ACG_MESHNODE_HH
56 
57 
58 //== INCLUDES =================================================================
59 
60 
61 
62 #include "BaseNode.hh"
63 #include <vector>
64 #include <ACG/GL/DrawMesh.hh>
65 #include <ACG/ShaderUtils/GLSLShader.hh>
66 
67 //== NAMESPACES ===============================================================
68 
69 
70 namespace ACG {
71 namespace SceneGraph {
72 
73 
74 //== CLASS DEFINITION =========================================================
75 
76 
79 class ACGDLLEXPORT MeshNodeBase : public BaseNode {
80  protected:
81  MeshNodeBase(BaseNode* _parent, std::string _name);
82 
83  void supplyDrawMesh(DrawMeshBase *drawMeshBase);
84 
85  public:
86  void updatePolyEdgeBuf();
87 
88  protected:
89 
90  DrawMeshBase *drawMeshBase_;
91 
92  // poly edge buffer used for wireframe/hiddenline rendering with barycentric interpolation in geometry shader
93  GLuint polyEdgeBuf_;
94 
95  // size in bytes of the poly edge buffer
96  int polyEdgeBufSize_;
97 
98  // texture object for polyEdgeBuf
99  GLuint polyEdgeBufTex_;
100 };
101 
102 
103 
109 template <class Mesh>
110 class MeshNodeT : public MeshNodeBase
111 {
112 public:
113  ACG_CLASSNAME(MeshNode);
114 
119  MeshNodeT( Mesh& _mesh,
120  BaseNode* _parent=0,
121  const std::string& _name="<MeshNode>" );
122 
124  virtual ~MeshNodeT();
125 
126 
132  void update_geometry();
133 
141  void update_topology();
142 
150  void update_color();
151 
156  void update_textures();
157 
158 private:
159 
164  typedef typename Mesh::Point Point;
165  typedef typename Point::value_type PointScalar;
166  typedef typename Mesh::Normal Normal;
167  typedef typename Normal::value_type NormalScalar;
168  typedef typename Mesh::Color Color;
169  typedef typename Color::value_type ColorScalar;
170 
171 //===========================================================================
174 //===========================================================================
175 
176 public:
177 
180  const Mesh& mesh() const { return mesh_; }
181 
182 private:
185 
188 //===========================================================================
191 //===========================================================================
192 private:
193  DrawMeshT<Mesh>* drawMesh_;
194 
199 //===========================================================================
202 //===========================================================================
203 
204 public:
205 
210  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
211 
212 private:
213 
216 
219 
222 //===========================================================================
225 //===========================================================================
226 
227 public:
229  bool normalsEnabled() { return enableNormals_; };
230 
232  void enableNormals(bool _enable) { enableNormals_ = _enable; };
233 
234 private:
235 
237  bool enableNormals_;
238 
241 //===========================================================================
244 //===========================================================================
245 public:
247  bool colorsEnabled() { return enableColors_; };
248 
250  void enableColors(bool _enable) { enableColors_ = _enable; };
251 
252 private:
253 
254  bool enableColors_;
255 
258 //===========================================================================
261 //===========================================================================
262 
263 public:
264 
270  void enable_arrays(unsigned int _arrays);
271 
272 private:
273 
276  {
277  NONE = 0,
278  PER_EDGE_VERTEX_ARRAY = 1,
279  PER_EDGE_COLOR_ARRAY = 2,
280  PER_HALFEDGE_VERTEX_ARRAY = 4,
281  PER_HALFEDGE_COLOR_ARRAY = 8
282  };
283 
285  unsigned int enabled_arrays_;
286 
287 
288 //===========================================================================
291 //===========================================================================
292 
293 public:
297  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
298 
302  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat) override;
303 
304 
307  DrawMeshT<Mesh>* getDrawMesh();
308 
309 
315  ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const override;
316 
317 private:
318 
322  inline void draw_vertices();
323 
324  inline void add_point_RenderObjects(IRenderer* _renderer, const RenderObject* _baseObj);
325 
329  inline void draw_lines();
330 
331  inline void add_line_RenderObjects(IRenderer* _renderer, const RenderObject* _baseObj);
332 
333 
337  inline void draw_halfedges();
338 
339 
343  void draw_faces();
344 
345  void add_face_RenderObjects(IRenderer* _renderer, const RenderObject* _baseObj, bool _nonindexed = false);
346 
347 private:
348 
352 //===========================================================================
355 //===========================================================================
356 public:
360  void pick(GLState& _state, PickTarget _target) override;
361 
364 //===========================================================================
367 //===========================================================================
368 
369 private:
370 
374  void pick_vertices(GLState& _state, bool _front = false);
375 
378 
381 
385 //===========================================================================
388 //===========================================================================
389 
390 
391 private:
395  void pick_edges(GLState& _state, bool _front = false);
396 
399 
402 
403 
406 //===========================================================================
409 //===========================================================================
410 
411 
412 private:
416  void pick_faces(GLState& _state);
417 
420 
423 
424 
427 //===========================================================================
430 //===========================================================================
431 
432 private:
433 
437  void pick_any(GLState& _state);
438 
441 
444 
448 //===========================================================================
451 //===========================================================================
452 public:
465  void setIndexPropertyName( std::string _indexPropertyName );
466 
468  const std::string& indexPropertyName() const;
469 
470 
476  void setHalfedgeTextcoordPropertyName( std::string _halfedgeTextcoordPropertyName );
477 
478  public:
479 
487  void setTextureMap( std::map< int, GLuint>* _map){ textureMap_ = _map; };
488 
489 private:
490 
492  bool perFaceTextureIndexAvailable_;
493 
495  std::map< int, GLuint>* textureMap_;
496 
499 
501 public:
502  void set_property_map( std::map< int, std::string>* _map){ };
503 
504 
507  unsigned int getMemoryUsage();
508 
509 private:
510  bool draw_with_offset_;
511 
512 public:
513  void set_offset(bool enable) { draw_with_offset_ = enable; }
514 };
515 
516 //=============================================================================
517 } // namespace SceneGraph
518 } // namespace ACG
519 //=============================================================================
520 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_MESHNODE_C)
521 #define ACG_MESHNODE_TEMPLATES
522 #include "MeshNode2T_impl.hh"
523 #endif
524 //=============================================================================
525 #endif // ACG_MESHNODE_HH defined
526 //=============================================================================
Kernel::Color Color
Color type.
Definition: PolyMeshT.hh:116
bool updateVertexPicking_
Flag indicating if the vertex picking has to be updated.
Definition: MeshNode2T.hh:377
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
Namespace providing different geometric functions concerning angles.
void set_property_map(std::map< int, std::string > *_map)
Definition: MeshNode2T.hh:502
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
bool updateEdgePicking_
Flag indicating if the edge picking has to be updated.
Definition: MeshNode2T.hh:398
Class to define the vertex input layout.
bool updateFacePicking_
Flag indicating if the edge picking has to be updated.
Definition: MeshNode2T.hh:419
unsigned int enabled_arrays_
which arrays are currently enabled?
Definition: MeshNode2T.hh:285
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
Vec3d bbMin_
bounding box lower left corner
Definition: MeshNode2T.hh:215
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:83
size_t facePickingBaseIndex_
Index of the first face in facepicking.
Definition: MeshNode2T.hh:422
size_t vertexPickingBaseIndex_
Index of the first vertex in vertexpicking.
Definition: MeshNode2T.hh:380
size_t edgePickingBaseIndex_
Index of the first edge in edgepicking.
Definition: MeshNode2T.hh:401
Vec3d bbMax_
bounding box upper right corner
Definition: MeshNode2T.hh:218
bool colorsEnabled()
Returns if the color array is currently activated.
Definition: MeshNode2T.hh:247
std::map< int, GLuint > * textureMap_
Mapping of mesh face texture indices to gltexture id ( has to be provided externally ) ...
Definition: MeshNode2T.hh:495
ArrayType
Enum controlling which array should be used for rendering.
Definition: MeshNode2T.hh:275
Mesh Drawing Class.
Definition: DrawMesh.hh:173
const Mesh & mesh() const
get the internal mesh
Definition: MeshNode2T.hh:180
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:487
bool enableColors_
Returns if the color array is currently activated.
Definition: MeshNode2T.hh:250
bool normalsEnabled()
Returns if the normal array is currently activated.
Definition: MeshNode2T.hh:229
bool updateAnyPicking_
Flag indicating if the any picking has to be updated.
Definition: MeshNode2T.hh:440
VertexDeclaration halfedgeDecl
Draws the object.
Definition: MeshNode2T.hh:349
bool enableNormals_
Flag if normals should be used.
Definition: MeshNode2T.hh:232
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
size_t anyPickingBaseIndex_
Index of the first face in anypicking.
Definition: MeshNode2T.hh:443
Mesh & mesh_
The mesh this node works on.
Definition: MeshNode2T.hh:184