Commit acadd249 authored by Philip Trettner's avatar Philip Trettner
Browse files

working on smart ranges

parent bed5c608
......@@ -16,6 +16,9 @@
// - vertex normal
// - curvature
// - topological properties
//
// Note: unary properties should be usable as free functions OR as index into handles
// e.g. valence(v) is the same as v[valence]
namespace polymesh
{
/// returns true if the vertex lies at a boundary
......@@ -33,7 +36,7 @@ bool is_isolated(vertex_handle v);
bool is_isolated(edge_handle v);
/// returns the vertex valence (number of adjacent vertices)
int valence_of(vertex_handle v);
int valence(vertex_handle v);
/// returns the area of the (flat) polygonal face
template <class Vec3>
......@@ -65,7 +68,7 @@ inline bool is_isolated(vertex_handle v) { return v.is_isolated(); }
inline bool is_isolated(edge_handle v) { return v.is_isolated(); }
inline int valence_of(vertex_handle v) { return v.adjacent_vertices().size(); }
inline int valence(vertex_handle v) { return v.adjacent_vertices().size(); }
template <class Vec3>
typename field_3d<Vec3>::Scalar triangle_area(face_handle f, vertex_attribute<Vec3> const& position)
......
......@@ -4,33 +4,33 @@
namespace polymesh
{
template <class this_t, class tag>
typename smart_range<this_t, tag>::handle smart_range<this_t, tag>::first() const
template <class this_t, class ElementT>
ElementT smart_range<this_t, ElementT>::first() const
{
for (auto h : static_cast<this_t const *>(this))
return h;
return handle::invalid();
return {};
}
template <class this_t, class tag>
typename smart_range<this_t, tag>::handle smart_range<this_t, tag>::last() const
template <class this_t, class ElementT>
ElementT smart_range<this_t, ElementT>::last() const
{
handle result;
ElementT result;
for (auto h : static_cast<this_t const *>(this))
result = h;
return result;
}
template <class this_t, class tag>
bool smart_range<this_t, tag>::any() const
template <class this_t, class ElementT>
bool smart_range<this_t, ElementT>::any() const
{
for (auto h : static_cast<this_t const *>(this))
return true;
return false;
}
template <class this_t, class tag>
template <typename PredT>
bool smart_range<this_t, tag>::any(PredT&& p) const
template <class this_t, class ElementT>
template <class PredT>
bool smart_range<this_t, ElementT>::any(PredT &&p) const
{
for (auto h : static_cast<this_t const *>(this))
if (p(h))
......@@ -38,8 +38,18 @@ bool smart_range<this_t, tag>::any(PredT&& p) const
return false;
}
template <class this_t, class tag>
int smart_range<this_t, tag>::count() const
template <class this_t, class ElementT>
template <class PredT>
bool smart_range<this_t, ElementT>::all(PredT &&p) const
{
for (auto h : static_cast<this_t const *>(this))
if (!p(h))
return false;
return true;
}
template <class this_t, class ElementT>
int smart_range<this_t, ElementT>::count() const
{
auto cnt = 0;
for (auto h : static_cast<this_t const *>(this))
......
......@@ -7,40 +7,43 @@
namespace polymesh
{
template <class T>
struct aabb
{
T min;
T max;
};
template<class this_t, class tag>
template <class this_t, class ElementT>
struct smart_range
{
template<class AttrT>
using attribute = typename primitive<tag>::template attribute<AttrT>;
using handle = typename primitive<tag>::handle;
/// returns the first element in this range
/// returns invalid on empty ranges
handle first() const;
/// returns the last element in this range
/// returns invalid on empty ranges
/// returns invalid on empty ranges (or default ctor'd one)
ElementT first() const;
/// returns the last element in this range
/// returns invalid on empty ranges (or default ctor'd one)
/// TODO: how to make this O(1)
handle last() const;
ElementT last() const;
/// returns true if the range is non-empty
bool any() const;
/// returns true if any handle fulfils p(h)
template<typename PredT>
/// also works for boolean attributes
template <class PredT>
bool any(PredT&& p) const;
/// returns true if any attribute is true for this range
// bool any(attribute<bool> const& a) const;
/// returns true if all handles fulfil p(h)
template<typename PredT>
/// also works for boolean attributes
template <class PredT>
bool all(PredT&& p) const;
/// returns true if all attributes are true for this range
// bool all(attribute<bool> const& a) const;
/// returns the number of elements in this range
/// NOTE: this is an O(n) operation, prefer size() if available
/// TODO: maybe SFINAE to implement this via size() if available?
int count() const;
// template<class T>
// T min() const;
// TODO:
// - average
// - sum
......@@ -51,15 +54,14 @@ struct smart_range
// - map
// - skip
// - only_valid
// - count
};
// ================= COLLECTION =================
template <class mesh_ptr, class tag, class iterator>
struct smart_collection : smart_range<smart_collection<mesh_ptr, tag, iterator>, tag>
struct smart_collection : smart_range<smart_collection<mesh_ptr, tag, iterator>, typename primitive<tag>::handle>
{
template <typename AttrT>
template <class AttrT>
using attribute = typename primitive<tag>::template attribute<AttrT>;
/// Number of primitives, INCLUDING those marked for deletion
......@@ -232,7 +234,7 @@ struct valid_halfedge_const_collection : smart_collection<Mesh const*, halfedge_
// ================= RINGS =================
template <class this_t, class tag>
struct primitive_ring : smart_range<this_t, tag>
struct primitive_ring : smart_range<this_t, typename primitive<tag>::handle>
{
using handle = typename primitive<tag>::handle;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment