42 #ifndef PROPERTYMANAGER_HH_
43 #define PROPERTYMANAGER_HH_
45 #include <OpenMesh/Core/System/config.h>
46 #include <OpenMesh/Core/Utils/HandleToPropHandle.hh>
47 #include <OpenMesh/Core/Mesh/PolyConnectivity.hh>
75 template<
typename PROPTYPE,
typename MeshT =
int>
79 using Value =
typename PROPTYPE::Value;
80 using value_type =
typename PROPTYPE::value_type;
81 using Handle =
typename PROPTYPE::Handle;
83 using Reference =
typename PROPTYPE::reference;
84 using ConstReference =
typename PROPTYPE::const_reference;
90 template <
typename PropertyManager2,
typename PropHandleT>
94 template <
typename PropertyManager2>
103 std::swap(*to, *from);
105 static ConstReference access_property_const(
PolyConnectivity& mesh,
const PROPTYPE& prop_handle,
const Handle&) {
108 static Reference access_property(
PolyConnectivity& mesh,
const PROPTYPE& prop_handle,
const Handle&) {
114 template <
typename PropertyManager2,
typename PropHandleT>
117 pm.
set_range(pm.mesh_.template all_elements<Handle>(), initial_value);
120 from.
copy_to(from.mesh_.template all_elements<Handle>(), to, to.mesh_.template all_elements<Handle>());
123 std::swap(lhs.mesh().
property(lhs.prop_).data_vector(), rhs.mesh().property(rhs.prop_).data_vector());
125 lhs.mesh().
property(lhs.prop_).resize(lhs.mesh().template n_elements<Handle>());
126 rhs.mesh().property(rhs.prop_).resize(rhs.mesh().template n_elements<Handle>());
128 static ConstReference access_property_const(
PolyConnectivity& mesh,
const PROPTYPE& prop_handle,
const Handle& handle) {
129 return mesh.
property(prop_handle, handle);
131 static Reference access_property(
PolyConnectivity& mesh,
const PROPTYPE& prop_handle,
const Handle& handle) {
132 return mesh.
property(prop_handle, handle);
136 using Storage = StorageT<Self, PROPTYPE>;
159 OM_DEPRECATED(
"Use the constructor without parameter 'existing' instead. Check for existance with hasProperty")
162 if (!PropertyManager::mesh().get_property_handle(prop_, propname)) {
163 std::ostringstream oss;
164 oss <<
"Requested property handle \"" << propname <<
"\" does not exist.";
165 throw std::runtime_error(oss.str());
168 PropertyManager::mesh().add_property(prop_, propname);
181 if (!PropertyManager::mesh().get_property_handle(prop_, propname)) {
182 PropertyManager::mesh().add_property(prop_, propname);
198 PropertyManager::mesh().add_property(prop_, propname);
199 Storage::initialize(*
this, initial_value);
211 PropertyManager::mesh().add_property(prop_, name_);
223 PropertyManager::mesh().add_property(prop_, name_);
224 Storage::initialize(*
this, initial_value);
244 retain_(rhs.retain_),
253 PropertyManager::mesh().add_property(prop_, name_);
254 Storage::copy(rhs, *
this);
267 Storage::copy(*
this, result);
273 if (&mesh_ == &rhs.mesh_ && prop_ == rhs.prop_)
276 Storage::copy(rhs, *
this);
284 void swap(PropertyManager &rhs) {
286 Storage::swap(rhs, *
this);
289 static bool propertyExists(PolyConnectivity &mesh,
const char *propname) {
291 return mesh.get_property_handle(dummy, propname);
294 bool isValid()
const {
return prop_.is_valid(); }
295 operator bool()
const {
return isValid(); }
297 const PROPTYPE &getRawProperty()
const {
return prop_; }
299 const std::string &getName()
const {
return name_; }
314 template <
typename MeshType >
315 const MeshType& getMesh()
const {
return dynamic_cast<const MeshType&
>(mesh_); }
317 const MeshT& getMesh()
const {
return dynamic_cast<const MeshT&
>(mesh_); }
325 OM_DEPRECATED(
"retain no longer has any effect. Instead, named properties are always retained, while unnamed ones are not.")
326 void retain(
bool = true) {}
335 retain_(rhs.retain_),
339 rhs.prop_.invalidate();
347 if ((&mesh_ != &rhs.mesh_) || (prop_ != rhs.prop_))
352 Storage::copy(rhs, *
this);
357 Storage::swap(rhs, *
this);
361 rhs.prop_.invalidate();
374 static PropertyManager createIfNotExists(PolyConnectivity &mesh,
const char *propname) {
387 template<
typename PROP_VALUE,
typename ITERATOR_TYPE>
388 static PropertyManager createIfNotExists(PolyConnectivity &mesh,
const char *propname,
389 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
390 const PROP_VALUE &init_value) {
391 const bool exists = propertyExists(mesh, propname);
395 pm.set_range(begin, end, init_value);
396 return std::move(pm);
408 template<
typename PROP_VALUE,
typename ITERATOR_RANGE>
409 static PropertyManager createIfNotExists(PolyConnectivity &mesh,
const char *propname,
410 const ITERATOR_RANGE &range,
const PROP_VALUE &init_value) {
411 return createIfNotExists(
412 mesh, propname, range.begin(), range.end(), init_value);
429 return mesh().mproperty(prop_)[0];
445 return mesh().mproperty(prop_)[0];
455 inline typename PROPTYPE::reference
operator[] (Handle handle) {
456 return mesh().property(prop_, handle);
466 inline typename PROPTYPE::const_reference
operator[] (
const Handle& handle)
const {
467 return mesh().property(prop_, handle);
477 inline typename PROPTYPE::reference
operator() (
const Handle& handle = Handle()) {
479 return Storage::access_property(mesh(), prop_, handle);
489 inline typename PROPTYPE::const_reference
operator() (
const Handle& handle = Handle())
const {
491 return Storage::access_property_const(mesh(), prop_, handle);
518 template<
typename HandleTypeIterator,
typename PROP_VALUE>
519 void set_range(HandleTypeIterator begin, HandleTypeIterator end,
520 const PROP_VALUE &value) {
521 for (; begin != end; ++begin)
522 (*
this)[*begin] = value;
525 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
526 template<
typename HandleTypeIteratorRange,
typename PROP_VALUE>
527 void set_range(
const HandleTypeIteratorRange &range,
528 const PROP_VALUE &value) {
529 set_range(range.begin(), range.end(), value);
547 template<
typename HandleTypeIterator,
typename PropertyManager2,
548 typename HandleTypeIterator2>
549 void copy_to(HandleTypeIterator begin, HandleTypeIterator end,
550 PropertyManager2 &dst_propmanager,
551 HandleTypeIterator2 dst_begin, HandleTypeIterator2 dst_end)
const {
553 for (; begin != end && dst_begin != dst_end; ++begin, ++dst_begin) {
554 dst_propmanager[*dst_begin] = (*this)[*begin];
558 template<
typename RangeType,
typename PropertyManager2,
560 void copy_to(
const RangeType &range,
561 PropertyManager2 &dst_propmanager,
562 const RangeType2 &dst_range)
const {
563 copy_to(range.begin(), range.end(), dst_propmanager,
564 dst_range.begin(), dst_range.end());
582 template<
typename RangeType,
typename RangeType2>
583 static void copy(
const char *prop_name,
588 DstPM dst(DstPM::createIfNotExists(dst_mesh, prop_name));
591 SrcPM src(src_mesh, prop_name,
true);
593 src.copy_to(src_range, dst, dst_range);
604 mesh().property(getRawProperty()).set_persistent(_persistence);
608 void deleteProperty() {
609 if (!retain_ && prop_.is_valid())
610 mesh().remove_property(prop_);
613 PolyConnectivity& mesh()
const
615 return const_cast<PolyConnectivity&
>(mesh_);
619 const PolyConnectivity& mesh_;
625 template <
typename PropertyT>
629 using Value =
typename PropertyT::Value;
630 using value_type =
typename PropertyT::value_type;
631 using Handle =
typename PropertyT::Handle;
636 prop_(property_handle)
639 inline const typename PropertyT::const_reference operator() (
const Handle& handle)
641 return mesh_.
property(prop_, handle);
644 inline const typename PropertyT::const_reference operator[] (
const Handle& handle)
646 return mesh_.
property(prop_, handle);
681 template<
typename ElementT,
typename T>
683 OM_DEPRECATED(
"Named temporary properties are deprecated. Either create a temporary without name or a non-temporary with name")
712 template<
typename ElementT,
typename T>
740 template<
typename ElementT,
typename T>
774 template<
typename ElementT,
typename T>
777 if (!hasProperty<ElementT, T>(mesh, propname))
779 std::ostringstream oss;
780 oss <<
"Requested property handle \"" << propname <<
"\" does not exist.";
781 throw std::runtime_error(oss.str());
815 template<
typename ElementT,
typename T>
830 template<
typename PROPTYPE>
831 OM_DEPRECATED(
"Use makeTemporaryProperty instead.")
849 template<
typename PROPTYPE,
typename MeshT =
int>
850 OM_DEPRECATED(
"Use getProperty instead.")
864 template<
typename PROPTYPE,
typename MeshT =
int>
865 OM_DEPRECATED(
"Use getOrMakeProperty instead.")
882 template<
typename PROPTYPE,
883 typename ITERATOR_TYPE,
typename PROP_VALUE>
884 OM_DEPRECATED(
"Use getOrMakeProperty instead.")
887 const ITERATOR_TYPE &begin, const ITERATOR_TYPE &end,
888 const PROP_VALUE &init_value) {
890 mesh, propname, begin, end, init_value);
904 template<
typename PROPTYPE,
905 typename ITERATOR_RANGE,
typename PROP_VALUE>
906 OM_DEPRECATED(
"Use getOrMakeProperty instead.")
909 const ITERATOR_RANGE &range,
910 const PROP_VALUE &init_value) {
911 return makePropertyManagerFromExistingOrNew<PROPTYPE>(
912 mesh, propname, range.begin(), range.end(), init_value);
919 template<
typename MeshT>
928 template<
typename MeshT>
935 template <
typename HandleT,
typename T>
938 template <
typename T>
941 template <
typename T>
944 template <
typename T>
947 template <
typename T>
950 template <
typename T>
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
void remove_property(VPropHandleT< T > &_ph)
You should not use this function directly.
Definition: BaseKernel.hh:194
PropertyT< T > & property(VPropHandleT< T > _ph)
In most cases you should use the convenient PropertyManager wrapper and use of this function should n...
Definition: BaseKernel.hh:310
bool get_property_handle(VPropHandleT< T > &_ph, const std::string &_name) const
You should not use this function directly.
Definition: BaseKernel.hh:254
Connectivity Class for polygonal meshes.
Definition: PolyConnectivity.hh:115
Definition: HandleToPropHandle.hh:10
Default property class for any type T.
Definition: Property.hh:93
Handle representing a vertex property.
Definition: Property.hh:417
Handle representing a mesh property.
Definition: Property.hh:477
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:76
PROPTYPE::reference & operator*()
Get the mesh corresponding to the property.
Definition: PropertyManager.hh:428
static void copy(const char *prop_name, PolyConnectivity &src_mesh, const RangeType &src_range, PolyConnectivity &dst_mesh, const RangeType2 &dst_range)
Copy the values of a property from a source range to a target range.
Definition: PropertyManager.hh:583
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Conveniently set the property for an entire range of values.
Definition: PropertyManager.hh:519
PropertyManager(const Value &initial_value, PolyConnectivity &mesh, const char *propname)
Constructor.
Definition: PropertyManager.hh:196
ConstPropertyViewer< OpenMesh::VPropHandleT< typename MeshT::Point > > getPointsProperty(const MeshT &mesh)
Returns a convenience wrapper around the points property of a mesh that only allows const access.
Definition: PropertyManager.hh:930
PropertyManager(PolyConnectivity &mesh, const char *propname, bool existing)
Definition: PropertyManager.hh:160
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > makeTemporaryProperty(PolyConnectivity &mesh)
Creates a new property whose lifetime is limited to the current scope.
Definition: PropertyManager.hh:714
PROPTYPE::reference operator[](Handle handle)
Enables convenient access to the encapsulated property.
Definition: PropertyManager.hh:455
bool hasProperty(const PolyConnectivity &mesh, const char *propname)
Tests whether a property with the given element type, value type, and name is present on the given me...
Definition: PropertyManager.hh:742
void copy_to(HandleTypeIterator begin, HandleTypeIterator end, PropertyManager2 &dst_propmanager, HandleTypeIterator2 dst_begin, HandleTypeIterator2 dst_end) const
Conveniently transfer the values managed by one property manager onto the values managed by a differe...
Definition: PropertyManager.hh:549
PropertyManager< OpenMesh::VPropHandleT< typename MeshT::Point > > getPointsProperty(MeshT &mesh)
Returns a convenience wrapper around the points property of a mesh.
Definition: PropertyManager.hh:921
PROPTYPE::const_reference & operator*() const
Access the value of the encapsulated mesh property.
Definition: PropertyManager.hh:444
void set_persistent(bool _persistence=true)
Mark whether this property should be stored when mesh is written to a file.
Definition: PropertyManager.hh:602
PropertyManager(const PolyConnectivity &mesh)
Constructor.
Definition: PropertyManager.hh:210
PropertyManager(const Value &initial_value, const PolyConnectivity &mesh)
Constructor.
Definition: PropertyManager.hh:222
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > getProperty(PolyConnectivity &mesh, const char *propname)
Obtains a handle to a named property.
Definition: PropertyManager.hh:776
PropertyManager clone()
Create property manager referring to a copy of the current property.
Definition: PropertyManager.hh:264
PropertyManager(PolyConnectivity &mesh, PROPTYPE property_handle)
Constructor.
Definition: PropertyManager.hh:235
PROPTYPE::reference operator()(const Handle &handle=Handle())
Enables convenient access to the encapsulated property.
Definition: PropertyManager.hh:477
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > getOrMakeProperty(PolyConnectivity &mesh, const char *propname)
Obtains a handle to a named property if it exists or creates a new one otherwise.
Definition: PropertyManager.hh:817
PropertyManager(PolyConnectivity &mesh, const char *propname)
Constructor.
Definition: PropertyManager.hh:180
Definition: PropertyManager.hh:627