Commit 7a2d40d8 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Rewrite for all circulators complete.

Conflicts:
	src/OpenMesh/Core/Mesh/CirculatorsT.hh

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@891 fdac6126-5c0c-442c-9429-916003d36597
parent b548bf22
......@@ -94,6 +94,28 @@ class GenericCirculator_CenterEntityFnsT<Mesh, typename Mesh::FaceHandle> {
}
};
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();
}
};
template<class Mesh, class CenterEntityHandle, class ValueHandle>
class GenericCirculator_ValueHandleFnsT {
public:
......@@ -112,22 +134,24 @@ class GenericCirculator_ValueHandleFnsT {
template<class Mesh, class CenterEntityHandle>
class GenericCirculator_ValueHandleFnsT<Mesh, CenterEntityHandle, typename Mesh::FaceHandle> {
public:
typedef GenericCirculator_DereferenciabilityCheckT<Mesh, CenterEntityHandle, typename Mesh::FaceHandle> GenericCirculator_DereferenciabilityCheck;
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())
if (heh.is_valid() && !GenericCirculator_DereferenciabilityCheck::isDereferenciable(mesh, heh, start, lap_counter) && lap_counter == 0)
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());
} while (is_valid(mesh, heh, start, lap_counter) && !GenericCirculator_DereferenciabilityCheck::isDereferenciable(mesh, heh, start, lap_counter));
}
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());
} while (is_valid(mesh, heh, start, lap_counter) && !GenericCirculator_DereferenciabilityCheck::isDereferenciable(mesh, heh, start, lap_counter));
}
};
......@@ -150,6 +174,10 @@ class GenericCirculatorBaseT {
return mesh_->face_handle(heh_);
}
inline typename Mesh::FaceHandle toOppositeFaceHandle() const {
return mesh_->face_handle(toOppositeHalfedgeHandle());
}
inline typename Mesh::EdgeHandle toEdgeHandle() const {
return mesh_->edge_handle(heh_);
}
......@@ -189,8 +217,6 @@ class GenericCirculatorBaseT {
};
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:
......@@ -247,12 +273,19 @@ class GenericCirculatorT : protected GenericCirculatorBaseT<Mesh> {
/// Standard dereferencing operator.
value_type operator*() const {
#ifndef NDEBUG
assert(this->heh_.is_valid());
value_type res = (this->*Handle2Value)();
assert(res.is_valid());
return res;
#else
return (this->*Handle2Value)();
#endif
}
/// Standard pointer operator.
value_type operator->() const {
return (this->*Handle2Value)();
return **this;
}
GenericCirculatorT &operator=(const GenericCirculatorT &rhs) {
......@@ -277,7 +310,7 @@ class GenericCirculatorT : protected GenericCirculatorBaseT<Mesh> {
return this->heh_;
}
DEPRECATED("Do not use this error prone implicit cast. Compare to end-iterator, instead.")
DEPRECATED("Do not use this error prone implicit cast. Compare to end-iterator or use is_valid(), instead.")
operator bool() const {
return is_valid();
}
......@@ -295,1569 +328,7 @@ class GenericCirculatorT : protected GenericCirculatorBaseT<Mesh> {
}
};
//== FORWARD DECLARATIONS =====================================================
template <class Mesh> class FaceVertexIterT;
template <class Mesh> class FaceHalfedgeIterT;
template <class Mesh> class FaceEdgeIterT;
template <class Mesh> class FaceFaceIterT;
template <class Mesh> class ConstFaceVertexIterT;
template <class Mesh> class ConstFaceHalfedgeIterT;
template <class Mesh> class ConstFaceEdgeIterT;
template <class Mesh> class ConstFaceFaceIterT;
//== CLASS DEFINITION =========================================================
/** \class FaceVertexIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
Circulator.
*/
template <class Mesh>
class FaceVertexIterT
{
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
FaceVertexIterT() : mesh_(0), lap_counter_(false) {}
/// Construct with mesh and a typename Mesh::FaceHandle
FaceVertexIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
mesh_(&_mesh),
start_(_mesh.halfedge_handle(_start)),
heh_(start_),
lap_counter_(_end)
{ ; }
/// Construct with mesh and start halfedge
FaceVertexIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
mesh_(&_mesh),
start_(_heh),
heh_(_heh),
lap_counter_(_end)
{ ; }
/// Copy constructor
FaceVertexIterT(const FaceVertexIterT& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// Assignment operator
FaceVertexIterT& operator=(const FaceVertexIterT<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
FaceVertexIterT(const FaceVertexIterT<Mesh>& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// assign from non-const circulator
FaceVertexIterT& operator=(const FaceVertexIterT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
start_ = _rhs.start_;
heh_ = _rhs.heh_;
lap_counter_ = _rhs.lap_counter_;
return *this;
}
#else
friend class ConstFaceVertexIterT<Mesh>;
#endif
/// Equal ?
bool operator==(const FaceVertexIterT& _rhs) const {
return ((mesh_ == _rhs.mesh_) &&
(start_ == _rhs.start_) &&
(heh_ == _rhs.heh_) &&
(lap_counter_ == _rhs.lap_counter_));
}
/// Not equal ?
bool operator!=(const FaceVertexIterT& _rhs) const {
return !operator==(_rhs);
}
/// Pre-Increment (next cw target)
FaceVertexIterT& operator++() {
assert(mesh_);
heh_=mesh_->next_halfedge_handle(heh_);
if(heh_ == start_) lap_counter_++;
return *this;
}
/// Pre-Decrement (next ccw target)
FaceVertexIterT& operator--() {
assert(mesh_);
if(heh_ == start_) lap_counter_--;
heh_=mesh_->prev_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 ConstFaceVertexIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
Circulator.
*/
template <class Mesh>
class ConstFaceVertexIterT
{
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
ConstFaceVertexIterT() : mesh_(0), lap_counter_(false) {}
/// Construct with mesh and a typename Mesh::FaceHandle
ConstFaceVertexIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
mesh_(&_mesh),
start_(_mesh.halfedge_handle(_start)),
heh_(start_),
lap_counter_(_end)
{ ; }
/// Construct with mesh and start halfedge
ConstFaceVertexIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
mesh_(&_mesh),
start_(_heh),
heh_(_heh),
lap_counter_(_end)
{ ; }
/// Copy constructor
ConstFaceVertexIterT(const ConstFaceVertexIterT& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// Assignment operator
ConstFaceVertexIterT& operator=(const ConstFaceVertexIterT<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
ConstFaceVertexIterT(const FaceVertexIterT<Mesh>& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// assign from non-const circulator
ConstFaceVertexIterT& operator=(const FaceVertexIterT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
start_ = _rhs.start_;
heh_ = _rhs.heh_;
lap_counter_ = _rhs.lap_counter_;
return *this;
}
#else
friend class ConstFaceVertexIterT<Mesh>;
#endif
/// Equal ?
bool operator==(const ConstFaceVertexIterT& _rhs) const {
return ((mesh_ == _rhs.mesh_) &&
(start_ == _rhs.start_) &&
(heh_ == _rhs.heh_) &&
(lap_counter_ == _rhs.lap_counter_));
}
/// Not equal ?
bool operator!=(const ConstFaceVertexIterT& _rhs) const {
return !operator==(_rhs);
}
/// Pre-Increment (next cw target)
ConstFaceVertexIterT& operator++() {
assert(mesh_);
heh_=mesh_->next_halfedge_handle(heh_);
if(heh_ == start_) lap_counter_++;
return *this;
}
/// Pre-Decrement (next ccw target)
ConstFaceVertexIterT& operator--() {
assert(mesh_);
if(heh_ == start_) lap_counter_--;
heh_=mesh_->prev_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 FaceHalfedgeIterT CirculatorsT.hh <OpenMesh/Mesh/Iterators/CirculatorsT.hh>
Circulator.
*/
template <class Mesh>
class FaceHalfedgeIterT
{
public:
//--- Typedefs ---
typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
typedef typename Mesh::Halfedge value_type;
typedef typename Mesh::HalfedgeHandle 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::Halfedge& reference;
typedef const typename Mesh::Halfedge* 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::Halfedge& reference;
typedef typename Mesh::Halfedge* pointer;
#endif
/// Default constructor
FaceHalfedgeIterT() : mesh_(0), lap_counter_(false) {}
/// Construct with mesh and a typename Mesh::FaceHandle
FaceHalfedgeIterT(mesh_ref _mesh, typename Mesh::FaceHandle _start, bool _end = false) :
mesh_(&_mesh),
start_(_mesh.halfedge_handle(_start)),
heh_(start_),
lap_counter_(_end)
{ ; }
/// Construct with mesh and start halfedge
FaceHalfedgeIterT(mesh_ref _mesh, HalfedgeHandle _heh, bool _end = false) :
mesh_(&_mesh),
start_(_heh),
heh_(_heh),
lap_counter_(_end)
{ ; }
/// Copy constructor
FaceHalfedgeIterT(const FaceHalfedgeIterT& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// Assignment operator
FaceHalfedgeIterT& operator=(const FaceHalfedgeIterT<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
FaceHalfedgeIterT(const FaceHalfedgeIterT<Mesh>& _rhs) :
mesh_(_rhs.mesh_),
start_(_rhs.start_),
heh_(_rhs.heh_),
lap_counter_(_rhs.lap_counter_)
{ ; }
/// assign from non-const circulator
FaceHalfedgeIterT& operator=(const FaceHalfedgeIterT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
start_ = _rhs.start_;
heh_ = _rhs.heh_;
lap_counter_ = _rhs.lap_counter_;
return *this;
}
#else
friend class ConstFaceHalfedgeIterT<Mesh>;
#endif
/// Equal ?
bool operator==(const FaceHalfedgeIterT& _rhs) const {
return ((mesh_ == _rhs.mesh_) &&
(start_ == _rhs.start_) &&
(heh_ == _rhs.heh_) &&
(lap_counter_ == _rhs.lap_counter_));
}
/// Not equal ?
bool operator!=(const FaceHalfedgeIterT& _rhs) const {
return !operator==(_rhs);
}
/// Pre-Increment (next cw target)
FaceHalfedgeIterT& operator++() {
assert(mesh_);
heh_=mesh_->next_halfedge_handle(heh_);
if(heh_ == start_) lap_counter_++;
return *this;
}