2009-02-06 13:37:46 +00:00
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2012-10-08 07:30:49 +00:00
|
|
|
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
|
2009-02-06 13:37:46 +00:00
|
|
|
* www.openmesh.org *
|
|
|
|
|
* *
|
|
|
|
|
*---------------------------------------------------------------------------*
|
2009-06-04 08:46:29 +00:00
|
|
|
* This file is part of OpenMesh. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* OpenMesh is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of *
|
|
|
|
|
* the License, or (at your option) any later version with the *
|
|
|
|
|
* following exceptions: *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* If other files instantiate templates or use macros *
|
|
|
|
|
* or inline functions from this file, or you compile this file and *
|
|
|
|
|
* link it with other files to produce an executable, this file does *
|
|
|
|
|
* not by itself cause the resulting executable to be covered by the *
|
|
|
|
|
* GNU Lesser General Public License. This exception does not however *
|
|
|
|
|
* invalidate any other reasons why the executable file might be *
|
|
|
|
|
* covered by the GNU Lesser General Public License. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* OpenMesh is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Lesser General Public License for more details. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2009-06-04 08:46:29 +00:00
|
|
|
* You should have received a copy of the GNU LesserGeneral Public *
|
|
|
|
|
* License along with OpenMesh. If not, *
|
|
|
|
|
* see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
\*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* $Revision$ *
|
|
|
|
|
* $Date$ *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
|
|
|
|
\*===========================================================================*/
|
2009-06-04 08:46:29 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
#ifndef OPENMESH_CIRCULATORS_HH
|
|
|
|
|
#define OPENMESH_CIRCULATORS_HH
|
|
|
|
|
//=============================================================================
|
|
|
|
|
//
|
|
|
|
|
// Vertex and Face circulators for PolyMesh/TriMesh
|
|
|
|
|
//
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== INCLUDES =================================================================
|
|
|
|
|
|
|
|
|
|
#include <OpenMesh/Core/System/config.h>
|
2013-06-12 13:14:36 +00:00
|
|
|
#include <cassert>
|
2011-01-05 09:52:58 +00:00
|
|
|
#include <cstddef>
|
2013-08-07 08:50:58 +00:00
|
|
|
#include <iterator>
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
//== NAMESPACES ===============================================================
|
|
|
|
|
|
|
|
|
|
namespace OpenMesh {
|
|
|
|
|
namespace Iterators {
|
|
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
template<class Mesh, class CenterEntityHandle>
|
|
|
|
|
class GenericCirculator_CenterEntityFnsT {
|
|
|
|
|
public:
|
|
|
|
|
static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter);
|
|
|
|
|
static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter);
|
|
|
|
|
};
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
template<class Mesh>
|
|
|
|
|
class GenericCirculator_CenterEntityFnsT<Mesh, typename Mesh::VertexHandle> {
|
|
|
|
|
public:
|
|
|
|
|
inline static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
|
|
|
|
heh = mesh->cw_rotated_halfedge_handle(heh);
|
|
|
|
|
if (heh == start) ++lap_counter;
|
|
|
|
|
}
|
|
|
|
|
inline static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
|
|
|
|
if (heh == start) --lap_counter;
|
|
|
|
|
heh = mesh->ccw_rotated_halfedge_handle(heh);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class Mesh>
|
|
|
|
|
class GenericCirculator_CenterEntityFnsT<Mesh, typename Mesh::FaceHandle> {
|
|
|
|
|
public:
|
|
|
|
|
inline static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
|
|
|
|
heh = mesh->next_halfedge_handle(heh);
|
|
|
|
|
if (heh == start) ++lap_counter;
|
|
|
|
|
}
|
|
|
|
|
inline static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
|
|
|
|
if (heh == start) --lap_counter;
|
|
|
|
|
heh = mesh->prev_halfedge_handle(heh);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-07 08:03:44 +00:00
|
|
|
template<class Mesh, class CenterEntityHandle, class ValueHandle>
|
|
|
|
|
class GenericCirculator_DereferenciabilityCheckT {
|
|
|
|
|
public:
|
|
|
|
|
//inline static bool isDereferenciable(const Mesh *mesh, const typename Mesh::HalfedgeHandle &heh, const typename Mesh::HalfedgeHandle &start, const int &lap_counter);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class Mesh>
|
|
|
|
|
class GenericCirculator_DereferenciabilityCheckT<Mesh, typename Mesh::FaceHandle, typename Mesh::FaceHandle> {
|
|
|
|
|
public:
|
|
|
|
|
inline static bool isDereferenciable(const Mesh *mesh, const typename Mesh::HalfedgeHandle &heh, const typename Mesh::HalfedgeHandle &start, const int &lap_counter) {
|
|
|
|
|
return mesh->face_handle(mesh->opposite_halfedge_handle(heh)).is_valid();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class Mesh>
|
|
|
|
|
class GenericCirculator_DereferenciabilityCheckT<Mesh, typename Mesh::VertexHandle, typename Mesh::FaceHandle> {
|
|
|
|
|
public:
|
|
|
|
|
inline static bool isDereferenciable(const Mesh *mesh, const typename Mesh::HalfedgeHandle &heh, const typename Mesh::HalfedgeHandle &start, const int &lap_counter) {
|
|
|
|
|
return mesh->face_handle(heh).is_valid();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
template<class Mesh, class CenterEntityHandle, class ValueHandle>
|
|
|
|
|
class GenericCirculator_ValueHandleFnsT {
|
|
|
|
|
public:
|
|
|
|
|
inline static bool is_valid(const Mesh *mesh, const typename Mesh::HalfedgeHandle &heh, const typename Mesh::HalfedgeHandle &start, const int &lap_counter) {
|
|
|
|
|
return heh.is_valid() && ((start != heh) || (lap_counter == 0));
|
|
|
|
|
}
|
|
|
|
|
inline static void init(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {};
|
|
|
|
|
inline static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
|
|
|
|
GenericCirculator_CenterEntityFnsT<Mesh, CenterEntityHandle>::increment(mesh, heh, start, lap_counter);
|
|
|
|
|
}
|
|
|
|
|
inline static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
|
|
|
|
GenericCirculator_CenterEntityFnsT<Mesh, CenterEntityHandle>::decrement(mesh, heh, start, lap_counter);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class Mesh, class CenterEntityHandle>
|
|
|
|
|
class GenericCirculator_ValueHandleFnsT<Mesh, CenterEntityHandle, typename Mesh::FaceHandle> {
|
|
|
|
|
public:
|
2013-08-07 08:03:44 +00:00
|
|
|
typedef GenericCirculator_DereferenciabilityCheckT<Mesh, CenterEntityHandle, typename Mesh::FaceHandle> GenericCirculator_DereferenciabilityCheck;
|
|
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
inline static bool is_valid(const Mesh *mesh, const typename Mesh::HalfedgeHandle &heh, const typename Mesh::HalfedgeHandle &start, const int &lap_counter) {
|
|
|
|
|
return heh.is_valid() && ((start != heh) || (lap_counter == 0));
|
|
|
|
|
}
|
|
|
|
|
inline static void init(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
2013-08-07 08:03:44 +00:00
|
|
|
if (heh.is_valid() && !GenericCirculator_DereferenciabilityCheck::isDereferenciable(mesh, heh, start, lap_counter) && lap_counter == 0)
|
2013-08-07 08:03:42 +00:00
|
|
|
increment(mesh, heh, start, lap_counter);
|
|
|
|
|
};
|
|
|
|
|
inline static void increment(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
|
|
|
|
do {
|
|
|
|
|
GenericCirculator_CenterEntityFnsT<Mesh, CenterEntityHandle>::increment(mesh, heh, start, lap_counter);
|
2013-08-07 08:03:44 +00:00
|
|
|
} while (is_valid(mesh, heh, start, lap_counter) && !GenericCirculator_DereferenciabilityCheck::isDereferenciable(mesh, heh, start, lap_counter));
|
2013-08-07 08:03:42 +00:00
|
|
|
}
|
|
|
|
|
inline static void decrement(const Mesh *mesh, typename Mesh::HalfedgeHandle &heh, typename Mesh::HalfedgeHandle &start, int &lap_counter) {
|
|
|
|
|
do {
|
|
|
|
|
GenericCirculator_CenterEntityFnsT<Mesh, CenterEntityHandle>::decrement(mesh, heh, start, lap_counter);
|
2013-08-07 08:03:44 +00:00
|
|
|
} while (is_valid(mesh, heh, start, lap_counter) && !GenericCirculator_DereferenciabilityCheck::isDereferenciable(mesh, heh, start, lap_counter));
|
2013-08-07 08:03:42 +00:00
|
|
|
}
|
|
|
|
|
};
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
template<class Mesh>
|
|
|
|
|
class GenericCirculatorBaseT {
|
|
|
|
|
public:
|
|
|
|
|
typedef const Mesh* mesh_ptr;
|
|
|
|
|
typedef const Mesh& mesh_ref;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
GenericCirculatorBaseT() : mesh_(0), lap_counter_(0) {}
|
|
|
|
|
|
|
|
|
|
GenericCirculatorBaseT(mesh_ref mesh, HalfedgeHandle heh, bool end = false) :
|
|
|
|
|
mesh_(&mesh), start_(heh), heh_(heh), lap_counter_(static_cast<int>(end)) {}
|
|
|
|
|
|
|
|
|
|
GenericCirculatorBaseT(const GenericCirculatorBaseT &rhs) :
|
|
|
|
|
mesh_(rhs.mesh_), start_(rhs.start_), heh_(rhs.heh_), lap_counter_(rhs.lap_counter_) {}
|
|
|
|
|
|
|
|
|
|
inline typename Mesh::FaceHandle toFaceHandle() const {
|
|
|
|
|
return mesh_->face_handle(heh_);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:03:44 +00:00
|
|
|
inline typename Mesh::FaceHandle toOppositeFaceHandle() const {
|
|
|
|
|
return mesh_->face_handle(toOppositeHalfedgeHandle());
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
inline typename Mesh::EdgeHandle toEdgeHandle() const {
|
|
|
|
|
return mesh_->edge_handle(heh_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline typename Mesh::HalfedgeHandle toHalfedgeHandle() const {
|
|
|
|
|
return heh_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline typename Mesh::HalfedgeHandle toOppositeHalfedgeHandle() const {
|
|
|
|
|
return mesh_->opposite_halfedge_handle(heh_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline typename Mesh::VertexHandle toVertexHandle() const {
|
|
|
|
|
return mesh_->to_vertex_handle(heh_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline GenericCirculatorBaseT &operator=(const GenericCirculatorBaseT &rhs) {
|
|
|
|
|
mesh_ = rhs.mesh_;
|
|
|
|
|
start_ = rhs.start_;
|
|
|
|
|
heh_ = rhs.heh_;
|
|
|
|
|
lap_counter_ = rhs.lap_counter_;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool operator==(const GenericCirculatorBaseT &rhs) const {
|
|
|
|
|
return mesh_ == rhs.mesh_ && start_ == rhs.start_ && heh_ == rhs.heh_ && lap_counter_ == rhs.lap_counter_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool operator!=(const GenericCirculatorBaseT &rhs) const {
|
|
|
|
|
return !operator==(rhs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
mesh_ptr mesh_;
|
|
|
|
|
typename Mesh::HalfedgeHandle start_, heh_;
|
|
|
|
|
int lap_counter_;
|
|
|
|
|
};
|
2009-02-06 13:37:46 +00:00
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
template<class Mesh, class CenterEntityHandle, class ValueHandle,
|
|
|
|
|
ValueHandle (GenericCirculatorBaseT<Mesh>::*Handle2Value)() const>
|
|
|
|
|
class GenericCirculatorT : protected GenericCirculatorBaseT<Mesh> {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
|
typedef ValueHandle value_type;
|
|
|
|
|
typedef const value_type& reference;
|
|
|
|
|
typedef const value_type* pointer;
|
|
|
|
|
typedef std::bidirectional_iterator_tag iterator_category;
|
|
|
|
|
|
|
|
|
|
typedef typename GenericCirculatorBaseT<Mesh>::mesh_ptr mesh_ptr;
|
|
|
|
|
typedef typename GenericCirculatorBaseT<Mesh>::mesh_ref mesh_ref;
|
|
|
|
|
typedef GenericCirculator_ValueHandleFnsT<Mesh, CenterEntityHandle, ValueHandle> GenericCirculator_ValueHandleFns;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
GenericCirculatorT() {}
|
|
|
|
|
GenericCirculatorT(mesh_ref mesh, CenterEntityHandle start, bool end = false) :
|
|
|
|
|
GenericCirculatorBaseT<Mesh>(mesh, mesh.halfedge_handle(start), end) {
|
|
|
|
|
|
|
|
|
|
GenericCirculator_ValueHandleFns::init(this->mesh_, this->heh_, this->start_, this->lap_counter_);
|
|
|
|
|
}
|
|
|
|
|
GenericCirculatorT(mesh_ref mesh, HalfedgeHandle heh, bool end = false) :
|
|
|
|
|
GenericCirculatorBaseT<Mesh>(mesh, heh, end) {
|
|
|
|
|
|
|
|
|
|
GenericCirculator_ValueHandleFns::init(this->mesh_, this->heh_, this->start_, this->lap_counter_);
|
|
|
|
|
}
|
|
|
|
|
GenericCirculatorT(const GenericCirculatorT &rhs) : GenericCirculatorBaseT<Mesh>(rhs) {}
|
|
|
|
|
|
|
|
|
|
GenericCirculatorT& operator++() {
|
|
|
|
|
assert(this->mesh_);
|
|
|
|
|
GenericCirculator_ValueHandleFns::increment(this->mesh_, this->heh_, this->start_, this->lap_counter_);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
GenericCirculatorT& operator--() {
|
|
|
|
|
assert(this->mesh_);
|
|
|
|
|
GenericCirculator_ValueHandleFns::decrement(this->mesh_, this->heh_, this->start_, this->lap_counter_);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Post-increment
|
|
|
|
|
GenericCirculatorT operator++(int) {
|
|
|
|
|
assert(this->mesh_);
|
|
|
|
|
GenericCirculatorT cpy(*this);
|
|
|
|
|
++(*this);
|
|
|
|
|
return cpy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Post-decrement
|
|
|
|
|
GenericCirculatorT operator--(int) {
|
|
|
|
|
assert(this->mesh_);
|
|
|
|
|
GenericCirculatorT cpy(*this);
|
|
|
|
|
--(*this);
|
|
|
|
|
return cpy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Standard dereferencing operator.
|
|
|
|
|
value_type operator*() const {
|
2013-08-07 08:03:44 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
|
assert(this->heh_.is_valid());
|
|
|
|
|
value_type res = (this->*Handle2Value)();
|
|
|
|
|
assert(res.is_valid());
|
|
|
|
|
return res;
|
|
|
|
|
#else
|
2013-08-07 08:03:42 +00:00
|
|
|
return (this->*Handle2Value)();
|
2013-08-07 08:03:44 +00:00
|
|
|
#endif
|
2013-08-07 08:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Standard pointer operator.
|
|
|
|
|
value_type operator->() const {
|
2013-08-07 08:03:44 +00:00
|
|
|
return **this;
|
2013-08-07 08:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GenericCirculatorT &operator=(const GenericCirculatorT &rhs) {
|
|
|
|
|
GenericCirculatorBaseT<Mesh>::operator=(rhs);
|
|
|
|
|
return *this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool operator==(const GenericCirculatorT &rhs) const {
|
|
|
|
|
return GenericCirculatorBaseT<Mesh>::operator==(rhs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator!=(const GenericCirculatorT &rhs) const {
|
|
|
|
|
return GenericCirculatorBaseT<Mesh>::operator!=(rhs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_valid() const {
|
|
|
|
|
return GenericCirculator_ValueHandleFns::is_valid(this->mesh_, this->heh_, this->start_, this->lap_counter_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEPRECATED("current_halfedge_handle() is an implementation detail and should not be accessed from outside the iterator class.")
|
|
|
|
|
const HalfedgeHandle ¤t_halfedge_handle() const {
|
|
|
|
|
return this->heh_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:03:44 +00:00
|
|
|
DEPRECATED("Do not use this error prone implicit cast. Compare to end-iterator or use is_valid(), instead.")
|
2013-08-07 08:03:42 +00:00
|
|
|
operator bool() const {
|
|
|
|
|
return is_valid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the handle of the current target.
|
|
|
|
|
DEPRECATED("This function clutters your code. Use dereferencing operators -> and * instead.")
|
|
|
|
|
value_type handle() const {
|
|
|
|
|
return **this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Cast to the handle of the current target.
|
|
|
|
|
DEPRECATED("Implicit casts of iterators are unsafe. Use dereferencing operators -> and * instead.")
|
|
|
|
|
operator value_type() const {
|
|
|
|
|
return **this;
|
|
|
|
|
}
|
2013-08-07 09:24:04 +00:00
|
|
|
|
|
|
|
|
template<typename STREAM>
|
|
|
|
|
friend STREAM &operator<< (STREAM &s, const GenericCirculatorT &self) {
|
|
|
|
|
return s << self.mesh_ << ", " << self.start_.idx() << ", " << self.heh_.idx() << ", " << self.lap_counter_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
};
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
} // namespace Iterators
|
|
|
|
|
} // namespace OpenMesh
|
2013-08-07 08:03:44 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
#endif
|