2009-02-06 13:37:46 +00:00
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Copyright (c) 2001-2015, RWTH-Aachen University *
|
|
|
|
|
* Department for Computer Graphics and Multimedia *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* www.openmesh.org *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
*---------------------------------------------------------------------------*
|
|
|
|
|
* This file is part of OpenMesh. *
|
|
|
|
|
*---------------------------------------------------------------------------*
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without *
|
|
|
|
|
* modification, are permitted provided that the following conditions *
|
|
|
|
|
* are met: *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, *
|
|
|
|
|
* this list of conditions and the following disclaimer. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 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. *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 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. *
|
2009-06-04 08:46:29 +00:00
|
|
|
* *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 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. *
|
|
|
|
|
* *
|
|
|
|
|
/*===========================================================================*\
|
2009-06-04 08:46:29 +00:00
|
|
|
|
|
|
|
|
/*===========================================================================*\
|
|
|
|
|
* *
|
|
|
|
|
* $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_ITERATORS_HH
|
|
|
|
|
#define OPENMESH_ITERATORS_HH
|
2009-06-04 08:46:29 +00:00
|
|
|
|
2009-02-06 13:37:46 +00:00
|
|
|
//=============================================================================
|
|
|
|
|
//
|
|
|
|
|
// Iterators for PolyMesh/TriMesh
|
|
|
|
|
//
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== INCLUDES =================================================================
|
|
|
|
|
|
|
|
|
|
#include <OpenMesh/Core/System/config.h>
|
|
|
|
|
#include <OpenMesh/Core/Mesh/Status.hh>
|
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 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//== FORWARD DECLARATIONS =====================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Mesh> class ConstVertexIterT;
|
2012-03-01 14:55:47 +00:00
|
|
|
template <class Mesh> class VertexIterT;
|
2009-02-06 13:37:46 +00:00
|
|
|
template <class Mesh> class ConstHalfedgeIterT;
|
2012-03-01 14:55:47 +00:00
|
|
|
template <class Mesh> class HalfedgeIterT;
|
2009-02-06 13:37:46 +00:00
|
|
|
template <class Mesh> class ConstEdgeIterT;
|
2012-03-01 14:55:47 +00:00
|
|
|
template <class Mesh> class EdgeIterT;
|
2009-02-06 13:37:46 +00:00
|
|
|
template <class Mesh> class ConstFaceIterT;
|
2012-03-01 14:55:47 +00:00
|
|
|
template <class Mesh> class FaceIterT;
|
2009-02-06 13:37:46 +00:00
|
|
|
|
|
|
|
|
|
2013-06-12 13:41:43 +00:00
|
|
|
template <class Mesh, class ValueHandle, class MemberOwner, bool (MemberOwner::*PrimitiveStatusMember)() const, size_t (MemberOwner::*PrimitiveCountMember)() const>
|
2012-03-01 15:41:44 +00:00
|
|
|
class GenericIteratorT {
|
2012-03-01 14:55:47 +00:00
|
|
|
public:
|
2012-03-01 15:41:44 +00:00
|
|
|
//--- Typedefs ---
|
|
|
|
|
|
|
|
|
|
typedef ValueHandle value_handle;
|
|
|
|
|
typedef value_handle value_type;
|
|
|
|
|
typedef std::bidirectional_iterator_tag iterator_category;
|
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
|
typedef const value_type& reference;
|
|
|
|
|
typedef const value_type* pointer;
|
|
|
|
|
typedef const Mesh* mesh_ptr;
|
|
|
|
|
typedef const Mesh& mesh_ref;
|
|
|
|
|
|
|
|
|
|
/// Default constructor.
|
|
|
|
|
GenericIteratorT()
|
|
|
|
|
: mesh_(0), skip_bits_(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/// Construct with mesh and a target handle.
|
|
|
|
|
GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
|
|
|
|
|
: mesh_(&_mesh), hnd_(_hnd), skip_bits_(0)
|
|
|
|
|
{
|
|
|
|
|
if (_skip) enable_skipping();
|
|
|
|
|
|
|
|
|
|
// Set vertex handle invalid if the mesh contains no vertex
|
2012-03-01 17:27:38 +00:00
|
|
|
if((mesh_->*PrimitiveCountMember)() == 0) hnd_ = value_handle(-1);
|
2012-03-01 15:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Standard dereferencing operator.
|
|
|
|
|
reference operator*() const {
|
|
|
|
|
return hnd_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Standard pointer operator.
|
|
|
|
|
pointer operator->() const {
|
|
|
|
|
return &hnd_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 09:22:50 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get the handle of the item the iterator refers to.
|
|
|
|
|
* \deprecated
|
|
|
|
|
* This function clutters your code. Use dereferencing operators -> and * instead.
|
|
|
|
|
*/
|
2013-08-07 08:03:42 +00:00
|
|
|
DEPRECATED("This function clutters your code. Use dereferencing operators -> and * instead.")
|
2012-03-01 15:41:44 +00:00
|
|
|
value_handle handle() const {
|
|
|
|
|
return hnd_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 09:22:50 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Cast to the handle of the item the iterator refers to.
|
|
|
|
|
* \deprecated
|
|
|
|
|
* Implicit casts of iterators are unsafe. Use dereferencing operators
|
|
|
|
|
* -> and * instead.
|
|
|
|
|
*/
|
2013-08-07 08:03:42 +00:00
|
|
|
DEPRECATED("Implicit casts of iterators are unsafe. Use dereferencing operators -> and * instead.")
|
2012-03-01 15:41:44 +00:00
|
|
|
operator value_handle() const {
|
|
|
|
|
return hnd_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Are two iterators equal? Only valid if they refer to the same mesh!
|
|
|
|
|
bool operator==(const GenericIteratorT& _rhs) const {
|
|
|
|
|
return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Not equal?
|
|
|
|
|
bool operator!=(const GenericIteratorT& _rhs) const {
|
|
|
|
|
return !operator==(_rhs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Standard pre-increment operator
|
|
|
|
|
GenericIteratorT& operator++() {
|
|
|
|
|
hnd_.__increment();
|
|
|
|
|
if (skip_bits_)
|
|
|
|
|
skip_fwd();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
/// Standard post-increment operator
|
|
|
|
|
GenericIteratorT operator++(int) {
|
|
|
|
|
GenericIteratorT cpy(*this);
|
|
|
|
|
++(*this);
|
|
|
|
|
return cpy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-01 15:41:44 +00:00
|
|
|
/// Standard pre-decrement operator
|
|
|
|
|
GenericIteratorT& operator--() {
|
|
|
|
|
hnd_.__decrement();
|
|
|
|
|
if (skip_bits_)
|
|
|
|
|
skip_bwd();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:03:42 +00:00
|
|
|
/// Standard post-decrement operator
|
|
|
|
|
GenericIteratorT operator--(int) {
|
|
|
|
|
GenericIteratorT cpy(*this);
|
|
|
|
|
--(*this);
|
|
|
|
|
return cpy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-01 15:41:44 +00:00
|
|
|
/// Turn on skipping: automatically skip deleted/hidden elements
|
|
|
|
|
void enable_skipping() {
|
2012-03-01 17:27:38 +00:00
|
|
|
if (mesh_ && (mesh_->*PrimitiveStatusMember)()) {
|
2012-03-01 15:41:44 +00:00
|
|
|
Attributes::StatusInfo status;
|
|
|
|
|
status.set_deleted(true);
|
|
|
|
|
status.set_hidden(true);
|
|
|
|
|
skip_bits_ = status.bits();
|
|
|
|
|
skip_fwd();
|
|
|
|
|
} else
|
|
|
|
|
skip_bits_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Turn on skipping: automatically skip deleted/hidden elements
|
|
|
|
|
void disable_skipping() {
|
|
|
|
|
skip_bits_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
void skip_fwd() {
|
|
|
|
|
assert(mesh_ && skip_bits_);
|
2012-03-01 17:27:38 +00:00
|
|
|
while ((hnd_.idx() < (signed) (mesh_->*PrimitiveCountMember)())
|
2012-03-01 15:41:44 +00:00
|
|
|
&& (mesh_->status(hnd_).bits() & skip_bits_))
|
|
|
|
|
hnd_.__increment();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void skip_bwd() {
|
|
|
|
|
assert(mesh_ && skip_bits_);
|
|
|
|
|
while ((hnd_.idx() >= 0) && (mesh_->status(hnd_).bits() & skip_bits_))
|
|
|
|
|
hnd_.__decrement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
mesh_ptr mesh_;
|
|
|
|
|
value_handle hnd_;
|
|
|
|
|
unsigned int skip_bits_;
|
2009-02-06 13:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
} // namespace Iterators
|
|
|
|
|
} // namespace OpenMesh
|
|
|
|
|
//=============================================================================
|
|
|
|
|
#endif
|
|
|
|
|
//=============================================================================
|