Commit b548bf22 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Rewrote vertex-centered circulators.

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@890 fdac6126-5c0c-442c-9429-916003d36597
parent 6d70b254
......@@ -61,21 +61,241 @@
namespace OpenMesh {
namespace Iterators {
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);
};
//== FORWARD DECLARATIONS =====================================================
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);
}
};
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:
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) {
if (is_valid(mesh, heh, start, lap_counter) && !mesh->face_handle(heh).is_valid())
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);
} while (is_valid(mesh, heh, start, lap_counter) && !mesh->face_handle(heh).is_valid());
}
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);
} while (is_valid(mesh, heh, start, lap_counter) && !mesh->face_handle(heh).is_valid());
}
};
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_);
}
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_;
};
template <class Mesh> class VertexVertexIterT;
template <class Mesh> class VertexIHalfedgeIterT;
template <class Mesh> class VertexOHalfedgeIterT;
template <class Mesh> class VertexEdgeIterT;
template <class Mesh> class VertexFaceIterT;
template<class Mesh, class CenterEntityHandle, class ValueHandle,
// void (GenericCirculatorBaseT<Mesh>::*Increment)(),
// void (GenericCirculatorBaseT<Mesh>::*Decrement)(),
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 {
return (this->*Handle2Value)();
}
/// Standard pointer operator.
value_type operator->() const {
return (this->*Handle2Value)();
}
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 &current_halfedge_handle() const {
return this->heh_;
}
DEPRECATED("Do not use this error prone implicit cast. Compare to end-iterator, instead.")
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;
}
};
template <class Mesh> class ConstVertexVertexIterT;
template <class Mesh> class ConstVertexIHalfedgeIterT;
template <class Mesh> class ConstVertexOHalfedgeIterT;
template <class Mesh> class ConstVertexEdgeIterT;
template <class Mesh> class ConstVertexFaceIterT;
//== FORWARD DECLARATIONS =====================================================
template <class Mesh> class FaceVertexIterT;
template <class Mesh> class FaceHalfedgeIterT;
......@@ -87,1944 +307,6 @@ template <class Mesh> class ConstFaceHalfedgeIterT;
template <class Mesh> class ConstFaceEdgeIterT;
template <class Mesh> class ConstFaceFaceIterT;
//== CLASS DEFINITION =========================================================
/** \class VertexVertexIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
Circulator.
*/
template <class Mesh>
class VertexVertexIterT
{
public:
//--- Typedefs ---
typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
typedef typename Mesh::Vertex value_type;
typedef typename Mesh::VertexHandle value_handle;
#if 0
typedef std::bidirectional_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
typedef const Mesh& mesh_ref;
typedef const Mesh* mesh_ptr;
typedef const typename Mesh::Vertex& reference;
typedef const typename Mesh::Vertex* pointer;
#else
typedef std::bidirectional_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
typedef Mesh& mesh_ref;
typedef Mesh* mesh_ptr;
typedef typename Mesh::Vertex& reference;
typedef typename Mesh::Vertex* pointer;
#endif
/// Default constructor
VertexVertexIterT() : mesh_(0), lap_counter_(0) {}
/// Construct with mesh and a typename Mesh::VertexHandle
VertexVertexIterT(mesh_ref _mesh, typename Mesh::VertexHandle _start, bool _end = false) :
mesh_(&_mesh),
start_(_mesh.halfedge_handle(_start)),
heh_(start_),
lap_counter_(_end)
{ ; }
/// Construct with mesh and start halfedge
VertexVertexIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
mesh_(&_mesh),
start_(_heh),
heh_(_heh),
lap_counter_(_end)
{ ; }
/// Copy constructor
VertexVertexIterT(const VertexVertexIterT& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// Assignment operator
VertexVertexIterT& operator=(const VertexVertexIterT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
start_ = _rhs.start_;
heh_ = _rhs.heh_;
lap_counter_ = _rhs.lap_counter_;
return *this;
}
#if 0
/// construct from non-const circulator type
VertexVertexIterT(const VertexVertexIterT<Mesh>& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// assign from non-const circulator
VertexVertexIterT& operator=(const VertexVertexIterT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
start_ = _rhs.start_;
heh_ = _rhs.heh_;
lap_counter_ = _rhs.lap_counter_;
return *this;
}
#else
friend class ConstVertexVertexIterT<Mesh>;
#endif
/// Equal ?
bool operator==(const VertexVertexIterT& _rhs) const {
return ((mesh_ == _rhs.mesh_) &&
(start_ == _rhs.start_) &&
(heh_ == _rhs.heh_) &&
(lap_counter_ == _rhs.lap_counter_));
}
/// Not equal ?
bool operator!=(const VertexVertexIterT& _rhs) const {
return !operator==(_rhs);
}
/// Pre-Increment (next cw target)
VertexVertexIterT& operator++() {
assert(mesh_);
heh_=mesh_->cw_rotated_halfedge_handle(heh_);
if(heh_ == start_) lap_counter_++;
return *this;
}
/// Pre-Decrement (next ccw target)
VertexVertexIterT& operator--() {
assert(mesh_);
if(heh_ == start_) lap_counter_--;
heh_=mesh_->ccw_rotated_halfedge_handle(heh_);
return *this;
}
/** Get the current halfedge. There are \c Vertex*Iters and \c
Face*Iters. For both the current state is defined by the
current halfedge. This is what this method returns.
*/
HalfedgeHandle current_halfedge_handle() const {
return heh_;
}
/// Return the handle of the current target.
typename Mesh::VertexHandle handle() const {
assert(mesh_);
return mesh_->to_vertex_handle(heh_);
}
/// Cast to the handle of the current target.
operator typename Mesh::VertexHandle() const {
assert(mesh_);
return mesh_->to_vertex_handle(heh_);
}
/// Return a reference to the current target.
reference operator*() const {
assert(mesh_);
return mesh_->deref(handle());
}
/// Return a pointer to the current target.
pointer operator->() const {
assert(mesh_);
return &mesh_->deref(handle());
}
/** Returns whether the circulator is still valid.
After one complete round around a vertex/face the circulator becomes
invalid, i.e. this function will return \c false. Nevertheless you
can continue circulating. This method just tells you whether you
have completed the first round.
*/
operator bool() const {
return heh_.is_valid() && ((start_ != heh_) || (lap_counter_ == 0));
}
protected:
mesh_ptr mesh_;
HalfedgeHandle start_, heh_;
int lap_counter_;
};
//== CLASS DEFINITION =========================================================
/** \class ConstVertexVertexIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
Circulator.
*/
template <class Mesh>
class ConstVertexVertexIterT
{
public:
//--- Typedefs ---
typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
typedef typename Mesh::Vertex value_type;
typedef typename Mesh::VertexHandle value_handle;
#if 1
typedef std::bidirectional_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
typedef const Mesh& mesh_ref;
typedef const Mesh* mesh_ptr;
typedef const typename Mesh::Vertex& reference;
typedef const typename Mesh::Vertex* pointer;
#else
typedef std::bidirectional_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
typedef Mesh& mesh_ref;
typedef Mesh* mesh_ptr;
typedef typename Mesh::Vertex& reference;
typedef typename Mesh::Vertex* pointer;
#endif
/// Default constructor
ConstVertexVertexIterT() : mesh_(0), lap_counter_(0) {}
/// Construct with mesh and a typename Mesh::VertexHandle
ConstVertexVertexIterT(mesh_ref _mesh, typename Mesh::VertexHandle _start, bool _end = false) :
mesh_(&_mesh),
start_(_mesh.halfedge_handle(_start)),
heh_(start_),
lap_counter_(_end)
{ ; }
/// Construct with mesh and start halfedge
ConstVertexVertexIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
mesh_(&_mesh),
start_(_heh),
heh_(_heh),
lap_counter_(_end)
{ ; }
/// Copy constructor
ConstVertexVertexIterT(const ConstVertexVertexIterT& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// Assignment operator
ConstVertexVertexIterT& operator=(const ConstVertexVertexIterT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
start_ = _rhs.start_;
heh_ = _rhs.heh_;
lap_counter_ = _rhs.lap_counter_;
return *this;
}
#if 1
/// construct from non-const circulator type
ConstVertexVertexIterT(const VertexVertexIterT<Mesh>& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// assign from non-const circulator
ConstVertexVertexIterT& operator=(const VertexVertexIterT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
start_ = _rhs.start_;
heh_ = _rhs.heh_;
lap_counter_ = _rhs.lap_counter_;
return *this;
}
#else
friend class ConstVertexVertexIterT<Mesh>;
#endif
/// Equal ?
bool operator==(const ConstVertexVertexIterT& _rhs) const {
return ((mesh_ == _rhs.mesh_) &&
(start_ == _rhs.start_) &&
(heh_ == _rhs.heh_) &&
(lap_counter_ == _rhs.lap_counter_));
}
/// Not equal ?
bool operator!=(const ConstVertexVertexIterT& _rhs) const {
return !operator==(_rhs);
}
/// Pre-Increment (next cw target)
ConstVertexVertexIterT& operator++() {
assert(mesh_);
heh_=mesh_->cw_rotated_halfedge_handle(heh_);
if(heh_ == start_) lap_counter_++;
return *this;
}
/// Pre-Decrement (next ccw target)
ConstVertexVertexIterT& operator--() {
assert(mesh_);
if(heh_ == start_) lap_counter_--;
heh_=mesh_->ccw_rotated_halfedge_handle(heh_);
return *this;
}
/** Get the current halfedge. There are \c Vertex*Iters and \c
Face*Iters. For both the current state is defined by the
current halfedge. This is what this method returns.
*/
HalfedgeHandle current_halfedge_handle() const {
return heh_;
}
/// Return the handle of the current target.
typename Mesh::VertexHandle handle() const {
assert(mesh_);
return mesh_->to_vertex_handle(heh_);
}
/// Cast to the handle of the current target.
operator typename Mesh::VertexHandle() const {
assert(mesh_);
return mesh_->to_vertex_handle(heh_);
}
/// Return a reference to the current target.
reference operator*() const {
assert(mesh_);
return mesh_->deref(handle());
}
/// Return a pointer to the current target.
pointer operator->() const {
assert(mesh_);
return &mesh_->deref(handle());
}
/** Returns whether the circulator is still valid.
After one complete round around a vertex/face the circulator becomes
invalid, i.e. this function will return \c false. Nevertheless you
can continue circulating. This method just tells you whether you
have completed the first round.
*/
operator bool() const {
return heh_.is_valid() && ((start_ != heh_) || (lap_counter_ == 0));
}
protected:
mesh_ptr mesh_;
HalfedgeHandle start_, heh_;
int lap_counter_;
};
//== CLASS DEFINITION =========================================================
/** \class VertexOHalfedgeIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
Circulator.
*/
template <class Mesh>
class VertexOHalfedgeIterT
{
public:
//--- Typedefs ---
typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
typedef typename Mesh::Halfedge value_type;
typedef typename Mesh::HalfedgeHandle value_handle;