ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkQuadEdgeMeshBaseIterator_h 00019 #define __itkQuadEdgeMeshBaseIterator_h 00020 00021 #include "itkMacro.h" 00022 00023 // ------------------------------------------------------------------------- 00024 #define itkQEDefineIteratorMethodsMacro(Op) \ 00025 virtual Iterator Begin##Op() \ 00026 { \ 00027 return Iterator(this, Self::Iterator::Operator##Op, true); \ 00028 } \ 00029 \ 00030 virtual ConstIterator Begin##Op() const \ 00031 { \ 00032 return ConstIterator(this, Self::ConstIterator::Operator##Op, \ 00033 true); \ 00034 } \ 00035 \ 00036 virtual Iterator End##Op() \ 00037 { \ 00038 return Iterator(this, Self::Iterator::Operator##Op, false); \ 00039 } \ 00040 \ 00041 virtual ConstIterator End##Op() const \ 00042 { \ 00043 return ConstIterator(this, Self::ConstIterator::Operator##Op, \ 00044 false); \ 00045 } 00046 00047 // ------------------------------------------------------------------------- 00048 #define itkQEDefineIteratorGeomMethodsMacro(Op) \ 00049 virtual IteratorGeom BeginGeom##Op() \ 00050 { \ 00051 return IteratorGeom(this, Self::IteratorGeom::Operator##Op, \ 00052 true); \ 00053 } \ 00054 \ 00055 virtual ConstIteratorGeom BeginGeom##Op() const \ 00056 { \ 00057 return ConstIteratorGeom(this, \ 00058 Self::ConstIteratorGeom::Operator##Op, true); \ 00059 } \ 00060 \ 00061 virtual IteratorGeom EndGeom##Op() \ 00062 { \ 00063 return IteratorGeom(this, Self::IteratorGeom::Operator##Op, \ 00064 false); \ 00065 } \ 00066 \ 00067 virtual ConstIteratorGeom EndGeom##Op() const \ 00068 { \ 00069 return ConstIteratorGeom(this, \ 00070 Self::ConstIteratorGeom::Operator##Op, false); \ 00071 } 00072 00073 namespace itk 00074 { 00081 template< typename TQuadEdge > 00082 class ITK_EXPORT QuadEdgeMeshBaseIterator 00083 { 00084 public: 00085 // Hierarchy typedefs & values. 00086 typedef QuadEdgeMeshBaseIterator Self; 00087 typedef TQuadEdge QuadEdgeType; 00088 00089 // Different types of iterators, one for each basic QE operation. 00090 enum { 00091 OperatorOnext = 0, 00092 OperatorSym = 1, 00093 OperatorLnext = 2, 00094 OperatorRnext = 3, 00095 OperatorDnext = 4, 00096 OperatorOprev = 5, 00097 OperatorLprev = 6, 00098 OperatorRprev = 7, 00099 OperatorDprev = 8, 00100 OperatorInvOnext = 9, 00101 OperatorInvLnext = 10, 00102 OperatorInvRnext = 11, 00103 OperatorInvDnext = 12 00104 }; 00105 public: 00106 // Object creation methods. 00107 QuadEdgeMeshBaseIterator(QuadEdgeType *e, 00108 int op = OperatorOnext, 00109 bool start = true): 00110 m_StartEdge(e), m_Iterator(e), 00111 m_OpType(op), m_Start(start) {} 00112 00113 virtual ~QuadEdgeMeshBaseIterator() {} 00114 00115 Self & operator=(const Self & r) 00116 { 00117 m_StartEdge = r.m_StartEdge; 00118 m_Iterator = r.m_Iterator; 00119 m_OpType = r.m_OpType; 00120 m_Start = r.m_Start; 00121 return ( *this ); 00122 } 00123 00124 QuadEdgeType * GetStartEdge() const { return ( m_StartEdge ); } 00125 QuadEdgeType * GetIterator() const { return ( m_Iterator ); } 00126 int GetOpType() const { return ( m_OpType ); } 00127 bool GetStart() const { return ( m_Start ); } 00128 00130 bool operator==(Self & r) 00131 { 00132 return ( ( m_StartEdge == r.m_StartEdge ) 00133 && ( m_Iterator == r.m_Iterator ) 00134 && ( m_OpType == r.m_OpType ) 00135 && ( m_Start == r.m_Start ) ); 00136 } 00137 00138 bool operator==(const Self & r) const 00139 { 00140 return ( ( m_StartEdge == r.m_StartEdge ) 00141 && ( m_Iterator == r.m_Iterator ) 00142 && ( m_OpType == r.m_OpType ) 00143 && ( m_Start == r.m_Start ) ); 00144 } 00145 00146 bool operator!=(Self & r) 00147 { 00148 return ( !( this->operator==(r) ) ); 00149 } 00150 00151 bool operator!=(const Self & r) const 00152 { 00153 return ( !( this->operator==(r) ) ); 00154 } 00155 00156 Self & operator++() 00157 { 00158 if ( m_Start ) 00159 { 00160 this->GoToNext(); 00161 m_Start = !( m_Iterator == m_StartEdge ); 00162 } 00163 00164 return ( *this ); 00165 } 00166 00167 Self & operator++(int) 00168 { 00169 if ( m_Start ) 00170 { 00171 this->GoToNext(); 00172 m_Start = !( m_Iterator == m_StartEdge ); 00173 } 00174 return ( *this ); 00175 } 00176 00177 protected: 00179 virtual void GoToNext() 00180 { 00181 switch ( m_OpType ) 00182 { 00183 case OperatorOnext: 00184 m_Iterator = m_Iterator->GetOnext(); 00185 break; 00186 case OperatorSym: 00187 m_Iterator = m_Iterator->GetSym(); 00188 break; 00189 case OperatorLnext: 00190 m_Iterator = m_Iterator->GetLnext(); 00191 break; 00192 case OperatorRnext: 00193 m_Iterator = m_Iterator->GetRnext(); 00194 break; 00195 case OperatorDnext: 00196 m_Iterator = m_Iterator->GetDnext(); 00197 break; 00198 case OperatorOprev: 00199 m_Iterator = m_Iterator->GetOprev(); 00200 break; 00201 case OperatorLprev: 00202 m_Iterator = m_Iterator->GetLprev(); 00203 break; 00204 case OperatorRprev: 00205 m_Iterator = m_Iterator->GetRprev(); 00206 break; 00207 case OperatorDprev: 00208 m_Iterator = m_Iterator->GetDprev(); 00209 break; 00210 case OperatorInvOnext: 00211 m_Iterator = m_Iterator->GetInvOnext(); 00212 break; 00213 case OperatorInvLnext: 00214 m_Iterator = m_Iterator->GetInvLnext(); 00215 break; 00216 case OperatorInvRnext: 00217 m_Iterator = m_Iterator->GetInvRnext(); 00218 break; 00219 case OperatorInvDnext: 00220 m_Iterator = m_Iterator->GetInvDnext(); 00221 break; 00222 default: 00223 break; 00224 } 00225 } 00227 00228 protected: 00236 }; 00237 00244 template< typename TQuadEdge > 00245 class ITK_EXPORT QuadEdgeMeshIterator: 00246 public QuadEdgeMeshBaseIterator< TQuadEdge > 00247 { 00248 public: 00249 00251 typedef QuadEdgeMeshIterator Self; 00252 typedef QuadEdgeMeshBaseIterator< TQuadEdge > Superclass; 00253 typedef TQuadEdge QuadEdgeType; 00254 public: 00255 00257 QuadEdgeMeshIterator(QuadEdgeType *e = (QuadEdgeType *)0, 00258 int op = Superclass::OperatorOnext, 00259 bool start = true): 00260 Superclass(e, op, start) {} 00261 00262 virtual ~QuadEdgeMeshIterator() {} 00263 00264 QuadEdgeType * Value() { return ( this->m_Iterator ); } 00265 const QuadEdgeType * Value() const { return ( this->m_Iterator ); } 00266 }; 00267 00274 template< typename TGeometricalQuadEdge > 00275 class ITK_EXPORT QuadEdgeMeshIteratorGeom: 00276 public QuadEdgeMeshIterator< TGeometricalQuadEdge > 00277 { 00278 public: 00279 00281 typedef QuadEdgeMeshIterator< TGeometricalQuadEdge > Superclass; 00282 typedef TGeometricalQuadEdge QuadEdgeType; 00283 00285 typedef typename QuadEdgeType::OriginRefType OriginRefType; 00286 public: 00287 QuadEdgeMeshIteratorGeom(QuadEdgeType *e = (QuadEdgeType *)0, 00288 int op = Superclass::OperatorOnext, 00289 bool start = true): 00290 Superclass(e, op, start) {} 00291 OriginRefType operator*() { return ( this->m_Iterator->GetOrigin() ); } 00292 }; 00294 00301 template< typename TQuadEdge > 00302 class ITK_EXPORT QuadEdgeMeshConstIterator: 00303 public QuadEdgeMeshBaseIterator< TQuadEdge > 00304 { 00305 public: 00306 00308 typedef QuadEdgeMeshConstIterator Self; 00309 typedef QuadEdgeMeshBaseIterator< TQuadEdge > Superclass; 00310 typedef QuadEdgeMeshIterator< TQuadEdge > NoConstType; 00311 typedef TQuadEdge QuadEdgeType; 00312 public: 00313 00315 QuadEdgeMeshConstIterator(const QuadEdgeType *e = (QuadEdgeType *)0, 00316 int op = Superclass::OperatorOnext, 00317 bool start = true): 00318 Superclass(const_cast< QuadEdgeType * >( e ), op, start) {} 00319 00320 virtual ~QuadEdgeMeshConstIterator() {} 00321 00322 Self & operator=(const NoConstType & r) 00323 { 00324 this->m_StartEdge = r.GetStartEdge(); 00325 this->m_Iterator = r.GetIterator(); 00326 this->m_OpType = r.GetOpType(); 00327 this->m_Start = r.GetStart(); 00328 return ( *this ); 00329 } 00330 00331 const QuadEdgeType * Value() const { return ( this->m_Iterator ); } 00332 }; 00333 00340 template< typename TGeometricalQuadEdge > 00341 class ITK_EXPORT QuadEdgeMeshConstIteratorGeom: 00342 public QuadEdgeMeshConstIterator< TGeometricalQuadEdge > 00343 { 00344 public: 00345 00347 typedef QuadEdgeMeshConstIteratorGeom Self; 00348 typedef QuadEdgeMeshConstIterator< TGeometricalQuadEdge > Superclass; 00349 typedef QuadEdgeMeshIteratorGeom< TGeometricalQuadEdge > NoConstType; 00350 typedef TGeometricalQuadEdge QuadEdgeType; 00351 00353 typedef typename QuadEdgeType::OriginRefType OriginRefType; 00354 public: 00355 QuadEdgeMeshConstIteratorGeom(const QuadEdgeType *e = (QuadEdgeType *)0, 00356 int op = Superclass::OperatorOnext, 00357 bool start = true): 00358 Superclass(e, op, start) {} 00359 00360 virtual ~QuadEdgeMeshConstIteratorGeom() {} 00361 00362 Self & operator=(const NoConstType & r) 00363 { 00364 this->m_StartEdge = r.GetStartEdge(); 00365 this->m_Iterator = r.GetIterator(); 00366 this->m_OpType = r.GetOpType(); 00367 this->m_Start = r.GetStart(); 00368 return ( *this ); 00369 } 00370 00371 const OriginRefType operator*() const 00372 { 00373 return ( this->m_Iterator->GetOrigin() ); 00374 } 00375 }; 00376 } 00377 00378 #endif 00379