00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkQuadEdgeMeshBaseIterator_h
00018 #define __itkQuadEdgeMeshBaseIterator_h
00019
00020
00021 #define itkQEDefineIteratorMethodsMacro( Op ) \
00022 virtual Iterator Begin##Op() \
00023 { \
00024 return Iterator( this, Self::Iterator::Operator##Op, true ); \
00025 } \
00026 \
00027 virtual ConstIterator Begin##Op() const \
00028 { \
00029 return ConstIterator( this, Self::ConstIterator::Operator##Op, \
00030 true ); \
00031 } \
00032 \
00033 virtual Iterator End##Op() \
00034 { \
00035 return Iterator( this, Self::Iterator::Operator##Op, false ); \
00036 } \
00037 \
00038 virtual ConstIterator End##Op() const \
00039 { \
00040 return ConstIterator( this, Self::ConstIterator::Operator##Op, \
00041 false ); \
00042 }
00043
00044
00045 #define itkQEDefineIteratorGeomMethodsMacro( Op ) \
00046 virtual IteratorGeom BeginGeom##Op() \
00047 { \
00048 return IteratorGeom( this, Self::IteratorGeom::Operator##Op, \
00049 true ); \
00050 } \
00051 \
00052 virtual ConstIteratorGeom BeginGeom##Op() const \
00053 { \
00054 return ConstIteratorGeom( this, \
00055 Self::ConstIteratorGeom::Operator##Op, true ); \
00056 } \
00057 \
00058 virtual IteratorGeom EndGeom##Op() \
00059 { \
00060 return IteratorGeom( this, Self::IteratorGeom::Operator##Op, \
00061 false ); \
00062 } \
00063 \
00064 virtual ConstIteratorGeom EndGeom##Op() const \
00065 { \
00066 return ConstIteratorGeom( this, \
00067 Self::ConstIteratorGeom::Operator##Op, false ); \
00068 }
00069
00070
00071 namespace itk
00072 {
00078 template< typename TQuadEdge >
00079 class QuadEdgeMeshBaseIterator
00080 {
00081 public:
00082
00083 typedef QuadEdgeMeshBaseIterator Self;
00084 typedef TQuadEdge QuadEdgeType;
00085
00086
00087 enum
00088 {
00089 OperatorOnext = 0,
00090 OperatorSym = 1,
00091 OperatorLnext = 2,
00092 OperatorRnext = 3,
00093 OperatorDnext = 4,
00094 OperatorOprev = 5,
00095 OperatorLprev = 6,
00096 OperatorRprev = 7,
00097 OperatorDprev = 8,
00098 OperatorInvOnext = 9,
00099 OperatorInvLnext = 10,
00100 OperatorInvRnext = 11,
00101 OperatorInvDnext = 12
00102 };
00103
00104 public:
00105
00106 QuadEdgeMeshBaseIterator( QuadEdgeType* e,
00107 int op = OperatorOnext,
00108 bool start = true )
00109 : m_StartEdge( e ), m_Iterator( e ),
00110 m_OpType( op ), m_Start( start ) {}
00111
00112 virtual ~QuadEdgeMeshBaseIterator() {}
00113
00114 Self& operator=( const Self& r )
00115 {
00116 m_StartEdge = r.m_StartEdge;
00117 m_Iterator = r.m_Iterator;
00118 m_OpType = r.m_OpType;
00119 m_Start = r.m_Start;
00120 return( *this );
00121 }
00122
00123 QuadEdgeType* GetStartEdge() const { return( m_StartEdge ); }
00124 QuadEdgeType* GetIterator() const { return( m_Iterator ); }
00125 int GetOpType() const { return( m_OpType ); }
00126 bool GetStart() const { return( m_Start ); }
00127
00129 bool operator==( Self & r )
00130 {
00131 return( ( m_StartEdge == r.m_StartEdge ) &&
00132 ( m_Iterator == r.m_Iterator ) &&
00133 ( m_OpType == r.m_OpType ) &&
00134 ( m_Start == r.m_Start ) );
00135 }
00136
00137 bool operator==( const Self & r ) const
00138 {
00139 return( ( m_StartEdge == r.m_StartEdge ) &&
00140 ( m_Iterator == r.m_Iterator ) &&
00141 ( m_OpType == r.m_OpType ) &&
00142 ( m_Start == r.m_Start ) );
00143 }
00144
00145 bool operator!=( Self & r )
00146 {
00147 return( !( this->operator==( r ) ) );
00148 }
00149
00150 bool operator!=( const Self & r ) const
00151 {
00152 return( !( this->operator==( r ) ) );
00153 }
00154
00155 Self & operator++()
00156 {
00157 if( m_Start )
00158 {
00159 this->GoToNext();
00160 m_Start = !( m_Iterator == m_StartEdge );
00161 }
00162
00163 return( *this );
00164 }
00165
00166 Self & operator++( int )
00167 {
00168 if( m_Start )
00169 {
00170 this->GoToNext();
00171 m_Start = !( m_Iterator == m_StartEdge );
00172 }
00173 return( *this );
00174 }
00175
00176 protected:
00178 virtual void GoToNext()
00179 {
00180 switch( m_OpType )
00181 {
00182 case OperatorOnext : m_Iterator = m_Iterator->GetOnext();
00183 break;
00184 case OperatorSym : m_Iterator = m_Iterator->GetSym();
00185 break;
00186 case OperatorLnext : m_Iterator = m_Iterator->GetLnext();
00187 break;
00188 case OperatorRnext : m_Iterator = m_Iterator->GetRnext();
00189 break;
00190 case OperatorDnext : m_Iterator = m_Iterator->GetDnext();
00191 break;
00192 case OperatorOprev : m_Iterator = m_Iterator->GetOprev();
00193 break;
00194 case OperatorLprev : m_Iterator = m_Iterator->GetLprev();
00195 break;
00196 case OperatorRprev : m_Iterator = m_Iterator->GetRprev();
00197 break;
00198 case OperatorDprev : m_Iterator = m_Iterator->GetDprev();
00199 break;
00200 case OperatorInvOnext : m_Iterator = m_Iterator->GetInvOnext();
00201 break;
00202 case OperatorInvLnext : m_Iterator = m_Iterator->GetInvLnext();
00203 break;
00204 case OperatorInvRnext : m_Iterator = m_Iterator->GetInvRnext();
00205 break;
00206 case OperatorInvDnext : m_Iterator = m_Iterator->GetInvDnext();
00207 break;
00208 default: break;
00209 }
00210 }
00212
00213 protected:
00214 QuadEdgeType * m_StartEdge;
00215 QuadEdgeType * m_Iterator;
00216 int m_OpType;
00217 bool m_Start;
00218 };
00219
00225 template< typename TQuadEdge >
00226 class QuadEdgeMeshIterator
00227 : public QuadEdgeMeshBaseIterator< TQuadEdge >
00228 {
00229 public:
00230
00232 typedef QuadEdgeMeshIterator Self;
00233 typedef QuadEdgeMeshBaseIterator< TQuadEdge > Superclass;
00234 typedef TQuadEdge QuadEdgeType;
00235
00236 public:
00238 QuadEdgeMeshIterator( QuadEdgeType* e = (QuadEdgeType*)0,
00239 int op = Superclass::OperatorOnext,
00240 bool start = true )
00241 : Superclass( e, op, start ) {}
00242
00243 virtual ~QuadEdgeMeshIterator() {}
00244
00245 QuadEdgeType * Value() { return( this->m_Iterator ); }
00246 const QuadEdgeType * Value() const { return( this->m_Iterator ); }
00247 };
00248
00254 template< typename TGeometricalQuadEdge >
00255 class QuadEdgeMeshIteratorGeom
00256 : public QuadEdgeMeshIterator< TGeometricalQuadEdge >
00257 {
00258 public:
00259
00261 typedef QuadEdgeMeshIterator< TGeometricalQuadEdge > Superclass;
00262 typedef TGeometricalQuadEdge QuadEdgeType;
00263
00265 typedef typename QuadEdgeType::OriginRefType OriginRefType;
00266
00267 public:
00268 QuadEdgeMeshIteratorGeom( QuadEdgeType* e = (QuadEdgeType*)0,
00269 int op = Superclass::OperatorOnext,
00270 bool start = true )
00271 : Superclass( e, op, start ) {}
00272 OriginRefType operator*() { return( this->m_Iterator->GetOrigin( ) ); }
00273 };
00274
00280 template< typename TQuadEdge >
00281 class QuadEdgeMeshConstIterator
00282 : public QuadEdgeMeshBaseIterator< TQuadEdge >
00283 {
00284 public:
00285
00287 typedef QuadEdgeMeshConstIterator Self;
00288 typedef QuadEdgeMeshBaseIterator< TQuadEdge > Superclass;
00289 typedef QuadEdgeMeshIterator< TQuadEdge > NoConstType;
00290 typedef TQuadEdge QuadEdgeType;
00291
00292 public:
00294 QuadEdgeMeshConstIterator( const QuadEdgeType* e = (QuadEdgeType*)0,
00295 int op = Superclass::OperatorOnext,
00296 bool start = true )
00297 : Superclass( const_cast<QuadEdgeType*>(e), op, start ) {}
00298
00299 virtual ~QuadEdgeMeshConstIterator() {}
00300
00301 Self& operator=( const NoConstType& r )
00302 {
00303 this->m_StartEdge = r.GetStartEdge();
00304 this->m_Iterator = r.GetIterator();
00305 this->m_OpType = r.GetOpType();
00306 this->m_Start = r.GetStart();
00307 return( *this );
00308 }
00309
00310 const QuadEdgeType* Value() const { return( this->m_Iterator ); }
00311 };
00312
00318 template< typename TGeometricalQuadEdge >
00319 class QuadEdgeMeshConstIteratorGeom
00320 : public QuadEdgeMeshConstIterator< TGeometricalQuadEdge >
00321 {
00322 public:
00323
00325 typedef QuadEdgeMeshConstIteratorGeom Self;
00326 typedef QuadEdgeMeshConstIterator< TGeometricalQuadEdge > Superclass;
00327 typedef QuadEdgeMeshIteratorGeom< TGeometricalQuadEdge > NoConstType;
00328 typedef TGeometricalQuadEdge QuadEdgeType;
00329
00331 typedef typename QuadEdgeType::OriginRefType OriginRefType;
00332
00333 public:
00334 QuadEdgeMeshConstIteratorGeom( const QuadEdgeType* e = (QuadEdgeType*)0,
00335 int op = Superclass::OperatorOnext,
00336 bool start = true )
00337 : Superclass( e, op, start ) {}
00338
00339 virtual ~QuadEdgeMeshConstIteratorGeom() {}
00340
00341 Self& operator=( const NoConstType& r )
00342 {
00343 this->m_StartEdge = r.GetStartEdge();
00344 this->m_Iterator = r.GetIterator();
00345 this->m_OpType = r.GetOpType();
00346 this->m_Start = r.GetStart();
00347 return( *this );
00348 }
00349
00350 const OriginRefType operator*() const
00351 {
00352 return( this->m_Iterator->GetOrigin() );
00353 }
00354 };
00355
00356 }
00357
00358 #endif
00359