ResourceManager.hh 12.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*===========================================================================*\
 *                                                                           *
 *                            OpenVolumeMesh                                 *
 *        Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen         *
 *                        www.openvolumemesh.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenVolumeMesh.                                     *
 *                                                                           *
 *  OpenVolumeMesh is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenVolumeMesh is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenVolumeMesh.  If not,                              *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

35
#pragma once
36

37
38
39
#ifndef NDEBUG
#include <iostream>
#endif
40
41
#include <string>
#include <vector>
42
#include <type_traits>
43
44
45

#include "OpenVolumeMeshProperty.hh"
#include "PropertyHandles.hh"
46
#include "ForwardDeclarations.hh"
47
48
49
50
51
52
53
54

namespace OpenVolumeMesh {

// Forward declarations
class BaseProperty;

class ResourceManager {
public:
55
    ResourceManager() = default;
56
    ResourceManager(const ResourceManager &other);
57
58
59
    ResourceManager(ResourceManager &&other);
    ResourceManager& operator=(const ResourceManager &other);
    ResourceManager& operator=(ResourceManager &&other);
60
61
    virtual ~ResourceManager();

62
63
    template <class PropT, class HandleT> friend class PropertyPtr;

64
    /// Change size of stored vertex properties
65
    void resize_vprops(size_t _nv);
66
67

    /// Change size of stored edge properties
68
    void resize_eprops(size_t _ne);
69
70

    /// Change size of stored face properties
71
    void resize_fprops(size_t _nf);
72
73

    /// Change size of stored cell properties
74
    void resize_cprops(size_t _nc);
75

76
77
protected:

78
79
80
81
82
83
84
85
    void vertex_deleted(const VertexHandle& _h);

    void edge_deleted(const EdgeHandle& _h);

    void face_deleted(const FaceHandle& _h);

    void cell_deleted(const CellHandle& _h);

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    void swap_cell_properties(CellHandle _h1, CellHandle _h2);

    void swap_face_properties(FaceHandle _h1, FaceHandle _h2);

    void swap_halfface_properties(HalfFaceHandle _h1, HalfFaceHandle _h2);

    void swap_edge_properties(EdgeHandle _h1, EdgeHandle _h2);

    void swap_halfedge_properties(HalfEdgeHandle _h1, HalfEdgeHandle _h2);

    void swap_vertex_properties(VertexHandle _h1, VertexHandle _h2);

    template <typename PropIterator, typename Handle>
    void swap_property_elements(PropIterator _begin, PropIterator _end, Handle _h1, Handle _h2)
    {
        PropIterator p_iter =  _begin;
        for (; p_iter != _end; ++p_iter)
103
            (*p_iter)->swap_elements(_h1.uidx(), _h2.uidx());
104
105
106
    }


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
public:

    void clear_vertex_props() { clearVec(vertex_props_); }

    void clear_edge_props() { clearVec(edge_props_); }

    void clear_halfedge_props() { clearVec(halfedge_props_); }

    void clear_face_props() { clearVec(face_props_); }

    void clear_halfface_props() { clearVec(halfface_props_); }

    void clear_cell_props() { clearVec(cell_props_); }

    void clear_mesh_props() { clearVec(mesh_props_); }

123
    /// Get number of vertices in mesh
124
    virtual size_t n_vertices() const = 0;
125
    /// Get number of edges in mesh
126
    virtual size_t n_edges() const = 0;
127
    /// Get number of halfedges in mesh
128
    virtual size_t n_halfedges() const = 0;
129
    /// Get number of faces in mesh
130
    virtual size_t n_faces() const = 0;
131
    /// Get number of halffaces in mesh
132
    virtual size_t n_halffaces() const = 0;
133
    /// Get number of cells in mesh
134
    virtual size_t n_cells() const = 0;
135

136
137
138
139
140
141

    template<typename T,
             typename EntityTag
             >
    PropertyTT<T, EntityTag> request_property(const std::string& _name = std::string(), const T _def = T());

142
    template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name = std::string(), const T _def = T());
143

144
    template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name = std::string(), const T _def = T());
145

146
    template<class T> HalfEdgePropertyT<T> request_halfedge_property(const std::string& _name = std::string(), const T _def = T());
147

148
    template<class T> FacePropertyT<T> request_face_property(const std::string& _name = std::string(), const T _def = T());
149

150
    template<class T> HalfFacePropertyT<T> request_halfface_property(const std::string& _name = std::string(), const T _def = T());
151

152
    template<class T> CellPropertyT<T> request_cell_property(const std::string& _name = std::string(), const T _def = T());
153

154
    template<class T> MeshPropertyT<T> request_mesh_property(const std::string& _name = std::string(), const T _def = T());
155

156

157
158
private:

159
    void release_property(VertexPropHandle _handle);
160

161
    void release_property(EdgePropHandle _handle);
162

163
    void release_property(HalfEdgePropHandle _handle);
164

165
    void release_property(FacePropHandle _handle);
166

167
    void release_property(HalfFacePropHandle _handle);
168

169
    void release_property(CellPropHandle _handle);
170

171
    void release_property(MeshPropHandle _handle);
172

173
174
public:

175
    size_t n_vertex_props() const { return vertex_props_.size(); }
176

177
    size_t n_edge_props() const { return edge_props_.size(); }
178

179
    size_t n_halfedge_props() const { return halfedge_props_.size(); }
180

181
    size_t n_face_props() const { return face_props_.size(); }
182

183
    size_t n_halfface_props() const { return halfface_props_.size(); }
184

185
    size_t n_cell_props() const { return cell_props_.size(); }
186

187
    size_t n_mesh_props() const { return mesh_props_.size(); }
188

189
190
    template<typename T, class EntityTag>
    void set_persistent(PropertyTT<T, EntityTag>& _prop, bool _flag = true);
