ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkQuadEdgeMeshFrontIterator.h
Go to the documentation of this file.
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 __itkQuadEdgeMeshFrontIterator_h
00019 #define __itkQuadEdgeMeshFrontIterator_h
00020 
00021 #include "itkMapContainer.h"
00022 
00023 // -------------------------------------------------------------------------
00024 #define itkQEDefineFrontIteratorMethodsMacro(MeshTypeArg)                       \
00025   /* Dual definition placed before others because of .NET that cannot */        \
00026   /* cope with definition of FrontIterator (that further hides the    */        \
00027   /* defintion of the template).                                      */        \
00028   typedef typename MeshTypeArg::QEDual   QEDualType;                            \
00029   typedef typename MeshTypeArg::QEPrimal QEPrimalType;                          \
00030   typedef QuadEdgeMeshFrontIterator< MeshTypeArg,                               \
00031                                      QEDualType > FrontDualIterator;            \
00032   typedef QuadEdgeMeshConstFrontIterator< MeshTypeArg,                          \
00033                                           QEDualType >                          \
00034   ConstFrontDualIterator;                                                       \
00035   typedef QuadEdgeMeshFrontIterator< MeshTypeArg,                               \
00036                                      QEPrimalType >   FrontIterator;            \
00037   typedef QuadEdgeMeshConstFrontIterator< MeshTypeArg,                          \
00038                                           QEPrimalType >                        \
00039   ConstFrontIterator;                                                           \
00040                                                                                 \
00041   virtual FrontIterator BeginFront(QEPrimalType * seed = (QEPrimalType *)0)     \
00042     {                                                                           \
00043     return ( FrontIterator(this, true, seed) );                                 \
00044     }                                                                           \
00045                                                                                 \
00046   virtual ConstFrontIterator BeginFront(QEPrimalType * seed) const              \
00047         { return ( ConstFrontIterator(this, true, seed) ); }                    \
00048                                                                                 \
00049   virtual FrontIterator EndFront()                                              \
00050     {                                                                           \
00051     return ( FrontIterator(this, false) );                                      \
00052     }                                                                           \
00053                                                                                 \
00054   virtual ConstFrontIterator EndFront() const                                   \
00055         { return ( ConstFrontIterator(this, false) ); }                         \
00056                                                                                 \
00057   virtual FrontDualIterator BeginDualFront(QEDualType * seed = (QEDualType *)0) \
00058     {                                                                           \
00059     return ( FrontDualIterator(this, true, seed) );                             \
00060     }                                                                           \
00061                                                                                 \
00062   virtual ConstFrontDualIterator BeginDualFront(QEDualType * seed) const        \
00063         { return ( ConstFrontDualIterator(this, true, seed) ); }                \
00064                                                                                 \
00065   virtual FrontDualIterator EndDualFront()                                      \
00066     {                                                                           \
00067     return ( FrontDualIterator(this, false) );                                  \
00068     }                                                                           \
00069                                                                                 \
00070   virtual ConstFrontDualIterator EndDualFront() const                           \
00071         { return ( ConstFrontDualIterator(this, false) ); }
00072 
00073 namespace itk
00074 {
00088 template< typename TMesh, typename TQE >
00089 class ITK_EXPORT QuadEdgeMeshFrontBaseIterator
00090 {
00091 public:
00092   // Hierarchy typedefs & values.
00093   typedef QuadEdgeMeshFrontBaseIterator Self;
00094 
00095   // Template types
00096   typedef TMesh MeshType;
00097   typedef TQE   QEType;
00098 protected:
00099   // Mesh types
00100   typedef typename MeshType::CoordRepType CoordRepType;
00101   // QE types
00102   typedef typename QEType::OriginRefType QEOriginType;
00103 
00113   class FrontAtom
00114   {
00115 public:
00116     FrontAtom(QEType *e = (QEType *)0, const CoordRepType c = 0):
00117       m_Edge(e), m_Cost(c)
00118     {}
00119     virtual ~FrontAtom() {}
00120     FrontAtom & operator=(const FrontAtom & r)
00121     { m_Edge = r.m_Edge; m_Cost = r.m_Cost; return *this; }
00122     bool operator==(const FrontAtom & r) const
00123     { return ( m_Edge == r.m_Edge ); }
00124     bool operator!=(const FrontAtom & r) const
00125     { return ( m_Edge != r.m_Edge ); }
00126     bool operator<(const FrontAtom & r) const
00127     { return ( m_Cost < r.m_Cost ); }
00128 public:
00129     QEType *     m_Edge;
00130     CoordRepType m_Cost;
00131   };
00133 
00137   typedef std::list< FrontAtom >       FrontType;
00138   typedef typename FrontType::iterator FrontTypeIterator;
00139   typedef FrontType *                  FrontTypePointer;
00140 
00144   typedef MapContainer< QEOriginType, bool >       IsVisitedContainerType;
00145   typedef typename IsVisitedContainerType::Pointer IsVisitedPointerType;
00146 public:
00147 
00149   QuadEdgeMeshFrontBaseIterator(MeshType *mesh  = (MeshType *)0,
00150                                 bool start = true,
00151                                 QEType *seed  = (QEType *)0);
00152   virtual ~QuadEdgeMeshFrontBaseIterator();
00154 
00155   Self & operator=(const Self & r)
00156   {
00157     m_Mesh  = r.m_Mesh;
00158     m_Start = r.m_Start;
00159     m_Seed  = r.m_Seed;
00160     m_Front = r.m_Front;
00161     m_IsPointVisited = r.m_IsPointVisited;
00162     m_CurrentEdge = r.m_CurrentEdge;
00163     return ( *this );
00164   }
00165 
00166   // Iteration methods.
00167   bool operator==(Self & r)
00168   {
00169     return ( m_Start == r.m_Start );
00170   }
00171 
00172   bool operator==(const Self & r) const
00173   {
00174     return ( m_Start == r.m_Start );
00175   }
00176 
00177   bool operator!=(Self & r)
00178   {
00179     return ( !( this->operator==(r) ) );
00180   }
00181 
00182   bool operator!=(const Self & r) const
00183   {
00184     return ( !( this->operator==(r) ) );
00185   }
00186 
00187   Self & operator++();
00188 
00189   Self & operator++(int) { return ( this->operator++() ); }
00190 
00191   MeshType * GetMesh() const { return this->m_Mesh; }
00192 protected:
00196   QEType * FindDefaultSeed();
00197 
00201   virtual CoordRepType GetCost(QEType *edge){ (void)edge; return ( 1 ); }
00202 protected:
00203 
00205   MeshType *m_Mesh;
00206 
00208   QEType *m_Seed;
00209 
00211   bool m_Start;
00212 
00214   FrontTypePointer m_Front;
00215 
00217   IsVisitedPointerType m_IsPointVisited;
00218 
00220   QEType *m_CurrentEdge;
00221 };
00222 
00229 template< typename TMesh, typename TQE >
00230 class ITK_EXPORT QuadEdgeMeshFrontIterator:
00231   public QuadEdgeMeshFrontBaseIterator< TMesh, TQE  >
00232 {
00233 public:
00234 
00236   typedef QuadEdgeMeshFrontIterator                   Self;
00237   typedef QuadEdgeMeshFrontBaseIterator< TMesh, TQE > Superclass;
00238   typedef typename Superclass::MeshType               MeshType;
00239   typedef typename Superclass::QEType                 QEType;
00240 public:
00241 
00243   QuadEdgeMeshFrontIterator(MeshType *mesh = (MeshType *)0,
00244                             bool start = true,
00245                             QEType *seed  = (QEType *)0):
00246     Superclass(mesh, start, seed) {}
00247   virtual ~QuadEdgeMeshFrontIterator() {}
00248   QEType * Value() { return ( this->m_CurrentEdge ); }
00249 };
00251 
00258 template< class TMesh, class TQE = typename TMesh::QEType >
00259 class ITK_EXPORT QuadEdgeMeshConstFrontIterator:
00260   public QuadEdgeMeshFrontBaseIterator< TMesh, TQE >
00261 {
00262 public:
00263 
00265   typedef QuadEdgeMeshConstFrontIterator                Self;
00266   typedef QuadEdgeMeshFrontBaseIterator< TMesh, TQE >   Superclass;
00267   typedef typename Superclass::QEType                   QEType;
00268   typedef typename Superclass::MeshType                 MeshType;
00269   typedef QuadEdgeMeshFrontIterator< MeshType, QEType > NoConstType;
00270 public:
00271 
00273   QuadEdgeMeshConstFrontIterator(const MeshType *mesh = (MeshType *)0,
00274                                  bool start = true,
00275                                  QEType *seed  = (QEType *)0)
00276   {
00277     (void)mesh;
00278     (void)start;
00279     (void)seed;
00280   }
00282 
00284   virtual ~QuadEdgeMeshConstFrontIterator() {}
00285   Self & operator=(const NoConstType & r)
00286   {
00287     this->m_Mesh  = r.GetMesh();
00288     return ( *this );
00289   }
00291 
00292   const QEType * Value() const { return ( this->m_CurrentEdge ); }
00293 };
00294 }
00295 
00296 #include "itkQuadEdgeMeshFrontIterator.hxx"
00297 
00298 #endif
00299