2015-04-28 11:54:17 +00:00
|
|
|
/* ========================================================================= *
|
2009-02-06 13:37:46 +00:00
|
|
|
* *
|
|
|
|
|
* OpenMesh *
|
2015-04-28 11:33:32 +00:00
|
|
|
* Copyright (c) 2001-2015, RWTH-Aachen University *
|
2015-04-28 13:07:46 +00:00
|
|
|
* Department of Computer Graphics and Multimedia *
|
2015-04-28 11:33:32 +00:00
|
|
|
* 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. *
|
2015-04-28 11:54:17 +00:00
|
|
|
* *
|
|
|
|
|
* ========================================================================= */
|
2009-06-04 08:46:29 +00:00
|
|
|
|
2019-01-15 11:21:12 +01:00
|
|
|
|
2019-09-26 11:14:31 +02:00
|
|
|
#pragma once
|
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>
|
2019-09-26 11:14:31 +02:00
|
|
|
#include <OpenMesh/Core/Mesh/SmartHandles.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 Mesh* mesh_ptr;
|
|
|
|
|
typedef const Mesh& mesh_ref;
|
2019-09-26 11:14:31 +02:00
|
|
|
typedef decltype(make_smart(std::declval<ValueHandle>(), std::declval<Mesh>())) SmartHandle;
|
|
|
|
|
typedef const SmartHandle& reference;
|
|
|
|
|
typedef const SmartHandle* pointer;
|
2012-03-01 15:41:44 +00:00
|
|
|
|
|
|
|
|
/// Default constructor.
|
|
|
|
|
GenericIteratorT()
|
2019-09-26 11:14:31 +02:00
|
|
|
: hnd_(make_smart(ValueHandle(),nullptr)), skip_bits_(0)
|
2012-03-01 15:41:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/// Construct with mesh and a target handle.
|
|
|
|
|
GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
|
2019-09-26 11:14:31 +02:00
|
|
|
: hnd_(make_smart(_hnd, _mesh)), skip_bits_(0)
|
2012-03-01 15:41:44 +00:00
|
|
|
{
|
|
|
|
|
if (_skip) enable_skipping();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
|
*/
|
2018-09-25 10:15:47 +02:00
|
|
|
OM_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.
|
|
|
|
|
*/
|
2018-09-25 10:15:47 +02:00
|
|
|
OM_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 {
|
2019-09-26 11:14:31 +02:00
|
|
|
return ((hnd_.mesh() == _rhs.hnd_.mesh()) && (hnd_ == _rhs.hnd_));
|
2012-03-01 15:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 16:03:19 +02:00
|
|
|
#if ((defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY)
|
2015-12-14 17:32:25 +01:00
|
|
|
template<class T = value_handle>
|
|
|
|
|
auto operator+=(int amount) ->
|
|
|
|
|
typename std::enable_if<
|
|
|
|
|
sizeof(decltype(std::declval<T>().__increment(amount))) >= 0,
|
|
|
|
|
GenericIteratorT&>::type {
|
|
|
|
|
static_assert(std::is_same<T, value_handle>::value,
|
|
|
|
|
"Template parameter must not deviate from default.");
|
|
|
|
|
if (skip_bits_)
|
|
|
|
|
throw std::logic_error("Skipping iterators do not support "
|
|
|
|
|
"random access.");
|
|
|
|
|
hnd_.__increment(amount);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T = value_handle>
|
|
|
|
|
auto operator+(int rhs) ->
|
|
|
|
|
typename std::enable_if<
|
|
|
|
|
sizeof(decltype(std::declval<T>().__increment(rhs), void (), int {})) >= 0,
|
|
|
|
|
GenericIteratorT>::type {
|
|
|
|
|
static_assert(std::is_same<T, value_handle>::value,
|
|
|
|
|
"Template parameter must not deviate from default.");
|
|
|
|
|
if (skip_bits_)
|
|
|
|
|
throw std::logic_error("Skipping iterators do not support "
|
|
|
|
|
"random access.");
|
|
|
|
|
GenericIteratorT result = *this;
|
|
|
|
|
result.hnd_.__increment(rhs);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
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() {
|
2019-09-26 11:14:31 +02:00
|
|
|
if (hnd_.mesh() && (hnd_.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() {
|
2019-09-26 11:14:31 +02:00
|
|
|
assert(hnd_.mesh() && skip_bits_);
|
|
|
|
|
while ((hnd_.idx() < (signed) (hnd_.mesh()->*PrimitiveCountMember)())
|
|
|
|
|
&& (hnd_.mesh()->status(hnd_).bits() & skip_bits_))
|
2012-03-01 15:41:44 +00:00
|
|
|
hnd_.__increment();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void skip_bwd() {
|
2019-09-26 11:14:31 +02:00
|
|
|
assert(hnd_.mesh() && skip_bits_);
|
|
|
|
|
while ((hnd_.idx() >= 0) && (hnd_.mesh()->status(hnd_).bits() & skip_bits_))
|
2012-03-01 15:41:44 +00:00
|
|
|
hnd_.__decrement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2019-09-26 11:14:31 +02:00
|
|
|
SmartHandle hnd_;
|
2012-03-01 15:41:44 +00:00
|
|
|
unsigned int skip_bits_;
|
2009-02-06 13:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
} // namespace Iterators
|
|
|
|
|
} // namespace OpenMesh
|
|
|
|
|
//=============================================================================
|