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