Loading...
Searching...
No Matches
IteratorsT.hh
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2025, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 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. *
* *
* 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. *
* *
* 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. *
* *
* ========================================================================= */
#pragma once
//=============================================================================
//
// Iterators for PolyMesh/TriMesh
//
//=============================================================================
//== INCLUDES =================================================================
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/Mesh/Status.hh>
#include <cassert>
#include <cstddef>
#include <iterator>
//== NAMESPACES ===============================================================
namespace OpenMesh {
namespace Iterators {
//== FORWARD DECLARATIONS =====================================================
template <class Mesh> class ConstVertexIterT;
template <class Mesh> class VertexIterT;
template <class Mesh> class ConstHalfedgeIterT;
template <class Mesh> class HalfedgeIterT;
template <class Mesh> class ConstEdgeIterT;
template <class Mesh> class EdgeIterT;
template <class Mesh> class ConstFaceIterT;
template <class Mesh> class FaceIterT;
template <class Mesh, class ValueHandle, class MemberOwner, bool (MemberOwner::*PrimitiveStatusMember)() const, size_t (MemberOwner::*PrimitiveCountMember)() const>
class GenericIteratorT {
public:
//--- 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;
typedef decltype(make_smart(std::declval<ValueHandle>(), std::declval<Mesh>())) SmartHandle;
typedef const SmartHandle& reference;
typedef const SmartHandle* pointer;
GenericIteratorT()
: hnd_(make_smart(ValueHandle(),nullptr)), skip_bits_(0)
{}
GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
: hnd_(make_smart(_hnd, _mesh)), skip_bits_(0)
{
if (_skip) enable_skipping();
}
reference operator*() const {
return hnd_;
}
pointer operator->() const {
return &hnd_;
}
OM_DEPRECATED("This function clutters your code. Use dereferencing operators -> and * instead.")
value_handle handle() const {
return hnd_;
}
OM_DEPRECATED("Implicit casts of iterators are unsafe. Use dereferencing operators -> and * instead.")
operator value_handle() const {
return hnd_;
}
bool operator==(const GenericIteratorT& _rhs) const {
return ((hnd_.mesh() == _rhs.hnd_.mesh()) && (hnd_ == _rhs.hnd_));
}
bool operator!=(const GenericIteratorT& _rhs) const {
return !operator==(_rhs);
}
GenericIteratorT& operator++() {
hnd_.__increment();
if (skip_bits_)
skip_fwd();
return *this;
}
GenericIteratorT operator++(int) {
GenericIteratorT cpy(*this);
++(*this);
return cpy;
}
#if ((defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY)
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
GenericIteratorT& operator--() {
hnd_.__decrement();
if (skip_bits_)
skip_bwd();
return *this;
}
GenericIteratorT operator--(int) {
GenericIteratorT cpy(*this);
--(*this);
return cpy;
}
void enable_skipping() {
if (hnd_.mesh() && (hnd_.mesh()->*PrimitiveStatusMember)()) {
Attributes::StatusInfo status;
status.set_deleted(true);
status.set_hidden(true);
skip_bits_ = status.bits();
skip_fwd();
} else
skip_bits_ = 0;
}
void disable_skipping() {
skip_bits_ = 0;
}
private:
void skip_fwd() {
assert(hnd_.mesh() && skip_bits_);
while ((hnd_.idx() < (signed) (hnd_.mesh()->*PrimitiveCountMember)())
&& (hnd_.mesh()->status(hnd_).bits() & skip_bits_))
hnd_.__increment();
}
void skip_bwd() {
assert(hnd_.mesh() && skip_bits_);
while ((hnd_.idx() >= 0) && (hnd_.mesh()->status(hnd_).bits() & skip_bits_))
hnd_.__decrement();
}
protected:
SmartHandle hnd_;
unsigned int skip_bits_;
};
//=============================================================================
} // namespace Iterators
} // namespace OpenMesh
//=============================================================================
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
OpenMesh::make_smart
SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity *_mesh)
Creats a SmartVertexHandle from a VertexHandle and a Mesh.
Definition SmartHandles.hh:265
OpenMesh::Iterators
Contains all mesh iterators and circulators.
OpenMesh::Iterators::ConstVertexIterT
Definition IteratorsT.hh:71
OpenMesh::Iterators::VertexIterT
Definition IteratorsT.hh:72
OpenMesh::Iterators::ConstHalfedgeIterT
Definition IteratorsT.hh:73
OpenMesh::Iterators::HalfedgeIterT
Definition IteratorsT.hh:74
OpenMesh::Iterators::ConstEdgeIterT
Definition IteratorsT.hh:75
OpenMesh::Iterators::EdgeIterT
Definition IteratorsT.hh:76
OpenMesh::Iterators::ConstFaceIterT
Definition IteratorsT.hh:77
OpenMesh::Iterators::FaceIterT
Definition IteratorsT.hh:78
OpenMesh::Iterators::GenericIteratorT
Definition IteratorsT.hh:82
OpenMesh::Iterators::GenericIteratorT::disable_skipping
void disable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition IteratorsT.hh:223
OpenMesh::Iterators::GenericIteratorT::operator--
GenericIteratorT operator--(int)
Standard post-decrement operator.
Definition IteratorsT.hh:204
OpenMesh::Iterators::GenericIteratorT::GenericIteratorT
GenericIteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
Construct with mesh and a target handle.
Definition IteratorsT.hh:102
OpenMesh::Iterators::GenericIteratorT::GenericIteratorT
GenericIteratorT()
Default constructor.
Definition IteratorsT.hh:97
OpenMesh::Iterators::GenericIteratorT::operator->
pointer operator->() const
Standard pointer operator.
Definition IteratorsT.hh:114
OpenMesh::Iterators::GenericIteratorT::operator++
GenericIteratorT operator++(int)
Standard post-increment operator.
Definition IteratorsT.hh:158
OpenMesh::Iterators::GenericIteratorT::operator--
GenericIteratorT & operator--()
Standard pre-decrement operator.
Definition IteratorsT.hh:196
OpenMesh::Iterators::GenericIteratorT::enable_skipping
void enable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition IteratorsT.hh:211
OpenMesh::Iterators::GenericIteratorT::operator*
reference operator*() const
Standard dereferencing operator.
Definition IteratorsT.hh:109
OpenMesh::Iterators::GenericIteratorT::operator==
bool operator==(const GenericIteratorT &_rhs) const
Are two iterators equal? Only valid if they refer to the same mesh!
Definition IteratorsT.hh:140
OpenMesh::Iterators::GenericIteratorT::operator++
GenericIteratorT & operator++()
Standard pre-increment operator.
Definition IteratorsT.hh:150
OpenMesh::Iterators::GenericIteratorT< This, This::VertexHandle, ArrayKernel, &ArrayKernel::has_vertex_status, &ArrayKernel::n_vertices >::handle
value_handle handle() const
Definition IteratorsT.hh:124
OpenMesh::Iterators::GenericIteratorT::operator!=
bool operator!=(const GenericIteratorT &_rhs) const
Not equal?
Definition IteratorsT.hh:145
OpenMesh::Attributes::StatusInfo
Add status information to a base class.
Definition Status.hh:95
OpenMesh::Attributes::StatusInfo::set_hidden
void set_hidden(bool _b)
set hidden
Definition Status.hh:123
OpenMesh::Attributes::StatusInfo::set_deleted
void set_deleted(bool _b)
set deleted
Definition Status.hh:105
OpenMesh::Attributes::StatusInfo::bits
unsigned int bits() const
return whole status
Definition Status.hh:151