MeshLib
 
Loading...
Searching...
No Matches
MRRingIterator.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshTopology.h"
4#include "MRIteratorRange.h"
5#include <iterator>
6
7namespace MR
8{
9
10// The iterator to find all edges in a ring of edges (e.g. all edges with same origin or all edges with same left face)
11template <typename N>
12class RingIterator : public N
13{
14public:
15 using iterator_category = std::forward_iterator_tag;
17 using difference_type = std::ptrdiff_t;
18
19 RingIterator( const MeshTopology & topology, EdgeId edge, bool first )
20 : N( topology ), edge_( edge ), first_( first )
21 {
22 }
24 {
25 first_ = false;
26 edge_ = N::next( edge_ );
27 return * this;
28 }
29 EdgeId operator *( ) const { return edge_; }
30 bool first() const { return first_; }
31
32private:
33 EdgeId edge_;
34 bool first_ = false;
35};
36
37template <typename N>
38inline bool operator ==( const RingIterator<N> & a, const RingIterator<N> & b )
39 { return *a == *b && a.first() == b.first(); }
40
41template <typename N>
42inline bool operator !=( const RingIterator<N> & a, const RingIterator<N> & b )
43 { return *a != *b || a.first() != b.first(); }
44
46{
47 const MeshTopology * topology_ = nullptr;
48
49public:
50 NextEdgeSameOrigin( const MeshTopology & topology ) : topology_( &topology ) { }
51 EdgeId next( EdgeId e ) const { return topology_->next( e ); }
52};
53
55
57{
58 const MeshTopology * topology_ = nullptr;
59
60public:
61 NextEdgeSameLeft( const MeshTopology & topology ) : topology_( &topology ) { }
62 EdgeId next( EdgeId e ) const { return topology_->prev( e.sym() ); }
63};
64
66
67
68// to iterate over all edges with same origin vertex as firstEdge (INCLUDING firstEdge)
69// for ( Edge e : orgRing( topology, firstEdge ) ) ...
71 { return { OrgRingIterator( topology, edge, edge.valid() ), OrgRingIterator( topology, edge, false ) }; }
72inline IteratorRange<OrgRingIterator> orgRing( const MeshTopology & topology, VertId v )
73 { return orgRing( topology, topology.edgeWithOrg( v ) ); }
74
75// to iterate over all edges with same origin vertex as firstEdge (EXCLUDING firstEdge)
76// for ( Edge e : orgRing0( topology, firstEdge ) ) ...
78 { return { ++OrgRingIterator( topology, edge, true ), OrgRingIterator( topology, edge, false ) }; }
79
80
81// to iterate over all edges with same left face as firstEdge (INCLUDING firstEdge)
82// for ( Edge e : leftRing( topology, firstEdge ) ) ...
84 { return { LeftRingIterator( topology, edge, edge.valid() ), LeftRingIterator( topology, edge, false ) }; }
85inline IteratorRange<LeftRingIterator> leftRing( const MeshTopology & topology, FaceId f )
86 { return leftRing( topology, topology.edgeWithLeft( f ) ); }
87
88// to iterate over all edges with same left face as firstEdge (EXCLUDING firstEdge)
89// for ( Edge e : leftRing0( topology, firstEdge ) ) ...
91 { return { ++LeftRingIterator( topology, edge, true ), LeftRingIterator( topology, edge, false ) }; }
92
93} //namespace MR
int VertId
Definition MRDotNet/MRMeshFwd.h:51
int FaceId
Definition MRDotNet/MRMeshFwd.h:53
int EdgeId
Definition MRDotNet/MRMeshFwd.h:52
Definition MRMesh/MRMeshTopology.h:18
EdgeId next(EdgeId he) const
next (counter clock wise) half-edge in the origin ring
Definition MRMesh/MRMeshTopology.h:71
EdgeId prev(EdgeId he) const
previous (clock wise) half-edge in the origin ring
Definition MRMesh/MRMeshTopology.h:74
Definition MRRingIterator.h:57
EdgeId next(EdgeId e) const
Definition MRRingIterator.h:62
NextEdgeSameLeft(const MeshTopology &topology)
Definition MRRingIterator.h:61
Definition MRRingIterator.h:46
EdgeId next(EdgeId e) const
Definition MRRingIterator.h:51
NextEdgeSameOrigin(const MeshTopology &topology)
Definition MRRingIterator.h:50
Definition MRRingIterator.h:13
RingIterator & operator++()
Definition MRRingIterator.h:23
std::forward_iterator_tag iterator_category
Definition MRRingIterator.h:15
EdgeId operator*() const
Definition MRRingIterator.h:29
std::ptrdiff_t difference_type
Definition MRRingIterator.h:17
EdgeId value_type
Definition MRRingIterator.h:16
bool first() const
Definition MRRingIterator.h:30
RingIterator(const MeshTopology &topology, EdgeId edge, bool first)
Definition MRRingIterator.h:19
MRMESH_API bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
bool operator!=(const SetBitIteratorT< T > &a, const SetBitIteratorT< T > &b)
Definition MRMesh/MRBitSet.h:259
Definition MRCameraOrientationPlugin.h:7
RingIterator< NextEdgeSameOrigin > OrgRingIterator
Definition MRRingIterator.h:54
IteratorRange< LeftRingIterator > leftRing0(const MeshTopology &topology, EdgeId edge)
Definition MRRingIterator.h:90
class MRMESH_CLASS MeshTopology
Definition MRMesh/MRMeshFwd.h:464
IteratorRange< LeftRingIterator > leftRing(const MeshTopology &topology, EdgeId edge)
Definition MRRingIterator.h:83
IteratorRange< OrgRingIterator > orgRing(const MeshTopology &topology, EdgeId edge)
Definition MRRingIterator.h:70
IteratorRange< OrgRingIterator > orgRing0(const MeshTopology &topology, EdgeId edge)
Definition MRRingIterator.h:77
RingIterator< NextEdgeSameLeft > LeftRingIterator
Definition MRRingIterator.h:65
Definition MRMesh/MRMeshFwd.h:366