allow PropertyManagers to be used in smart ranges
This commit is contained in:
@@ -59,7 +59,7 @@ struct SmartRangeT
|
||||
// TODO: Someone with better c++ knowledge may improve the code below.
|
||||
|
||||
template <typename Functor>
|
||||
auto sum(Functor f) -> decltype (f(std::declval<HandleT>())+f(std::declval<HandleT>()))
|
||||
auto sum(Functor&& f) -> decltype (f(std::declval<HandleT>())+f(std::declval<HandleT>()))
|
||||
{
|
||||
auto range = static_cast<const RangeT*>(this);
|
||||
auto begin = range->begin();
|
||||
@@ -73,6 +73,27 @@ struct SmartRangeT
|
||||
return sum;
|
||||
}
|
||||
|
||||
template <typename Functor>
|
||||
auto avg(Functor&& f) -> decltype (1.0 * (f(std::declval<HandleT>())+f(std::declval<HandleT>())))
|
||||
{
|
||||
auto range = static_cast<const RangeT*>(this);
|
||||
auto begin = range->begin();
|
||||
auto end = range->end();
|
||||
assert(begin != end);
|
||||
decltype (f(*begin) + f(*begin)) sum = f(*begin);
|
||||
auto it = begin;
|
||||
++it;
|
||||
int n_elements = 1;
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
sum += f(*it);
|
||||
++n_elements;
|
||||
}
|
||||
return (1.0 / n_elements) * sum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -380,6 +380,30 @@ class PropertyManager {
|
||||
return mesh_->property(prop_, handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables convenient access to the encapsulated property.
|
||||
*
|
||||
* For a usage example see this class' documentation.
|
||||
*
|
||||
* @param handle A handle of the appropriate handle type. (I.e. \p VertexHandle for \p VPropHandleT, etc.)
|
||||
*/
|
||||
template<typename HandleType>
|
||||
inline typename PROPTYPE::reference operator() (const HandleType &handle) {
|
||||
return mesh_->property(prop_, handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables convenient access to the encapsulated property.
|
||||
*
|
||||
* For a usage example see this class' documentation.
|
||||
*
|
||||
* @param handle A handle of the appropriate handle type. (I.e. \p VertexHandle for \p VPropHandleT, etc.)
|
||||
*/
|
||||
template<typename HandleType>
|
||||
inline typename PROPTYPE::const_reference operator() (const HandleType &handle) const {
|
||||
return mesh_->property(prop_, handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Conveniently set the property for an entire range of values.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user