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> 79 template<
typename PROPTYPE,
typename MeshT =
int>
83 using Value =
typename PROPTYPE::Value;
84 using value_type =
typename PROPTYPE::value_type;
85 using Handle =
typename PROPTYPE::Handle;
87 using Reference =
typename PROPTYPE::reference;
88 using ConstReference =
typename PROPTYPE::const_reference;
94 template <
typename PropertyManager2,
typename PropHandleT>
98 template <
typename PropertyManager2>
99 struct StorageT<PropertyManager2, MPropHandleT<Value>> {
104 std::swap(*to, *from);
106 static ConstReference access_property_const(
PolyConnectivity& mesh,
const PROPTYPE& prop_handle,
const Handle&) {
109 static Reference access_property(
PolyConnectivity& mesh,
const PROPTYPE& prop_handle,
const Handle&) {
115 template <
typename PropertyManager2,
typename PropHandleT>
118 from.
copy_to(from.mesh_.template all_elements<Handle>(), to, to.mesh_.template all_elements<Handle>());
121 std::swap(lhs.mesh().property(lhs.prop_).data_vector(), rhs.mesh().property(rhs.prop_).data_vector());
123 lhs.mesh().property(lhs.prop_).resize(lhs.mesh().template n_elements<Handle>());
124 rhs.mesh().property(rhs.prop_).resize(rhs.mesh().template n_elements<Handle>());
126 static ConstReference access_property_const(
PolyConnectivity& mesh,
const PROPTYPE& prop_handle,
const Handle& handle) {
127 return mesh.
property(prop_handle, handle);
129 static Reference access_property(
PolyConnectivity& mesh,
const PROPTYPE& prop_handle,
const Handle& handle) {
130 return mesh.
property(prop_handle, handle);
134 using Storage = StorageT<Self, PROPTYPE>;
157 OM_DEPRECATED(
"Use the constructor without parameter 'existing' instead. Check for existance with hasProperty")
160 if (!PropertyManager::mesh().get_property_handle(prop_, propname)) {
161 std::ostringstream oss;
162 oss <<
"Requested property handle \"" << propname <<
"\" does not exist.";
163 throw std::runtime_error(oss.str());
166 PropertyManager::mesh().add_property(prop_, propname);
179 if (!PropertyManager::mesh().get_property_handle(prop_, propname)) {
180 PropertyManager::mesh().add_property(prop_, propname);
195 if (!mesh_.get_property_handle(prop_, propname)) {
196 PropertyManager::mesh().add_property(prop_, propname);
197 set_range(mesh_.all_elements<Handle>(), initial_value);
209 PropertyManager::mesh().add_property(prop_, name_);
221 PropertyManager::mesh().add_property(prop_, name_);
222 set_range(mesh_.all_elements<Handle>(), initial_value);
242 retain_(rhs.retain_),
251 PropertyManager::mesh().add_property(prop_, name_);
252 Storage::copy(rhs, *
this);
265 Storage::copy(*
this, result);
271 if (&mesh_ == &rhs.mesh_ && prop_ == rhs.prop_)
274 Storage::copy(rhs, *
this);
284 Storage::swap(rhs, *
this);
292 bool isValid()
const {
return prop_.is_valid(); }
293 operator bool()
const {
return isValid(); }
295 const PROPTYPE &getRawProperty()
const {
return prop_; }
297 const std::string &getName()
const {
return name_; }
312 template <
typename MeshType >
313 const MeshType& getMesh()
const {
return dynamic_cast<const MeshType&
>(mesh_); }
315 const MeshT& getMesh()
const {
return dynamic_cast<const MeshT&
>(mesh_); }
323 OM_DEPRECATED(
"retain no longer has any effect. Instead, named properties are always retained, while unnamed ones are not.")
324 void retain(
bool =
true) {}
333 retain_(rhs.retain_),
337 rhs.prop_.invalidate();
345 if ((&mesh_ != &rhs.mesh_) || (prop_ != rhs.prop_))
350 Storage::copy(rhs, *
this);
355 Storage::swap(rhs, *
this);
359 rhs.prop_.invalidate();
385 template<
typename PROP_VALUE,
typename ITERATOR_TYPE>
387 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
388 const PROP_VALUE &init_value) {
389 const bool exists = propertyExists(mesh, propname);
394 return std::move(pm);
406 template<
typename PROP_VALUE,
typename ITERATOR_RANGE>
408 const ITERATOR_RANGE &range,
const PROP_VALUE &init_value) {
409 return createIfNotExists(
410 mesh, propname, range.begin(), range.end(), init_value);
453 inline typename PROPTYPE::reference
operator[] (Handle handle) {
454 return mesh().
property(prop_, handle);
464 inline typename PROPTYPE::const_reference
operator[] (
const Handle& handle)
const {
465 return mesh().
property(prop_, handle);
475 inline typename PROPTYPE::reference
operator() (
const Handle& handle = Handle()) {
477 return Storage::access_property(mesh(), prop_, handle);
487 inline typename PROPTYPE::const_reference
operator() (
const Handle& handle = Handle())
const {
489 return Storage::access_property_const(mesh(), prop_, handle);
516 template<
typename HandleTypeIterator,
typename PROP_VALUE>
517 void set_range(HandleTypeIterator begin, HandleTypeIterator end,
518 const PROP_VALUE &value) {
519 for (; begin != end; ++begin)
520 (*
this)[*begin] = value;
523 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 524 template<
typename HandleTypeIteratorRange,
typename PROP_VALUE>
525 void set_range(
const HandleTypeIteratorRange &range,
526 const PROP_VALUE &value) {
527 set_range(range.begin(), range.end(), value);
545 template<
typename HandleTypeIterator,
typename PROPTYPE_2,
546 typename HandleTypeIterator_2>
547 void copy_to(HandleTypeIterator begin, HandleTypeIterator end,
549 HandleTypeIterator_2 dst_begin, HandleTypeIterator_2 dst_end)
const {
551 for (; begin != end && dst_begin != dst_end; ++begin, ++dst_begin) {
552 dst_propmanager[*dst_begin] = (*this)[*begin];
556 template<
typename RangeType,
typename PROPTYPE_2,
557 typename RangeType_2>
558 void copy_to(
const RangeType &range,
560 const RangeType_2 &dst_range)
const {
561 copy_to(range.begin(), range.end(), dst_propmanager,
562 dst_range.begin(), dst_range.end());
580 template<
typename RangeType,
typename RangeType_2>
581 static void copy(
const char *prop_name,
586 DstPM dst(DstPM::createIfNotExists(dst_mesh, prop_name));
589 SrcPM src(src_mesh, prop_name,
true);
591 src.copy_to(src_range, dst, dst_range);
595 void deleteProperty() {
596 if (!retain_ && prop_.is_valid())
612 template <
typename PropertyT>
616 using Value =
typename PropertyT::Value;
617 using value_type =
typename PropertyT::value_type;
618 using Handle =
typename PropertyT::Handle;
623 prop_(property_handle)
626 inline const typename PropertyT::const_reference
operator() (
const Handle& handle)
628 return mesh_.property(prop_, handle);
631 inline const typename PropertyT::const_reference
operator[] (
const Handle& handle)
633 return mesh_.property(prop_, handle);
668 template<
typename ElementT,
typename T>
670 OM_DEPRECATED(
"Named temporary properties are deprecated. Either create a temporary without name or a non-temporary with name")
699 template<
typename ElementT,
typename T>
727 template<
typename ElementT,
typename T>
761 template<
typename ElementT,
typename T>
764 if (!hasProperty<ElementT, T>(mesh, propname))
766 std::ostringstream oss;
767 oss <<
"Requested property handle \"" << propname <<
"\" does not exist.";
768 throw std::runtime_error(oss.str());
802 template<
typename ElementT,
typename T>
817 template<
typename PROPTYPE>
818 OM_DEPRECATED(
"Use makeTemporaryProperty instead.")
836 template<
typename PROPTYPE,
typename MeshT =
int>
837 OM_DEPRECATED(
"Use getProperty instead.")
851 template<
typename PROPTYPE,
typename MeshT =
int>
852 OM_DEPRECATED(
"Use getOrMakeProperty instead.")
869 template<
typename PROPTYPE,
870 typename ITERATOR_TYPE,
typename PROP_VALUE>
871 OM_DEPRECATED(
"Use getOrMakeProperty instead.")
874 const ITERATOR_TYPE &begin, const ITERATOR_TYPE &end,
875 const PROP_VALUE &init_value) {
877 mesh, propname, begin, end, init_value);
891 template<
typename PROPTYPE,
892 typename ITERATOR_RANGE,
typename PROP_VALUE>
893 OM_DEPRECATED(
"Use getOrMakeProperty instead.")
896 const ITERATOR_RANGE &range,
897 const PROP_VALUE &init_value) {
898 return makePropertyManagerFromExistingOrNew<PROPTYPE>(
899 mesh, propname, range.begin(), range.end(), init_value);
906 template<
typename MeshT>
915 template<
typename MeshT>
922 template <
typename HandleT,
typename T>
925 template <
typename T>
928 template <
typename T>
931 template <
typename T>
934 template <
typename T>
937 template <
typename T>
PROPTYPE::reference operator()(const Handle &handle=Handle())
Enables convenient access to the encapsulated property.
Definition: PropertyManager.hh:475
bool get_property_handle(VPropHandleT< T > &_ph, const std::string &_name) const
You should not use this function directly.
Definition: BaseKernel.hh:254
Handle representing a vertex property.
Definition: Property.hh:484
PropertyManager< PROPTYPE > makePropertyManagerFromNew(PolyConnectivity &mesh, const char *propname)
Definition: PropertyManager.hh:819
PropertyManager< OpenMesh::VPropHandleT< typename MeshT::Point > > getPointsProperty(MeshT &mesh)
Definition: PropertyManager.hh:908
PropertyManager(const Value &initial_value, const PolyConnectivity &mesh)
Constructor.
Definition: PropertyManager.hh:220
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:80
PropertyManager clone()
Create property manager referring to a copy of the current property.
Definition: PropertyManager.hh:262
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > makeTemporaryProperty(PolyConnectivity &mesh)
Definition: PropertyManager.hh:701
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
Conveniently set the property for an entire range of values.
Definition: PropertyManager.hh:517
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
PROPTYPE::reference operator[](Handle handle)
Enables convenient access to the encapsulated property.
Definition: PropertyManager.hh:453
PROPTYPE::const_reference & operator*() const
Access the value of the encapsulated mesh property.
Definition: PropertyManager.hh:442
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExisting(PolyConnectivity &mesh, const char *propname)
Definition: PropertyManager.hh:838
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > getProperty(PolyConnectivity &mesh, const char *propname)
Definition: PropertyManager.hh:763
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(PolyConnectivity &mesh, const char *propname)
Definition: PropertyManager.hh:853
static void copy(const char *prop_name, PolyConnectivity &src_mesh, const RangeType &src_range, PolyConnectivity &dst_mesh, const RangeType_2 &dst_range)
Copy the values of a property from a source range to a target range.
Definition: PropertyManager.hh:581
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > getOrMakeProperty(PolyConnectivity &mesh, const char *propname)
Definition: PropertyManager.hh:804
PropertyManager(const Value &initial_value, PolyConnectivity &mesh, const char *propname)
Constructor.
Definition: PropertyManager.hh:194
void copy_to(HandleTypeIterator begin, HandleTypeIterator end, PropertyManager< PROPTYPE_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:547
Definition: PropertyManager.hh:613
PropertyT< T > & mproperty(MPropHandleT< T > _ph)
In most cases you should use the convenient PropertyManager wrapper and use of this function should n...
Definition: BaseKernel.hh:346
Definition: HandleToPropHandle.hh:10
PROPTYPE::reference & operator*()
Get the mesh corresponding to the property.
Definition: PropertyManager.hh:426
Default property class for any type T.
Definition: Property.hh:89
void remove_property(VPropHandleT< T > &_ph)
You should not use this function directly.
Definition: BaseKernel.hh:194
bool hasProperty(const PolyConnectivity &mesh, const char *propname)
Definition: PropertyManager.hh:729
Connectivity Class for polygonal meshes.
Definition: PolyConnectivity.hh:112
PropertyManager(const PolyConnectivity &mesh)
Constructor.
Definition: PropertyManager.hh:208
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > makeTemporaryProperty(PolyConnectivity &mesh, const char *propname)
Definition: PropertyManager.hh:671
PropertyManager(PolyConnectivity &mesh, const char *propname)
Constructor.
Definition: PropertyManager.hh:178
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
PropertyManager(PolyConnectivity &mesh, PROPTYPE property_handle)
Constructor.
Definition: PropertyManager.hh:233
ConstPropertyViewer< OpenMesh::VPropHandleT< typename MeshT::Point > > getPointsProperty(const MeshT &mesh)
Definition: PropertyManager.hh:917