Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkQuadEdgeMeshBaseIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkQuadEdgeMeshBaseIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/12/23 17:55:34 $
00007   Version:   $Revision: 1.6 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 // -------------------------------------------------------------------------
00018 // This code is an implementation of the well known quad edge (QE) data
00019 // structure in the ITK library. Although the original QE can handle non
00020 // orientable 2-manifolds and its dual and its mirror, this implementation
00021 // is specifically dedicated to handle orientable 2-manifolds along with
00022 // their dual.
00023 //
00024 // Any comment, criticism and/or donation is welcome.
00025 //
00026 // Please contact any member of the team:
00027 //
00028 // - The frog master (Eric Boix)       eboix@ens-lyon.fr
00029 // - The duck master (Alex Gouaillard) alexandre.gouaillard@sun.com
00030 // - The cow  master (Leonardo Florez) florez@creatis.insa-lyon.fr
00031 // -------------------------------------------------------------------------
00032 
00033 #ifndef __itkQuadEdgeMeshBaseIterator_h
00034 #define __itkQuadEdgeMeshBaseIterator_h
00035 
00036 // -------------------------------------------------------------------------
00037 #define itkQEDefineIteratorMethodsMacro( Op )                             \
00038   virtual Iterator Begin##Op()                                            \
00039     {                                                                     \
00040     return Iterator( this, Self::Iterator::Operator##Op, true );          \
00041     }                                                                     \
00042                                                                           \
00043   virtual ConstIterator Begin##Op() const                                 \
00044     {                                                                     \
00045     return ConstIterator( this, Self::ConstIterator::Operator##Op,        \
00046     true );                                                               \
00047     }                                                                     \
00048                                                                           \
00049   virtual Iterator End##Op()                                              \
00050     {                                                                     \
00051     return Iterator( this, Self::Iterator::Operator##Op, false );         \
00052     }                                                                     \
00053                                                                           \
00054   virtual ConstIterator End##Op() const                                   \
00055     {                                                                     \
00056     return ConstIterator( this, Self::ConstIterator::Operator##Op,        \
00057     false );                                                              \
00058     }
00059 
00060 // -------------------------------------------------------------------------
00061 #define itkQEDefineIteratorGeomMethodsMacro( Op )                         \
00062   virtual IteratorGeom BeginGeom##Op()                                    \
00063     {                                                                     \
00064     return IteratorGeom( this, Self::IteratorGeom::Operator##Op,          \
00065     true );                                                               \
00066     }                                                                     \
00067                                                                           \
00068   virtual ConstIteratorGeom BeginGeom##Op() const                         \
00069     {                                                                     \
00070     return ConstIteratorGeom( this,                                       \
00071     Self::ConstIteratorGeom::Operator##Op, true );                        \
00072     }                                                                     \
00073                                                                           \
00074   virtual IteratorGeom EndGeom##Op()                                      \
00075     {                                                                     \
00076     return IteratorGeom( this, Self::IteratorGeom::Operator##Op,          \
00077     false );                                                              \
00078     }                                                                     \
00079                                                                           \
00080   virtual ConstIteratorGeom EndGeom##Op() const                           \
00081     {                                                                     \
00082     return ConstIteratorGeom( this,                                       \
00083     Self::ConstIteratorGeom::Operator##Op, false );                       \
00084     }
00085 
00086 
00087 namespace itk
00088 {
00094 template< typename TQuadEdge >
00095 class QuadEdgeMeshBaseIterator
00096 {
00097 public:
00098   // Hierarchy typedefs & values.
00099   typedef QuadEdgeMeshBaseIterator Self;
00100   typedef TQuadEdge                QuadEdgeType;
00101 
00102   // Different types of iterators, one for each basic QE operation.
00103   enum
00104     {
00105     OperatorOnext    =  0,
00106     OperatorSym      =  1,
00107     OperatorLnext    =  2,
00108     OperatorRnext    =  3,
00109     OperatorDnext    =  4,
00110     OperatorOprev    =  5,
00111     OperatorLprev    =  6,
00112     OperatorRprev    =  7,
00113     OperatorDprev    =  8,
00114     OperatorInvOnext =  9,
00115     OperatorInvLnext = 10,
00116     OperatorInvRnext = 11,
00117     OperatorInvDnext = 12
00118     };
00119   
00120 public:
00121 // Object creation methods.
00122   QuadEdgeMeshBaseIterator( QuadEdgeType* e,
00123                             int op = OperatorOnext,
00124                             bool start = true )
00125     : m_StartEdge( e ), m_Iterator( e ),
00126       m_OpType( op ), m_Start( start ) {}
00127   
00128   virtual ~QuadEdgeMeshBaseIterator() {}
00129   
00130   Self& operator=( const Self& r )
00131     {
00132     m_StartEdge = r.m_StartEdge;
00133     m_Iterator = r.m_Iterator;
00134     m_OpType = r.m_OpType;
00135     m_Start = r.m_Start;
00136     return( *this );
00137     }
00138 
00139   QuadEdgeType* GetStartEdge() const { return( m_StartEdge ); }
00140   QuadEdgeType* GetIterator() const  { return( m_Iterator ); }
00141   int           GetOpType() const    { return( m_OpType ); }
00142   bool          GetStart() const     { return( m_Start ); }
00143 
00145   bool operator==( Self & r )
00146     {
00147     return( ( m_StartEdge == r.m_StartEdge ) &&
00148       ( m_Iterator  == r.m_Iterator )  &&
00149       ( m_OpType    == r.m_OpType )  &&
00150       ( m_Start     == r.m_Start ) );
00151     }
00152 
00153   bool operator==( const Self & r ) const
00154     {
00155     return( ( m_StartEdge == r.m_StartEdge ) &&
00156       ( m_Iterator  == r.m_Iterator )  &&
00157       ( m_OpType    == r.m_OpType )  &&
00158       ( m_Start     == r.m_Start ) );
00159     }
00160 
00161   bool operator!=( Self & r )
00162     { 
00163     return( !( this->operator==( r ) ) );
00164     }
00165   
00166   bool operator!=( const Self & r ) const
00167     {
00168     return( !( this->operator==( r ) ) );
00169     }
00170   
00171   Self & operator++()
00172     {
00173     if( m_Start )
00174       {
00175       this->GoToNext();
00176       m_Start = !( m_Iterator == m_StartEdge );
00177       }
00178 
00179     return( *this );
00180     }
00181   
00182   Self & operator++( int )
00183     {
00184     if( m_Start )
00185       {
00186       this->GoToNext();
00187       m_Start = !( m_Iterator == m_StartEdge );
00188       }  
00189     return( *this );
00190     }
00191   
00192 protected:
00194   virtual void GoToNext()
00195     {
00196     switch( m_OpType )
00197       {
00198       case OperatorOnext    : m_Iterator = m_Iterator->GetOnext();
00199         break;
00200       case OperatorSym      : m_Iterator = m_Iterator->GetSym();
00201         break;
00202       case OperatorLnext    : m_Iterator = m_Iterator->GetLnext();
00203         break;
00204       case OperatorRnext    : m_Iterator = m_Iterator->GetRnext();
00205         break;
00206       case OperatorDnext    : m_Iterator = m_Iterator->GetDnext();
00207         break;
00208       case OperatorOprev    : m_Iterator = m_Iterator->GetOprev();
00209         break;
00210       case OperatorLprev    : m_Iterator = m_Iterator->GetLprev();
00211         break;
00212       case OperatorRprev    : m_Iterator = m_Iterator->GetRprev();
00213         break;
00214       case OperatorDprev    : m_Iterator = m_Iterator->GetDprev();
00215         break;
00216       case OperatorInvOnext : m_Iterator = m_Iterator->GetInvOnext();
00217         break;
00218       case OperatorInvLnext : m_Iterator = m_Iterator->GetInvLnext();
00219         break;
00220       case OperatorInvRnext : m_Iterator = m_Iterator->GetInvRnext();
00221         break;
00222       case OperatorInvDnext : m_Iterator = m_Iterator->GetInvDnext();
00223         break;
00224       default: break;
00225       }
00226     }
00228 
00229 protected:
00230   QuadEdgeType * m_StartEdge; 
00231   QuadEdgeType * m_Iterator;  
00232   int            m_OpType;    
00233   bool           m_Start;     
00234 };
00235 
00241 template< typename TQuadEdge >
00242 class QuadEdgeMeshIterator
00243 : public QuadEdgeMeshBaseIterator< TQuadEdge >
00244 {
00245 public:
00246 
00248   typedef QuadEdgeMeshIterator                  Self;
00249   typedef QuadEdgeMeshBaseIterator< TQuadEdge > Superclass;
00250   typedef TQuadEdge                             QuadEdgeType;
00251 
00252 public:
00254   QuadEdgeMeshIterator( QuadEdgeType* e = (QuadEdgeType*)0,
00255             int op = Superclass::OperatorOnext,
00256             bool start = true )
00257       : Superclass( e, op, start ) {}
00258 
00259   virtual ~QuadEdgeMeshIterator() {}
00260 
00261   QuadEdgeType * Value() { return( this->m_Iterator ); }
00262   const QuadEdgeType * Value() const { return( this->m_Iterator ); }
00263 };
00264 
00270 template< typename TGeometricalQuadEdge >
00271 class QuadEdgeMeshIteratorGeom
00272   : public QuadEdgeMeshIterator< TGeometricalQuadEdge >
00273 {
00274 public:
00275 
00277   typedef QuadEdgeMeshIterator< TGeometricalQuadEdge > Superclass;
00278   typedef TGeometricalQuadEdge                         QuadEdgeType;
00279 
00281   typedef typename QuadEdgeType::OriginRefType OriginRefType;
00282 
00283 public:
00284   QuadEdgeMeshIteratorGeom( QuadEdgeType* e = (QuadEdgeType*)0,
00285                             int op = Superclass::OperatorOnext,
00286                             bool start = true )
00287     : Superclass( e, op, start ) {}
00288   OriginRefType operator*() { return( this->m_Iterator->GetOrigin( ) ); }
00289 };
00290 
00296 template< typename TQuadEdge >
00297 class QuadEdgeMeshConstIterator
00298   : public QuadEdgeMeshBaseIterator< TQuadEdge >
00299 {
00300 public:
00301 
00303   typedef QuadEdgeMeshConstIterator             Self;
00304   typedef QuadEdgeMeshBaseIterator< TQuadEdge > Superclass;
00305   typedef QuadEdgeMeshIterator< TQuadEdge >     NoConstType;
00306   typedef TQuadEdge                             QuadEdgeType;
00307 
00308 public:
00310   QuadEdgeMeshConstIterator( const QuadEdgeType* e = (QuadEdgeType*)0,
00311                              int op = Superclass::OperatorOnext,
00312                              bool start = true )
00313     : Superclass( const_cast<QuadEdgeType*>(e), op, start ) {}
00314 
00315   virtual ~QuadEdgeMeshConstIterator() {}
00316 
00317   Self& operator=( const NoConstType& r )
00318     {
00319     this->m_StartEdge = r.GetStartEdge();
00320     this->m_Iterator = r.GetIterator();
00321     this->m_OpType = r.GetOpType();
00322     this->m_Start = r.GetStart();
00323     return( *this );
00324     }
00325 
00326   const QuadEdgeType* Value() const { return( this->m_Iterator ); }
00327 };
00328 
00334 template< typename TGeometricalQuadEdge >
00335 class QuadEdgeMeshConstIteratorGeom
00336   : public QuadEdgeMeshConstIterator< TGeometricalQuadEdge >
00337 {
00338 public:
00339 
00341   typedef QuadEdgeMeshConstIteratorGeom                     Self;
00342   typedef QuadEdgeMeshConstIterator< TGeometricalQuadEdge > Superclass;
00343   typedef QuadEdgeMeshIteratorGeom< TGeometricalQuadEdge >  NoConstType;
00344   typedef TGeometricalQuadEdge                              QuadEdgeType;
00345 
00347   typedef typename QuadEdgeType::OriginRefType OriginRefType;
00348 
00349 public:
00350   QuadEdgeMeshConstIteratorGeom( const QuadEdgeType* e = (QuadEdgeType*)0,
00351                                  int op = Superclass::OperatorOnext,
00352                                  bool start = true )
00353     : Superclass( e, op, start ) {}
00354   
00355   virtual ~QuadEdgeMeshConstIteratorGeom() {}
00356   
00357   Self& operator=( const NoConstType& r )
00358     {
00359     this->m_StartEdge = r.GetStartEdge();
00360     this->m_Iterator = r.GetIterator();
00361     this->m_OpType = r.GetOpType();
00362     this->m_Start = r.GetStart();
00363     return( *this );
00364     }
00365   
00366   const OriginRefType operator*() const
00367     {
00368     return( this->m_Iterator->GetOrigin() );
00369     }
00370 };
00371 
00372 } 
00373 
00374 #endif 
00375 

Generated at Tue Jul 29 21:49:51 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000