Developer Documentation
ResourceManager.cc
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 #include "ResourceManager.hh"
44 
45 namespace OpenVolumeMesh {
46 
47 ResourceManager::ResourceManager() {
48 }
49 
50 ResourceManager::ResourceManager(const ResourceManager &other) {
51  auto cloneProps = [this](const Properties &src, Properties &dest) {
52  dest.reserve(src.size());
53  for (BaseProperty *bp: src) {
54  dest.push_back(bp->clone(*this, bp->handle()));
55  }
56  };
57  cloneProps(other.vertex_props_, vertex_props_);
58  cloneProps(other.edge_props_, edge_props_);
59  cloneProps(other.halfedge_props_, halfedge_props_);
60  cloneProps(other.face_props_, face_props_);
61  cloneProps(other.halfface_props_, halfface_props_);
62  cloneProps(other.cell_props_, cell_props_);
63  cloneProps(other.mesh_props_, mesh_props_);
64 }
65 
66 ResourceManager::~ResourceManager() {
67 
68  // Delete persistent props
69  clearVec(vertex_props_);
70  clearVec(edge_props_);
71  clearVec(halfedge_props_);
72  clearVec(face_props_);
73  clearVec(halfface_props_);
74  clearVec(cell_props_);
75  clearVec(mesh_props_);
76 }
77 
79 
80  resize_props(vertex_props_, _nv);
81 }
82 
84 
85  resize_props(edge_props_, _ne);
86  resize_props(halfedge_props_, _ne*2u);
87 }
88 
90 
91  resize_props(face_props_, _nf);
92  resize_props(halfface_props_, _nf*2u);
93 }
94 
96 
97  resize_props(cell_props_, _nc);
98 }
99 
100 void ResourceManager::vertex_deleted(const VertexHandle& _h) {
101 
102  entity_deleted(vertex_props_, _h);
103 }
104 
105 void ResourceManager::edge_deleted(const EdgeHandle& _h) {
106 
107  entity_deleted(edge_props_, _h);
108  entity_deleted(halfedge_props_, OpenVolumeMeshHandle(_h.idx()*2 + 1));
109  entity_deleted(halfedge_props_, OpenVolumeMeshHandle(_h.idx()*2));
110 }
111 
112 void ResourceManager::face_deleted(const FaceHandle& _h) {
113 
114  entity_deleted(face_props_, _h);
115  entity_deleted(halfface_props_, OpenVolumeMeshHandle(_h.idx()*2 + 1));
116  entity_deleted(halfface_props_, OpenVolumeMeshHandle(_h.idx()*2));
117 }
118 
119 void ResourceManager::cell_deleted(const CellHandle& _h) {
120 
121  entity_deleted(cell_props_, _h);
122 }
123 
124 void ResourceManager::swap_cell_properties(CellHandle _h1, CellHandle _h2){
125 
126  swap_property_elements(cell_props_begin(), cell_props_end(), _h1, _h2);
127 }
128 
129 void ResourceManager::swap_face_properties(FaceHandle _h1, FaceHandle _h2){
130 
131  swap_property_elements(face_props_begin(), face_props_end(), _h1, _h2);
132 }
133 
134 void ResourceManager::swap_halfface_properties(HalfFaceHandle _h1, HalfFaceHandle _h2){
135 
136  swap_property_elements(halfface_props_begin(), halfface_props_end(), _h1, _h2);
137 }
138 
139 void ResourceManager::swap_edge_properties(EdgeHandle _h1, EdgeHandle _h2){
140 
141  swap_property_elements(edge_props_begin(), edge_props_end(), _h1, _h2);
142 }
143 
144 void ResourceManager::swap_halfedge_properties(HalfEdgeHandle _h1, HalfEdgeHandle _h2){
145 
146  swap_property_elements(halfedge_props_begin(), halfedge_props_end(), _h1, _h2);
147 }
148 
149 void ResourceManager::swap_vertex_properties(VertexHandle _h1, VertexHandle _h2){
150 
151  swap_property_elements(vertex_props_begin(), vertex_props_end(), _h1, _h2);
152 }
153 
154 void ResourceManager::release_property(VertexPropHandle _handle) {
155 
156  remove_property(vertex_props_, _handle.idx());
157 }
158 
159 void ResourceManager::release_property(EdgePropHandle _handle) {
160 
161  remove_property(edge_props_, _handle.idx());
162 }
163 
164 void ResourceManager::release_property(HalfEdgePropHandle _handle) {
165 
166  remove_property(halfedge_props_, _handle.idx());
167 }
168 
169 void ResourceManager::release_property(FacePropHandle _handle) {
170 
171  remove_property(face_props_, _handle.idx());
172 }
173 
174 void ResourceManager::release_property(HalfFacePropHandle _handle) {
175 
176  remove_property(halfface_props_, _handle.idx());
177 }
178 
179 void ResourceManager::release_property(CellPropHandle _handle) {
180 
181  remove_property(cell_props_, _handle.idx());
182 }
183 
184 void ResourceManager::release_property(MeshPropHandle _handle) {
185 
186  remove_property(mesh_props_, _handle.idx());
187 }
188 
189 void ResourceManager::delete_multiple_vertex_props(const std::vector<bool>& _tags) {
190 
191  Properties::iterator vp_it = vertex_props_.begin();
192  Properties::iterator vp_end = vertex_props_.end();
193  for(; vp_it != vp_end; ++vp_it) {
194  (*vp_it)->delete_multiple_entries(_tags);
195  }
196 }
197 
198 void ResourceManager::delete_multiple_edge_props(const std::vector<bool>& _tags) {
199 
200  Properties::iterator ep_it = edge_props_.begin();
201  Properties::iterator ep_end = edge_props_.end();
202  for(; ep_it != ep_end; ++ep_it) {
203  (*ep_it)->delete_multiple_entries(_tags);
204  }
205  // Create tags vector for halfedges
206  std::vector<bool> hetags;
207  for(std::vector<bool>::const_iterator t_it = _tags.begin(),
208  t_end = _tags.end(); t_it != t_end; ++t_it) {
209  hetags.push_back(*t_it);
210  hetags.push_back(*t_it);
211  }
212  Properties::iterator hep_it = halfedge_props_.begin();
213  Properties::iterator hep_end = halfedge_props_.end();
214  for(; hep_it != hep_end; ++hep_it) {
215  (*hep_it)->delete_multiple_entries(hetags);
216  }
217 }
218 
219 void ResourceManager::delete_multiple_face_props(const std::vector<bool>& _tags) {
220 
221  Properties::iterator fp_it = face_props_.begin();
222  Properties::iterator fp_end = face_props_.end();
223  for(; fp_it != fp_end; ++fp_it) {
224  (*fp_it)->delete_multiple_entries(_tags);
225  }
226  // Create tags vector for halffaces
227  std::vector<bool> hftags;
228  for(std::vector<bool>::const_iterator t_it = _tags.begin(),
229  t_end = _tags.end(); t_it != t_end; ++t_it) {
230  hftags.push_back(*t_it);
231  hftags.push_back(*t_it);
232  }
233  Properties::iterator hfp_it = halfface_props_.begin();
234  Properties::iterator hfp_end = halfface_props_.end();
235  for(; hfp_it != hfp_end; ++hfp_it) {
236  (*hfp_it)->delete_multiple_entries(hftags);
237  }
238 }
239 
240 void ResourceManager::delete_multiple_cell_props(const std::vector<bool>& _tags) {
241 
242  Properties::iterator cp_it = cell_props_.begin();
243  Properties::iterator cp_end = cell_props_.end();
244  for(; cp_it != cp_end; ++cp_it) {
245  (*cp_it)->delete_multiple_entries(_tags);
246  }
247 }
248 
249 } // Namespace OpenVolumeMesh
void resize_cprops(size_t _nc)
Change size of stored cell properties.
void resize_eprops(size_t _ne)
Change size of stored edge properties.
void resize_vprops(size_t _nv)
Change size of stored vertex properties.
The properties storage class.
Definition: Properties.hh:92
void resize_fprops(size_t _nf)
Change size of stored face properties.