42 #ifndef PROPERTYMANAGER_HH_ 43 #define PROPERTYMANAGER_HH_ 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);
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);
197 if (!mesh_.get_property_handle(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);
286 Storage::swap(rhs, *
this);
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();
387 template<
typename PROP_VALUE,
typename ITERATOR_TYPE>
389 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
390 const PROP_VALUE &init_value) {
391 const bool exists = propertyExists(mesh, propname);
396 return std::move(pm);
408 template<
typename PROP_VALUE,
typename ITERATOR_RANGE>
410 const ITERATOR_RANGE &range,
const PROP_VALUE &init_value) {
411 return createIfNotExists(
412 mesh, propname, range.begin(), range.end(), init_value);
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())
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>
849 template<
typename PROPTYPE,
typename MeshT =
int>
864 template<
typename PROPTYPE,
typename MeshT =
int>
882 template<
typename PROPTYPE,
883 typename ITERATOR_TYPE,
typename PROP_VALUE>
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>
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>
static void copy(const char *prop_name, PolyConnectivity &src_mesh, const RangeType &src_range, PolyConnectivity &dst_mesh, const RangeType2 &dst_range)
PROPTYPE::const_reference & operator*() const
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(PolyConnectivity &mesh, const char *propname)
void copy_to(HandleTypeIterator begin, HandleTypeIterator end, PropertyManager2 &dst_propmanager, HandleTypeIterator2 dst_begin, HandleTypeIterator2 dst_end) const
void set_range(HandleTypeIterator begin, HandleTypeIterator end, const PROP_VALUE &value)
bool hasProperty(const PolyConnectivity &mesh, const char *propname)
PROPTYPE::reference operator[](Handle handle)
PropertyManager(const PolyConnectivity &mesh)
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > getOrMakeProperty(PolyConnectivity &mesh, const char *propname)
bool get_property_handle(VPropHandleT< T > &_ph, const std::string &_name) const
void remove_property(VPropHandleT< T > &_ph)
void set_persistent(bool _persistence=true)
OM_DEPRECATED("Use the constructor without parameter 'existing' instead. Check for existance with hasProperty") PropertyManager(PolyConnectivity &mesh
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > getProperty(PolyConnectivity &mesh, const char *propname)
Default property class for any type T.
PropertyT< T > & mproperty(MPropHandleT< T > _ph)
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > makeTemporaryProperty(PolyConnectivity &mesh)
PropertyManager< typename HandleToPropHandle< ElementT, T >::type > makeTemporaryProperty(PolyConnectivity &mesh, const char *propname)
PropertyManager(PolyConnectivity &mesh, PROPTYPE property_handle)
PropertyManager(PolyConnectivity &mesh, const char *propname)
PropertyManager< OpenMesh::VPropHandleT< typename MeshT::Point > > getPointsProperty(MeshT &mesh)
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExisting(PolyConnectivity &mesh, const char *propname)
ConstPropertyViewer< OpenMesh::VPropHandleT< typename MeshT::Point > > getPointsProperty(const MeshT &mesh)
PropertyT< T > & property(VPropHandleT< T > _ph)
PROPTYPE::reference operator()(const Handle &handle=Handle())
PropertyManager< PROPTYPE > makePropertyManagerFromNew(PolyConnectivity &mesh, const char *propname)
PROPTYPE::reference & operator*()
Connectivity Class for polygonal meshes.
PropertyManager(const Value &initial_value, const PolyConnectivity &mesh)
PropertyManager(const Value &initial_value, PolyConnectivity &mesh, const char *propname)