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

templated rings

parent a9a33e0f
......@@ -19,4 +19,3 @@ Best used with glm and glow.
* smart ranges: average, min, max, any, all, first, last ...
* mid-level topo API: edge-rotate-next/prev, edge-split, edge-collapse, halfedge-split, halfedge-collapse, vertex-collapse
* annotate property preservation for mid-level topo API
* move "remove" API to handles
......@@ -184,200 +184,102 @@ struct valid_halfedge_const_collection : smart_collection<Mesh const*, halfedge_
// ================= RINGS =================
// rings
/// all vertices belonging to a face
struct face_vertex_ring
template <class this_t, class element_handle>
struct primitive_ring
{
face_handle face;
/// Number of vertices
/// Number of elements
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(vertex_handle v) const;
// Iteration:
face_vertex_circulator begin() const { return {face.any_halfedge(), false}; }
face_vertex_circulator end() const { return {face.any_halfedge(), true}; }
bool contains(element_handle v) const;
};
/// all halfedges belonging to a face
struct face_halfedge_ring
template <class element_handle, class circulator>
struct face_primitive_ring : primitive_ring<face_primitive_ring<element_handle, circulator>, element_handle>
{
face_handle face;
/// Number of vertices
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(halfedge_handle h) const;
face_primitive_ring(face_handle f) { face = f; }
// Iteration:
face_halfedge_circulator begin() const { return {face.any_halfedge(), false}; }
face_halfedge_circulator end() const { return {face.any_halfedge(), true}; }
circulator begin() const { return {face.any_halfedge(), false}; }
circulator end() const { return {face.any_halfedge(), true}; }
};
/// all edges belonging to a face
struct face_edge_ring
template <class element_handle, class circulator>
struct vertex_primitive_ring : primitive_ring<vertex_primitive_ring<element_handle, circulator>, element_handle>
{
face_handle face;
/// Number of vertices
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(edge_handle e) const;
vertex_handle vertex;
vertex_primitive_ring(vertex_handle v) { vertex = v; }
// Iteration:
face_edge_circulator begin() const { return {face.any_halfedge(), false}; }
face_edge_circulator end() const { return {face.any_halfedge(), true}; }
circulator begin() const { return {vertex.any_outgoing_halfedge(), vertex.is_isolated()}; }
circulator end() const { return {vertex.any_outgoing_halfedge(), true}; }
};
/// all adjacent faces belonging to a face
struct face_face_ring
/// all vertices belonging to a face
struct face_vertex_ring : face_primitive_ring<vertex_handle, face_vertex_circulator>
{
face_handle face;
/// Number of vertices
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(face_handle f) const;
using face_primitive_ring<vertex_handle, face_vertex_circulator>::face_primitive_ring;
};
// Iteration:
face_face_circulator begin() const { return {face.any_halfedge(), false}; }
face_face_circulator end() const { return {face.any_halfedge(), true}; }
/// all halfedges belonging to a face
struct face_halfedge_ring : face_primitive_ring<halfedge_handle, face_halfedge_circulator>
{
using face_primitive_ring<halfedge_handle, face_halfedge_circulator>::face_primitive_ring;
};
/// all outgoing half-edges from a vertex
struct vertex_halfedge_out_ring
/// all edges belonging to a face
struct face_edge_ring : face_primitive_ring<edge_handle, face_edge_circulator>
{
vertex_handle vertex;
using face_primitive_ring<edge_handle, face_edge_circulator>::face_primitive_ring;
};
/// Number of vertices
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(halfedge_handle h) const;
/// all adjacent faces belonging to a face
struct face_face_ring : face_primitive_ring<face_handle, face_face_circulator>
{
using face_primitive_ring<face_handle, face_face_circulator>::face_primitive_ring;
};
// Iteration:
vertex_halfedge_out_circulator begin() const { return {vertex.any_outgoing_halfedge(), vertex.is_isolated()}; }
vertex_halfedge_out_circulator end() const { return {vertex.any_outgoing_halfedge(), true}; }
/// all outgoing half-edges from a vertex
struct vertex_halfedge_out_ring : vertex_primitive_ring<halfedge_handle, vertex_halfedge_out_circulator>
{
using vertex_primitive_ring<halfedge_handle, vertex_halfedge_out_circulator>::vertex_primitive_ring;
};
/// all incoming half-edges from a vertex
struct vertex_halfedge_in_ring
struct vertex_halfedge_in_ring : vertex_primitive_ring<halfedge_handle, vertex_halfedge_in_circulator>
{
vertex_handle vertex;
/// Number of vertices
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(halfedge_handle h) const;
// Iteration:
vertex_halfedge_in_circulator begin() const { return {vertex.any_outgoing_halfedge(), vertex.is_isolated()}; }
vertex_halfedge_in_circulator end() const { return {vertex.any_outgoing_halfedge(), true}; }
using vertex_primitive_ring<halfedge_handle, vertex_halfedge_in_circulator>::vertex_primitive_ring;
};
/// all adjacent vertices of a vertex
struct vertex_vertex_ring
struct vertex_vertex_ring : vertex_primitive_ring<vertex_handle, vertex_vertex_circulator>
{
vertex_handle vertex;
/// Number of vertices
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(vertex_handle v) const;
// Iteration:
vertex_vertex_circulator begin() const { return {vertex.any_outgoing_halfedge(), vertex.is_isolated()}; }
vertex_vertex_circulator end() const { return {vertex.any_outgoing_halfedge(), true}; }
using vertex_primitive_ring<vertex_handle, vertex_vertex_circulator>::vertex_primitive_ring;
};
/// all adjacent edges of a vertex
struct vertex_edge_ring
struct vertex_edge_ring : vertex_primitive_ring<edge_handle, vertex_edge_circulator>
{
vertex_handle vertex;
/// Number of vertices
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(edge_handle e) const;
// Iteration:
vertex_edge_circulator begin() const { return {vertex.any_outgoing_halfedge(), vertex.is_isolated()}; }
vertex_edge_circulator end() const { return {vertex.any_outgoing_halfedge(), true}; }
using vertex_primitive_ring<edge_handle, vertex_edge_circulator>::vertex_primitive_ring;
};
/// all adjacent faces of a vertex (INCLUDES invalid ones for boundaries)
struct vertex_face_ring
struct vertex_face_ring : vertex_primitive_ring<face_handle, vertex_face_circulator>
{
vertex_handle vertex;
/// Number of vertices
/// O(result) computation
int size() const;
/// Returns true if handle is contained in this ring
bool contains(face_handle f) const;
// Iteration:
vertex_face_circulator begin() const { return {vertex.any_outgoing_halfedge(), vertex.is_isolated()}; }
vertex_face_circulator end() const { return {vertex.any_outgoing_halfedge(), true}; }
using vertex_primitive_ring<face_handle, vertex_face_circulator>::vertex_primitive_ring;
};
/// ======== IMPLEMENTATION ========
inline int face_vertex_ring::size() const
{
auto cnt = 0;
for (auto v : *this)
{
(void)v; // unused
cnt++;
}
return cnt;
}
inline int face_edge_ring::size() const
{
auto cnt = 0;
for (auto v : *this)
{
(void)v; // unused
cnt++;
}
return cnt;
}
inline int face_halfedge_ring::size() const
{
auto cnt = 0;
for (auto v : *this)
{
(void)v; // unused
cnt++;
}
return cnt;
}
inline int face_face_ring::size() const
{
auto cnt = 0;
for (auto v : *this)
{
(void)v; // unused
cnt++;
}
return cnt;
}
inline int vertex_halfedge_out_ring::size() const
template <class this_t, class element_handle>
int primitive_ring<this_t, element_handle>::size() const
{
auto cnt = 0;
for (auto v : *this)
for (auto v : *static_cast<this_t const*>(this))
{
(void)v; // unused
cnt++;
......@@ -385,119 +287,12 @@ inline int vertex_halfedge_out_ring::size() const
return cnt;
}
inline int vertex_halfedge_in_ring::size() const
template <class this_t, class element_handle>
bool primitive_ring<this_t, element_handle>::contains(element_handle v) const
{
auto cnt = 0;
for (auto v : *this)
{
(void)v; // unused
cnt++;
}
return cnt;
}
inline int vertex_vertex_ring::size() const
{
auto cnt = 0;
for (auto v : *this)
{
(void)v; // unused
cnt++;
}
return cnt;
}
inline int vertex_edge_ring::size() const
{
auto cnt = 0;
for (auto v : *this)
{
(void)v; // unused
cnt++;
}
return cnt;
}
inline int vertex_face_ring::size() const
{
auto cnt = 0;
for (auto v : *this)
{
(void)v; // unused
cnt++;
}
return cnt;
}
inline bool face_vertex_ring::contains(vertex_handle v) const
{
for (auto v2 : *this)
if (v == v2)
return true;
return false;
}
inline bool face_edge_ring::contains(edge_handle e) const
{
for (auto e2 : *this)
if (e == e2)
return true;
return false;
}
inline bool face_halfedge_ring::contains(halfedge_handle h) const
{
for (auto h2 : *this)
if (h == h2)
return true;
return false;
}
inline bool face_face_ring::contains(face_handle f) const
{
for (auto f2 : *this)
if (f == f2)
return true;
return false;
}
inline bool vertex_halfedge_out_ring::contains(halfedge_handle h) const
{
for (auto h2 : *this)
if (h == h2)
return true;
return false;
}
inline bool vertex_halfedge_in_ring::contains(halfedge_handle h) const
{
for (auto h2 : *this)
if (h == h2)
return true;
return false;
}
inline bool vertex_vertex_ring::contains(vertex_handle v) const
{
for (auto v2 : *this)
for (auto v2 : *static_cast<this_t const*>(this))
if (v == v2)
return true;
return false;
}
inline bool vertex_edge_ring::contains(edge_handle e) const
{
for (auto e2 : *this)
if (e == e2)
return true;
return false;
}
inline bool vertex_face_ring::contains(face_handle f) const
{
for (auto f2 : *this)
if (f == f2)
return true;
return false;
}
}
Markdown is supported
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