ResourceManager.hh 13 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
35
36
37
38
39
40
41
42
43
44
45
/*===========================================================================*\
 *                                                                           *
 *                            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/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Date$                    *
 *   $LastChangedBy$                                                *
 *                                                                           *
\*===========================================================================*/

#ifndef RESOURCEMANAGER_HH_
#define RESOURCEMANAGER_HH_

46
47
48
#ifndef NDEBUG
#include <iostream>
#endif
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <string>
#include <vector>

#include "OpenVolumeMeshProperty.hh"
#include "PropertyHandles.hh"

namespace OpenVolumeMesh {

// Forward declarations
class BaseProperty;
template <class T>
class VertexPropertyT;
template <class T>
class EdgePropertyT;
template <class T>
class HalfEdgePropertyT;
template <class T>
class FacePropertyT;
template <class T>
class HalfFacePropertyT;
template <class T>
class CellPropertyT;
template <class T>
class MeshPropertyT;
73
74
template <class PropT, class HandleT>
class PropertyPtr;
75
76
77
78

class ResourceManager {
public:
    ResourceManager();
79
    ResourceManager(const ResourceManager &other);
80
81
    ResourceManager& operator=(const ResourceManager &other) = delete;

82
83
    virtual ~ResourceManager();

84
85
    template <class PropT, class HandleT> friend class PropertyPtr;

86
    /// Change size of stored vertex properties
87
    void resize_vprops(size_t _nv);
88
89

    /// Change size of stored edge properties
90
    void resize_eprops(size_t _ne);
91
92

    /// Change size of stored face properties
93
    void resize_fprops(size_t _nf);
94
95

    /// Change size of stored cell properties
96
    void resize_cprops(size_t _nc);
97

98
99
protected:

100
101
102
103
104
105
106
107
    void vertex_deleted(const VertexHandle& _h);

    void edge_deleted(const EdgeHandle& _h);

    void face_deleted(const FaceHandle& _h);

    void cell_deleted(const CellHandle& _h);

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    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)
125
            (*p_iter)->swap_elements(_h1.idx(), _h2.idx());
126
127
128
    }


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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_); }

145
    /// Get number of vertices in mesh
146
    virtual size_t n_vertices() const = 0;
147
    /// Get number of edges in mesh
148
    virtual size_t n_edges() const = 0;
149
    /// Get number of halfedges in mesh
150
    virtual size_t n_halfedges() const = 0;
151
    /// Get number of faces in mesh
152
    virtual size_t n_faces() const = 0;
153
    /// Get number of halffaces in mesh
154
    virtual size_t n_halffaces() const = 0;
155
    /// Get number of cells in mesh
156
    virtual size_t n_cells() const = 0;
157

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

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

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

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

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

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

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

172
173
private:

174
    void release_property(VertexPropHandle _handle);
175

176
    void release_property(EdgePropHandle _handle);
177

178
    void release_property(HalfEdgePropHandle _handle);
179

180
    void release_property(FacePropHandle _handle);
181

182
    void release_property(HalfFacePropHandle _handle);
183

184
    void release_property(CellPropHandle _handle);
185

186
    void release_property(MeshPropHandle _handle);
187

188
189
public:

190
    size_t n_vertex_props() const { return vertex_props_.size(); }
191

192
    size_t n_edge_props() const { return edge_props_.size(); }
193

194
    size_t n_halfedge_props() const { return halfedge_props_.size(); }
195

196
    size_t n_face_props() const { return face_props_.size(); }
197

198
    size_t n_halfface_props() const { return halfface_props_.size(); }
199

200
    size_t n_cell_props() const { return cell_props_.size(); }
201

202
    size_t n_mesh_props() const { return mesh_props_.size(); }
203

204
    template<class T> void set_persistent(VertexPropertyT<T>& _prop, bool _flag = true);
Mike Kremer's avatar
Mike Kremer committed
205

206
    template<class T> void set_persistent(EdgePropertyT<T>& _prop, bool _flag = true);
Mike Kremer's avatar
Mike Kremer committed
207

