Commit 844de414 authored by Max Lyon's avatar Max Lyon
Browse files

avoid diamond inheritance and add range and convenience functions

parent 04ba5651
......@@ -66,6 +66,54 @@ SmartHalfedgeHandle SmartVertexHandle::in() const
return out().opp();
}
PolyConnectivity::ConstVertexFaceRange SmartVertexHandle::faces() const
{
assert(mesh() != nullptr);
return mesh()->vf_range(*this);
}
PolyConnectivity::ConstVertexEdgeRange SmartVertexHandle::edges() const
{
assert(mesh() != nullptr);
return mesh()->ve_range(*this);
}
PolyConnectivity::ConstVertexVertexRange SmartVertexHandle::vertices() const
{
assert(mesh() != nullptr);
return mesh()->vv_range(*this);
}
PolyConnectivity::ConstVertexIHalfedgeRange SmartVertexHandle::incoming_halfedges() const
{
assert(mesh() != nullptr);
return mesh()->vih_range(*this);
}
PolyConnectivity::ConstVertexOHalfedgeRange SmartVertexHandle::outgoing_halfedges() const
{
assert(mesh() != nullptr);
return mesh()->voh_range(*this);
}
uint SmartVertexHandle::valence() const
{
assert(mesh() != nullptr);
return mesh()->valence(*this);
}
bool SmartVertexHandle::is_boundary() const
{
assert(mesh() != nullptr);
return mesh()->is_boundary(*this);
}
bool SmartVertexHandle::is_manifold() const
{
assert(mesh() != nullptr);
return mesh()->is_manifold(*this);
}
SmartHalfedgeHandle SmartHalfedgeHandle::next() const
{
assert(mesh() != nullptr);
......@@ -102,12 +150,23 @@ SmartFaceHandle SmartHalfedgeHandle::face() const
return make_smart(mesh()->face_handle(*this), mesh());
}
SmartHalfedgeHandle SmartEdgeHandle::h(unsigned int _i) const
bool SmartHalfedgeHandle::is_boundary() const
{
assert(mesh() != nullptr);
return mesh()->is_boundary(*this);
}
SmartHalfedgeHandle SmartEdgeHandle::halfedge(unsigned int _i) const
{
assert(mesh() != nullptr);
return make_smart(mesh()->halfedge_handle(*this, _i), mesh());
}
SmartHalfedgeHandle SmartEdgeHandle::h(unsigned int _i) const
{
return halfedge(_i);
}
SmartHalfedgeHandle SmartEdgeHandle::h0() const
{
return h(0);
......@@ -118,9 +177,14 @@ SmartHalfedgeHandle SmartEdgeHandle::h1() const
return h(1);
}
SmartVertexHandle SmartEdgeHandle::vertex(unsigned int _i) const
{
return halfedge(_i).from();
}
SmartVertexHandle SmartEdgeHandle::v(unsigned int _i) const
{
return h(_i).from();
return vertex(_i);
}
SmartVertexHandle SmartEdgeHandle::v0() const
......@@ -133,12 +197,54 @@ SmartVertexHandle SmartEdgeHandle::v1() const
return v(1);
}
bool SmartEdgeHandle::is_boundary() const
{
assert(mesh() != nullptr);
return mesh()->is_boundary(*this);
}
SmartHalfedgeHandle SmartFaceHandle::halfedge() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->halfedge_handle(*this), mesh());
}
PolyConnectivity::ConstFaceVertexRange SmartFaceHandle::vertices() const
{
assert(mesh() != nullptr);
return mesh()->fv_range(*this);
}
PolyConnectivity::ConstFaceHalfedgeRange SmartFaceHandle::halfedges() const
{
assert(mesh() != nullptr);
return mesh()->fh_range(*this);
}
PolyConnectivity::ConstFaceEdgeRange SmartFaceHandle::edges() const
{
assert(mesh() != nullptr);
return mesh()->fe_range(*this);
}
PolyConnectivity::ConstFaceFaceRange SmartFaceHandle::faces() const
{
assert(mesh() != nullptr);
return mesh()->ff_range(*this);
}
uint SmartFaceHandle::valence() const
{
assert(mesh() != nullptr);
return mesh()->valence(*this);
}
bool SmartFaceHandle::is_boundary() const
{
assert(mesh() != nullptr);
return mesh()->is_boundary(*this);
}
}
......
......@@ -47,6 +47,7 @@
//== INCLUDES =================================================================
#include "Handles.hh"
#include <OpenMesh/Core/Mesh/PolyConnectivity.hh>
//== NAMESPACES ===============================================================
......@@ -55,7 +56,6 @@ namespace OpenMesh {
//== FORWARD DECLARATION ======================================================
class PolyConnectivity;
struct SmartVertexHandle;
struct SmartHalfedgeHandle;
struct SmartEdgeHandle;
......@@ -64,66 +64,95 @@ struct SmartFaceHandle;
//== CLASS DEFINITION =========================================================
class SmartBaseHandle : public BaseHandle
class SmartBaseHandle
{
public:
explicit SmartBaseHandle(int _idx=-1, PolyConnectivity* _mesh = nullptr) : BaseHandle(_idx), mesh_(_mesh) {}
explicit SmartBaseHandle(const PolyConnectivity* _mesh = nullptr) : mesh_(_mesh) {}
/// Get the underlying mesh of this handle
PolyConnectivity* mesh() const { return mesh_; }
const PolyConnectivity* mesh() const { return mesh_; }
// TODO: should operators ==, !=, < look at mesh_?
private:
PolyConnectivity* mesh_;
const PolyConnectivity* mesh_;
};
struct SmartVertexHandle : public SmartBaseHandle, VertexHandle
{
explicit SmartVertexHandle(int _idx=-1, PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_idx, _mesh) {}
explicit SmartVertexHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), VertexHandle(_idx) {}
SmartHalfedgeHandle out() const;
SmartHalfedgeHandle out() const;
SmartHalfedgeHandle halfedge() const; // alias for out
SmartHalfedgeHandle in() const;
SmartHalfedgeHandle in() const;
PolyConnectivity::ConstVertexFaceRange faces() const;
PolyConnectivity::ConstVertexEdgeRange edges() const;
PolyConnectivity::ConstVertexVertexRange vertices() const;
PolyConnectivity::ConstVertexIHalfedgeRange incoming_halfedges() const;
PolyConnectivity::ConstVertexOHalfedgeRange outgoing_halfedges() const;
uint valence() const;
bool is_boundary() const;
bool is_manifold() const;
};
struct SmartHalfedgeHandle : public SmartBaseHandle, HalfedgeHandle
{
explicit SmartHalfedgeHandle(int _idx=-1, PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_idx, _mesh) {}
SmartHalfedgeHandle next() const;
SmartHalfedgeHandle prev() const;
SmartHalfedgeHandle opp() const;
SmartVertexHandle to() const;
SmartVertexHandle from() const;
SmartFaceHandle face() const;
explicit SmartHalfedgeHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), HalfedgeHandle(_idx) {}
SmartHalfedgeHandle next() const;
SmartHalfedgeHandle prev() const;
SmartHalfedgeHandle opp() const;
SmartVertexHandle to() const;
SmartVertexHandle from() const;
SmartFaceHandle face() const;
bool is_boundary() const;
};
struct SmartEdgeHandle : public SmartBaseHandle, EdgeHandle
{
explicit SmartEdgeHandle(int _idx=-1, PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_idx, _mesh) {}
SmartHalfedgeHandle h(unsigned int _i) const;
SmartHalfedgeHandle h0() const;
SmartHalfedgeHandle h1() const;
SmartVertexHandle v(unsigned int _i) const;
SmartVertexHandle v0() const;
SmartVertexHandle v1() const;
explicit SmartEdgeHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), EdgeHandle(_idx) {}
SmartHalfedgeHandle halfedge(unsigned int _i) const;
SmartHalfedgeHandle h(unsigned int _i) const;
SmartHalfedgeHandle h0() const;
SmartHalfedgeHandle h1() const;
SmartVertexHandle vertex(unsigned int _i) const;
SmartVertexHandle v(unsigned int _i) const;
SmartVertexHandle v0() const;
SmartVertexHandle v1() const;
bool is_boundary() const;
};
struct SmartFaceHandle : public SmartBaseHandle, FaceHandle
{
explicit SmartFaceHandle(int _idx=-1, PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_idx, _mesh) {}
explicit SmartFaceHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), FaceHandle(_idx) {}
SmartHalfedgeHandle halfedge() const;
PolyConnectivity::ConstFaceVertexRange vertices() const;
PolyConnectivity::ConstFaceHalfedgeRange halfedges() const;
PolyConnectivity::ConstFaceEdgeRange edges() const;
PolyConnectivity::ConstFaceFaceRange faces() const;
uint valence() const;
bool is_boundary() const;
};
inline SmartVertexHandle make_smart(VertexHandle _vh, PolyConnectivity* _mesh) { return SmartVertexHandle (_vh.idx(), _mesh); }
inline SmartHalfedgeHandle make_smart(HalfedgeHandle _vh, PolyConnectivity* _mesh) { return SmartHalfedgeHandle(_vh.idx(), _mesh); }
inline SmartEdgeHandle make_smart(EdgeHandle _vh, PolyConnectivity* _mesh) { return SmartEdgeHandle (_vh.idx(), _mesh); }
inline SmartFaceHandle make_smart(FaceHandle _vh, PolyConnectivity* _mesh) { return SmartFaceHandle (_vh.idx(), _mesh); }
inline SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity* _mesh) { return SmartVertexHandle (_vh.idx(), _mesh); }
inline SmartHalfedgeHandle make_smart(HalfedgeHandle _vh, const PolyConnectivity* _mesh) { return SmartHalfedgeHandle(_vh.idx(), _mesh); }
inline SmartEdgeHandle make_smart(EdgeHandle _vh, const PolyConnectivity* _mesh) { return SmartEdgeHandle (_vh.idx(), _mesh); }
inline SmartFaceHandle make_smart(FaceHandle _vh, const PolyConnectivity* _mesh) { return SmartFaceHandle (_vh.idx(), _mesh); }
inline SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity& _mesh) { return SmartVertexHandle (_vh.idx(), &_mesh); }
inline SmartHalfedgeHandle make_smart(HalfedgeHandle _vh, const PolyConnectivity& _mesh) { return SmartHalfedgeHandle(_vh.idx(), &_mesh); }
inline SmartEdgeHandle make_smart(EdgeHandle _vh, const PolyConnectivity& _mesh) { return SmartEdgeHandle (_vh.idx(), &_mesh); }
inline SmartFaceHandle make_smart(FaceHandle _vh, const PolyConnectivity& _mesh) { return SmartFaceHandle (_vh.idx(), &_mesh); }
//=============================================================================
......
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