]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/DataStructures/QuadEdgeIterators.h
...
[cpPlugins.git] / lib / cpExtensions / DataStructures / QuadEdgeIterators.h
1 #ifndef __CPEXTENSIONS__DATASTRUCTURES__QUADEDGEITERATORS__H__
2 #define __CPEXTENSIONS__DATASTRUCTURES__QUADEDGEITERATORS__H__
3
4 #include <cstdlib>
5
6 // -------------------------------------------------------------------------
7 #define cpPluginsQEIteratorsMacro( op, it, cit )        \
8   inline it Begin##op( )                                \
9   { return( it( this, it::Op##op, true ) ); }           \
10   inline it End##op( )                                  \
11   { return( it( this, it::Op##op, false ) ); }          \
12   inline cit Begin##op( ) const                         \
13   { return( cit( this, cit::Op##op, true ) ); }         \
14   inline cit End##op( ) const                           \
15   { return( cit( this, cit::Op##op, false ) ); }
16
17 // -------------------------------------------------------------------------
18 #define cpPluginsExtensionsQEPointIteratorsMacro( op, it, cit ) \
19   inline Point##it BeginPoint##op( )                            \
20   { return( Point##it( this, it::Op##op, true ) ); }            \
21   inline Point##it EndPoint##op( )                              \
22   { return( Point##it( this, it::Op##op, false ) ); }           \
23   inline Point##cit BeginPoint##op( ) const                     \
24   { return( Point##cit( this, cit::Op##op, true ) ); }          \
25   inline Point##cit EndPoint  ##op( ) const                     \
26   { return( Point##cit( this, cit::Op##op, false ) ); }
27
28 // -------------------------------------------------------------------------
29 #define cpPluginsExtensionsQEAllIteratorsMacro( op )                    \
30   cpPluginsQEIteratorsMacro( op, Iterator, ConstIterator );             \
31   cpPluginsExtensionsQEPointIteratorsMacro( op, Iterator, ConstIterator );
32
33 namespace cpExtensions
34   {
35     namespace DataStructures
36     {
37       /**
38        */
39       template< class E >
40       class QuadEdgeBaseIterator
41       {
42       public:
43         typedef QuadEdgeBaseIterator Self;
44         typedef E                    TQuadEdge;
45
46         // Different types of logical iterators
47         enum
48         {
49           OpOnext = 0,
50           OpLnext = 1,
51           OpRnext = 2,
52           OpDnext = 3,
53           OpOprev = 4,
54           OpLprev = 5,
55           OpRprev = 6,
56           OpDprev = 7
57         };
58
59       public:
60         QuadEdgeBaseIterator( E* e, int op = OpOnext, bool start = true );
61         virtual ~QuadEdgeBaseIterator( );
62         Self& operator=( const Self& r );
63
64         E*   GetStartEdge( ) const;
65         E*   GetIterator( ) const;
66         int  GetOpType( ) const;
67         bool GetStart( ) const;
68
69         bool  operator==( Self& r );
70         bool  operator==( const Self& r ) const;
71         bool  operator!=( Self& r );
72         bool  operator!=( const Self& r ) const;
73         Self& operator++( );
74         Self& operator++( int );
75
76       protected:
77         /// Method that should do all the iteration work
78       virtual void _GoToNext( );
79
80       protected:
81         E*   m_StartEdge; /**< Start edge */
82         E*   m_Iterator;  /**< Current iteration position */
83         int  m_OpType;    /**< Operation type */
84         bool m_Start;     /**< Indicates iteration has just started */
85       };
86
87       /**
88        */
89       template< class E >
90       class QuadEdgeIterator
91         : public QuadEdgeBaseIterator< E >
92       {
93       public:
94         typedef QuadEdgeIterator          Self;
95         typedef QuadEdgeBaseIterator< E > Superclass;
96         typedef E                         TQuadEdge;
97
98       public:
99         QuadEdgeIterator(
100           E* e = NULL, int op = Superclass::OpOnext, bool start = true
101           );
102         virtual ~QuadEdgeIterator( );
103         E* operator*( );
104       };
105
106       /**
107        */
108       template< class E >
109       class QuadEdgeConstIterator
110         : public QuadEdgeBaseIterator< const E >
111       {
112       public:
113         typedef QuadEdgeConstIterator           Self;
114         typedef QuadEdgeBaseIterator< const E > Superclass;
115         typedef E                               TQuadEdge;
116
117       public:
118         QuadEdgeConstIterator(
119           const E* e = NULL, int op = Superclass::OpOnext, bool start = true
120           );
121         virtual ~QuadEdgeConstIterator( );
122         const E* operator*( ) const;
123       };
124
125       /**
126        */
127       template< class E >
128       class QuadEdgePointIterator
129         : public QuadEdgeBaseIterator< const E >
130       {
131       public:
132         typedef QuadEdgePointIterator           Self;
133         typedef QuadEdgeBaseIterator< const E > Superclass;
134         typedef E                               TQuadEdge;
135
136       public:
137         QuadEdgePointIterator(
138           const E* e = NULL, int op = Superclass::OpOnext, bool start = true
139           );
140         virtual ~QuadEdgePointIterator( );
141         typename E::TPrimalGeometry& operator*( );
142       };
143
144       /**
145        */
146       template< class E >
147       class QuadEdgePointConstIterator
148         : public QuadEdgeBaseIterator< const E >
149       {
150       public:
151         typedef QuadEdgePointConstIterator      Self;
152         typedef QuadEdgeBaseIterator< const E > Superclass;
153         typedef E                               TQuadEdge;
154
155       public:
156         QuadEdgePointConstIterator(
157           const E* e = NULL, int op = Superclass::OpOnext, bool start = true
158           );
159         virtual ~QuadEdgePointConstIterator( );
160         const typename E::TPrimalGeometry& operator*( ) const;
161       };
162
163     } // ecapseman
164
165 } // ecapseman
166
167 #include <cpExtensions/DataStructures/QuadEdgeIterators.hxx>
168
169 #endif // __CPEXTENSIONS__DATASTRUCTURES__QUADEDGEITERATORS__H__
170
171 // eof - $RCSfile$