Developer Documentation
StatusNodesT.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 // Status Nodes
50 //
51 //=============================================================================
52 
53 
54 #ifndef ACG_STATUS_NODES_HH
55 #define ACG_STATUS_NODES_HH
56 
57 
58 //== INCLUDES =================================================================
59 
60 
62 
63 #include "MaterialNode.hh"
64 #include "DrawModes.hh"
65 
66 #include <ACG/GL/VertexDeclaration.hh>
67 #include <ACG/GL/IRenderer.hh>
68 #include <ACG/GL/DrawMesh.hh>
69 
70 #include <vector>
71 
72 
73 //== NAMESPACES ===============================================================
74 
75 
76 template<class Mod>
78  public:
79  enum {
80  StaticUsage = true
81  };
82 };
83 
84 namespace ACG {
85 namespace SceneGraph {
86 
87 
88 //== CLASS DEFINITION =========================================================
89 
96 class ACGDLLEXPORT StatusNodesBase
97 {
98 public:
100  virtual ~StatusNodesBase();
101 
102 protected:
103  //index buffer objects ,previously direct ram access was used in compat
104  //now use ibos / vbos on both compat and core profile.
105  GLuint heVBO_, eIBO_, fIBO_, vIBO_, pIBO_;
106 
107  void updateIBOData(GLuint& bufferName_, size_t numberOfElements_, size_t sizeOfElements_, void* data_);
108  void updateHEVBOPoints(size_t numberOfElements_, size_t sizeOfElements_, void* data_);
109 
110 private:
111  GLint prevBuffer;
112  void createHEVBO();
113  void createIBO(GLuint& _name);
114  void bindHEVBO();
115  void unbindHEVBO();
116  void bindIBO(GLuint& _name);
117  void unbindIBO();
118 };
119 
120 template<class Mesh, class Mod, const bool StaticUsage> class StatusNodeBaseT;
121 
122 template<class Mesh, class Mod>
123 
124 class StatusNodeBaseT<Mesh, Mod, true> : public MaterialNode {
125  public:
126  StatusNodeBaseT(BaseNode* _parent, const std::string& _name) :
127  MaterialNode(_parent, _name) {}
128 
129  virtual ~StatusNodeBaseT() {}
130 
131  protected:
132  bool is_vertex_selected(
133  const Mesh &mesh, typename Mesh::VertexHandle vh) {
134  return Mod::is_vertex_selected(mesh, vh);
135  }
136 
137  bool is_halfedge_selected(
138  const Mesh &mesh, typename Mesh::HalfedgeHandle heh) {
139  return Mod::is_halfedge_selected(mesh, heh);
140  }
141 
142  bool is_edge_selected(const Mesh &mesh, typename Mesh::EdgeHandle eh) {
143  return Mod::is_edge_selected(mesh, eh);
144  }
145 
146  bool is_face_selected(const Mesh &mesh, typename Mesh::FaceHandle fh) {
147  return Mod::is_face_selected(mesh, fh);
148  }
149 };
150 
151 template<class Mesh, class Mod>
152 class StatusNodeBaseT<Mesh, Mod, false> : public MaterialNode {
153 
154  public:
155  StatusNodeBaseT(BaseNode* _parent, const std::string& _name) :
156  MaterialNode(_parent, _name), modInstance(0) {}
157 
158  virtual ~StatusNodeBaseT() {
159  delete modInstance;
160  }
161 
168  void provideModInstance(Mod *mod) {
169  delete modInstance;
170  modInstance = mod;
171  }
172 
173  protected:
174  bool is_vertex_selected(
175  const Mesh &mesh, typename Mesh::VertexHandle vh) {
176  assert(modInstance);
177  return modInstance->is_vertex_selected(mesh, vh);
178  }
179 
180  bool is_halfedge_selected(
181  const Mesh &mesh, typename Mesh::HalfedgeHandle heh) {
182  assert(modInstance);
183  return modInstance->is_halfedge_selected(mesh, heh);
184  }
185 
186  bool is_edge_selected(const Mesh &mesh, typename Mesh::EdgeHandle eh) {
187  assert(modInstance);
188  return modInstance->is_edge_selected(mesh, eh);
189  }
190 
191  bool is_face_selected(const Mesh &mesh, typename Mesh::FaceHandle fh) {
192  assert(modInstance);
193  return modInstance->is_face_selected(mesh, fh);
194  }
195 
196  protected:
197  Mod *modInstance;
198 };
199 
200 
206 template <class Mesh, class Mod>
207 class StatusNodeT :
208  public StatusNodeBaseT<Mesh, Mod, ::StatusNodes_ModTraits<Mod>::StaticUsage>,
210 {
211 public:
213  typedef Mod ModType;
214 
216  StatusNodeT( const Mesh& _mesh,
217  BaseNode* _parent = 0,
218  const std::string& _name = "<StatusNode>" );
219 
221  virtual ~StatusNodeT() {}
222 
223  ACG_CLASSNAME(StatusNode);
224 
225 
228  void updateGeometry();
229 
232  void updateTopology();
233 
236  void updateSelection();
237 
244  void setDrawMesh(DrawMeshT<Mesh>* _drawmesh);
245 
246 
253  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const class Material* _mat) override;
254 
255 
256  DrawModes::DrawMode availableDrawModes() const override;
257  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
258  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
259  void pick(GLState& /* _state */ , PickTarget /* _target */ ) override {}
260 
261 
262 private:
263 
267  void update_cache();
268 
269  typedef typename Mesh::Face Face;
270  typedef typename Mesh::Vertex Vertex;
271  typedef typename Mesh::Halfedge Halfedge;
272  typedef typename Mesh::Edge Edge;
273  typedef typename Mesh::FaceHandle FaceHandle;
274  typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
275 
276  typedef typename Mesh::Point Point;
277  typedef typename Mesh::Normal Normal;
278 
279  void draw_points();
280  void draw_edges();
281  void draw_halfedges();
282  void draw_faces(bool _per_vertex);
283 
284  Point halfedge_point(const HalfedgeHandle _heh);
285 
286 
287 private:
288 
289  const Mesh& mesh_;
290  DrawMeshT<Mesh>* drawMesh_;
291 
292  //indices used for indexed rendering
293  std::vector<unsigned int> v_cache_, e_cache_, f_cache_, poly_cache_;
294  std::vector<FaceHandle> fh_cache_;
295 
296  //halfedges are rendered directly from ram in compat profile
297  std::vector<Point> he_points_;
298  std::vector<Normal> he_normals_;
299 
300  // bounding box
301  Vec3d bbMin_;
302  Vec3d bbMax_;
303 
306 
307  bool vertexIndexInvalid_;
308  bool halfedgeCacheInvalid_;
309  bool edgeIndexInvalid_;
310  bool faceIndexInvalid_;
311 
312 
313  // vertex-formats for new renderer
314  VertexDeclaration pointVertexDecl_;
315  VertexDeclaration halfedgeVertexDecl_;
316 };
317 
318 
319 
320 //== CLASS DEFINITION =========================================================
321 
322 
323 template <class Mesh, unsigned int Bit>
325 {
326  static bool is_vertex_selected(const Mesh& _mesh,
327  typename Mesh::VertexHandle _vh)
328  {
329  return _mesh.status(_vh).is_bit_set(Bit);
330  }
331 
332  static bool is_edge_selected(const Mesh& _mesh,
333  typename Mesh::EdgeHandle _eh)
334  {
335  return _mesh.status(_eh).is_bit_set(Bit);
336  }
337 
338  static bool is_halfedge_selected(const Mesh& _mesh,
339  typename Mesh::HalfedgeHandle _heh)
340  {
341  return _mesh.status(_heh).is_bit_set(Bit);
342  }
343 
344  static bool is_face_selected(const Mesh& _mesh,
345  typename Mesh::FaceHandle _fh)
346  {
347  return _mesh.status(_fh).is_bit_set(Bit);
348  }
349 };
350 
351 
352 
353 //== CLASS DEFINITION =========================================================
354 
355 
356 template <class Mesh>
358  : public StatusModT<Mesh, OpenMesh::Attributes::SELECTED>
359 {};
360 
361 
362 
368 template <class Mesh>
370  : virtual public StatusNodeT<Mesh, SelectionModT<Mesh> >
371 {
372 public:
373 
379  SelectionNodeT( const Mesh& _mesh,
380  BaseNode* _parent = 0,
381  const std::string& _name = "<SelectionNode>" )
382  : StatusNodeT<Mesh, SelectionModT<Mesh> > (_mesh, _parent, _name)
383  {}
384 };
385 
386 
387 //== CLASS DEFINITION =========================================================
388 
389 
390 template <class Mesh>
391 struct LockModT
392  : public StatusModT<Mesh, OpenMesh::Attributes::LOCKED>
393 {};
394 
395 
396 template <class Mesh>
397 class LockNodeT : public StatusNodeT<Mesh, LockModT<Mesh> >
398 {
399 public:
400 
401  LockNodeT( const Mesh& _mesh,
402  BaseNode* _parent = 0,
403  const std::string& _name = "<LockNode>" )
404  : StatusNodeT<Mesh, LockModT<Mesh> > (_mesh, _parent, _name)
405  {}
406 };
407 
408 
409 //=============================================================================
410 } // namespace SceneGraph
411 } // namespace ACG
412 //=============================================================================
413 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_STATUS_NODES_C)
414 #define ACG_STATUS_NODES_TEMPLATES
415 #include "StatusNodesT_impl.hh"
416 #endif
417 //=============================================================================
418 #endif // ACG_STATUS_NODES_HH defined
419 //=============================================================================
420 
Kernel::Edge Edge
Edge type.
Definition: PolyMeshT.hh:128
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
Kernel::Vertex Vertex
Vertex type.
Definition: PolyMeshT.hh:124
Namespace providing different geometric functions concerning angles.
bool invalidGeometry_
State variables.
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
Class to define the vertex input layout.
The StatusNodesBase class extends StatusNodesT with a halfEdge vbo for coreProfile rendering support...
Definition: StatusNodesT.hh:96
Kernel::Face Face
Face type.
Definition: PolyMeshT.hh:130
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
virtual ~StatusNodeT()
destructor
SelectionNodeT(const Mesh &_mesh, BaseNode *_parent=0, const std::string &_name="<SelectionNode>")
Constructor.
Mesh Drawing Class.
Definition: DrawMesh.hh:171
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
Kernel::Halfedge Halfedge
Halfedge type.
Definition: PolyMeshT.hh:126
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136