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