ResourceManager.cc 9.82 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 46 47 48 49 50 51 52 53
/*===========================================================================*\
 *                                                                           *
 *                            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$                                                *
 *                                                                           *
\*===========================================================================*/

#include "ResourceManager.hh"
#include "BaseProperty.hh"

namespace OpenVolumeMesh {

ResourceManager::ResourceManager() {
}

ResourceManager::~ResourceManager() {

    // Delete all persistent properties
Mike Kremer's avatar
Mike Kremer committed
54 55
    for(std::vector<BaseProperty*>::iterator it = persistent_vprops_.begin();
            it != persistent_vprops_.end(); ++it) {
56 57
        delete *it;
    }
Mike Kremer's avatar
Mike Kremer committed
58 59 60
    persistent_vprops_.clear();
    for(std::vector<BaseProperty*>::iterator it = persistent_eprops_.begin();
            it != persistent_eprops_.end(); ++it) {
61 62
        delete *it;
    }
Mike Kremer's avatar
Mike Kremer committed
63 64 65
    persistent_eprops_.clear();
    for(std::vector<BaseProperty*>::iterator it = persistent_heprops_.begin();
            it != persistent_heprops_.end(); ++it) {
66 67
        delete *it;
    }
Mike Kremer's avatar
Mike Kremer committed
68 69 70
    persistent_heprops_.clear();
    for(std::vector<BaseProperty*>::iterator it = persistent_fprops_.begin();
            it != persistent_fprops_.end(); ++it) {
71 72
        delete *it;
    }
Mike Kremer's avatar
Mike Kremer committed
73 74 75
    persistent_fprops_.clear();
    for(std::vector<BaseProperty*>::iterator it = persistent_hfprops_.begin();
            it != persistent_hfprops_.end(); ++it) {
76 77
        delete *it;
    }
Mike Kremer's avatar
Mike Kremer committed
78 79 80
    persistent_hfprops_.clear();
    for(std::vector<BaseProperty*>::iterator it = persistent_cprops_.begin();
            it != persistent_cprops_.end(); ++it) {
81 82
        delete *it;
    }
Mike Kremer's avatar
Mike Kremer committed
83 84 85
    persistent_cprops_.clear();
    for(std::vector<BaseProperty*>::iterator it = persistent_mprops_.begin();
            it != persistent_mprops_.end(); ++it) {
86 87
        delete *it;
    }
Mike Kremer's avatar
Mike Kremer committed
88
    persistent_mprops_.clear();
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
}

void ResourceManager::resize_vprops(unsigned int _nv) {

    for(std::vector<BaseProperty*>::iterator it = vertex_props_.begin();
            it != vertex_props_.end(); ++it) {
        (*it)->resize(_nv);
    }
}

void ResourceManager::resize_eprops(unsigned int _ne) {

    for(std::vector<BaseProperty*>::iterator it = edge_props_.begin();
            it != edge_props_.end(); ++it) {
        (*it)->resize(_ne);
    }
    for(std::vector<BaseProperty*>::iterator it = halfedge_props_.begin();
            it != halfedge_props_.end(); ++it) {
        (*it)->resize(2u*_ne);
    }
}

void ResourceManager::resize_fprops(unsigned int _nf) {

    for(std::vector<BaseProperty*>::iterator it = face_props_.begin();
            it != face_props_.end(); ++it) {
        (*it)->resize(_nf);
    }
    for(std::vector<BaseProperty*>::iterator it = halfface_props_.begin();
            it != halfface_props_.end(); ++it) {
        (*it)->resize(2u*_nf);
    }
}

void ResourceManager::resize_cprops(unsigned int _nc) {

125 126
    for(std::vector<BaseProperty*>::iterator it = cell_props_.begin();
            it != cell_props_.end(); ++it) {
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
        (*it)->resize(_nc);
    }
}

void ResourceManager::vertex_deleted(const VertexHandle& _h) {

    for(std::vector<BaseProperty*>::iterator it = vertex_props_.begin();
            it != vertex_props_.end(); ++it) {
        (*it)->delete_element(_h.idx());
    }
}

void ResourceManager::edge_deleted(const EdgeHandle& _h) {

    for(std::vector<BaseProperty*>::iterator it = edge_props_.begin();
            it != edge_props_.end(); ++it) {
        (*it)->delete_element(_h.idx());
    }
    for(std::vector<BaseProperty*>::iterator it = halfedge_props_.begin();
            it != halfedge_props_.end(); ++it) {
        (*it)->delete_element(_h.idx()*2 + 1);
        (*it)->delete_element(_h.idx()*2);
    }
}

void ResourceManager::face_deleted(const FaceHandle& _h) {

    for(std::vector<BaseProperty*>::iterator it = face_props_.begin();
            it != face_props_.end(); ++it) {
        (*it)->delete_element(_h.idx());
    }
    for(std::vector<BaseProperty*>::iterator it = halfface_props_.begin();
            it != halfface_props_.end(); ++it) {
        (*it)->delete_element(_h.idx()*2 + 1);
        (*it)->delete_element(_h.idx()*2);
    }
}

void ResourceManager::cell_deleted(const CellHandle& _h) {

    for(std::vector<BaseProperty*>::iterator it = cell_props_.begin();
            it != cell_props_.end(); ++it) {
        (*it)->delete_element(_h.idx());
    }
}

void ResourceManager::released_property(VertexPropHandle _handle) {

Mike Kremer's avatar
Mike Kremer committed
175
    delete (*(vertex_props_.begin() + _handle.idx()));
176
    std::vector<BaseProperty*>::iterator it = vertex_props_.erase(vertex_props_.begin() + _handle.idx());
177
    VertexPropHandle decrHandle(_handle.idx());
178 179
    for(; it < vertex_props_.end(); ++it) {
        (*it)->set_handle(decrHandle);
180
        decrHandle.idx(decrHandle.idx()+1);
181 182 183 184 185
    }
}

void ResourceManager::released_property(EdgePropHandle _handle) {

Mike Kremer's avatar
Mike Kremer committed
186
    delete (*(edge_props_.begin() + _handle.idx()));
187
    std::vector<BaseProperty*>::iterator it = edge_props_.erase(edge_props_.begin() + _handle.idx());
188
    EdgePropHandle decrHandle(_handle.idx());
189 190
    for(; it < edge_props_.end(); ++it) {
        (*it)->set_handle(decrHandle);
191
        decrHandle.idx(decrHandle.idx()+1);
192 193 194 195 196
    }
}

void ResourceManager::released_property(HalfEdgePropHandle _handle) {

Mike Kremer's avatar
Mike Kremer committed
197
    delete (*(halfedge_props_.begin() + _handle.idx()));
198
    std::vector<BaseProperty*>::iterator it = halfedge_props_.erase(halfedge_props_.begin() + _handle.idx());
199
    HalfEdgePropHandle decrHandle(_handle.idx());
200 201
    for(; it < halfedge_props_.end(); ++it) {
        (*it)->set_handle(decrHandle);
202
        decrHandle.idx(decrHandle.idx()+1);
203 204 205 206 207
    }
}

void ResourceManager::released_property(FacePropHandle _handle) {

Mike Kremer's avatar
Mike Kremer committed
208
    delete (*(face_props_.begin() + _handle.idx()));
209
    std::vector<BaseProperty*>::iterator it = face_props_.erase(face_props_.begin() + _handle.idx());
210
    FacePropHandle decrHandle(_handle.idx());
211 212
    for(; it < face_props_.end(); ++it) {
        (*it)->set_handle(decrHandle);
213
        decrHandle.idx(decrHandle.idx()+1);
214 215 216 217 218
    }
}

void ResourceManager::released_property(HalfFacePropHandle _handle) {

Mike Kremer's avatar
Mike Kremer committed
219
    delete (*(halfface_props_.begin() + _handle.idx()));
220
    std::vector<BaseProperty*>::iterator it = halfface_props_.erase(halfface_props_.begin() + _handle.idx());
221
    HalfFacePropHandle decrHandle(_handle.idx());
222 223
    for(; it < halfface_props_.end(); ++it) {
        (*it)->set_handle(decrHandle);
224
        decrHandle.idx(decrHandle.idx()+1);
225 226 227 228 229
    }
}

void ResourceManager::released_property(CellPropHandle _handle) {

Mike Kremer's avatar
Mike Kremer committed
230
    delete (*(cell_props_.begin() + _handle.idx()));
231
    std::vector<BaseProperty*>::iterator it = cell_props_.erase(cell_props_.begin() + _handle.idx());
232
    CellPropHandle decrHandle(_handle.idx());
233 234
    for(; it < cell_props_.end(); ++it) {
        (*it)->set_handle(decrHandle);
235
        decrHandle.idx(decrHandle.idx()+1);
236 237 238 239 240
    }
}

void ResourceManager::released_property(MeshPropHandle _handle) {

Mike Kremer's avatar
Mike Kremer committed
241
    delete (*(mesh_props_.begin() + _handle.idx()));
242
    std::vector<BaseProperty*>::iterator it = mesh_props_.erase(mesh_props_.begin() + _handle.idx());
243
    MeshPropHandle decrHandle(_handle.idx());
244 245
    for(; it < mesh_props_.end(); ++it) {
        (*it)->set_handle(decrHandle);
246
        decrHandle.idx(decrHandle.idx()+1);
247 248 249 250
    }
}

} // Namespace OpenVolumeMesh