42 #ifndef PROPERTYMANAGER_HH_ 43 #define PROPERTYMANAGER_HH_ 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>
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);
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);
258 if (&mesh_ == &rhs.mesh_ && prop_ == rhs.prop_)
261 Storage::copy(rhs, *
this);
271 Storage::swap(rhs, *
this);
279 bool isValid()
const {
return prop_.is_valid(); }
280 operator bool()
const {
return isValid(); }
282 const PROPTYPE &getRawProperty()
const {
return prop_; }
284 const std::string &getName()
const {
return name_; }
299 template <
typename MeshType >
300 const MeshType& getMesh()
const {
return dynamic_cast<const MeshType&
>(mesh_); }
302 const MeshT& getMesh()
const {
return dynamic_cast<const MeshT&
>(mesh_); }
310 OM_DEPRECATED(
"retain no longer has any effect. Instead, named properties are always retained, while unnamed ones are not.")
311 void retain(
bool =
true) {}
320 retain_(rhs.retain_),
324 rhs.prop_.invalidate();
332 if ((&mesh_ != &rhs.mesh_) || (prop_ != rhs.prop_))
337 Storage::copy(rhs, *
this);
342 Storage::swap(rhs, *
this);
346 rhs.prop_.invalidate();
372 template<
typename PROP_VALUE,
typename ITERATOR_TYPE>
374 const ITERATOR_TYPE &begin,
const ITERATOR_TYPE &end,
375 const PROP_VALUE &init_value) {
376 const bool exists = propertyExists(mesh, propname);
381 return std::move(pm);
393 template<
typename PROP_VALUE,
typename ITERATOR_RANGE>
395 const ITERATOR_RANGE &range,
const PROP_VALUE &init_value) {
396 return createIfNotExists(
397 mesh, propname, range.begin(), range.end(), init_value);
440 inline typename PROPTYPE::reference
operator[] (Handle handle) {
441 return mesh().
property(prop_, handle);
451 inline typename PROPTYPE::const_reference
operator[] (
const Handle& handle)
const {
452 return mesh().
property(prop_, handle);
462 inline typename PROPTYPE::reference
operator() (
const Handle& handle = Handle()) {
464 return Storage::access_property(mesh(), prop_, handle);
474 inline typename PROPTYPE::const_reference
operator() (
const Handle& handle = Handle())
const {
476 return Storage::access_property_const(mesh(), prop_, handle);
503 template<
typename HandleTypeIterator,
typename PROP_VALUE>
504 void set_range(HandleTypeIterator begin, HandleTypeIterator end,
505 const PROP_VALUE &value) {
506 for (; begin != end; ++begin)
507 (*
this)[*begin] = value;
510 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) 511 template<
typename HandleTypeIteratorRange,
typename PROP_VALUE>
512 void set_range(
const HandleTypeIteratorRange &range,
513 const PROP_VALUE &value) {
514 set_range(range.begin(), range.end(), value);
532 template<
typename HandleTypeIterator,
typename PROPTYPE_2,
533 typename HandleTypeIterator_2>
534 void copy_to(HandleTypeIterator begin, HandleTypeIterator end,
536 HandleTypeIterator_2 dst_begin, HandleTypeIterator_2 dst_end)
const {
538 for (; begin != end && dst_begin != dst_end; ++begin, ++dst_begin) {
539 dst_propmanager[*dst_begin] = (*this)[*begin];
543 template<
typename RangeType,
typename PROPTYPE_2,
544 typename RangeType_2>
545 void copy_to(
const RangeType &range,
547 const RangeType_2 &dst_range)
const {
548 copy_to(range.begin(), range.end(), dst_propmanager,
549 dst_range.begin(), dst_range.end());
567 template<
typename RangeType,
typename RangeType_2>
568 static void copy(
const char *prop_name,
573 DstPM dst(DstPM::createIfNotExists(dst_mesh, prop_name));
576 SrcPM src(src_mesh, prop_name,
true);
578 src.copy_to(src_range, dst, dst_range);
582 void deleteProperty() {
583 if (!retain_ && prop_.is_valid())
599 template <
typename PropertyT>
603 using Value =
typename PropertyT::Value;
604 using value_type =
typename PropertyT::value_type;
605 using Handle =
typename PropertyT::Handle;
610 prop_(property_handle)
613 inline const typename PropertyT::const_reference
operator() (
const Handle& handle)
615 return mesh_.property(prop_, handle);
618 inline const typename PropertyT::const_reference
operator[] (
const Handle& handle)
620 return mesh_.property(prop_, handle);
655 template<
typename ElementT,
typename T>
657 OM_DEPRECATED(
"Named temporary properties are deprecated. Either create a temporary without name or a non-temporary with name")
686 template<
typename ElementT,
typename T>
714 template<
typename ElementT,
typename T>
748 template<
typename ElementT,
typename T>
751 if (!hasProperty<ElementT, T>(mesh, propname))
753 std::ostringstream oss;
754 oss <<
"Requested property handle \"" << propname <<
"\" does not exist.";
755 throw std::runtime_error(oss.str());
789 template<
typename ElementT,
typename T>
804 template<
typename PROPTYPE>
823 template<
typename PROPTYPE,
typename MeshT =
int>
838 template<
typename PROPTYPE,
typename MeshT =
int>
856 template<
typename PROPTYPE,
857 typename ITERATOR_TYPE,
typename PROP_VALUE>
861 const ITERATOR_TYPE &begin, const ITERATOR_TYPE &end,
862 const PROP_VALUE &init_value) {
864 mesh, propname, begin, end, init_value);
878 template<
typename PROPTYPE,
879 typename ITERATOR_RANGE,
typename PROP_VALUE>
883 const ITERATOR_RANGE &range,
884 const PROP_VALUE &init_value) {
885 return makePropertyManagerFromExistingOrNew<PROPTYPE>(
886 mesh, propname, range.begin(), range.end(), init_value);
893 template<
typename MeshT>
902 template<
typename MeshT>
909 template <
typename HandleT,
typename T>
912 template <
typename T>
915 template <
typename T>
918 template <
typename T>
921 template <
typename T>
924 template <
typename T>
PROPTYPE::const_reference & operator*() const
PropertyManager< PROPTYPE, MeshT > makePropertyManagerFromExistingOrNew(PolyConnectivity &mesh, const char *propname)
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
static void copy(const char *prop_name, PolyConnectivity &src_mesh, const RangeType &src_range, PolyConnectivity &dst_mesh, const RangeType_2 &dst_range)
void remove_property(VPropHandleT< T > &_ph)
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)
void copy_to(HandleTypeIterator begin, HandleTypeIterator end, PropertyManager< PROPTYPE_2 > &dst_propmanager, HandleTypeIterator_2 dst_begin, HandleTypeIterator_2 dst_end) const