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/02/26 15:46:54 $
00007   Version:   $Revision: 1.4 $
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 > class QuadEdgeMeshBaseIterator
00095 {
00096 public:
00097   // Hierarchy typedefs & values.
00098   typedef QuadEdgeMeshBaseIterator Self;
00099   typedef TQuadEdge                QuadEdgeType;
00100 
00101   // Different types of iterators, one for each basic QE operation.
00102   enum
00103     {
00104     OperatorOnext    =  0,
00105     OperatorSym      =  1,
00106     OperatorLnext    =  2,
00107     OperatorRnext    =  3,
00108     OperatorDnext    =  4,
00109     OperatorOprev    =  5,
00110     OperatorLprev    =  6,
00111     OperatorRprev    =  7,
00112     OperatorDprev    =  8,
00113     OperatorInvOnext =  9,
00114     OperatorInvLnext = 10,
00115     OperatorInvRnext = 11,
00116     OperatorInvDnext = 12
00117     };
00118   
00119 public:
00120 // Object creation methods.
00121   QuadEdgeMeshBaseIterator( QuadEdgeType* e,
00122                             int op = OperatorOnext,
00123                             bool start = true )
00124     : m_StartEdge( e ), m_Iterator( e ),
00125       m_OpType( op ), m_Start( start ) {}
00126   
00127   virtual ~QuadEdgeMeshBaseIterator() {}
00128   
00129   Self& operator=( const Self& r )
00130     {
00131     m_StartEdge = r.m_StartEdge;
00132     m_Iterator = r.m_Iterator;
00133     m_OpType = r.m_OpType;
00134     m_Start = r.m_Start;
00135     return *this;
00136     }
00137 
00138   QuadEdgeType* GetStartEdge() const { return m_StartEdge; }
00139   QuadEdgeType* GetIterator() const  { return m_Iterator; }
00140   int           GetOpType() const    { return m_OpType; }
00141   bool          GetStart() const     { return m_Start; }
00142 
00144   bool operator==( Self & r )
00145     {
00146     return ( m_StartEdge == r.m_StartEdge ) &&
00147       ( m_Iterator  == r.m_Iterator )  &&
00148       ( m_OpType    == r.m_OpType )  &&
00149       ( m_Start     == r.m_Start );
00150     }
00151 
00152   bool operator==( const Self & r ) const
00153     {
00154     return ( m_StartEdge == r.m_StartEdge ) &&
00155       ( m_Iterator  == r.m_Iterator )  &&
00156       ( m_OpType    == r.m_OpType )  &&
00157       ( m_Start     == r.m_Start );
00158     }
00159 
00160   bool operator!=( Self & r )
00161     { 
00162     return !( this->operator==( r ) );
00163     }
00164   
00165   bool operator!=( const Self & r ) const
00166     {
00167     return !( this->operator==( r ) );
00168     }
00169   
00170   Self & operator++()
00171     {
00172     if( m_Start )
00173       {
00174       this->GoToNext();
00175       m_Start = !( m_Iterator == m_StartEdge );
00176       }
00177 
00178     return *this;
00179     }
00180   
00181   Self & operator++( int )
00182     {
00183     if( m_Start )
00184       {
00185       this->GoToNext();
00186       m_Start = !( m_Iterator == m_StartEdge );
00187       }
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 : public QuadEdgeMeshBaseIterator< TQuadEdge >
00243 {
00244 public:
00245 
00247   typedef QuadEdgeMeshIterator                  Self;
00248   typedef QuadEdgeMeshBaseIterator< TQuadEdge > Superclass;
00249   typedef TQuadEdge                             QuadEdgeType;
00250 
00251 public:
00253   QuadEdgeMeshIterator( QuadEdgeType* e = (QuadEdgeType*)0,
00254             int op = Superclass::OperatorOnext,
00255             bool start = true )
00256       : Superclass( e, op, start ) {}
00257 
00258   virtual ~QuadEdgeMeshIterator() {}
00259 
00260   QuadEdgeType * Value() { return this->m_Iterator; }
00261   const QuadEdgeType * Value() const { return this->m_Iterator; }
00262 };
00263 
00269 template< typename TGeometricalQuadEdge >
00270 class QuadEdgeMeshIteratorGeom
00271   : public QuadEdgeMeshIterator< TGeometricalQuadEdge >
00272 {
00273 public:
00274 
00276   typedef QuadEdgeMeshIterator< TGeometricalQuadEdge > Superclass;
00277   typedef TGeometricalQuadEdge                         QuadEdgeType;
00278 
00280   typedef typename QuadEdgeType::OriginRefType OriginRefType;
00281 
00282 public:
00283   QuadEdgeMeshIteratorGeom( QuadEdgeType* e = (QuadEdgeType*)0,
00284                             int op = Superclass::OperatorOnext,
00285                             bool start = true )
00286     : Superclass( e, op, start ) {}
00287   OriginRefType operator*() { return this->m_Iterator->GetOrigin(); }
00288 };
00289 
00295 template< typename TQuadEdge >
00296 class QuadEdgeMeshConstIterator
00297   : public QuadEdgeMeshBaseIterator< TQuadEdge >
00298 {
00299 public:
00300 
00302   typedef QuadEdgeMeshConstIterator             Self;
00303   typedef QuadEdgeMeshBaseIterator< TQuadEdge > Superclass;
00304   typedef QuadEdgeMeshIterator< TQuadEdge >     NoConstType;
00305   typedef TQuadEdge                             QuadEdgeType;
00306 
00307 public:
00309   QuadEdgeMeshConstIterator( const QuadEdgeType* e = (QuadEdgeType*)0,
00310                              int op = Superclass::OperatorOnext,
00311                              bool start = true )
00312     : Superclass( ( QuadEdgeType* )e, op, start ) {}
00313 
00314   virtual ~QuadEdgeMeshConstIterator() {}
00315 
00316   Self& operator=( const NoConstType& r )
00317     {
00318     this->m_StartEdge = r.GetStartEdge();
00319     this->m_Iterator = r.GetIterator();
00320     this->m_OpType = r.GetOpType();
00321     this->m_Start = r.GetStart();
00322     return *this;
00323     }
00324 
00325   const QuadEdgeType* Value() const { return this->m_Iterator; }
00326 };
00327 
00333 template< typename TGeometricalQuadEdge >
00334 class QuadEdgeMeshConstIteratorGeom
00335   : public QuadEdgeMeshConstIterator< TGeometricalQuadEdge >
00336 {
00337 public:
00338 
00340   typedef QuadEdgeMeshConstIteratorGeom                     Self;
00341   typedef QuadEdgeMeshConstIterator< TGeometricalQuadEdge > Superclass;
00342   typedef QuadEdgeMeshIteratorGeom< TGeometricalQuadEdge >  NoConstType;
00343   typedef TGeometricalQuadEdge                              QuadEdgeType;
00344 
00346   typedef typename QuadEdgeType::OriginRefType OriginRefType;
00347 
00348 public:
00349   QuadEdgeMeshConstIteratorGeom( const QuadEdgeType* e = (QuadEdgeType*)0,
00350                                  int op = Superclass::OperatorOnext,
00351                                  bool start = true )
00352     : Superclass( e, op, start ) {}
00353   
00354   virtual ~QuadEdgeMeshConstIteratorGeom() {}
00355   
00356   Self& operator=( const NoConstType& r )
00357     {
00358     this->m_StartEdge = r.GetStartEdge();
00359     this->m_Iterator = r.GetIterator();
00360     this->m_OpType = r.GetOpType();
00361     this->m_Start = r.GetStart();
00362     return *this;
00363     }
00364   
00365   const OriginRefType operator*() const
00366     {
00367     return this->m_Iterator->GetOrigin();
00368     }
00369 };
00370 
00371 } 
00372 
00373 #endif 
00374 

Generated at Mon Mar 12 02:22:47 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000