let iterators return smart handles

This commit is contained in:
Max Lyon
2019-09-26 11:14:31 +02:00
parent 89f0dcbb51
commit 253c9b6afa
5 changed files with 97 additions and 72 deletions

View File

@@ -40,9 +40,7 @@
* ========================================================================= */
#ifndef OPENMESH_ITERATORS_HH
#define OPENMESH_ITERATORS_HH
#pragma once
//=============================================================================
//
@@ -56,6 +54,7 @@
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/Mesh/Status.hh>
#include <OpenMesh/Core/Mesh/SmartHandles.hh>
#include <cassert>
#include <cstddef>
#include <iterator>
@@ -89,19 +88,20 @@ class GenericIteratorT {
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;
typedef decltype(make_smart(std::declval<ValueHandle>(), std::declval<Mesh>())) SmartHandle;
typedef const SmartHandle& reference;
typedef const SmartHandle* pointer;
/// Default constructor.
GenericIteratorT()
: mesh_(0), skip_bits_(0)
: hnd_(make_smart(ValueHandle(),nullptr)), 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)
: hnd_(make_smart(_hnd, _mesh)), skip_bits_(0)
{
if (_skip) enable_skipping();
}
@@ -139,7 +139,7 @@ class GenericIteratorT {
/// 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_));
return ((hnd_.mesh() == _rhs.hnd_.mesh()) && (hnd_ == _rhs.hnd_));
}
/// Not equal?
@@ -210,7 +210,7 @@ class GenericIteratorT {
/// Turn on skipping: automatically skip deleted/hidden elements
void enable_skipping() {
if (mesh_ && (mesh_->*PrimitiveStatusMember)()) {
if (hnd_.mesh() && (hnd_.mesh()->*PrimitiveStatusMember)()) {
Attributes::StatusInfo status;
status.set_deleted(true);
status.set_hidden(true);
@@ -228,21 +228,20 @@ class GenericIteratorT {
private:
void skip_fwd() {
assert(mesh_ && skip_bits_);
while ((hnd_.idx() < (signed) (mesh_->*PrimitiveCountMember)())
&& (mesh_->status(hnd_).bits() & skip_bits_))
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(mesh_ && skip_bits_);
while ((hnd_.idx() >= 0) && (mesh_->status(hnd_).bits() & skip_bits_))
assert(hnd_.mesh() && skip_bits_);
while ((hnd_.idx() >= 0) && (hnd_.mesh()->status(hnd_).bits() & skip_bits_))
hnd_.__decrement();
}
protected:
mesh_ptr mesh_;
value_handle hnd_;
SmartHandle hnd_;
unsigned int skip_bits_;
};
@@ -250,5 +249,3 @@ class GenericIteratorT {
} // namespace Iterators
} // namespace OpenMesh
//=============================================================================
#endif
//=============================================================================

View File

@@ -719,6 +719,46 @@ PolyConnectivity::ConstFaceIter PolyConnectivity::faces_end() const
return ConstFaceIter(*this, FaceHandle(int(n_faces())));
}
PolyConnectivity::VertexIter PolyConnectivity::vertices_sbegin()
{
return VertexIter(*this, VertexHandle(0), true);
}
PolyConnectivity::ConstVertexIter PolyConnectivity::vertices_sbegin() const
{
return ConstVertexIter(*this, VertexHandle(0), true);
}
PolyConnectivity::HalfedgeIter PolyConnectivity::halfedges_sbegin()
{
return HalfedgeIter(*this, HalfedgeHandle(0), true);
}
PolyConnectivity::ConstHalfedgeIter PolyConnectivity::halfedges_sbegin() const
{
return ConstHalfedgeIter(*this, HalfedgeHandle(0), true);
}
PolyConnectivity::EdgeIter PolyConnectivity::edges_sbegin()
{
return EdgeIter(*this, EdgeHandle(0), true);
}
PolyConnectivity::ConstEdgeIter PolyConnectivity::edges_sbegin() const
{
return ConstEdgeIter(*this, EdgeHandle(0), true);
}
PolyConnectivity::FaceIter PolyConnectivity::faces_sbegin()
{
return FaceIter(*this, FaceHandle(0), true);
}
PolyConnectivity::ConstFaceIter PolyConnectivity::faces_sbegin() const
{
return ConstFaceIter(*this, FaceHandle(0), true);
}
//-----------------------------------------------------------------------------
void PolyConnectivity::collapse(HalfedgeHandle _hh)
{

View File

@@ -45,12 +45,17 @@
#define OPENMESH_POLYCONNECTIVITY_HH
#include <OpenMesh/Core/Mesh/ArrayKernel.hh>
#include <OpenMesh/Core/Mesh/IteratorsT.hh>
#include <OpenMesh/Core/Mesh/CirculatorsT.hh>
namespace OpenMesh
{
namespace Iterators
{
template <class Mesh, class ValueHandle, class MemberOwner, bool (MemberOwner::*PrimitiveStatusMember)() const, size_t (MemberOwner::*PrimitiveCountMember)() const>
class GenericIteratorT;
}
/** \brief Connectivity Class for polygonal meshes
*/
class OPENMESHDLLEXPORT PolyConnectivity : public ArrayKernel
@@ -532,32 +537,24 @@ public:
//@{
/// Begin iterator for vertices
VertexIter vertices_sbegin()
{ return VertexIter(*this, VertexHandle(0), true); }
VertexIter vertices_sbegin();
/// Const begin iterator for vertices
ConstVertexIter vertices_sbegin() const
{ return ConstVertexIter(*this, VertexHandle(0), true); }
ConstVertexIter vertices_sbegin() const;
/// Begin iterator for halfedges
HalfedgeIter halfedges_sbegin()
{ return HalfedgeIter(*this, HalfedgeHandle(0), true); }
HalfedgeIter halfedges_sbegin();
/// Const begin iterator for halfedges
ConstHalfedgeIter halfedges_sbegin() const
{ return ConstHalfedgeIter(*this, HalfedgeHandle(0), true); }
ConstHalfedgeIter halfedges_sbegin() const;
/// Begin iterator for edges
EdgeIter edges_sbegin()
{ return EdgeIter(*this, EdgeHandle(0), true); }
EdgeIter edges_sbegin();
/// Const begin iterator for edges
ConstEdgeIter edges_sbegin() const
{ return ConstEdgeIter(*this, EdgeHandle(0), true); }
ConstEdgeIter edges_sbegin() const;
/// Begin iterator for faces
FaceIter faces_sbegin()
{ return FaceIter(*this, FaceHandle(0), true); }
FaceIter faces_sbegin();
/// Const begin iterator for faces
ConstFaceIter faces_sbegin() const
{ return ConstFaceIter(*this, FaceHandle(0), true); }
ConstFaceIter faces_sbegin() const;
//@}
@@ -1627,4 +1624,6 @@ private: // Working storage for add_face()
}//namespace OpenMesh
#include <OpenMesh/Core/Mesh/IteratorsT.hh>
#endif//OPENMESH_POLYCONNECTIVITY_HH

View File

@@ -40,8 +40,7 @@
* ========================================================================= */
#ifndef OPENMESH_SMARTHANDLES_HH
#define OPENMESH_SMARTHANDLES_HH
#pragma once
//== INCLUDES =================================================================
@@ -401,6 +400,4 @@ inline bool SmartFaceHandle::is_boundary() const
} // namespace OpenMesh
//=============================================================================
#endif // OPENMESH_SMARTHANDLES_HH
//=============================================================================