allow custom start for vih_range and voh_range

This commit is contained in:
Max Lyon
2021-03-09 09:03:55 +01:00
parent fd5e4ef9e3
commit b3821e6289
3 changed files with 54 additions and 10 deletions

View File

@@ -60,6 +60,9 @@
//== NAMESPACES =============================================================== //== NAMESPACES ===============================================================
namespace OpenMesh { namespace OpenMesh {
template <typename> class CirculatorRange;
namespace Iterators { namespace Iterators {
template<class Mesh, class CenterEntityHandle, bool CW> template<class Mesh, class CenterEntityHandle, bool CW>
@@ -192,6 +195,8 @@ class GenericCirculatorBaseT {
typedef const Mesh* mesh_ptr; typedef const Mesh* mesh_ptr;
typedef const Mesh& mesh_ref; typedef const Mesh& mesh_ref;
template <typename> friend class OpenMesh::CirculatorRange;
public: public:
GenericCirculatorBaseT() : mesh_(0), lap_counter_(0) {} GenericCirculatorBaseT() : mesh_(0), lap_counter_(0) {}
@@ -267,16 +272,18 @@ class GenericCirculatorT : protected GenericCirculatorBaseT<typename GenericCirc
typedef typename GenericCirculatorBaseT<Mesh>::mesh_ref mesh_ref; typedef typename GenericCirculatorBaseT<Mesh>::mesh_ref mesh_ref;
typedef GenericCirculator_ValueHandleFnsT<Mesh, CenterEntityHandle, value_type, CW> GenericCirculator_ValueHandleFns; typedef GenericCirculator_ValueHandleFnsT<Mesh, CenterEntityHandle, value_type, CW> GenericCirculator_ValueHandleFns;
template <typename> friend class OpenMesh::CirculatorRange;
public: public:
GenericCirculatorT() {} GenericCirculatorT() {}
GenericCirculatorT(mesh_ref mesh, CenterEntityHandle start, bool end = false) : GenericCirculatorT(mesh_ref mesh, CenterEntityHandle start, bool end = false) :
GenericCirculatorBaseT<Mesh>(mesh, mesh.halfedge_handle(start), end) { GenericCirculatorBaseT<Mesh>(mesh, mesh.halfedge_handle(start), end)
{
GenericCirculator_ValueHandleFns::init(this->mesh_, this->heh_, this->start_, this->lap_counter_); GenericCirculator_ValueHandleFns::init(this->mesh_, this->heh_, this->start_, this->lap_counter_);
} }
GenericCirculatorT(mesh_ref mesh, typename Mesh::HalfedgeHandle heh, bool end = false) : GenericCirculatorT(mesh_ref mesh, typename Mesh::HalfedgeHandle heh, bool end = false) :
GenericCirculatorBaseT<Mesh>(mesh, heh, end) { GenericCirculatorBaseT<Mesh>(mesh, heh, end)
{
GenericCirculator_ValueHandleFns::init(this->mesh_, this->heh_, this->start_, this->lap_counter_); GenericCirculator_ValueHandleFns::init(this->mesh_, this->heh_, this->start_, this->lap_counter_);
} }
GenericCirculatorT(const GenericCirculatorT &rhs) : GenericCirculatorBaseT<Mesh>(rhs) {} GenericCirculatorT(const GenericCirculatorT &rhs) : GenericCirculatorBaseT<Mesh>(rhs) {}
@@ -440,6 +447,8 @@ class GenericCirculatorT_DEPRECATED : protected GenericCirculatorBaseT<typename
typedef typename GenericCirculatorBaseT<Mesh>::mesh_ref mesh_ref; typedef typename GenericCirculatorBaseT<Mesh>::mesh_ref mesh_ref;
typedef GenericCirculator_ValueHandleFnsT_DEPRECATED<Mesh, CenterEntityHandle, value_type> GenericCirculator_ValueHandleFns; typedef GenericCirculator_ValueHandleFnsT_DEPRECATED<Mesh, CenterEntityHandle, value_type> GenericCirculator_ValueHandleFns;
template <typename> friend class OpenMesh::CirculatorRange;
public: public:
GenericCirculatorT_DEPRECATED() {} GenericCirculatorT_DEPRECATED() {}
GenericCirculatorT_DEPRECATED(mesh_ref mesh, CenterEntityHandle start, bool end = false) : GenericCirculatorT_DEPRECATED(mesh_ref mesh, CenterEntityHandle start, bool end = false) :

View File

@@ -98,8 +98,10 @@ struct CirculatorRangeTraitT
using ITER_TYPE = ITER_T; using ITER_TYPE = ITER_T;
using CENTER_ENTITY_TYPE = CENTER_ENTITY_T; using CENTER_ENTITY_TYPE = CENTER_ENTITY_T;
using TO_ENTITYE_TYPE = TO_ENTITY_T; using TO_ENTITYE_TYPE = TO_ENTITY_T;
static ITER_TYPE begin(const CONTAINER_TYPE& _container, CENTER_ENTITY_TYPE _ce) { return (_container.*begin_fn)(_ce); } static ITER_TYPE begin(const CONTAINER_TYPE& _container, CENTER_ENTITY_TYPE _ce) { return (_container.*begin_fn)(_ce); }
static ITER_TYPE end(const CONTAINER_TYPE& _container, CENTER_ENTITY_TYPE _ce) { return (_container.*end_fn)(_ce); } static ITER_TYPE begin(const CONTAINER_TYPE& _container, HalfedgeHandle _heh, int) { return ITER_TYPE(_container, _heh); }
static ITER_TYPE end(const CONTAINER_TYPE& _container, CENTER_ENTITY_TYPE _ce) { return (_container.*end_fn)(_ce); }
static ITER_TYPE end(const CONTAINER_TYPE& _container, HalfedgeHandle _heh, int) { return ITER_TYPE(_container, _heh, true); }
}; };
struct SmartVertexHandle; struct SmartVertexHandle;
@@ -1250,12 +1252,26 @@ public:
*/ */
ConstVertexIHalfedgeRange vih_range(VertexHandle _vh) const; ConstVertexIHalfedgeRange vih_range(VertexHandle _vh) const;
/**
* @return The incoming halfedges incident to the specified vertex
* as a range object suitable for C++11 range based for loops.
* Like vih_range(VertexHandle _heh.to()) but starts iteration at _heh
*/
ConstVertexIHalfedgeRange vih_range(HalfedgeHandle _heh) const;
/** /**
* @return The outgoing halfedges incident to the specified vertex * @return The outgoing halfedges incident to the specified vertex
* as a range object suitable for C++11 range based for loops. * as a range object suitable for C++11 range based for loops.
*/ */
ConstVertexOHalfedgeRange voh_range(VertexHandle _vh) const; ConstVertexOHalfedgeRange voh_range(VertexHandle _vh) const;
/**
* @return The outgoing halfedges incident to the specified vertex
* as a range object suitable for C++11 range based for loops.
* Like voh_range(VertexHandle _heh.from()) but starts iteration at _heh
*/
ConstVertexOHalfedgeRange voh_range(HalfedgeHandle _heh) const;
/** /**
* @return The edges incident to the specified vertex * @return The edges incident to the specified vertex
* as a range object suitable for C++11 range based for loops. * as a range object suitable for C++11 range based for loops.

View File

@@ -43,6 +43,7 @@
#error Do not include this directly, include instead PolyConnectivity.hh #error Do not include this directly, include instead PolyConnectivity.hh
#endif // OPENMESH_POLYCONNECTIVITY_INTERFACE_INCLUDE #endif // OPENMESH_POLYCONNECTIVITY_INTERFACE_INCLUDE
#include <OpenMesh/Core/Mesh/PolyConnectivity.hh> // To help some IDEs
#include <OpenMesh/Core/Mesh/IteratorsT.hh> #include <OpenMesh/Core/Mesh/IteratorsT.hh>
#include <OpenMesh/Core/Mesh/CirculatorsT.hh> #include <OpenMesh/Core/Mesh/CirculatorsT.hh>
@@ -99,13 +100,23 @@ class CirculatorRange : public SmartRangeT<CirculatorRange<CirculatorRangeTraitT
CirculatorRange( CirculatorRange(
const CONTAINER_TYPE &container, const CONTAINER_TYPE &container,
CENTER_ENTITY_TYPE center) : CENTER_ENTITY_TYPE center) :
container_(container), center_(center) {} container_(container), heh_()
ITER_TYPE begin() const { return CirculatorRangeTraitT::begin(container_, center_); } {
ITER_TYPE end() const { return CirculatorRangeTraitT::end(container_, center_); } auto it = CirculatorRangeTraitT::begin(container_, center);
heh_ = it.heh_;
}
CirculatorRange(
const CONTAINER_TYPE &container,
HalfedgeHandle heh, int) :
container_(container), heh_(heh) {}
ITER_TYPE begin() const { return CirculatorRangeTraitT::begin(container_, heh_, 1); }
ITER_TYPE end() const { return CirculatorRangeTraitT::end(container_, heh_, 1); }
private: private:
const CONTAINER_TYPE &container_; const CONTAINER_TYPE &container_;
CENTER_ENTITY_TYPE center_; HalfedgeHandle heh_;
}; };
@@ -136,10 +147,18 @@ inline PolyConnectivity::ConstVertexIHalfedgeRange PolyConnectivity::vih_range(V
return ConstVertexIHalfedgeRange(*this, _vh); return ConstVertexIHalfedgeRange(*this, _vh);
} }
inline PolyConnectivity::ConstVertexIHalfedgeRange PolyConnectivity::vih_range(HalfedgeHandle _heh) const {
return ConstVertexIHalfedgeRange(*this, opposite_halfedge_handle(_heh), 1);
}
inline PolyConnectivity::ConstVertexOHalfedgeRange PolyConnectivity::voh_range(VertexHandle _vh) const { inline PolyConnectivity::ConstVertexOHalfedgeRange PolyConnectivity::voh_range(VertexHandle _vh) const {
return ConstVertexOHalfedgeRange(*this, _vh); return ConstVertexOHalfedgeRange(*this, _vh);
} }
inline PolyConnectivity::ConstVertexOHalfedgeRange PolyConnectivity::voh_range(HalfedgeHandle _heh) const {
return ConstVertexOHalfedgeRange(*this, _heh, 1);
}
inline PolyConnectivity::ConstVertexEdgeRange PolyConnectivity::ve_range(VertexHandle _vh) const { inline PolyConnectivity::ConstVertexEdgeRange PolyConnectivity::ve_range(VertexHandle _vh) const {
return ConstVertexEdgeRange(*this, _vh); return ConstVertexEdgeRange(*this, _vh);
} }