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#include <OpenVolumeMesh/Core/ResourceManager.hh>
36
37namespace OpenVolumeMesh {
38
39ResourceManager::ResourceManager(const ResourceManager &other)
40{
41 clone_persistent_properties_from(other);
42}
43
44
55{
56 if (this == &other) return *this;
57
58 // make existing properties anonymous (invisible to mesh API users)
60
61 // Resize remaining, anonymized properties:
62 for_each_entity([&](auto entity_tag) {
63 resize_props<decltype(entity_tag)>(other.n<decltype(entity_tag)>());
64 });
65
66 clone_persistent_properties_from(other);
67
68
69 return *this;
70}
71
72void ResourceManager::clone_persistent_properties_from(ResourceManager const& other)
73{
74 for_each_entity([&](auto entity_tag) {
75 using ET = decltype(entity_tag);
76 const auto &other_props = other.persistent_props_.get<ET>();
77 auto &our_props = persistent_props_.get<ET>();
78 for(const auto &p: other_props) {
79 auto copy = p->clone();
80 copy->set_tracker(&storage_tracker<ET>());
81 our_props.insert(copy->shared_from_this());
82 }
83 });
84}
85
86
87detail::Tracker<PropertyStorageBase> &
88ResourceManager::storage_tracker(EntityType type) const
89{
90 return storage_trackers_.get(type);
91}
92
94 resize_props<Entity::Vertex>(_nv);
95}
96
98 resize_props<Entity::Edge>(_ne);
99 resize_props<Entity::HalfEdge>(2 * _ne);
100}
101
103 resize_props<Entity::Face>(_nf);
104 resize_props<Entity::HalfFace>(2 * _nf);
105}
106
108 resize_props<Entity::Cell>(_nc);
109}
110
111void ResourceManager::reserve_vprops(size_t _n) {
112 reserve_props<Entity::Vertex>(_n);
113}
114void ResourceManager::reserve_eprops(size_t _n) {
115 reserve_props<Entity::Edge>(_n);
116 reserve_props<Entity::HalfEdge>(2 * _n);
117}
118void ResourceManager::reserve_fprops(size_t _n) {
119 reserve_props<Entity::Face>(_n);
120 reserve_props<Entity::HalfFace>(2 * _n);
121}
122void ResourceManager::reserve_cprops(size_t _n) {
123 reserve_props<Entity::Cell>(_n);
124}
125
126
127void ResourceManager::vertex_deleted(const VertexHandle& _h) {
128 entity_deleted(_h);
129}
130
131void ResourceManager::edge_deleted(const EdgeHandle& _h) {
132 entity_deleted(_h);
133 entity_deleted(_h.halfedge_handle(1));
134 entity_deleted(_h.halfedge_handle(0));
135}
136
137void ResourceManager::face_deleted(const FaceHandle& _h)
138{
139 entity_deleted(_h);
140 entity_deleted(_h.halfface_handle(1));
141 entity_deleted(_h.halfface_handle(0));
142}
143
144void ResourceManager::cell_deleted(const CellHandle& _h) {
145 entity_deleted(_h);
146}
147
149{
150 for_each_entity([this](auto entity_tag){ clear_props<decltype(entity_tag)>();});
151}
152
153
154template<> size_t OVM_EXPORT ResourceManager::n<Entity::Vertex>() const { return n_vertices(); }
155template<> size_t OVM_EXPORT ResourceManager::n<Entity::Edge>() const { return n_edges(); }
156template<> size_t OVM_EXPORT ResourceManager::n<Entity::HalfEdge>() const { return n_halfedges(); }
157template<> size_t OVM_EXPORT ResourceManager::n<Entity::Face>() const { return n_faces(); }
158template<> size_t OVM_EXPORT ResourceManager::n<Entity::HalfFace>() const { return n_halffaces(); }
159template<> size_t OVM_EXPORT ResourceManager::n<Entity::Cell>() const { return n_cells(); }
160template<> size_t OVM_EXPORT ResourceManager::n<Entity::Mesh>() const { return 1; }
161
162
163
164} // Namespace OpenVolumeMesh
void resize_vprops(size_t _nv)
Change size of stored vertex properties.
size_t n() const
Get number of entities of given kind in mesh.
ResourceManager & operator=(const ResourceManager &other)
void clear_all_props()
drop all persistent properties.
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_fprops(size_t _nf)
Change size of stored face properties.