OpenVolumeMesh
 All Classes Functions Variables Typedefs Pages
ResourceManager.hh
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh 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  * OpenVolumeMesh 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 OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 217 $ *
38  * $Date: 2012-07-18 15:04:05 +0200 (Wed, 18 Jul 2012) $ *
39  * $LastChangedBy: kremer $ *
40  * *
41 \*===========================================================================*/
42 
43 #ifndef RESOURCEMANAGER_HH_
44 #define RESOURCEMANAGER_HH_
45 
46 #include <string>
47 #include <vector>
48 
49 #include "OpenVolumeMeshProperty.hh"
50 #include "PropertyHandles.hh"
51 
52 namespace OpenVolumeMesh {
53 
54 // Forward declarations
55 class BaseProperty;
56 template <class T>
57 class VertexPropertyT;
58 template <class T>
59 class EdgePropertyT;
60 template <class T>
61 class HalfEdgePropertyT;
62 template <class T>
63 class FacePropertyT;
64 template <class T>
65 class HalfFacePropertyT;
66 template <class T>
67 class CellPropertyT;
68 template <class T>
69 class MeshPropertyT;
70 template <class PropT, class HandleT>
71 class PropertyPtr;
72 
74 public:
76  virtual ~ResourceManager();
77 
78  template <class PropT, class HandleT> friend class PropertyPtr;
79 
81  void resize_vprops(unsigned int _nv);
82 
84  void resize_eprops(unsigned int _ne);
85 
87  void resize_fprops(unsigned int _nf);
88 
90  void resize_cprops(unsigned int _nc);
91 
92 protected:
93 
94  void vertex_deleted(const VertexHandle& _h);
95 
96  void edge_deleted(const EdgeHandle& _h);
97 
98  void face_deleted(const FaceHandle& _h);
99 
100  void cell_deleted(const CellHandle& _h);
101 
102 public:
103 
104  void clear_vertex_props() { clearVec(vertex_props_); }
105 
106  void clear_edge_props() { clearVec(edge_props_); }
107 
108  void clear_halfedge_props() { clearVec(halfedge_props_); }
109 
110  void clear_face_props() { clearVec(face_props_); }
111 
112  void clear_halfface_props() { clearVec(halfface_props_); }
113 
114  void clear_cell_props() { clearVec(cell_props_); }
115 
116  void clear_mesh_props() { clearVec(mesh_props_); }
117 
119  virtual unsigned int n_vertices() const = 0;
121  virtual unsigned int n_edges() const = 0;
123  virtual unsigned int n_halfedges() const = 0;
125  virtual unsigned int n_faces() const = 0;
127  virtual unsigned int n_halffaces() const = 0;
129  virtual unsigned int n_cells() const = 0;
130 
131  template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name = std::string(), const T _def = T());
132 
133  template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name = std::string(), const T _def = T());
134 
135  template<class T> HalfEdgePropertyT<T> request_halfedge_property(const std::string& _name = std::string(), const T _def = T());
136 
137  template<class T> FacePropertyT<T> request_face_property(const std::string& _name = std::string(), const T _def = T());
138 
139  template<class T> HalfFacePropertyT<T> request_halfface_property(const std::string& _name = std::string(), const T _def = T());
140 
141  template<class T> CellPropertyT<T> request_cell_property(const std::string& _name = std::string(), const T _def = T());
142 
143  template<class T> MeshPropertyT<T> request_mesh_property(const std::string& _name = std::string(), const T _def = T());
144 
145 private:
146 
147  void release_property(VertexPropHandle _handle);
148 
149  void release_property(EdgePropHandle _handle);
150 
151  void release_property(HalfEdgePropHandle _handle);
152 
153  void release_property(FacePropHandle _handle);
154 
155  void release_property(HalfFacePropHandle _handle);
156 
157  void release_property(CellPropHandle _handle);
158 
159  void release_property(MeshPropHandle _handle);
160 
161 public:
162 
163  unsigned int n_vertex_props() const { return vertex_props_.size(); }
164 
165  unsigned int n_edge_props() const { return edge_props_.size(); }
166 
167  unsigned int n_halfedge_props() const { return halfedge_props_.size(); }
168 
169  unsigned int n_face_props() const { return face_props_.size(); }
170 
171  unsigned int n_halfface_props() const { return halfface_props_.size(); }
172 
173  unsigned int n_cell_props() const { return cell_props_.size(); }
174 
175  unsigned int n_mesh_props() const { return mesh_props_.size(); }
176 
177  template<class T> void set_persistent(VertexPropertyT<T>& _prop, bool _flag = true);
178 
179  template<class T> void set_persistent(EdgePropertyT<T>& _prop, bool _flag = true);
180 
181  template<class T> void set_persistent(HalfEdgePropertyT<T>& _prop, bool _flag = true);
182 
183  template<class T> void set_persistent(FacePropertyT<T>& _prop, bool _flag = true);
184 
185  template<class T> void set_persistent(HalfFacePropertyT<T>& _prop, bool _flag = true);
186 
187  template<class T> void set_persistent(CellPropertyT<T>& _prop, bool _flag = true);
188 
189  template<class T> void set_persistent(MeshPropertyT<T>& _prop, bool _flag = true);
190 
191  typedef std::vector<BaseProperty*> Properties;
192 
193  Properties::const_iterator vertex_props_begin() const { return vertex_props_.begin(); }
194 
195  Properties::const_iterator vertex_props_end() const { return vertex_props_.end(); }
196 
197  Properties::const_iterator edge_props_begin() const { return edge_props_.begin(); }
198 
199  Properties::const_iterator edge_props_end() const { return edge_props_.end(); }
200 
201  Properties::const_iterator halfedge_props_begin() const { return halfedge_props_.begin(); }
202 
203  Properties::const_iterator halfedge_props_end() const { return halfedge_props_.end(); }
204 
205  Properties::const_iterator face_props_begin() const { return face_props_.begin(); }
206 
207  Properties::const_iterator face_props_end() const { return face_props_.end(); }
208 
209  Properties::const_iterator halfface_props_begin() const { return halfface_props_.begin(); }
210 
211  Properties::const_iterator halfface_props_end() const { return halfface_props_.end(); }
212 
213  Properties::const_iterator cell_props_begin() const { return cell_props_.begin(); }
214 
215  Properties::const_iterator cell_props_end() const { return cell_props_.end(); }
216 
217  Properties::const_iterator mesh_props_begin() const { return mesh_props_.begin(); }
218 
219  Properties::const_iterator mesh_props_end() const { return mesh_props_.end(); }
220 
221  template <class FullPropT, class PropIterT>
222  bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const {
223 
224  if(_name.length() == 0) {
225  std::cerr << "Checking for the existance of anonymous properties is ambiguous!" << std::endl;
226  return false;
227  }
228 
229  PropIterT it = _begin;
230  for(; it != _end; ++it) {
231  if((*it)->name() == _name && dynamic_cast<FullPropT*>(*it) != NULL) {
232  return true;
233  }
234  }
235  return false;
236  }
237 
238  template <class PropT>
239  bool vertex_property_exists(const std::string& _name) const {
240  return property_exists<VertexPropertyT<PropT> >(vertex_props_begin(), vertex_props_end(), _name);
241  }
242 
243  template <class PropT>
244  bool edge_property_exists(const std::string& _name) const {
245  return property_exists<EdgePropertyT<PropT> >(edge_props_begin(), edge_props_end(), _name);
246  }
247 
248  template <class PropT>
249  bool halfedge_property_exists(const std::string& _name) const {
250  return property_exists<HalfEdgePropertyT<PropT> >(halfedge_props_begin(), halfedge_props_end(), _name);
251  }
252 
253  template <class PropT>
254  bool face_property_exists(const std::string& _name) const {
255  return property_exists<FacePropertyT<PropT> >(face_props_begin(), face_props_end(), _name);
256  }
257 
258  template <class PropT>
259  bool halfface_property_exists(const std::string& _name) const {
260  return property_exists<HalfFacePropertyT<PropT> >(halfface_props_begin(), halfface_props_end(), _name);
261  }
262 
263  template <class PropT>
264  bool cell_property_exists(const std::string& _name) const {
265  return property_exists<CellPropertyT<PropT> >(cell_props_begin(), cell_props_end(), _name);
266  }
267 
268  template <class PropT>
269  bool mesh_property_exists(const std::string& _name) const {
270  return property_exists<MeshPropertyT<PropT> >(mesh_props_begin(), mesh_props_end(), _name);
271  }
272 
273 protected:
274 
275  void delete_multiple_vertex_props(const std::vector<bool>& _tags);
276 
277  void delete_multiple_edge_props(const std::vector<bool>& _tags);
278 
279  void delete_multiple_face_props(const std::vector<bool>& _tags);
280 
281  void delete_multiple_cell_props(const std::vector<bool>& _tags);
282 
283 private:
284 
285  template<class StdVecT>
286  void resize_props(StdVecT& _vec, unsigned int _n);
287 
288  template<class StdVecT>
289  void entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle& _h);
290 
291  template<class StdVecT>
292  void remove_property(StdVecT& _vec, size_t _idx);
293 
294  template<class StdVecT, class PropT, class HandleT, class T>
295  PropT request_property(StdVecT& _vec, const std::string& _name, size_t _size, const T _def = T());
296 
297  template<class PropT>
298  void set_persistentT(PropT& _prop, bool _flag);
299 
300  template<class StdVecT>
301  void clearVec(StdVecT& _vec);
302 
303  Properties vertex_props_;
304 
305  Properties edge_props_;
306 
307  Properties halfedge_props_;
308 
309  Properties face_props_;
310 
311  Properties halfface_props_;
312 
313  Properties cell_props_;
314 
315  Properties mesh_props_;
316 };
317 
318 }
319 
320 #if defined(INCLUDE_TEMPLATES) && !defined(RESOURCEMANAGERT_CC)
321 #include "ResourceManagerT.cc"
322 #endif
323 
324 #endif /* RESOURCEMANAGER_HH_ */