Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StatusNodesT.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openflipper.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenFlipper. *
9  * *
10  * OpenFlipper is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenFlipper is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenFlipper. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 12560 $ *
38  * $Author: moebius $ *
39  * $Date: 2011-10-10 08:23:41 +0200 (Mo, 10 Okt 2011) $ *
40  * *
41 \*===========================================================================*/
42 
43 
44 
45 
46 //=============================================================================
47 //
48 // Status Nodes
49 //
50 //=============================================================================
51 
52 
53 #ifndef ACG_STATUS_NODES_HH
54 #define ACG_STATUS_NODES_HH
55 
56 
57 //== INCLUDES =================================================================
58 
59 
61 
62 #include "MaterialNode.hh"
63 #include "DrawModes.hh"
64 
65 #include <vector>
66 
67 
68 //== NAMESPACES ===============================================================
69 
70 
71 namespace ACG {
72 namespace SceneGraph {
73 
74 
75 //== CLASS DEFINITION =========================================================
76 
77 
83 template <class Mesh, class Mod>
84 class StatusNodeT : public MaterialNode
85 {
86 public:
87 
89  StatusNodeT( const Mesh& _mesh,
90  BaseNode* _parent = 0,
91  const std::string& _name = "<StatusNode>" );
92 
95 
96  ACG_CLASSNAME(StatusNode);
97 
98 
101  void updateGeometry();
102 
105  void updateTopology();
106 
109  void updateSelection();
110 
111 
113  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
114  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
115  void pick(GLState& /* _state */ , PickTarget /* _target */ ) {}
116 
117 
118 private:
119 
123  void update_cache();
124 
125  typedef typename Mesh::Face Face;
126  typedef typename Mesh::Vertex Vertex;
127  typedef typename Mesh::Halfedge Halfedge;
128  typedef typename Mesh::Edge Edge;
129  typedef typename Mesh::FaceHandle FaceHandle;
130  typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
131 
132  typedef typename Mesh::Point Point;
133  typedef typename Mesh::Normal Normal;
134 
135  void draw_points();
136  void draw_edges();
137  void draw_halfedges();
138  void draw_faces(bool _per_vertex);
139 
140  Point halfedge_point(const HalfedgeHandle _heh);
141 
142 
143 private:
144 
145  const Mesh& mesh_;
146  std::vector<unsigned int> v_cache_, e_cache_, f_cache_;
147  std::vector<FaceHandle> fh_cache_;
148 
149  std::vector<Point> he_points_;
150  std::vector<Normal> he_normals_;
151 
152  // bounding box
153  Vec3d bbMin_;
154  Vec3d bbMax_;
155 
158 
159  bool vertexIndexInvalid_;
160  bool halfedgeCacheInvalid_;
161  bool edgeIndexInvalid_;
162  bool faceIndexInvalid_;
163 
164 };
165 
166 
167 
168 //== CLASS DEFINITION =========================================================
169 
170 
171 template <class Mesh, unsigned int Bit>
173 {
174  static bool is_vertex_selected(const Mesh& _mesh,
175  typename Mesh::VertexHandle _vh)
176  {
177  return _mesh.status(_vh).is_bit_set(Bit);
178  }
179 
180  static bool is_edge_selected(const Mesh& _mesh,
181  typename Mesh::EdgeHandle _eh)
182  {
183  return _mesh.status(_eh).is_bit_set(Bit);
184  }
185 
186  static bool is_halfedge_selected(const Mesh& _mesh,
187  typename Mesh::HalfedgeHandle _heh)
188  {
189  return _mesh.status(_heh).is_bit_set(Bit);
190  }
191 
192  static bool is_face_selected(const Mesh& _mesh,
193  typename Mesh::FaceHandle _fh)
194  {
195  return _mesh.status(_fh).is_bit_set(Bit);
196  }
197 };
198 
199 
200 
201 //== CLASS DEFINITION =========================================================
202 
203 
204 template <class Mesh>
206  : public StatusModT<Mesh, OpenMesh::Attributes::SELECTED>
207 {};
208 
209 
210 
216 template <class Mesh>
218  : virtual public StatusNodeT<Mesh, SelectionModT<Mesh> >
219 {
220 public:
221 
227  SelectionNodeT( const Mesh& _mesh,
228  BaseNode* _parent = 0,
229  const std::string& _name = "<SelectionNode>" )
230  : StatusNodeT<Mesh, SelectionModT<Mesh> > (_mesh, _parent, _name)
231  {}
232 };
233 
234 
235 //== CLASS DEFINITION =========================================================
236 
237 
238 template <class Mesh>
239 struct LockModT
240  : public StatusModT<Mesh, OpenMesh::Attributes::LOCKED>
241 {};
242 
243 
244 template <class Mesh>
245 class LockNodeT : public StatusNodeT<Mesh, LockModT<Mesh> >
246 {
247 public:
248 
249  LockNodeT( const Mesh& _mesh,
250  BaseNode* _parent = 0,
251  const std::string& _name = "<LockNode>" )
252  : StatusNodeT<Mesh, LockModT<Mesh> > (_mesh, _parent, _name)
253  {}
254 };
255 
256 
257 //=============================================================================
258 } // namespace SceneGraph
259 } // namespace ACG
260 //=============================================================================
261 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_STATUS_NODES_C)
262 #define ACG_STATUS_NODES_TEMPLATES
263 #include "StatusNodesT.cc"
264 #endif
265 //=============================================================================
266 #endif // ACG_STATUS_NODES_HH defined
267 //=============================================================================
268