42 #ifndef PROPERTYMANAGER_HH_ 43 #define PROPERTYMANAGER_HH_ 45 #include <OpenMesh/Core/System/config.h> 46 #include <OpenMesh/Core/Utils/HandleToPropHandle.hh> 76 template<
typename PROPTYPE,
typename MeshT>
78 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 113 PropertyManager(MeshT &mesh,
const char *propname,
bool existing =
false) : mesh_(&mesh), retain_(existing), name_(propname) {
115 if (!mesh_->get_property_handle(prop_, propname)) {
116 std::ostringstream oss;
117 oss <<
"Requested property handle \"" << propname <<
"\" does not exist.";
118 throw std::runtime_error(oss.str());
121 mesh_->add_property(prop_, propname);
133 std::swap(mesh_, rhs.mesh_);
134 std::swap(prop_, rhs.prop_);
135 std::swap(retain_, rhs.retain_);
136 std::swap(name_, rhs.name_);
139 static bool propertyExists(MeshT &mesh,
const char *propname) {
141 return mesh.get_property_handle(dummy, propname);
144 bool isValid()
const {
return mesh_ != 0; }
145 operator bool()
const {
return isValid(); }
147 const PROPTYPE &getRawProperty()
const {
return prop_; }
149 const std::string &getName()
const {
return name_; }
151 MeshT &getMesh()
const {
return *mesh_; }
153 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 173 retain_ = rhs.retain_;
189 PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
191 return std::move(pm);
203 template<
typename PROP_VALUE,
typename ITERATOR_TYPE>
205 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
206 const PROP_VALUE &init_value) {
207 const bool exists = propertyExists(mesh, propname);
212 return std::move(pm);
224 template<
typename PROP_VALUE,
typename ITERATOR_RANGE>
226 const ITERATOR_RANGE &range,
const PROP_VALUE &init_value) {
228 mesh, propname, range.begin(), range.end(), init_value);
233 pm.mesh_->property(pm.prop_) = mesh_->property(prop_);
241 return std::move(*
this);
247 Proxy(MeshT *mesh_, PROPTYPE prop_,
bool retain_,
const std::string &name_) :
248 mesh_(mesh_), prop_(prop_), retain_(retain_), name_(name_) {}
258 Proxy p(mesh_, prop_, retain_, name_);
268 PropertyManager(Proxy p) : mesh_(p.mesh_), prop_(p.prop_), retain_(p.retain_), name_(p.name_) {}
284 PropertyManager pm(mesh, propname, mesh.get_property_handle(dummy_prop, propname));
298 template<
typename PROP_VALUE,
typename ITERATOR_TYPE>
300 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
301 const PROP_VALUE &init_value) {
302 const bool exists = propertyExists(mesh, propname);
310 Proxy duplicate(
const char *clone_name) {
312 pm.mesh_->property(pm.prop_) = mesh_->property(prop_);
323 inline void retain(
bool doRetain =
true) {
348 template<
typename HandleType>
349 inline typename PROPTYPE::reference
operator[] (
const HandleType &handle) {
350 return mesh_->property(prop_, handle);
360 template<
typename HandleType>
361 inline typename PROPTYPE::const_reference
operator[] (
const HandleType &handle)
const {
362 return mesh_->property(prop_, handle);
389 template<
typename HandleTypeIterator,
typename PROP_VALUE>
390 void set_range(HandleTypeIterator begin, HandleTypeIterator end,
391 const PROP_VALUE &value) {
392 for (; begin != end; ++begin)
393 (*
this)[*begin] = value;
396 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 397 template<
typename HandleTypeIteratorRange,
typename PROP_VALUE>
398 void set_range(
const HandleTypeIteratorRange &range,
399 const PROP_VALUE &value) {
400 set_range(range.begin(), range.end(), value);
418 template<
typename HandleTypeIterator,
typename PROPTYPE_2,
419 typename MeshT_2,
typename HandleTypeIterator_2>
420 void copy_to(HandleTypeIterator begin, HandleTypeIterator end,
422 HandleTypeIterator_2 dst_begin, HandleTypeIterator_2 dst_end)
const {
424 for (; begin != end && dst_begin != dst_end; ++begin, ++dst_begin) {
425 dst_propmanager[*dst_begin] = (*this)[*begin];
429 template<
typename RangeType,
typename PROPTYPE_2,
430 typename MeshT_2,
typename RangeType_2>
431 void copy_to(
const RangeType &range,
433 const RangeType_2 &dst_range)
const {
434 copy_to(range.begin(), range.end(), dst_propmanager,
435 dst_range.begin(), dst_range.end());
452 template<
typename RangeType,
typename MeshT_2,
typename RangeType_2>
453 static void copy(
const char *prop_name,
454 MeshT &src_mesh,
const RangeType &src_range,
455 MeshT_2 &dst_mesh,
const RangeType_2 &dst_range) {
458 DstPM dst(DstPM::createIfNotExists(dst_mesh, prop_name));
461 SrcPM src(src_mesh, prop_name,
true);
463 src.copy_to(src_range, dst, dst_range);
467 void deleteProperty() {
469 mesh_->remove_property(prop_);
505 template<
typename ElementT,
typename T,
typename MeshT>
539 template<
typename ElementT,
typename T,
typename MeshT>
542 return PropertyManager<typename HandleToPropHandle<ElementT, T>::type, MeshT>(mesh, propname,
true);
575 template<
typename ElementT,
typename T,
typename MeshT>
576 PropertyManager<typename HandleToPropHandle<ElementT, T>::type, MeshT>
578 return PropertyManager<typename HandleToPropHandle<ElementT, T>::type, MeshT>
::createIfNotExists(mesh, propname);
590 template<
typename PROPTYPE,
typename MeshT>
591 OM_DEPRECATED(
"Use makeTemporaryProperty instead.")
609 template<
typename PROPTYPE,
typename MeshT>
610 OM_DEPRECATED(
"Use getProperty instead.")
624 template<
typename PROPTYPE,
typename MeshT>
625 OM_DEPRECATED(
"Use getOrMakeProperty instead.")
642 template<
typename PROPTYPE,
typename MeshT,
643 typename ITERATOR_TYPE,
typename PROP_VALUE>
645 MeshT &mesh,
const char *propname,
646 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
647 const PROP_VALUE &init_value) {
649 mesh, propname, begin, end, init_value);
663 template<
typename PROPTYPE,
typename MeshT,
664 typename ITERATOR_RANGE,
typename PROP_VALUE>
666 MeshT &mesh,
const char *propname,
667 const ITERATOR_RANGE &range,
668 const PROP_VALUE &init_value) {
669 return makePropertyManagerFromExistingOrNew<PROPTYPE, MeshT>(
670 mesh, propname, range.begin(), range.end(), init_value);
static void copy(const char *prop_name, MeshT &src_mesh, const RangeType &src_range, MeshT_2 &dst_mesh, const RangeType_2 &dst_range)
Copy the values of a property from a source range to a target range.
Definition: PropertyManager.hh:453
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:77
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExisting(MeshT &mesh, const char *propname)
Definition: PropertyManager.hh:611
Definition: PropertyManager.hh:245
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Conveniently set the property for an entire range of values.
Definition: PropertyManager.hh:390
PropertyManager< typename HandleToPropHandle< ElementT, T >::type, MeshT > getProperty(MeshT &mesh, const char *propname)
Definition: PropertyManager.hh:541
PROPTYPE::reference operator[](const HandleType &handle)
Enables convenient access to the encapsulated property.
Definition: PropertyManager.hh:349
static Proxy createIfNotExists(MeshT &mesh, const char *propname)
Create a property manager for the supplied property and mesh.
Definition: PropertyManager.hh:282
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromNew(MeshT &mesh, const char *propname)
Definition: PropertyManager.hh:592
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
static Proxy createIfNotExists(MeshT &mesh, const char *propname, const ITERATOR_TYPE &begin, const ITERATOR_TYPE &end, const PROP_VALUE &init_value)
Like createIfNotExists() with two parameters except, if the property doesn't exist, it is initialized with the supplied value over the supplied range after creation.
Definition: PropertyManager.hh:299
PropertyManager< typename HandleToPropHandle< ElementT, T >::type, MeshT > makeTemporaryProperty(MeshT &mesh, const char *propname="")
Definition: PropertyManager.hh:507
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(MeshT &mesh, const char *propname, const ITERATOR_TYPE &begin, const ITERATOR_TYPE &end, const PROP_VALUE &init_value)
Definition: PropertyManager.hh:644
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(MeshT &mesh, const char *propname)
Definition: PropertyManager.hh:626
PROPTYPE & operator*()
Access the encapsulated property.
Definition: PropertyManager.hh:330
void copy_to(HandleTypeIterator begin, HandleTypeIterator end, PropertyManager< PROPTYPE_2, MeshT_2 > &dst_propmanager, HandleTypeIterator_2 dst_begin, HandleTypeIterator_2 dst_end) const
Conveniently transfer the values managed by one property manager onto the values managed by a differe...
Definition: PropertyManager.hh:420
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(MeshT &mesh, const char *propname, const ITERATOR_RANGE &range, const PROP_VALUE &init_value)
Definition: PropertyManager.hh:665
PropertyManager< typename HandleToPropHandle< ElementT, T >::type, MeshT > getOrMakeProperty(MeshT &mesh, const char *propname)
Definition: PropertyManager.hh:577
void retain(bool doRetain=true)
Disable lifecycle management for this property.
Definition: PropertyManager.hh:323
PropertyManager(MeshT &mesh, const char *propname, bool existing=false)
Constructor.
Definition: PropertyManager.hh:113