Commit 2cadd067 authored by Philip Trettner's avatar Philip Trettner
Browse files

added primitive_handle

parent 63658644
......@@ -448,93 +448,29 @@ AttrT const& primitive_index<tag>::operator[](primitive_index::attribute<AttrT>
return (*attr)[*this];
}
template <class AttrT>
AttrT& face_handle::operator[](face_attribute<AttrT>& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT const& face_handle::operator[](face_attribute<AttrT> const& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT& vertex_handle::operator[](vertex_attribute<AttrT>& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT const& vertex_handle::operator[](vertex_attribute<AttrT> const& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT& edge_handle::operator[](edge_attribute<AttrT>& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT const& edge_handle::operator[](edge_attribute<AttrT> const& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT& halfedge_handle::operator[](halfedge_attribute<AttrT>& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT const& halfedge_handle::operator[](halfedge_attribute<AttrT> const& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT& face_handle::operator[](face_attribute<AttrT>* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT const& face_handle::operator[](face_attribute<AttrT> const* attr) const
{
return (*attr)[*this];
}
template <class tag>
template <class AttrT>
AttrT& vertex_handle::operator[](vertex_attribute<AttrT>* attr) const
AttrT& primitive_handle<tag>::operator[](primitive_handle::attribute<AttrT>& attr) const
{
return (*attr)[*this];
return attr[idx];
}
template <class tag>
template <class AttrT>
AttrT const& vertex_handle::operator[](vertex_attribute<AttrT> const* attr) const
AttrT const& primitive_handle<tag>::operator[](primitive_handle::attribute<AttrT> const& attr) const
{
return (*attr)[*this];
return attr[idx];
}
template <class tag>
template <class AttrT>
AttrT& edge_handle::operator[](edge_attribute<AttrT>* attr) const
AttrT& primitive_handle<tag>::operator[](primitive_handle::attribute<AttrT>* attr) const
{
return (*attr)[*this];
return (*attr)[idx];
}
template <class tag>
template <class AttrT>
AttrT const& edge_handle::operator[](edge_attribute<AttrT> const* attr) const
AttrT const& primitive_handle<tag>::operator[](primitive_handle::attribute<AttrT> const* attr) const
{
return (*attr)[*this];
return (*attr)[idx];
}
template <class AttrT>
AttrT& halfedge_handle::operator[](halfedge_attribute<AttrT>* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT const& halfedge_handle::operator[](halfedge_attribute<AttrT> const* attr) const
{
return (*attr)[*this];
}
}
......@@ -6,9 +6,9 @@
namespace polymesh
{
// ======================== INDICES ========================
// ======================== BASE ========================
template <typename tag>
template <class tag>
struct primitive_index
{
template <class AttrT>
......@@ -38,60 +38,64 @@ struct primitive_index
AttrT const& operator[](attribute<AttrT> const* prop) const;
};
template <class tag>
struct primitive_handle
{
template <class AttrT>
using attribute = typename primitive<tag>::template attribute<AttrT>;
using index_t = typename primitive<tag>::index;
using handle_t = typename primitive<tag>::handle;
Mesh const* mesh = nullptr;
index_t idx;
primitive_handle() = default;
primitive_handle(Mesh const* mesh, index_t idx) : mesh(mesh), idx(idx) {}
bool operator==(index_t const& rhs) const { return idx == rhs; }
bool operator!=(index_t const& rhs) const { return idx != rhs; }
bool operator==(handle_t const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(handle_t const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
template <class AttrT>
AttrT& operator[](attribute<AttrT>& prop) const;
template <class AttrT>
AttrT const& operator[](attribute<AttrT> const& prop) const;
template <class AttrT>
AttrT& operator[](attribute<AttrT>* prop) const;
template <class AttrT>
AttrT const& operator[](attribute<AttrT> const* prop) const;
bool is_valid() const { return idx.is_valid(); } ///< valid idx (but could be deleted in some iterators)
bool is_invalid() const { return !idx.is_valid(); } ///< invalid idx
};
// ======================== INDICES ========================
struct face_index : primitive_index<face_tag>
{
using primitive_index::primitive_index;
using primitive_index::operator=;
};
struct edge_index : primitive_index<edge_tag>
{
using primitive_index::primitive_index;
using primitive_index::operator=;
};
struct halfedge_index : primitive_index<halfedge_tag>
{
using primitive_index::primitive_index;
using primitive_index::operator=;
};
struct vertex_index : primitive_index<vertex_tag>
{
using primitive_index::primitive_index;
using primitive_index::operator=;
};
// ===========================================
// OLD CODE:
// ======================== HANDLES ========================
struct face_handle
struct face_handle : primitive_handle<face_tag>
{
Mesh const* mesh = nullptr;
face_index idx;
face_handle() = default;
face_handle(Mesh const* mesh, face_index idx) : mesh(mesh), idx(idx) {}
bool operator==(face_index const& rhs) const { return idx == rhs; }
bool operator!=(face_index const& rhs) const { return idx != rhs; }
bool operator==(face_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(face_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
template <class AttrT>
AttrT& operator[](face_attribute<AttrT>& prop) const;
template <class AttrT>
AttrT const& operator[](face_attribute<AttrT> const& prop) const;
template <class AttrT>
AttrT& operator[](face_attribute<AttrT>* prop) const;
template <class AttrT>
AttrT const& operator[](face_attribute<AttrT> const* prop) const;
bool is_valid() const { return idx.is_valid(); } ///< valid idx (but could be deleted in some iterators)
bool is_invalid() const { return !idx.is_valid(); } ///< invalid idx
bool is_removed() const; ///< marked for deletion (but valid idx)
using primitive_handle::primitive_handle;
bool is_removed() const; ///< marked for deletion (but valid idx)
bool is_boundary() const; ///< true if this face lies at a boundary
vertex_handle any_vertex() const;
......@@ -103,32 +107,11 @@ struct face_handle
face_face_ring adjacent_faces() const; ///< includes invalid ones for boundaries!
};
struct vertex_handle
struct vertex_handle : primitive_handle<vertex_tag>
{
Mesh const* mesh = nullptr;
vertex_index idx;
vertex_handle() = default;
vertex_handle(Mesh const* mesh, vertex_index idx) : mesh(mesh), idx(idx) {}
bool operator==(vertex_index const& rhs) const { return idx == rhs; }
bool operator!=(vertex_index const& rhs) const { return idx != rhs; }
bool operator==(vertex_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(vertex_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
template <class AttrT>
AttrT& operator[](vertex_attribute<AttrT>& prop) const;
template <class AttrT>
AttrT const& operator[](vertex_attribute<AttrT> const& prop) const;
template <class AttrT>
AttrT& operator[](vertex_attribute<AttrT>* prop) const;
template <class AttrT>
AttrT const& operator[](vertex_attribute<AttrT> const* prop) const;
bool is_valid() const { return idx.is_valid(); } ///< valid idx (but could be deleted in some iterators)
bool is_invalid() const { return !idx.is_valid(); } ///< invalid idx
bool is_removed() const; ///< marked for deletion (but valid idx)
using primitive_handle::primitive_handle;
bool is_removed() const; ///< marked for deletion (but valid idx)
bool is_isolated() const; ///< true if this vertex is not connected at all
bool is_boundary() const; ///< true if this vertex lies at a boundary
......@@ -145,32 +128,11 @@ struct vertex_handle
vertex_vertex_ring adjacent_vertices() const;
};
struct edge_handle
struct edge_handle : primitive_handle<edge_tag>
{
Mesh const* mesh = nullptr;
edge_index idx;
edge_handle() = default;
edge_handle(Mesh const* mesh, edge_index idx) : mesh(mesh), idx(idx) {}
bool operator==(edge_index const& rhs) const { return idx == rhs; }
bool operator!=(edge_index const& rhs) const { return idx != rhs; }
bool operator==(edge_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(edge_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
template <class AttrT>
AttrT& operator[](edge_attribute<AttrT>& prop) const;
template <class AttrT>
AttrT const& operator[](edge_attribute<AttrT> const& prop) const;
template <class AttrT>
AttrT& operator[](edge_attribute<AttrT>* prop) const;
template <class AttrT>
AttrT const& operator[](edge_attribute<AttrT> const* prop) const;
bool is_valid() const { return idx.is_valid(); } ///< valid idx (but could be deleted in some iterators)
bool is_invalid() const { return !idx.is_valid(); } ///< invalid idx
bool is_removed() const; ///< marked for deletion (but valid idx)
using primitive_handle::primitive_handle;
bool is_removed() const; ///< marked for deletion (but valid idx)
bool is_isolated() const; ///< true if this edge has no faces
bool is_boundary() const; ///< true if this edge is a boundary
......@@ -182,32 +144,11 @@ struct edge_handle
face_handle faceB() const; ///< can be invalid if boundary
};
struct halfedge_handle
struct halfedge_handle : primitive_handle<halfedge_tag>
{
Mesh const* mesh = nullptr;
halfedge_index idx;
halfedge_handle() = default;
halfedge_handle(Mesh const* mesh, halfedge_index idx) : mesh(mesh), idx(idx) {}
bool operator==(halfedge_index const& rhs) const { return idx == rhs; }
bool operator!=(halfedge_index const& rhs) const { return idx != rhs; }
bool operator==(halfedge_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
bool operator!=(halfedge_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
template <class AttrT>
AttrT& operator[](halfedge_attribute<AttrT>& prop) const;
template <class AttrT>
AttrT const& operator[](halfedge_attribute<AttrT> const& prop) const;
template <class AttrT>
AttrT& operator[](halfedge_attribute<AttrT>* prop) const;
template <class AttrT>
AttrT const& operator[](halfedge_attribute<AttrT> const* prop) const;
bool is_valid() const { return idx.is_valid(); } ///< valid idx (but could be deleted in some iterators)
bool is_invalid() const { return !idx.is_valid(); } ///< invalid idx
bool is_removed() const; ///< marked for deletion (but valid idx)
using primitive_handle::primitive_handle;
bool is_removed() const; ///< marked for deletion (but valid idx)
bool is_boundary() const; ///< true if this half-edge is a boundary (CAUTION: its opposite might not be)
vertex_handle vertex_to() const;
......@@ -222,53 +163,19 @@ struct halfedge_handle
/// ======== IMPLEMENTATION ========
inline std::ostream& operator<<(std::ostream& out, vertex_index v)
template <class tag>
std::ostream& operator<<(std::ostream& out, primitive_index<tag> const& v)
{
out << "vertex " << v.value;
out << primitive<tag>::name << " " << v.value;
if (v.is_invalid())
out << " (invalid)";
return out;
}
inline std::ostream& operator<<(std::ostream& out, face_index f)
{
out << "face " << f.value;
if (f.is_invalid())
out << " (invalid)";
return out;
}
inline std::ostream& operator<<(std::ostream& out, edge_index e)
{
out << "edge " << e.value;
if (e.is_invalid())
out << " (invalid)";
return out;
}
inline std::ostream& operator<<(std::ostream& out, halfedge_index h)
{
out << "half-edge " << h.value;
if (h.is_invalid())
out << " (invalid)";
return out;
}
inline std::ostream& operator<<(std::ostream& out, vertex_handle v)
template <class tag>
std::ostream& operator<<(std::ostream& out, primitive_handle<tag> const& v)
{
out << v.idx;
return out;
}
inline std::ostream& operator<<(std::ostream& out, face_handle f)
{
out << f.idx;
return out;
}
inline std::ostream& operator<<(std::ostream& out, edge_handle e)
{
out << e.idx;
return out;
}
inline std::ostream& operator<<(std::ostream& out, halfedge_handle h)
{
out << h.idx;
return out;
}
}
......@@ -10,6 +10,8 @@ struct primitive;
template<>
struct primitive<vertex_tag>
{
static constexpr auto name = "vertex";
using index = vertex_index;
using handle = vertex_handle;
......@@ -20,6 +22,8 @@ struct primitive<vertex_tag>
template<>
struct primitive<face_tag>
{
static constexpr auto name = "face";
using index = face_index;
using handle = face_handle;
......@@ -30,6 +34,8 @@ struct primitive<face_tag>
template<>
struct primitive<edge_tag>
{
static constexpr auto name = "edge";
using index = edge_index;
using handle = edge_handle;
......@@ -40,6 +46,8 @@ struct primitive<edge_tag>
template<>
struct primitive<halfedge_tag>
{
static constexpr auto name = "half-edge";
using index = halfedge_index;
using handle = halfedge_handle;
......
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