ResourceManagerT.cc 10.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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*===========================================================================*\
 *                                                                           *
 *                            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$                                                *
 *                                                                           *
\*===========================================================================*/

#define RESOURCEMANAGERT_CC

#include "ResourceManager.hh"

#include "PropertyDefines.hh"

#include "PropertyPtr.hh"

namespace OpenVolumeMesh {

template<class T>
VertexPropertyT<T> ResourceManager::request_vertex_property(const std::string& _name) {

Mike Kremer's avatar
Mike Kremer committed
56 57 58 59 60
    for(std::vector<BaseProperty*>::iterator it = persistent_vprops_.begin();
            it != persistent_vprops_.end(); ++it) {
        if((*it)->name() == _name) {
            VertexPropertyT<T>* prop = dynamic_cast<VertexPropertyT<T>* >(*it);
            return *prop;
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
        }
    }

    VertexPropHandle handle = vertex_props_.size();

    VertexPropertyT<T>* prop = new VertexPropertyT<T>(_name, *this, handle);
    (*prop)->resize(n_vertices());

    // Store property pointer
    vertex_props_.push_back(prop);

    // Decrease reference counter by one
    // since the property is going to be copied
    // on return
    --(*prop).h_->count_;

    return *prop;
}

template<class T>
EdgePropertyT<T> ResourceManager::request_edge_property(const std::string& _name) {

Mike Kremer's avatar
Mike Kremer committed
83 84 85 86 87
    for(std::vector<BaseProperty*>::iterator it = persistent_eprops_.begin();
            it != persistent_eprops_.end(); ++it) {
        if((*it)->name() == _name) {
            EdgePropertyT<T>* prop = dynamic_cast<EdgePropertyT<T>* >(*it);
            return *prop;
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        }
    }

    EdgePropHandle handle = edge_props_.size();

    EdgePropertyT<T>* prop = new EdgePropertyT<T>(_name, *this, handle);
    (*prop)->resize(n_edges());

    // Store property pointer
    edge_props_.push_back(prop);

    // Decrease reference counter by one
    // since the property is going to be copied
    // on return
    --(*prop).h_->count_;

    return *prop;
}

template<class T>
HalfEdgePropertyT<T> ResourceManager::request_halfedge_property(const std::string& _name) {

Mike Kremer's avatar
Mike Kremer committed
110 111 112 113 114
    for(std::vector<BaseProperty*>::iterator it = persistent_heprops_.begin();
            it != persistent_heprops_.end(); ++it) {
        if((*it)->name() == _name) {
            HalfEdgePropertyT<T>* prop = dynamic_cast<HalfEdgePropertyT<T>* >(*it);
            return *prop;
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
        }
    }

    HalfEdgePropHandle handle = halfedge_props_.size();

    HalfEdgePropertyT<T>* prop = new HalfEdgePropertyT<T>(_name, *this, handle);
    (*prop)->resize(n_halfedges());

    // Store property pointer
    halfedge_props_.push_back(prop);

    // Decrease reference counter by one
    // since the property is going to be copied
    // on return
    --(*prop).h_->count_;

    return *prop;
}

template<class T>
FacePropertyT<T> ResourceManager::request_face_property(const std::string& _name) {

Mike Kremer's avatar
Mike Kremer committed
137 138 139 140 141
    for(std::vector<BaseProperty*>::iterator it = persistent_fprops_.begin();
            it != persistent_fprops_.end(); ++it) {
        if((*it)->name() == _name) {
            FacePropertyT<T>* prop = dynamic_cast<FacePropertyT<T>* >(*it);
            return *prop;
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
        }
    }

    FacePropHandle handle = face_props_.size();

    FacePropertyT<T>* prop = new FacePropertyT<T>(_name, *this, handle);
    (*prop)->resize(n_faces());

    // Store property pointer
    face_props_.push_back(prop);

    // Decrease reference counter by one
    // since the property is going to be copied
    // on return
    --(*prop).h_->count_;

    return *prop;
}

template<class T>
HalfFacePropertyT<T> ResourceManager::request_halfface_property(const std::string& _name) {

Mike Kremer's avatar
Mike Kremer committed
164 165 166 167 168
    for(std::vector<BaseProperty*>::iterator it = persistent_hfprops_.begin();
            it != persistent_hfprops_.end(); ++it) {
        if((*it)->name() == _name) {
            HalfFacePropertyT<T>* prop = dynamic_cast<HalfFacePropertyT<T>* >(*it);
            return *prop;
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
        }
    }

    HalfFacePropHandle handle = halfface_props_.size();

    HalfFacePropertyT<T>* prop = new HalfFacePropertyT<T>(_name, *this, handle);
    (*prop)->resize(n_halffaces());

    // Store property pointer
    halfface_props_.push_back(prop);

    // Decrease reference counter by one
    // since the property is going to be copied
    // on return
    --(*prop).h_->count_;

    return *prop;
}

template<class T>
CellPropertyT<T> ResourceManager::request_cell_property(const std::string& _name) {

Mike Kremer's avatar
Mike Kremer committed
191 192 193 194 195
    for(std::vector<BaseProperty*>::iterator it = persistent_cprops_.begin();
            it != persistent_cprops_.end(); ++it) {
        if((*it)->name() == _name) {
            CellPropertyT<T>* prop = dynamic_cast<CellPropertyT<T>* >(*it);
            return *prop;
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
        }
    }

    CellPropHandle handle = cell_props_.size();

    CellPropertyT<T>* prop = new CellPropertyT<T>(_name, *this, handle);
    (*prop)->resize(n_cells());

    // Store property pointer
    cell_props_.push_back(prop);

    // Decrease reference counter by one
    // since the property is going to be copied
    // on return
    --(*prop).h_->count_;

    return *prop;
}

template<class T>
MeshPropertyT<T> ResourceManager::request_mesh_property(const std::string& _name) {

Mike Kremer's avatar
Mike Kremer committed
218 219 220 221 222
    for(std::vector<BaseProperty*>::iterator it = persistent_mprops_.begin();
            it != persistent_mprops_.end(); ++it) {
        if((*it)->name() == _name) {
            MeshPropertyT<T>* prop = dynamic_cast<MeshPropertyT<T>* >(*it);
            return *prop;
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
        }
    }

    MeshPropHandle handle = mesh_props_.size();

    MeshPropertyT<T>* prop = new MeshPropertyT<T>(_name, *this, handle);
    (*prop)->resize(1u);

    // Store property pointer
    mesh_props_.push_back(prop);

    // Decrease reference counter by one
    // since the property is going to be copied
    // on return
    --(*prop).h_->count_;

    return *prop;
}

Mike Kremer's avatar
Mike Kremer committed
242 243 244
template<class T>
void ResourceManager::set_persistent(VertexPropertyT<T>& _prop) {

245 246
    if(_prop.h_->persistent_) return;
    _prop.h_->persistent_ = true;
Mike Kremer's avatar
Mike Kremer committed
247 248 249 250 251 252 253
    VertexPropertyT<T>* prop = new VertexPropertyT<T>(_prop);
    persistent_vprops_.push_back(prop);
}

template<class T>
void ResourceManager::set_persistent(EdgePropertyT<T>& _prop) {

254 255
    if(_prop.h_->persistent_) return;
    _prop.h_->persistent_ = true;
Mike Kremer's avatar
Mike Kremer committed
256 257 258 259 260 261 262
    EdgePropertyT<T>* prop = new EdgePropertyT<T>(_prop);
    persistent_eprops_.push_back(prop);
}

template<class T>
void ResourceManager::set_persistent(HalfEdgePropertyT<T>& _prop) {

263 264
    if(_prop.h_->persistent_) return;
    _prop.h_->persistent_ = true;
Mike Kremer's avatar
Mike Kremer committed
265 266 267 268 269 270 271
    HalfEdgePropertyT<T>* prop = new HalfEdgePropertyT<T>(_prop);
    persistent_heprops_.push_back(prop);
}

template<class T>
void ResourceManager::set_persistent(FacePropertyT<T>& _prop) {

272 273
    if(_prop.h_->persistent_) return;
    _prop.h_->persistent_ = true;
Mike Kremer's avatar
Mike Kremer committed
274 275 276 277 278 279 280
    FacePropertyT<T>* prop = new FacePropertyT<T>(_prop);
    persistent_fprops_.push_back(prop);
}

template<class T>
void ResourceManager::set_persistent(HalfFacePropertyT<T>& _prop) {

281 282
    if(_prop.h_->persistent_) return;
    _prop.h_->persistent_ = true;
Mike Kremer's avatar
Mike Kremer committed
283 284 285 286 287 288 289
    HalfFacePropertyT<T>* prop = new HalfFacePropertyT<T>(_prop);
    persistent_hfprops_.push_back(prop);
}

template<class T>
void ResourceManager::set_persistent(CellPropertyT<T>& _prop) {

290 291
    if(_prop.h_->persistent_) return;
    _prop.h_->persistent_ = true;
Mike Kremer's avatar
Mike Kremer committed
292 293 294 295 296 297 298
    CellPropertyT<T>* prop = new CellPropertyT<T>(_prop);
    persistent_cprops_.push_back(prop);
}

template<class T>
void ResourceManager::set_persistent(MeshPropertyT<T>& _prop) {

299 300
    if(_prop.h_->persistent_) return;
    _prop.h_->persistent_ = true;
Mike Kremer's avatar
Mike Kremer committed
301 302 303 304
    MeshPropertyT<T>* prop = new MeshPropertyT<T>(_prop);
    persistent_mprops_.push_back(prop);
}

305
} // Namespace OpenVolumeMesh