avoid diamond inheritance and add range and convenience functions

This commit is contained in:
Max Lyon
2019-09-25 09:52:18 +02:00
parent 04ba56511b
commit 844de4145c
2 changed files with 164 additions and 29 deletions

View File

@@ -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) {}
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;
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) {}
explicit SmartEdgeHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), EdgeHandle(_idx) {}
SmartHalfedgeHandle h(unsigned int _i) const;
SmartHalfedgeHandle h0() const;
SmartHalfedgeHandle h1() const;
SmartVertexHandle v(unsigned int _i) const;
SmartVertexHandle v0() const;
SmartVertexHandle v1() const;
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); }
//=============================================================================