208
    template<class T> void set_persistent(HalfEdgePropertyT<T>& _prop, bool _flag = true);
Mike Kremer's avatar
Mike Kremer committed
209

210
    template<class T> void set_persistent(FacePropertyT<T>& _prop, bool _flag = true);
Mike Kremer's avatar
Mike Kremer committed
211

212
    template<class T> void set_persistent(HalfFacePropertyT<T>& _prop, bool _flag = true);
Mike Kremer's avatar
Mike Kremer committed
213

214
    template<class T> void set_persistent(CellPropertyT<T>& _prop, bool _flag = true);
Mike Kremer's avatar
Mike Kremer committed
215

216
    template<class T> void set_persistent(MeshPropertyT<T>& _prop, bool _flag = true);
Mike Kremer's avatar
Mike Kremer committed
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    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(); }

248
249
private:

250
    template <class FullPropT, class PropIterT>
251
252
    bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const {

253
254
255
256
257
        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
258
259
260
261
            return false;
        }

        PropIterT it = _begin;
David Bommes's avatar
David Bommes committed
262
263
264
265
266
267
268
269
270
271
272
273
        for(; it != _end; ++it)
        {
            if((*it)->name() == _name )
            {
#if OVM_FORCE_STATIC_CAST
            return true;
#else
            if(dynamic_cast<FullPropT*>(*it) != NULL)
            {
            return true;
            }
#endif
274
            }
275
276
277
278
        }
        return false;
    }

279
280
public:

281
    template <class PropT>
282
    bool vertex_property_exists(const std::string& _name) const {
283
        return property_exists<VertexPropertyT<PropT> >(vertex_props_begin(), vertex_props_end(), _name);
284
285
    }

286
    template <class PropT>
287
    bool edge_property_exists(const std::string& _name) const {
288
        return property_exists<EdgePropertyT<PropT> >(edge_props_begin(), edge_props_end(), _name);
289
290
    }

291
    template <class PropT>
292
    bool halfedge_property_exists(const std::string& _name) const {
293
        return property_exists<HalfEdgePropertyT<PropT> >(halfedge_props_begin(), halfedge_props_end(), _name);
294
295
    }

296
    template <class PropT>
297
    bool face_property_exists(const std::string& _name) const {
298
        return property_exists<FacePropertyT<PropT> >(face_props_begin(), face_props_end(), _name);
299
300
    }

301
    template <class PropT>
302
    bool halfface_property_exists(const std::string& _name) const {
303
        return property_exists<HalfFacePropertyT<PropT> >(halfface_props_begin(), halfface_props_end(), _name);
304
305
    }

306
    template <class PropT>
307
    bool cell_property_exists(const std::string& _name) const {
308
        return property_exists<CellPropertyT<PropT> >(cell_props_begin(), cell_props_end(), _name);
309
310
    }

311
    template <class PropT>
312
    bool mesh_property_exists(const std::string& _name) const {
313
        return property_exists<MeshPropertyT<PropT> >(mesh_props_begin(), mesh_props_end(), _name);
314
315
    }

316
317
318
319
320
321
322
323
324
325
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);

326
327
private:

328
    template<class StdVecT>
329
    void resize_props(StdVecT& _vec, size_t _n);
330
331
332
333
334
335
336

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

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

337
338
    template<class StdVecT, class PropT, class HandleT, class T>
    PropT request_property(StdVecT& _vec, const std::string& _name, size_t _size, const T _def = T());
339
340
341
342
343
344
345

    template<class PropT>
    void set_persistentT(PropT& _prop, bool _flag);

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

346
    Properties vertex_props_;
347

348
    Properties edge_props_;
349

350
    Properties halfedge_props_;
351

352
    Properties face_props_;
353

354
    Properties halfface_props_;
355

356
    Properties cell_props_;
357

358
    Properties mesh_props_;
359
360
361
362
363
};

}

#if defined(INCLUDE_TEMPLATES) && !defined(RESOURCEMANAGERT_CC)
364
#include "ResourceManagerT_impl.hh"
365
366
367
#endif

#endif /* RESOURCEMANAGER_HH_ */