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

working on iteration

parent dc2a0eeb
......@@ -19,3 +19,4 @@ 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
......@@ -138,8 +138,8 @@ private:
halfedge_index prev_valid_idx_from(halfedge_index idx) const;
// Iterators
vertex_iterator vertices_begin() const { return {{this, vertex_index(0)}}; }
vertex_iterator vertices_end() const { return {{this, vertex_index(size_vertices())}}; }
all_vertex_iterator vertices_begin() const { return {{this, vertex_index(0)}}; }
all_vertex_iterator vertices_end() const { return {{this, vertex_index(size_vertices())}}; }
valid_vertex_iterator valid_vertices_begin() const { return {{this, vertex_index(0)}}; }
valid_vertex_iterator valid_vertices_end() const { return {{this, vertex_index(size_vertices())}}; }
......@@ -349,7 +349,7 @@ private:
private:
friend struct vertex_handle;
friend struct vertex_collection;
friend struct vertex_iterator;
friend struct all_vertex_iterator;
friend struct valid_vertex_iterator;
friend struct valid_vertex_collection;
friend struct const_vertex_collection;
......@@ -384,7 +384,7 @@ private:
template <class tag>
friend struct primitive_collection;
template <class tag>
friend struct primitive_iterator;
friend struct all_primitive_iterator;
template <class tag>
friend struct valid_primitive_iterator;
template <class tag>
......@@ -907,7 +907,7 @@ inline valid_vertex_iterator &valid_vertex_iterator::operator++()
handle.idx = handle.mesh->next_valid_idx_from(handle.idx);
return *this;
}
inline vertex_iterator &vertex_iterator::operator++()
inline all_vertex_iterator &all_vertex_iterator::operator++()
{
handle.idx.value++;
return *this;
......@@ -1024,12 +1024,12 @@ inline vertex_handle vertex_collection::add() const
return mesh->handle_of(mesh->add_vertex());
}
inline vertex_iterator vertex_collection::begin() const
inline all_vertex_iterator vertex_collection::begin() const
{
return mesh->vertices_begin();
}
inline vertex_iterator vertex_collection::end() const
inline all_vertex_iterator vertex_collection::end() const
{
return mesh->vertices_end();
}
......@@ -1039,12 +1039,12 @@ inline int const_vertex_collection::size() const
return mesh->size_vertices();
}
inline vertex_iterator const_vertex_collection::begin() const
inline all_vertex_iterator const_vertex_collection::begin() const
{
return mesh->vertices_begin();
}
inline vertex_iterator const_vertex_collection::end() const
inline all_vertex_iterator const_vertex_collection::end() const
{
return mesh->vertices_end();
}
......
......@@ -18,6 +18,11 @@ struct edge_attribute;
template <class AttrT>
struct halfedge_attribute;
template <typename tag>
struct all_primitive_iterator;
template <typename tag>
struct valid_primitive_iterator;
struct vertex_index;
struct face_index;
struct edge_index;
......
......@@ -10,241 +10,80 @@
namespace polymesh
{
// struct valid_primitive_iterator
// {
//
// };
// ===========================================
// OLD CODE:
struct valid_vertex_iterator
template <typename tag>
struct valid_primitive_iterator
{
valid_vertex_iterator() = default;
valid_vertex_iterator(vertex_handle handle) : handle(handle) { move_to_valid(); }
using handle_t = typename primitive<tag>::handle;
vertex_handle operator*() const { return handle; }
valid_vertex_iterator& operator++();
valid_vertex_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(valid_vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(valid_vertex_iterator const& rhs) const
valid_primitive_iterator() = default;
valid_primitive_iterator(handle_t handle) : handle(handle)
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
handle.idx = handle.mesh->next_valid_idx_from(handle.idx);
}
private:
vertex_handle handle;
void move_to_valid();
};
struct vertex_iterator
{
vertex_iterator() = default;
vertex_iterator(vertex_handle handle) : handle(handle) {}
vertex_handle operator*() const { return handle; }
vertex_iterator& operator++();
vertex_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(vertex_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(vertex_iterator const& rhs) const
handle_t operator*() const { return handle; }
valid_primitive_iterator& operator++()
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
handle.idx.value++;
handle.idx = handle.mesh->next_valid_idx_from(handle.idx);
return *this;
}
private:
vertex_handle handle;
};
struct valid_face_iterator
{
valid_face_iterator() = default;
valid_face_iterator(face_handle handle) : handle(handle) { move_to_valid(); }
face_handle operator*() const { return handle; }
valid_face_iterator& operator++();
valid_face_iterator operator++(int)
valid_primitive_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(valid_face_iterator const& rhs) const
bool operator==(valid_primitive_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(valid_face_iterator const& rhs) const
bool operator!=(valid_primitive_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
face_handle handle;
void move_to_valid();
handle_t handle;
};
struct face_iterator
template <typename tag>
struct all_primitive_iterator
{
face_iterator() = default;
face_iterator(face_handle handle) : handle(handle) {}
face_handle operator*() const { return handle; }
face_iterator& operator++();
face_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(face_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(face_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
using handle_t = typename primitive<tag>::handle;
private:
face_handle handle;
};
all_primitive_iterator() = default;
all_primitive_iterator(handle_t handle) : handle(handle) {}
struct valid_edge_iterator
{
valid_edge_iterator() = default;
valid_edge_iterator(edge_handle handle) : handle(handle) { move_to_valid(); }
edge_handle operator*() const { return handle; }
valid_edge_iterator& operator++();
valid_edge_iterator operator++(int)
handle_t operator*() const { return handle; }
all_primitive_iterator& operator++()
{
auto i = *this;
return ++i;
}
bool operator==(valid_edge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(valid_edge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
handle.idx.value++;
return *this;
}
private:
edge_handle handle;
void move_to_valid();
};
struct edge_iterator
{
edge_iterator() = default;
edge_iterator(edge_handle handle) : handle(handle) {}
edge_handle operator*() const { return handle; }
edge_iterator& operator++();
edge_iterator operator++(int)
all_primitive_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(edge_iterator const& rhs) const
bool operator==(all_primitive_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(edge_iterator const& rhs) const
bool operator!=(all_primitive_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
edge_handle handle;
handle_t handle;
};
struct valid_halfedge_iterator
{
valid_halfedge_iterator() = default;
valid_halfedge_iterator(halfedge_handle handle) : handle(handle) { move_to_valid(); }
halfedge_handle operator*() const { return handle; }
valid_halfedge_iterator& operator++();
valid_halfedge_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(valid_halfedge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(valid_halfedge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
halfedge_handle handle;
void move_to_valid();
};
struct halfedge_iterator
{
halfedge_iterator() = default;
halfedge_iterator(halfedge_handle handle) : handle(handle) {}
halfedge_handle operator*() const { return handle; }
halfedge_iterator& operator++();
halfedge_iterator operator++(int)
{
auto i = *this;
return ++i;
}
bool operator==(halfedge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx == rhs.handle.idx;
}
bool operator!=(halfedge_iterator const& rhs) const
{
assert(handle.mesh == rhs.handle.mesh && "comparing iterators from different meshes");
return handle.idx != rhs.handle.idx;
}
private:
halfedge_handle handle;
};
// ===========================================
// OLD CODE:
/// Iterates over all vertices of a given face
struct face_vertex_circulator
......
......@@ -16,6 +16,8 @@ struct primitive<vertex_tag>
using handle = vertex_handle;
using collection = vertex_collection;
using const_collection = const_vertex_collection;
using all_iterator = all_primitive_iterator<vertex_tag>;
using valid_iterator = valid_primitive_iterator<vertex_tag>;
template<class AttrT>
using attribute = vertex_attribute<AttrT>;
......@@ -33,6 +35,8 @@ struct primitive<face_tag>
using handle = face_handle;
using collection = face_collection;
using const_collection = const_face_collection;
using all_iterator = all_primitive_iterator<face_tag>;
using valid_iterator = valid_primitive_iterator<face_tag>;
template<class AttrT>
using attribute = face_attribute<AttrT>;
......@@ -50,6 +54,8 @@ struct primitive<edge_tag>
using handle = edge_handle;
using collection = edge_collection;
using const_collection = const_edge_collection;
using all_iterator = all_primitive_iterator<edge_tag>;
using valid_iterator = valid_primitive_iterator<edge_tag>;
template<class AttrT>
using attribute = edge_attribute<AttrT>;
......@@ -67,6 +73,8 @@ struct primitive<halfedge_tag>
using handle = halfedge_handle;
using collection = halfedge_collection;
using const_collection = const_halfedge_collection;
using all_iterator = all_primitive_iterator<halfedge_tag>;
using valid_iterator = valid_primitive_iterator<halfedge_tag>;
template<class AttrT>
using attribute = halfedge_attribute<AttrT>;
......
......@@ -7,18 +7,38 @@
namespace polymesh
{
/// Collection of all vertices of a mesh, including deleted ones
/// Basically a smart std::vector
struct vertex_collection
template<class tag, class iterator>
struct smart_collection
{
Mesh* mesh;
template<typename AttrT>
using attribute = typename primitive<tag>::template attribute<AttrT>;
/// Number of vertices, INCLUDING deleted/invalid ones
/// Number of primitives, INCLUDING those marked for deletion
/// O(1) computation
int size() const;
/// Ensures that a given number of vertices can be stored without reallocation
/// Ensures that a given number of primitives can be stored without reallocation
void reserve(int capacity) const;
/// Creates a new vertex attribute
template <class PropT>
attribute<PropT> make_attribute(PropT const& def_value = PropT());
// Iteration:
iterator begin() const;
iterator end() const;
private:
/// Backreference to mesh
Mesh* mesh;
friend class Mesh;
};
/// Collection of all vertices of a mesh, including deleted ones
/// Basically a smart std::vector
struct vertex_collection : smart_collection<vertex_tag, primitive<vertex_tag>::all_iterator>
{
/// Adds a new vertex and returns its handle
/// Does NOT invalidate any iterator!
vertex_handle add() const;
......@@ -26,14 +46,6 @@ struct vertex_collection
/// Removes a vertex (and all adjacent faces and edges)
/// (marks them as removed, compactify mesh to actually remove them)
void remove(vertex_handle v) const;
/// Creates a new vertex attribute
template <class PropT>
vertex_attribute<PropT> make_attribute(PropT const& def_value = PropT());
// Iteration:
vertex_iterator begin() const;
vertex_iterator end() const;
};
/// same as vertex_collection but const
......@@ -50,8 +62,8 @@ struct const_vertex_collection
vertex_attribute<PropT> make_attribute(PropT const& def_value = PropT());
// Iteration:
vertex_iterator begin() const;
vertex_iterator end() const;
all_vertex_iterator begin() const;
all_vertex_iterator end() const;
};
/// Same as vertex_collection but only including valid, non-deleted vertices
......
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