Mike Kremer's avatar
Mike Kremer committed
191

192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
    typedef std::vector<BaseProperty*> Properties;

    Properties::const_iterator vertex_props_begin() const { return vertex_props_.begin(); }

    Properties::const_iterator vertex_props_end() const { return vertex_props_.end(); }

    Properties::const_iterator edge_props_begin() const { return edge_props_.begin(); }

    Properties::const_iterator edge_props_end() const { return edge_props_.end(); }

    Properties::const_iterator halfedge_props_begin() const { return halfedge_props_.begin(); }

    Properties::const_iterator halfedge_props_end() const { return halfedge_props_.end(); }

    Properties::const_iterator face_props_begin() const { return face_props_.begin(); }

    Properties::const_iterator face_props_end() const { return face_props_.end(); }

    Properties::const_iterator halfface_props_begin() const { return halfface_props_.begin(); }

    Properties::const_iterator halfface_props_end() const { return halfface_props_.end(); }

    Properties::const_iterator cell_props_begin() const { return cell_props_.begin(); }

    Properties::const_iterator cell_props_end() const { return cell_props_.end(); }

    Properties::const_iterator mesh_props_begin() const { return mesh_props_.begin(); }

    Properties::const_iterator mesh_props_end() const { return mesh_props_.end(); }

222
223
private:

224
    template <class FullPropT, class PropIterT>
225
226
    bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const {

227
228
229
230
231
        if(_name.empty()) {
#ifndef NDEBUG
            std::cerr << "property_exists(): Checking for the existence of anonymous properties is" << std::endl;
            std::cerr << "ambiguous!" << std::endl;
#endif
232
233
234
235
            return false;
        }

        PropIterT it = _begin;
David Bommes's avatar
David Bommes committed
236
237
238
239
        for(; it != _end; ++it)
        {
            if((*it)->name() == _name )
            {
240
#if defined OVM_FORCE_STATIC_CAST && OVM_FORCE_STATIC_CAST
David Bommes's avatar
David Bommes committed
241
242
            return true;
#else
243
            if(dynamic_cast<FullPropT*>(*it) != nullptr)
David Bommes's avatar
David Bommes committed
244
245
246
247
            {
            return true;
            }
#endif
248
            }
249
250
251
252
        }
        return false;
    }

253
254
public:

255
    template <class PropT>
256
    bool vertex_property_exists(const std::string& _name) const {
257
        return property_exists<VertexPropertyT<PropT> >(vertex_props_begin(), vertex_props_end(), _name);
258
259
    }

260
    template <class PropT>
261
    bool edge_property_exists(const std::string& _name) const {
262
        return property_exists<EdgePropertyT<PropT> >(edge_props_begin(), edge_props_end(), _name);
263
264
    }

265
    template <class PropT>
266
    bool halfedge_property_exists(const std::string& _name) const {
267
        return property_exists<HalfEdgePropertyT<PropT> >(halfedge_props_begin(), halfedge_props_end(), _name);
268
269
    }

270
    template <class PropT>
271
    bool face_property_exists(const std::string& _name) const {
272
        return property_exists<FacePropertyT<PropT> >(face_props_begin(), face_props_end(), _name);
273
274
    }

275
    template <class PropT>
276
    bool halfface_property_exists(const std::string& _name) const {
277
        return property_exists<HalfFacePropertyT<PropT> >(halfface_props_begin(), halfface_props_end(), _name);
278
279
    }

280
    template <class PropT>
281
    bool cell_property_exists(const std::string& _name) const {
282
        return property_exists<CellPropertyT<PropT> >(cell_props_begin(), cell_props_end(), _name);
283
284
    }

285
    template <class PropT>
286
    bool mesh_property_exists(const std::string& _name) const {
287
        return property_exists<MeshPropertyT<PropT> >(mesh_props_begin(), mesh_props_end(), _name);
288
289
    }

290
291
292
293
294
295
296
297
298
299
protected:

    void delete_multiple_vertex_props(const std::vector<bool>& _tags);

    void delete_multiple_edge_props(const std::vector<bool>& _tags);

    void delete_multiple_face_props(const std::vector<bool>& _tags);

    void delete_multiple_cell_props(const std::vector<bool>& _tags);

300
301
private:

302
    template<class StdVecT>
303
    void resize_props(StdVecT& _vec, size_t _n);
304
305
306
307
308
309
310

    template<class StdVecT>
    void entity_deleted(StdVecT& _vec, const OpenVolumeMeshHandle& _h);

    template<class StdVecT>
    void remove_property(StdVecT& _vec, size_t _idx);

311
    template<class StdVecT, class PropT, class HandleT, class T>
312
    PropT internal_request_property(StdVecT& _vec, const std::string& _name, size_t _size, const T _def = T());
313
314
315
316

    template<class StdVecT>
    void clearVec(StdVecT& _vec);

317
318
319
    template<class StdVecT>
    void updatePropHandles(StdVecT& _vec);

320
321
322
323
324
325
    template<bool Move>
    void assignProperties(typename std::conditional<Move, Properties&, const Properties&>::type src,
                          Properties &dest);
    template<bool Move>
    void assignAllPropertiesFrom(typename std::conditional<Move, ResourceManager*, const ResourceManager*>::type src);

326
    Properties vertex_props_;
327

328
    Properties edge_props_;
329

330
    Properties halfedge_props_;
331

332
    Properties face_props_;
333

334
    Properties halfface_props_;
335

336
    Properties cell_props_;
337

338
    Properties mesh_props_;
339
340
341
342
343
};

}

#if defined(INCLUDE_TEMPLATES) && !defined(RESOURCEMANAGERT_CC)
344
#include "ResourceManagerT_impl.hh"
345
346
#endif