Loading...
Searching...
No Matches
SmartHandles.hh
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2019, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
#ifndef OPENMESH_POLYCONNECTIVITY_INTERFACE_INCLUDE
#error Do not include this directly, include instead PolyConnectivity.hh
#endif//OPENMESH_POLYCONNECTIVITY_INTERFACE_INCLUDE
#include <OpenMesh/Core/Mesh/PolyConnectivity.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
//== FORWARD DECLARATION ======================================================
struct SmartVertexHandle;
struct SmartHalfedgeHandle;
struct SmartEdgeHandle;
struct SmartFaceHandle;
//== CLASS DEFINITION =========================================================
class OPENMESHDLLEXPORT SmartBaseHandle
{
public:
explicit SmartBaseHandle(const PolyConnectivity* _mesh = nullptr) : mesh_(_mesh) {}
const PolyConnectivity* mesh() const { return mesh_; }
// TODO: should operators ==, !=, < look at mesh_?
private:
const PolyConnectivity* mesh_;
};
template <typename HandleType>
class SmartHandleStatusPredicates
{
public:
bool feature() const;
bool selected() const;
bool tagged() const;
bool tagged2() const;
bool locked() const;
bool hidden() const;
bool deleted() const;
};
template <typename HandleType>
class SmartHandleBoundaryPredicate
{
public:
bool is_boundary() const;
};
struct OPENMESHDLLEXPORT SmartVertexHandle : public SmartBaseHandle, VertexHandle, SmartHandleStatusPredicates<SmartVertexHandle>, SmartHandleBoundaryPredicate<SmartVertexHandle>
{
explicit SmartVertexHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), VertexHandle(_idx) {}
SmartHalfedgeHandle out() const;
SmartHalfedgeHandle halfedge() const; // alias for out
SmartHalfedgeHandle in() const;
PolyConnectivity::ConstVertexFaceRange faces() const;
PolyConnectivity::ConstVertexFaceCWRange faces_cw() const;
PolyConnectivity::ConstVertexFaceCCWRange faces_ccw() const;
PolyConnectivity::ConstVertexEdgeRange edges() const;
PolyConnectivity::ConstVertexEdgeCWRange edges_cw() const;
PolyConnectivity::ConstVertexEdgeCCWRange edges_ccw() const;
PolyConnectivity::ConstVertexVertexRange vertices() const;
PolyConnectivity::ConstVertexVertexCWRange vertices_cw() const;
PolyConnectivity::ConstVertexVertexCCWRange vertices_ccw() const;
PolyConnectivity::ConstVertexIHalfedgeRange incoming_halfedges() const;
PolyConnectivity::ConstVertexIHalfedgeCWRange incoming_halfedges_cw() const;
PolyConnectivity::ConstVertexIHalfedgeCCWRange incoming_halfedges_ccw() const;
PolyConnectivity::ConstVertexIHalfedgeRange incoming_halfedges(HalfedgeHandle _heh) const;
PolyConnectivity::ConstVertexIHalfedgeCWRange incoming_halfedges_cw(HalfedgeHandle _heh) const;
PolyConnectivity::ConstVertexIHalfedgeCCWRange incoming_halfedges_ccw(HalfedgeHandle _heh) const;
PolyConnectivity::ConstVertexOHalfedgeRange outgoing_halfedges() const;
PolyConnectivity::ConstVertexOHalfedgeCWRange outgoing_halfedges_cw() const;
PolyConnectivity::ConstVertexOHalfedgeCCWRange outgoing_halfedges_ccw() const;
PolyConnectivity::ConstVertexOHalfedgeRange outgoing_halfedges(HalfedgeHandle _heh) const;
PolyConnectivity::ConstVertexOHalfedgeCWRange outgoing_halfedges_cw(HalfedgeHandle _heh) const;
PolyConnectivity::ConstVertexOHalfedgeCCWRange outgoing_halfedges_ccw(HalfedgeHandle _heh) const;
uint valence() const;
bool is_manifold() const;
};
struct OPENMESHDLLEXPORT SmartHalfedgeHandle : public SmartBaseHandle, HalfedgeHandle, SmartHandleStatusPredicates<SmartHalfedgeHandle>, SmartHandleBoundaryPredicate<SmartHalfedgeHandle>
{
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;
SmartEdgeHandle edge() const;
SmartFaceHandle face() const;
PolyConnectivity::ConstHalfedgeLoopRange loop() const;
PolyConnectivity::ConstHalfedgeLoopCWRange loop_cw() const;
PolyConnectivity::ConstHalfedgeLoopCCWRange loop_ccw() const;
};
struct OPENMESHDLLEXPORT SmartEdgeHandle : public SmartBaseHandle, EdgeHandle, SmartHandleStatusPredicates<SmartEdgeHandle>, SmartHandleBoundaryPredicate<SmartEdgeHandle>
{
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;
};
struct OPENMESHDLLEXPORT SmartFaceHandle : public SmartBaseHandle, FaceHandle, SmartHandleStatusPredicates<SmartFaceHandle>, SmartHandleBoundaryPredicate<SmartFaceHandle>
{
explicit SmartFaceHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), FaceHandle(_idx) {}
SmartHalfedgeHandle halfedge() const;
PolyConnectivity::ConstFaceVertexRange vertices() const;
PolyConnectivity::ConstFaceVertexCWRange vertices_cw() const;
PolyConnectivity::ConstFaceVertexCCWRange vertices_ccw() const;
PolyConnectivity::ConstFaceHalfedgeRange halfedges() const;
PolyConnectivity::ConstFaceHalfedgeCWRange halfedges_cw() const;
PolyConnectivity::ConstFaceHalfedgeCCWRange halfedges_ccw() const;
PolyConnectivity::ConstFaceEdgeRange edges() const;
PolyConnectivity::ConstFaceEdgeCWRange edges_cw() const;
PolyConnectivity::ConstFaceEdgeCCWRange edges_ccw() const;
PolyConnectivity::ConstFaceFaceRange faces() const;
PolyConnectivity::ConstFaceFaceCWRange faces_cw() const;
PolyConnectivity::ConstFaceFaceCCWRange faces_ccw() const;
uint valence() const;
};
inline SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity* _mesh) { return SmartVertexHandle (_vh.idx(), _mesh); }
inline SmartHalfedgeHandle make_smart(HalfedgeHandle _hh, const PolyConnectivity* _mesh) { return SmartHalfedgeHandle(_hh.idx(), _mesh); }
inline SmartEdgeHandle make_smart(EdgeHandle _eh, const PolyConnectivity* _mesh) { return SmartEdgeHandle (_eh.idx(), _mesh); }
inline SmartFaceHandle make_smart(FaceHandle _fh, const PolyConnectivity* _mesh) { return SmartFaceHandle (_fh.idx(), _mesh); }
inline SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity& _mesh) { return SmartVertexHandle (_vh.idx(), &_mesh); }
inline SmartHalfedgeHandle make_smart(HalfedgeHandle _hh, const PolyConnectivity& _mesh) { return SmartHalfedgeHandle(_hh.idx(), &_mesh); }
inline SmartEdgeHandle make_smart(EdgeHandle _eh, const PolyConnectivity& _mesh) { return SmartEdgeHandle (_eh.idx(), &_mesh); }
inline SmartFaceHandle make_smart(FaceHandle _fh, const PolyConnectivity& _mesh) { return SmartFaceHandle (_fh.idx(), &_mesh); }
// helper to convert Handle Types to Smarthandle Types
template <typename HandleT>
struct SmartHandle;
template <> struct SmartHandle<VertexHandle> { using type = SmartVertexHandle; };
template <> struct SmartHandle<HalfedgeHandle> { using type = SmartHalfedgeHandle; };
template <> struct SmartHandle<EdgeHandle> { using type = SmartEdgeHandle; };
template <> struct SmartHandle<FaceHandle> { using type = SmartFaceHandle; };
template <typename HandleType>
inline bool SmartHandleStatusPredicates<HandleType>::feature() const
{
const auto& handle = static_cast<const HandleType&>(*this);
assert(handle.mesh() != nullptr);
return handle.mesh()->status(handle).feature();
}
template <typename HandleType>
inline bool SmartHandleStatusPredicates<HandleType>::selected() const
{
const auto& handle = static_cast<const HandleType&>(*this);
assert(handle.mesh() != nullptr);
return handle.mesh()->status(handle).selected();
}
template <typename HandleType>
inline bool SmartHandleStatusPredicates<HandleType>::tagged() const
{
const auto& handle = static_cast<const HandleType&>(*this);
assert(handle.mesh() != nullptr);
return handle.mesh()->status(handle).tagged();
}
template <typename HandleType>
inline bool SmartHandleStatusPredicates<HandleType>::tagged2() const
{
const auto& handle = static_cast<const HandleType&>(*this);
assert(handle.mesh() != nullptr);
return handle.mesh()->status(handle).tagged2();
}
template <typename HandleType>
inline bool SmartHandleStatusPredicates<HandleType>::locked() const
{
const auto& handle = static_cast<const HandleType&>(*this);
assert(handle.mesh() != nullptr);
return handle.mesh()->status(handle).locked();
}
template <typename HandleType>
inline bool SmartHandleStatusPredicates<HandleType>::hidden() const
{
const auto& handle = static_cast<const HandleType&>(*this);
assert(handle.mesh() != nullptr);
return handle.mesh()->status(handle).hidden();
}
template <typename HandleType>
inline bool SmartHandleStatusPredicates<HandleType>::deleted() const
{
const auto& handle = static_cast<const HandleType&>(*this);
assert(handle.mesh() != nullptr);
return handle.mesh()->status(handle).deleted();
}
template <typename HandleType>
inline bool SmartHandleBoundaryPredicate<HandleType>::is_boundary() const
{
const auto& handle = static_cast<const HandleType&>(*this);
assert(handle.mesh() != nullptr);
return handle.mesh()->is_boundary(handle);
}
inline SmartHalfedgeHandle SmartVertexHandle::out() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->halfedge_handle(*this), mesh());
}
inline SmartHalfedgeHandle SmartVertexHandle::halfedge() const
{
return out();
}
inline SmartHalfedgeHandle SmartVertexHandle::in() const
{
return out().opp();
}
inline uint SmartVertexHandle::valence() const
{
assert(mesh() != nullptr);
return mesh()->valence(*this);
}
inline bool SmartVertexHandle::is_manifold() const
{
assert(mesh() != nullptr);
return mesh()->is_manifold(*this);
}
inline SmartHalfedgeHandle SmartHalfedgeHandle::next() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->next_halfedge_handle(*this), mesh());
}
inline SmartHalfedgeHandle SmartHalfedgeHandle::prev() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->prev_halfedge_handle(*this), mesh());
}
inline SmartHalfedgeHandle SmartHalfedgeHandle::opp() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->opposite_halfedge_handle(*this), mesh());
}
inline SmartVertexHandle SmartHalfedgeHandle::to() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->to_vertex_handle(*this), mesh());
}
inline SmartVertexHandle SmartHalfedgeHandle::from() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->from_vertex_handle(*this), mesh());
}
inline SmartEdgeHandle SmartHalfedgeHandle::edge() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->edge_handle(*this), mesh());
}
inline SmartFaceHandle SmartHalfedgeHandle::face() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->face_handle(*this), mesh());
}
inline SmartHalfedgeHandle SmartEdgeHandle::halfedge(unsigned int _i) const
{
assert(mesh() != nullptr);
return make_smart(mesh()->halfedge_handle(*this, _i), mesh());
}
inline SmartHalfedgeHandle SmartEdgeHandle::h(unsigned int _i) const
{
return halfedge(_i);
}
inline SmartHalfedgeHandle SmartEdgeHandle::h0() const
{
return h(0);
}
inline SmartHalfedgeHandle SmartEdgeHandle::h1() const
{
return h(1);
}
inline SmartVertexHandle SmartEdgeHandle::vertex(unsigned int _i) const
{
return halfedge(_i).from();
}
inline SmartVertexHandle SmartEdgeHandle::v(unsigned int _i) const
{
return vertex(_i);
}
inline SmartVertexHandle SmartEdgeHandle::v0() const
{
return v(0);
}
inline SmartVertexHandle SmartEdgeHandle::v1() const
{
return v(1);
}
inline SmartHalfedgeHandle SmartFaceHandle::halfedge() const
{
assert(mesh() != nullptr);
return make_smart(mesh()->halfedge_handle(*this), mesh());
}
inline uint SmartFaceHandle::valence() const
{
assert(mesh() != nullptr);
return mesh()->valence(*this);
}
//=============================================================================
} // namespace OpenMesh
//=============================================================================
//=============================================================================
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
OpenMesh::make_smart
SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity *_mesh)
Creats a SmartVertexHandle from a VertexHandle and a Mesh.
Definition SmartHandles.hh:256
OpenMesh::CirculatorRange
Generic class for iterator ranges.
Definition PolyConnectivity_inline_impl.hh:92
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition Handles.hh:69
OpenMesh::VertexHandle
Handle for a vertex entity.
Definition Handles.hh:121
OpenMesh::HalfedgeHandle
Handle for a halfedge entity.
Definition Handles.hh:128
OpenMesh::EdgeHandle
Handle for a edge entity.
Definition Handles.hh:135
OpenMesh::FaceHandle
Handle for a face entity.
Definition Handles.hh:142
OpenMesh::PolyConnectivity
Connectivity Class for polygonal meshes.
Definition PolyConnectivity.hh:115
OpenMesh::PolyConnectivity::valence
uint valence(VertexHandle _vh) const
Vertex valence.
Definition PolyConnectivity.cc:1075
OpenMesh::PolyConnectivity::is_manifold
bool is_manifold(VertexHandle _vh) const
Is (the mesh at) vertex _vh two-manifold ?
Definition PolyConnectivity.cc:84
OpenMesh::SmartBaseHandle
Base class for all smart handle types.
Definition SmartHandles.hh:64
OpenMesh::SmartBaseHandle::mesh
const PolyConnectivity * mesh() const
Get the underlying mesh of this handle.
Definition SmartHandles.hh:69
OpenMesh::SmartHandleStatusPredicates
Base class for all smart handle types that contains status related methods.
Definition SmartHandles.hh:81
OpenMesh::SmartHandleStatusPredicates::selected
bool selected() const
Returns true iff the handle is marked as selected.
Definition SmartHandles.hh:293
OpenMesh::SmartHandleStatusPredicates::feature
bool feature() const
Returns true iff the handle is marked as feature.
Definition SmartHandles.hh:285
OpenMesh::SmartHandleStatusPredicates::locked
bool locked() const
Returns true iff the handle is marked as locked.
Definition SmartHandles.hh:317
OpenMesh::SmartHandleStatusPredicates::deleted
bool deleted() const
Returns true iff the handle is marked as deleted.
Definition SmartHandles.hh:333
OpenMesh::SmartHandleStatusPredicates::tagged
bool tagged() const
Returns true iff the handle is marked as tagged.
Definition SmartHandles.hh:301
OpenMesh::SmartHandleStatusPredicates::tagged2
bool tagged2() const
Returns true iff the handle is marked as tagged2.
Definition SmartHandles.hh:309
OpenMesh::SmartHandleStatusPredicates::hidden
bool hidden() const
Returns true iff the handle is marked as hidden.
Definition SmartHandles.hh:325
OpenMesh::SmartHandleBoundaryPredicate
Base class for all smart handle types that contains status related methods.
Definition SmartHandles.hh:102
OpenMesh::SmartHandleBoundaryPredicate::is_boundary
bool is_boundary() const
Returns true iff the handle is boundary.
Definition SmartHandles.hh:341
OpenMesh::SmartVertexHandle
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
Definition SmartHandles.hh:110
OpenMesh::SmartVertexHandle::halfedge
SmartHalfedgeHandle halfedge() const
Returns an outgoing halfedge.
Definition SmartHandles.hh:354
OpenMesh::SmartVertexHandle::out
SmartHalfedgeHandle out() const
Returns an outgoing halfedge.
Definition SmartHandles.hh:348
OpenMesh::SmartVertexHandle::is_manifold
bool is_manifold() const
Returns true iff (the mesh at) the vertex is two-manifold ?
Definition SmartHandles.hh:370
OpenMesh::SmartVertexHandle::in
SmartHalfedgeHandle in() const
Returns an incoming halfedge.
Definition SmartHandles.hh:359
OpenMesh::SmartVertexHandle::valence
uint valence() const
Returns valence of the vertex.
Definition SmartHandles.hh:364
OpenMesh::SmartHalfedgeHandle
Definition SmartHandles.hh:170
OpenMesh::SmartHalfedgeHandle::face
SmartFaceHandle face() const
Returns incident face of halfedge.
Definition SmartHandles.hh:412
OpenMesh::SmartHalfedgeHandle::from
SmartVertexHandle from() const
Returns vertex at start of halfedge.
Definition SmartHandles.hh:400
OpenMesh::SmartHalfedgeHandle::next
SmartHalfedgeHandle next() const
Returns next halfedge handle.
Definition SmartHandles.hh:376
OpenMesh::SmartHalfedgeHandle::prev
SmartHalfedgeHandle prev() const
Returns previous halfedge handle.
Definition SmartHandles.hh:382
OpenMesh::SmartHalfedgeHandle::edge
SmartEdgeHandle edge() const
Returns incident edge of halfedge.
Definition SmartHandles.hh:406
OpenMesh::SmartHalfedgeHandle::opp
SmartHalfedgeHandle opp() const
Returns opposite halfedge handle.
Definition SmartHandles.hh:388
OpenMesh::SmartHalfedgeHandle::to
SmartVertexHandle to() const
Returns vertex pointed to by halfedge.
Definition SmartHandles.hh:394
OpenMesh::SmartEdgeHandle
Definition SmartHandles.hh:197
OpenMesh::SmartEdgeHandle::v
SmartVertexHandle v(unsigned int _i) const
Shorthand for vertex()
Definition SmartHandles.hh:444
OpenMesh::SmartEdgeHandle::v1
SmartVertexHandle v1() const
Shorthand for vertex(1)
Definition SmartHandles.hh:454
OpenMesh::SmartEdgeHandle::h
SmartHalfedgeHandle h(unsigned int _i) const
Shorthand for halfedge()
Definition SmartHandles.hh:424
OpenMesh::SmartEdgeHandle::h1
SmartHalfedgeHandle h1() const
Shorthand for halfedge(1)
Definition SmartHandles.hh:434
OpenMesh::SmartEdgeHandle::vertex
SmartVertexHandle vertex(unsigned int _i) const
Returns one of the two incident vertices of the edge.
Definition SmartHandles.hh:439
OpenMesh::SmartEdgeHandle::v0
SmartVertexHandle v0() const
Shorthand for vertex(0)
Definition SmartHandles.hh:449
OpenMesh::SmartEdgeHandle::halfedge
SmartHalfedgeHandle halfedge(unsigned int _i) const
Returns one of the two halfedges of the edge.
Definition SmartHandles.hh:418
OpenMesh::SmartEdgeHandle::h0
SmartHalfedgeHandle h0() const
Shorthand for halfedge(0)
Definition SmartHandles.hh:429
OpenMesh::SmartFaceHandle
Definition SmartHandles.hh:219
OpenMesh::SmartFaceHandle::valence
uint valence() const
Returns the valence of the face.
Definition SmartHandles.hh:465
OpenMesh::SmartFaceHandle::halfedge
SmartHalfedgeHandle halfedge() const
Returns one of the halfedges of the face.
Definition SmartHandles.hh:459
OpenMesh::SmartHandle
Definition SmartHandles.hh:276