Developer Documentation
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 #pragma once
36 
37 #ifndef NDEBUG
38 #include <iostream>
39 #endif
40 #include <string>
41 #include <vector>
42 
43 #include "OpenVolumeMeshProperty.hh"
44 #include "PropertyHandles.hh"
45 #include "ForwardDeclarations.hh"
46 
47 namespace OpenVolumeMesh {
48 
49 // Forward declarations
50 class BaseProperty;
51 
53 public:
55  ResourceManager(const ResourceManager &other);
56  ResourceManager& operator=(const ResourceManager &other) = delete;
57 
58  virtual ~ResourceManager();
59 
60  template <class PropT, class HandleT> friend class PropertyPtr;
61 
63  void resize_vprops(size_t _nv);
64 
66  void resize_eprops(size_t _ne);
67 
69  void resize_fprops(size_t _nf);
70 
72  void resize_cprops(size_t _nc);
73 
74 protected:
75 
76  void vertex_deleted(const VertexHandle& _h);
77 
78  void edge_deleted(const EdgeHandle& _h);
79 
80  void face_deleted(const FaceHandle& _h);
81 
82  void cell_deleted(const CellHandle& _h);
83 
84  void swap_cell_properties(CellHandle _h1, CellHandle _h2);
85 
86  void swap_face_properties(FaceHandle _h1, FaceHandle _h2);
87 
88  void swap_halfface_properties(HalfFaceHandle _h1, HalfFaceHandle _h2);
89 
90  void swap_edge_properties(EdgeHandle _h1, EdgeHandle _h2);
91 
92  void swap_halfedge_properties(HalfEdgeHandle _h1, HalfEdgeHandle _h2);
93 
94  void swap_vertex_properties(VertexHandle _h1, VertexHandle _h2);
95 
96  template <typename PropIterator, typename Handle>
97  void swap_property_elements(PropIterator _begin, PropIterator _end, Handle _h1, Handle _h2)
98  {
99  PropIterator p_iter = _begin;
100  for (; p_iter != _end; ++p_iter)
101  (*p_iter)->swap_elements(_h1.idx(), _h2.idx());
102  }
103 
104 
105 public:
106 
107  void clear_vertex_props() { clearVec(vertex_props_); }
108 
109  void clear_edge_props() { clearVec(edge_props_); }
110 
111  void clear_halfedge_props() { clearVec(halfedge_props_); }
112 
113  void clear_face_props() { clearVec(face_props_); }
114 
115  void clear_halfface_props() { clearVec(halfface_props_); }
116 
117  void clear_cell_props() { clearVec(cell_props_); }
118 
119  void clear_mesh_props() { clearVec(mesh_props_); }
120 
122  virtual size_t n_vertices() const = 0;
124  virtual size_t n_edges() const = 0;
126  virtual size_t n_halfedges() const = 0;
128  virtual size_t n_faces() const = 0;
130  virtual size_t n_halffaces() const = 0;
132  virtual size_t n_cells() const = 0;
133 
134  template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name = std::string(), const T _def = T());
135 
136  template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name = std::string(), const T _def = T());
137 
138  template<class T> HalfEdgePropertyT<T> request_halfedge_property(const std::string& _name = std::string(), const T _def = T());
139 
140  template<class T> FacePropertyT<T> request_face_property(const std::string& _name = std::string(), const T _def = T());
141 
142  template<class T> HalfFacePropertyT<T> request_halfface_property(const std::string& _name = std::string(), const T _def = T());
143 
144  template<class T> CellPropertyT<T> request_cell_property(const std::string& _name = std::string(), const T _def = T());
145 
146  template<class T> MeshPropertyT<T> request_mesh_property(const std::string& _name = std::string(), const T _def = T());
147 
148 private:
149 
150  void release_property(VertexPropHandle _handle);
151 
152  void release_property(EdgePropHandle _handle);
153 
154  void release_property(HalfEdgePropHandle _handle);
155 
156  void release_property(FacePropHandle _handle);
157 
158  void release_property(HalfFacePropHandle _handle);
159 
160  void release_property(CellPropHandle _handle);
161 
162  void release_property(MeshPropHandle _handle);
163 
164 public:
165 
166  size_t n_vertex_props() const { return vertex_props_.size(); }
167 
168  size_t n_edge_props() const { return edge_props_.size(); }
169 
170  size_t n_halfedge_props() const { return halfedge_props_.size(); }
171 
172  size_t n_face_props() const { return face_props_.size(); }
173 
174  size_t n_halfface_props() const { return halfface_props_.size(); }
175 
176  size_t n_cell_props() const { return cell_props_.size(); }
177 
178  size_t n_mesh_props() const { return mesh_props_.size(); }
179 
180  template<class T> void set_persistent(VertexPropertyT<T>& _prop, bool _flag = true);
181 
182  template<class T> void set_persistent(EdgePropertyT<T>& _prop, bool _flag = true);
183 
184  template<class T> void set_persistent(HalfEdgePropertyT<T>& _prop, bool _flag = true);
185 
186  template<class T> void set_persistent(FacePropertyT<T>& _prop, bool _flag = true);
187 
188  template<class T> void set_persistent(HalfFacePropertyT<T>& _prop, bool _flag = true);
189 
190  template<class T> void set_persistent(CellPropertyT<T>& _prop, bool _flag = true);
191 
192  template<class T> void set_persistent(MeshPropertyT<T>& _prop, bool _flag = true);
193 
194  typedef std::vector<BaseProperty*> Properties;
195 
196  Properties::const_iterator vertex_props_begin() const { return vertex_props_.begin(); }
197 
198  Properties::const_iterator vertex_props_end() const { return vertex_props_.end(); }
199 
200  Properties::const_iterator edge_props_begin() const { return edge_props_.begin(); }
201 
202  Properties::const_iterator edge_props_end() const { return edge_props_.end(); }
203 
204  Properties::const_iterator halfedge_props_begin() const { return halfedge_props_.begin(); }
205 
206  Properties::const_iterator halfedge_props_end() const { return halfedge_props_.end(); }
207 
208  Properties::const_iterator face_props_begin() const { return face_props_.begin(); }
209 
210  Properties::const_iterator face_props_end() const { return face_props_.end(); }
211 
212  Properties::const_iterator halfface_props_begin() const { return halfface_props_.begin(); }
213 
214  Properties::const_iterator halfface_props_end() const { return halfface_props_.end(); }
215 
216  Properties::const_iterator cell_props_begin() const { return cell_props_.begin(); }
217 
218  Properties::const_iterator cell_props_end() const { return cell_props_.end(); }
219 
220  Properties::const_iterator mesh_props_begin() const { return mesh_props_.begin(); }
221 
222  Properties::const_iterator mesh_props_end() const { return mesh_props_.end(); }
223 
224 private:
225 
226  template <class FullPropT, class PropIterT>
227  bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const {
228 
229  if(_name.empty()) {
230 #ifndef NDEBUG
231  std::cerr << "property_exists(): Checking for the existence of anonymous properties is" << std::endl;
232  std::cerr << "ambiguous!" << std::endl;
233 #endif
234  return false;
235  }
236 
237  PropIterT it = _begin;
238  for(; it != _end; ++it)
239  {
240  if((*it)->name() == _name )
241  {
242 #if OVM_FORCE_STATIC_CAST
243  return true;
244 #else
245  if(dynamic_cast<FullPropT*>(*it) != NULL)
246  {
247  return true;
248  }
249 #endif
250  }
251  }
252  return false;
253  }
254 
255 public:
256 
257  template <class PropT>
258  bool vertex_property_exists(const std::string& _name) const {
259  return property_exists<VertexPropertyT<PropT> >(vertex_props_begin(), vertex_props_end(), _name);
260  }
261 
262  template <class PropT>
263  bool edge_property_exists(const std::string& _name) const {
264  return property_exists<EdgePropertyT<PropT> >(edge_props_begin(), edge_props_end(), _name);
265  }
266 
267  template <class PropT>
268  bool halfedge_property_exists(const std::string& _name) const {
269  return property_exists<HalfEdgePropertyT<PropT> >(halfedge_props_begin(), halfedge_props_end(), _name);
270  }
271 
272  template <class PropT>
273  bool face_property_exists(const std::string& _name) const {
274  return property_exists<FacePropertyT<PropT> >(face_props_begin(), face_props_end(), _name);
275  }
276 
277  template <class PropT>
278  bool halfface_property_exists(const std::string& _name) const {
279  return property_exists<HalfFacePropertyT<PropT> >(halfface_props_begin(), halfface_props_end(), _name);
280  }
281 
282  template <class PropT>
283  bool cell_property_exists(const std::string& _name) const {
284  return property_exists<CellPropertyT<PropT> >(cell_props_begin(), cell_props_end(), _name);
285  }
286 
287  template <class PropT>
288  bool mesh_property_exists(const std::string& _name) const {
289  return property_exists<MeshPropertyT<PropT> >(mesh_props_begin(), mesh_props_end(), _name);
290  }
291 
292 protected:
293 
294  void delete_multiple_vertex_props(const std::vector<bool>& _tags);
295 
296  void delete_multiple_edge_props(const std::vector<bool>& _tags);
297 
298  void delete_multiple_face_props(const std::vector<bool>& _tags);
299 
300  void delete_multiple_cell_props(const std::vector<bool>& _tags);
301 
302 private:
303 
304  template<class StdVecT>
305  void resize_props(StdVecT& _vec, size_t _n);
306 
307  template<class StdVecT>
308  void entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle& _h);
309 
310  template<class StdVecT>
311  void remove_property(StdVecT& _vec, size_t _idx);
312 
313  template<class StdVecT, class PropT, class HandleT, class T>
314  PropT request_property(StdVecT& _vec, const std::string& _name, size_t _size, const T _def = T());
315 
316  template<class PropT>
317  void set_persistentT(PropT& _prop, bool _flag);
318 
319  template<class StdVecT>
320  void clearVec(StdVecT& _vec);
321 
322  Properties vertex_props_;
323 
324  Properties edge_props_;
325 
326  Properties halfedge_props_;
327 
328  Properties face_props_;
329 
330  Properties halfface_props_;
331 
332  Properties cell_props_;
333 
334  Properties mesh_props_;
335 };
336 
337 }
338 
339 #if defined(INCLUDE_TEMPLATES) && !defined(RESOURCEMANAGERT_CC)
340 #include "ResourceManagerT_impl.hh"
341 #endif
342 
void resize_cprops(size_t _nc)
Change size of stored cell properties.
virtual size_t n_cells() const =0
Get number of cells in mesh.
void resize_eprops(size_t _ne)
Change size of stored edge properties.
void resize_vprops(size_t _nv)
Change size of stored vertex properties.
virtual size_t n_vertices() const =0
Get number of vertices in mesh.
void resize_fprops(size_t _nf)
Change size of stored face properties.
virtual size_t n_halfedges() const =0
Get number of halfedges in mesh.
virtual size_t n_faces() const =0
Get number of faces in mesh.
virtual size_t n_edges() const =0
Get number of edges in mesh.
virtual size_t n_halffaces() const =0
Get number of halffaces in mesh.