Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // Status Nodes
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_STATUS_NODES_HH
61 #define ACG_STATUS_NODES_HH
62 
63 
64 //== INCLUDES =================================================================
65 
66 
68 
69 #include "MaterialNode.hh"
70 #include "DrawModes.hh"
71 
72 #include <ACG/GL/VertexDeclaration.hh>
73 #include <ACG/GL/IRenderer.hh>
74 #include <ACG/GL/DrawMesh.hh>
75 
76 #include <vector>
77 
78 
79 //== NAMESPACES ===============================================================
80 
81 
82 template<class Mod>
84  public:
85  enum {
86  StaticUsage = true
87  };
88 };
89 
90 namespace ACG {
91 namespace SceneGraph {
92 
93 
94 //== CLASS DEFINITION =========================================================
95 
96 template<class Mesh, class Mod, const bool StaticUsage> class StatusNodeBaseT;
97 
98 template<class Mesh, class Mod>
99 
100 class StatusNodeBaseT<Mesh, Mod, true> : public MaterialNode {
101  public:
102  StatusNodeBaseT(BaseNode* _parent, const std::string& _name) :
103  MaterialNode(_parent, _name) {}
104 
105  virtual ~StatusNodeBaseT() {}
106 
107  protected:
108  bool is_vertex_selected(
109  const Mesh &mesh, typename Mesh::VertexHandle vh) {
110  return Mod::is_vertex_selected(mesh, vh);
111  }
112 
113  bool is_halfedge_selected(
114  const Mesh &mesh, typename Mesh::HalfedgeHandle heh) {
115  return Mod::is_halfedge_selected(mesh, heh);
116  }
117 
118  bool is_edge_selected(const Mesh &mesh, typename Mesh::EdgeHandle eh) {
119  return Mod::is_edge_selected(mesh, eh);
120  }
121 
122  bool is_face_selected(const Mesh &mesh, typename Mesh::FaceHandle fh) {
123  return Mod::is_face_selected(mesh, fh);
124  }
125 };
126 
127 template<class Mesh, class Mod>
128 class StatusNodeBaseT<Mesh, Mod, false> : public MaterialNode {
129 
130  public:
131  StatusNodeBaseT(BaseNode* _parent, const std::string& _name) :
132  MaterialNode(_parent, _name), modInstance(0) {}
133 
134  virtual ~StatusNodeBaseT() {
135  delete modInstance;
136  }
137 
144  void provideModInstance(Mod *mod) {
145  delete modInstance;
146  modInstance = mod;
147  }
148 
149  protected:
150  bool is_vertex_selected(
151  const Mesh &mesh, typename Mesh::VertexHandle vh) {
152  assert(modInstance);
153  return modInstance->is_vertex_selected(mesh, vh);
154  }
155 
156  bool is_halfedge_selected(
157  const Mesh &mesh, typename Mesh::HalfedgeHandle heh) {
158  assert(modInstance);
159  return modInstance->is_halfedge_selected(mesh, heh);
160  }
161 
162  bool is_edge_selected(const Mesh &mesh, typename Mesh::EdgeHandle eh) {
163  assert(modInstance);
164  return modInstance->is_edge_selected(mesh, eh);
165  }
166 
167  bool is_face_selected(const Mesh &mesh, typename Mesh::FaceHandle fh) {
168  assert(modInstance);
169  return modInstance->is_face_selected(mesh, fh);
170  }
171 
172  protected:
173  Mod *modInstance;
174 };
175 
176 
182 template <class Mesh, class Mod>
183 class StatusNodeT :
184  public StatusNodeBaseT<Mesh, Mod, ::StatusNodes_ModTraits<Mod>::StaticUsage>
185 {
186 public:
188  typedef Mod ModType;
189 
191  StatusNodeT( const Mesh& _mesh,
192  BaseNode* _parent = 0,
193  const std::string& _name = "<StatusNode>" );
194 
196  virtual ~StatusNodeT() {}
197 
198  ACG_CLASSNAME(StatusNode);
199 
200 
203  void updateGeometry();
204 
207  void updateTopology();
208 
211  void updateSelection();
212 
219  void setDrawMesh(DrawMeshT<Mesh>* _drawmesh);
220 
221 
228  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const class Material* _mat);
229 
230 
231  DrawModes::DrawMode availableDrawModes() const;
232  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
233  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
234  void pick(GLState& /* _state */ , PickTarget /* _target */ ) {}
235 
236 
237 private:
238 
242  void update_cache();
243 
244  typedef typename Mesh::Face Face;
245  typedef typename Mesh::Vertex Vertex;
246  typedef typename Mesh::Halfedge Halfedge;
247  typedef typename Mesh::Edge Edge;
248  typedef typename Mesh::FaceHandle FaceHandle;
249  typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
250 
251  typedef typename Mesh::Point Point;
252  typedef typename Mesh::Normal Normal;
253 
254  void draw_points();
255  void draw_edges();
256  void draw_halfedges();
257  void draw_faces(bool _per_vertex);
258 
259  Point halfedge_point(const HalfedgeHandle _heh);
260 
261 
262 private:
263 
264  const Mesh& mesh_;
265  DrawMeshT<Mesh>* drawMesh_;
266 
267  std::vector<unsigned int> v_cache_, e_cache_, f_cache_, poly_cache_;
268  std::vector<FaceHandle> fh_cache_;
269 
270  std::vector<Point> he_points_;
271  std::vector<Normal> he_normals_;
272 
273  // bounding box
274  Vec3d bbMin_;
275  Vec3d bbMax_;
276 
279 
280  bool vertexIndexInvalid_;
281  bool halfedgeCacheInvalid_;
282  bool edgeIndexInvalid_;
283  bool faceIndexInvalid_;
284 
285 
286  // vertex-formats for new renderer
287  VertexDeclaration pointVertexDecl_;
288  VertexDeclaration halfedgeVertexDecl_;
289 };
290 
291 
292 
293 //== CLASS DEFINITION =========================================================
294 
295 
296 template <class Mesh, unsigned int Bit>
298 {
299  static bool is_vertex_selected(const Mesh& _mesh,
300  typename Mesh::VertexHandle _vh)
301  {
302  return _mesh.status(_vh).is_bit_set(Bit);
303  }
304 
305  static bool is_edge_selected(const Mesh& _mesh,
306  typename Mesh::EdgeHandle _eh)
307  {
308  return _mesh.status(_eh).is_bit_set(Bit);
309  }
310 
311  static bool is_halfedge_selected(const Mesh& _mesh,
312  typename Mesh::HalfedgeHandle _heh)
313  {
314  return _mesh.status(_heh).is_bit_set(Bit);
315  }
316 
317  static bool is_face_selected(const Mesh& _mesh,
318  typename Mesh::FaceHandle _fh)
319  {
320  return _mesh.status(_fh).is_bit_set(Bit);
321  }
322 };
323 
324 
325 
326 //== CLASS DEFINITION =========================================================
327 
328 
329 template <class Mesh>
331  : public StatusModT<Mesh, OpenMesh::Attributes::SELECTED>
332 {};
333 
334 
335 
341 template <class Mesh>
343  : virtual public StatusNodeT<Mesh, SelectionModT<Mesh> >
344 {
345 public:
346 
352  SelectionNodeT( const Mesh& _mesh,
353  BaseNode* _parent = 0,
354  const std::string& _name = "<SelectionNode>" )
355  : StatusNodeT<Mesh, SelectionModT<Mesh> > (_mesh, _parent, _name)
356  {}
357 };
358 
359 
360 //== CLASS DEFINITION =========================================================
361 
362 
363 template <class Mesh>
364 struct LockModT
365  : public StatusModT<Mesh, OpenMesh::Attributes::LOCKED>
366 {};
367 
368 
369 template <class Mesh>
370 class LockNodeT : public StatusNodeT<Mesh, LockModT<Mesh> >
371 {
372 public:
373 
374  LockNodeT( const Mesh& _mesh,
375  BaseNode* _parent = 0,
376  const std::string& _name = "<LockNode>" )
377  : StatusNodeT<Mesh, LockModT<Mesh> > (_mesh, _parent, _name)
378  {}
379 };
380 
381 
382 //=============================================================================
383 } // namespace SceneGraph
384 } // namespace ACG
385 //=============================================================================
386 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_STATUS_NODES_C)
387 #define ACG_STATUS_NODES_TEMPLATES
388 #include "StatusNodesT.cc"
389 #endif
390 //=============================================================================
391 #endif // ACG_STATUS_NODES_HH defined
392 //=============================================================================
393 
void setDrawMesh(DrawMeshT< Mesh > *_drawmesh)
Set drawmesh.
Mesh Drawing Class.
Definition: DrawMesh.hh:172
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
Kernel::Face Face
Face type.
Definition: PolyMeshT.hh:133
void updateGeometry()
set geometry invalid, topology and selection is kept
Kernel::Vertex Vertex
Vertex type.
Definition: PolyMeshT.hh:127
virtual ~StatusNodeT()
destructor
bool invalidGeometry_
State variables.
void updateSelection()
set selection invalid (Only selection changed, rest is kept)
Kernel::Edge Edge
Edge type.
Definition: PolyMeshT.hh:131
void updateTopology()
set topology invalid (updates everything)
Class to define the vertex input layout.
StatusNodeT(const Mesh &_mesh, BaseNode *_parent=0, const std::string &_name="<StatusNode>")
constructor
Definition: StatusNodesT.cc:80
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const class Material *_mat)
support for shader-pipeline
SelectionNodeT(const Mesh &_mesh, BaseNode *_parent=0, const std::string &_name="<SelectionNode>")
Constructor.
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
Kernel::Halfedge Halfedge
Halfedge type.
Definition: PolyMeshT.hh:129
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:117