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

added primitive index

parent eba11f32
......@@ -23,6 +23,16 @@
namespace polymesh
{
template <class Primitive, class AttrT>
struct primitive_attribute
{
};
// ===========================================
// OLD CODE:
template <class AttrT>
struct vertex_attribute : vertex_attribute_base
{
......@@ -413,37 +423,44 @@ halfedge_attribute<AttrT>& halfedge_attribute<AttrT>::operator=(halfedge_attribu
/// ======== CURSOR IMPLEMENTATION ========
template <class tag>
template <class AttrT>
AttrT& face_index::operator[](face_attribute<AttrT>& attr) const
AttrT& primitive_index<tag>::operator[](primitive_index::attribute<AttrT>& attr) const
{
return attr[*this];
}
template <class tag>
template <class AttrT>
AttrT const& face_index::operator[](face_attribute<AttrT> const& attr) const
AttrT const& primitive_index<tag>::operator[](primitive_index::attribute<AttrT> const& attr) const
{
return attr[*this];
}
template <class tag>
template <class AttrT>
AttrT& face_handle::operator[](face_attribute<AttrT>& attr) const
AttrT& primitive_index<tag>::operator[](primitive_index::attribute<AttrT>* attr) const
{
return attr[*this];
return (*attr)[*this];
}
template <class tag>
template <class AttrT>
AttrT const& face_handle::operator[](face_attribute<AttrT> const& attr) const
AttrT const& primitive_index<tag>::operator[](primitive_index::attribute<AttrT> const* attr) const
{
return attr[*this];
return (*attr)[*this];
}
template <class AttrT>
AttrT& vertex_index::operator[](vertex_attribute<AttrT>& attr) const
AttrT& face_handle::operator[](face_attribute<AttrT>& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT const& vertex_index::operator[](vertex_attribute<AttrT> const& attr) const
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
{
......@@ -455,16 +472,6 @@ AttrT const& vertex_handle::operator[](vertex_attribute<AttrT> const& attr) cons
return attr[*this];
}
template <class AttrT>
AttrT& edge_index::operator[](edge_attribute<AttrT>& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT const& edge_index::operator[](edge_attribute<AttrT> const& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT& edge_handle::operator[](edge_attribute<AttrT>& attr) const
{
......@@ -476,16 +483,6 @@ AttrT const& edge_handle::operator[](edge_attribute<AttrT> const& attr) const
return attr[*this];
}
template <class AttrT>
AttrT& halfedge_index::operator[](halfedge_attribute<AttrT>& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT const& halfedge_index::operator[](halfedge_attribute<AttrT> const& attr) const
{
return attr[*this];
}
template <class AttrT>
AttrT& halfedge_handle::operator[](halfedge_attribute<AttrT>& attr) const
{
......@@ -497,16 +494,6 @@ AttrT const& halfedge_handle::operator[](halfedge_attribute<AttrT> const& attr)
return attr[*this];
}
template <class AttrT>
AttrT& face_index::operator[](face_attribute<AttrT>* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT const& face_index::operator[](face_attribute<AttrT> const* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT& face_handle::operator[](face_attribute<AttrT>* attr) const
{
......@@ -518,16 +505,6 @@ AttrT const& face_handle::operator[](face_attribute<AttrT> const* attr) const
return (*attr)[*this];
}
template <class AttrT>
AttrT& vertex_index::operator[](vertex_attribute<AttrT>* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT const& vertex_index::operator[](vertex_attribute<AttrT> const* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT& vertex_handle::operator[](vertex_attribute<AttrT>* attr) const
{
......@@ -539,16 +516,6 @@ AttrT const& vertex_handle::operator[](vertex_attribute<AttrT> const* attr) cons
return (*attr)[*this];
}
template <class AttrT>
AttrT& edge_index::operator[](edge_attribute<AttrT>* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT const& edge_index::operator[](edge_attribute<AttrT> const* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT& edge_handle::operator[](edge_attribute<AttrT>* attr) const
{
......@@ -560,16 +527,6 @@ AttrT const& edge_handle::operator[](edge_attribute<AttrT> const* attr) const
return (*attr)[*this];
}
template <class AttrT>
AttrT& halfedge_index::operator[](halfedge_attribute<AttrT>* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT const& halfedge_index::operator[](halfedge_attribute<AttrT> const* attr) const
{
return (*attr)[*this];
}
template <class AttrT>
AttrT& halfedge_handle::operator[](halfedge_attribute<AttrT>* attr) const
{
......
......@@ -2,132 +2,67 @@
#include <iostream>
#include "primitives.hh"
namespace polymesh
{
class Mesh;
template <class PropT>
struct vertex_attribute;
template <class PropT>
struct face_attribute;
template <class PropT>
struct edge_attribute;
template <class PropT>
struct halfedge_attribute;
struct vertex_handle;
struct face_handle;
struct edge_handle;
struct halfedge_handle;
struct face_vertex_ring;
struct face_edge_ring;
struct face_halfedge_ring;
struct face_face_ring;
struct vertex_halfedge_out_ring;
struct vertex_halfedge_in_ring;
struct vertex_face_ring;
struct vertex_edge_ring;
struct vertex_vertex_ring;
// ======================== INDICES ========================
struct face_index
template <typename tag>
struct primitive_index
{
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;
int value = -1;
face_index() = default;
explicit face_index(int idx) : value(idx) {}
primitive_index() = default;
explicit primitive_index(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
bool is_invalid() const { return value < 0; }
static face_index invalid() { return {}; }
bool operator==(face_index const& rhs) const { return value == rhs.value; }
bool operator!=(face_index const& rhs) const { return value != rhs.value; }
template <class PropT>
PropT& operator[](face_attribute<PropT>& prop) const;
template <class PropT>
PropT const& operator[](face_attribute<PropT> const& prop) const;
template <class PropT>
PropT& operator[](face_attribute<PropT>* prop) const;
template <class PropT>
PropT const& operator[](face_attribute<PropT> const* prop) const;
static index_t invalid() { return {}; }
bool operator==(index_t const& rhs) const { return value == rhs.value; }
bool operator!=(index_t const& rhs) const { return value != rhs.value; }
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;
};
struct vertex_index
struct face_index : primitive_index<face_tag>
{
int value = -1;
vertex_index() = default;
explicit vertex_index(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
bool is_invalid() const { return value < 0; }
static vertex_index invalid() { return {}; }
bool operator==(vertex_index const& rhs) const { return value == rhs.value; }
bool operator!=(vertex_index const& rhs) const { return value != rhs.value; }
template <class PropT>
PropT& operator[](vertex_attribute<PropT>& prop) const;
template <class PropT>
PropT const& operator[](vertex_attribute<PropT> const& prop) const;
template <class PropT>
PropT& operator[](vertex_attribute<PropT>* prop) const;
template <class PropT>
PropT const& operator[](vertex_attribute<PropT> const* prop) const;
using primitive_index::primitive_index;
using primitive_index::operator=;
};
struct edge_index
struct edge_index : primitive_index<edge_tag>
{
int value = -1;
edge_index() = default;
explicit edge_index(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
bool is_invalid() const { return value < 0; }
static edge_index invalid() { return {}; }
bool operator==(edge_index const& rhs) const { return value == rhs.value; }
bool operator!=(edge_index const& rhs) const { return value != rhs.value; }
template <class PropT>
PropT& operator[](edge_attribute<PropT>& prop) const;
template <class PropT>
PropT const& operator[](edge_attribute<PropT> const& prop) const;
template <class PropT>
PropT& operator[](edge_attribute<PropT>* prop) const;
template <class PropT>
PropT const& operator[](edge_attribute<PropT> const* prop) const;
using primitive_index::primitive_index;
using primitive_index::operator=;
};
struct halfedge_index
struct halfedge_index : primitive_index<halfedge_tag>
{
int value = -1;
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=;
};
halfedge_index() = default;
explicit halfedge_index(int idx) : value(idx) {}
bool is_valid() const { return value >= 0; }
bool is_invalid() const { return value < 0; }
static halfedge_index invalid() { return {}; }
bool operator==(halfedge_index const& rhs) const { return value == rhs.value; }
bool operator!=(halfedge_index const& rhs) const { return value != rhs.value; }
template <class PropT>
PropT& operator[](halfedge_attribute<PropT>& prop) const;
template <class PropT>
PropT const& operator[](halfedge_attribute<PropT> const& prop) const;
template <class PropT>
PropT& operator[](halfedge_attribute<PropT>* prop) const;
template <class PropT>
PropT const& operator[](halfedge_attribute<PropT> const* prop) const;
};
// ===========================================
// OLD CODE:
// ======================== HANDLES ========================
......@@ -144,14 +79,14 @@ struct face_handle
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 PropT>
PropT& operator[](face_attribute<PropT>& prop) const;
template <class PropT>
PropT const& operator[](face_attribute<PropT> const& prop) const;
template <class PropT>
PropT& operator[](face_attribute<PropT>* prop) const;
template <class PropT>
PropT const& operator[](face_attribute<PropT> 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;
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
......@@ -181,14 +116,14 @@ struct vertex_handle
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 PropT>
PropT& operator[](vertex_attribute<PropT>& prop) const;
template <class PropT>
PropT const& operator[](vertex_attribute<PropT> const& prop) const;
template <class PropT>
PropT& operator[](vertex_attribute<PropT>* prop) const;
template <class PropT>
PropT const& operator[](vertex_attribute<PropT> 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;
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
......@@ -223,14 +158,14 @@ struct edge_handle
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 PropT>
PropT& operator[](edge_attribute<PropT>& prop) const;
template <class PropT>
PropT const& operator[](edge_attribute<PropT> const& prop) const;
template <class PropT>
PropT& operator[](edge_attribute<PropT>* prop) const;
template <class PropT>
PropT const& operator[](edge_attribute<PropT> 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;
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
......@@ -260,14 +195,14 @@ struct halfedge_handle
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 PropT>
PropT& operator[](halfedge_attribute<PropT>& prop) const;
template <class PropT>
PropT const& operator[](halfedge_attribute<PropT> const& prop) const;
template <class PropT>
PropT& operator[](halfedge_attribute<PropT>* prop) const;
template <class PropT>
PropT const& operator[](halfedge_attribute<PropT> 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;
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
......
#pragma once
namespace polymesh
{
class Mesh;
struct vertex_tag;
struct face_tag;
struct edge_tag;
struct halfedge_tag;
template <class PropT>
struct vertex_attribute;
template <class PropT>
struct face_attribute;
template <class PropT>
struct edge_attribute;
template <class PropT>
struct halfedge_attribute;
struct vertex_index;
struct face_index;
struct edge_index;
struct halfedge_index;
struct vertex_handle;
struct face_handle;
struct edge_handle;
struct halfedge_handle;
struct face_vertex_ring;
struct face_edge_ring;
struct face_halfedge_ring;
struct face_face_ring;
struct vertex_halfedge_out_ring;
struct vertex_halfedge_in_ring;
struct vertex_face_ring;
struct vertex_edge_ring;
struct vertex_vertex_ring;
}
......@@ -9,6 +9,19 @@
namespace polymesh
{
struct valid_primitive_iterator
{
};
// ===========================================
// OLD CODE:
struct valid_vertex_iterator
{
valid_vertex_iterator() = default;
......
#pragma once
#include "fwd.hh"
namespace polymesh
{
template<typename tag>
struct primitive;
template<>
struct primitive<vertex_tag>
{
using index = vertex_index;
using handle = vertex_handle;
template<class AttrT>
using attribute = vertex_attribute<AttrT>;
};
template<>
struct primitive<face_tag>
{
using index = face_index;
using handle = face_handle;
template<class AttrT>
using attribute = face_attribute<AttrT>;
};
template<>
struct primitive<edge_tag>
{
using index = edge_index;
using handle = edge_handle;
template<class AttrT>
using attribute = edge_attribute<AttrT>;
};
template<>
struct primitive<halfedge_tag>
{
using index = halfedge_index;
using handle = halfedge_handle;
template<class AttrT>
using attribute = halfedge_attribute<AttrT>;
};
}
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