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

itkConstShapedNeighborhoodIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkConstShapedNeighborhoodIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-10-07 12:04:18 $
00007   Version:   $Revision: 1.15 $
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 #ifndef __itkConstShapedNeighborhoodIterator_h
00018 #define __itkConstShapedNeighborhoodIterator_h
00019 
00020 #include <vector>
00021 #include <list>
00022 #include "itkNeighborhoodIterator.h"
00023 
00024 namespace itk 
00025 {
00026 
00068 template<class TImage,  class TBoundaryCondition
00069                        = ZeroFluxNeumannBoundaryCondition<TImage> >
00070 class ITK_EXPORT ConstShapedNeighborhoodIterator
00071   :  private NeighborhoodIterator<TImage, TBoundaryCondition>
00072 {
00073 public:
00074 
00076   typedef typename TImage::InternalPixelType InternalPixelType;
00077   typedef typename TImage::PixelType         PixelType;
00078 
00080   itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
00081 
00083   typedef ConstShapedNeighborhoodIterator                  Self;
00084   typedef NeighborhoodIterator<TImage, TBoundaryCondition> Superclass;
00085 
00087   typedef typename Superclass::OffsetType      OffsetType;
00088   typedef typename OffsetType::OffsetValueType OffsetValueType;
00089   typedef typename Superclass::RadiusType      RadiusType;  
00090   typedef typename Superclass::SizeType        SizeType;
00091   typedef typename Superclass::SizeValueType   SizeValueType;
00092 
00094   typedef TImage                                   ImageType;
00095   typedef typename TImage::RegionType              RegionType;
00096   typedef Index<itkGetStaticConstMacro(Dimension)> IndexType;
00097   typedef typename IndexType::IndexValueType       IndexValueType;
00098   typedef Neighborhood<PixelType, itkGetStaticConstMacro(Dimension)> 
00099                                                    NeighborhoodType;
00101 
00104   typedef std::list<unsigned int> IndexListType;
00105 
00107   typedef TBoundaryCondition BoundaryConditionType;
00108 
00110   typedef ImageBoundaryCondition<ImageType> *ImageBoundaryConditionPointerType;
00111 
00113   struct ConstIterator
00114     {
00115     ConstIterator() { m_NeighborhoodIterator = 0; }
00116     ConstIterator(Self *s)
00117       {
00118       m_NeighborhoodIterator = s;
00119       this->GoToBegin();
00120       }
00121     ~ConstIterator() {}
00122     const ConstIterator &operator=(const ConstIterator &o)
00123       {
00124       m_NeighborhoodIterator = o.m_NeighborhoodIterator;
00125       m_ListIterator = o.m_ListIterator;
00126       return *this;
00127       }
00129 
00130     ConstIterator(const ConstIterator &o)
00131       {
00132       m_NeighborhoodIterator = o.m_NeighborhoodIterator;
00133       m_ListIterator = o.m_ListIterator;
00134       }
00135 
00136     void operator++(int)
00137       { m_ListIterator++; }
00138 
00139     void operator--(int)
00140       { m_ListIterator--; }
00141       
00142     const ConstIterator &operator++()
00143       {
00144       m_ListIterator++;
00145       return *this;
00146       }
00147     const ConstIterator &operator--()
00148       {
00149       m_ListIterator--;
00150       return *this;
00151       }
00152       
00153     bool operator!=(const ConstIterator &o) const
00154       { return m_ListIterator != o.m_ListIterator; }
00155     bool operator==(const ConstIterator &o) const
00156       { return m_ListIterator == o.m_ListIterator; }
00157 
00158     bool IsAtEnd() const
00159       {
00160       if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
00161         {
00162         return true; 
00163         }
00164       else 
00165         { 
00166         return false; 
00167         }
00168       }
00169 
00170     void GoToBegin()
00171       {
00172       m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
00173       }
00174 
00175     void GoToEnd()
00176       {
00177       m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
00178       }
00179 
00180     PixelType Get() const
00181       { return m_NeighborhoodIterator->GetPixel(*m_ListIterator); }
00182 
00183     OffsetType GetNeighborhoodOffset() const
00184       { return m_NeighborhoodIterator->GetOffset(*m_ListIterator); }
00185 
00186     typename IndexListType::value_type GetNeighborhoodIndex() const
00187       { return *m_ListIterator; }
00188 
00189   protected:
00190       
00191     Self *m_NeighborhoodIterator;
00192       
00193     typename IndexListType::const_iterator m_ListIterator;
00194 
00195     void ProtectedSet(const PixelType &v) const
00196       { m_NeighborhoodIterator->SetPixel(*m_ListIterator, v); } 
00197     };
00198 
00201   const ConstIterator &Begin() const
00202     { return m_ConstBeginIterator; }
00203 
00206   const ConstIterator &End() const
00207     { return m_ConstEndIterator; }
00208 
00210   ConstShapedNeighborhoodIterator()
00211     {
00212     m_ConstBeginIterator = ConstIterator(this);
00213     m_ConstEndIterator = ConstIterator(this);
00214     m_ConstEndIterator.GoToEnd();
00215     m_CenterIsActive = false;
00216     }
00218 
00220   virtual ~ConstShapedNeighborhoodIterator()  { }
00221 
00224   ConstShapedNeighborhoodIterator(const SizeType &radius,
00225                        const ImageType * ptr,
00226                        const RegionType &region) 
00227                    : Superclass (radius, const_cast<ImageType*>(ptr), region)
00228     {
00229     m_ConstBeginIterator = ConstIterator(this);
00230     m_ConstEndIterator = ConstIterator(this);
00231     m_ConstEndIterator.GoToEnd();
00232     m_CenterIsActive = false;
00233     }
00235 
00236   // Expose the following methods from the superclass.  This is a restricted
00237   // subset of the methods available for ConstNeighborhoodIterator.
00238   Superclass::GetImagePointer;
00239   Superclass::GetRadius;
00240   Superclass::GetIndex;
00241   Superclass::GetNeighborhoodIndex;
00242   Superclass::GetCenterNeighborhoodIndex;
00243   Superclass::GetRegion;
00244   Superclass::GetBeginIndex;
00245   Superclass::GoToBegin;
00246   Superclass::GoToEnd;
00247   Superclass::IsAtBegin;
00248   Superclass::IsAtEnd;
00249   Superclass::GetOffset;
00250   Superclass::operator==;
00251   Superclass::operator!=;
00252   Superclass::operator<;
00253   Superclass::operator>;
00254   Superclass::operator>=;
00255   Superclass::operator<=;
00256   Superclass::operator[];
00257   Superclass::GetElement;
00258   Superclass::SetLocation;
00259   Superclass::GetCenterPointer;
00260   Superclass::GetCenterPixel;
00261   Superclass::OverrideBoundaryCondition;
00262   Superclass::ResetBoundaryCondition;
00263   Superclass::GetBoundaryCondition;
00264   Superclass::Print;
00265   Superclass::operator-;
00266  
00267   Superclass::GetPixel;
00268   
00270   Self &operator=(const Self& orig)
00271     {
00272     Superclass::operator=(orig);
00273     m_ActiveIndexList = orig.m_ActiveIndexList;
00274     m_CenterIsActive = orig.m_CenterIsActive;
00276 
00277     // Reset begin and end pointers
00278     m_ConstBeginIterator.GoToBegin();
00279     m_ConstEndIterator.GoToBegin();
00280     return *this;
00281     }
00282 
00284   virtual void PrintSelf(std::ostream &, Indent) const;
00285 
00289   virtual void ActivateOffset(const OffsetType& off)
00290     { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
00291   virtual void DeactivateOffset(const OffsetType& off)
00292     { this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) );}
00294 
00296   virtual void ClearActiveList()
00297     {
00298     m_ActiveIndexList.clear();
00299     m_ConstBeginIterator.GoToBegin();
00300     m_ConstEndIterator.GoToEnd();
00301     m_CenterIsActive = false;
00302     }
00304 
00306   const IndexListType &GetActiveIndexList() const
00307     { return m_ActiveIndexList; }
00308 
00310   typename IndexListType::size_type GetActiveIndexListSize() const
00311     { return m_ActiveIndexList.size(); }
00312 
00315   Self &operator++();
00316 
00319   Self &operator--();
00320 
00324   Self &operator+=(const OffsetType &);
00325 
00329   Self &operator-=(const OffsetType &);
00330 
00331   // Should be protected, but Borland compiler will not allow it.  A workaround
00332   // must be found.
00333   Superclass::SetPixel;
00334   Superclass::SetCenterPixel;
00335 protected:
00337   ConstShapedNeighborhoodIterator( const ConstShapedNeighborhoodIterator & );
00338   // purposely not implemented
00339 
00340   friend struct ConstIterator;
00341   
00344   //  Superclass::SetPixel;
00345   //  Superclass::SetCenterPixel;
00346 
00352   virtual void ActivateIndex(const unsigned int);
00353   virtual void DeactivateIndex(const unsigned int);
00355 
00356   bool          m_CenterIsActive;
00357   IndexListType m_ActiveIndexList;
00358   ConstIterator m_ConstEndIterator;
00359   ConstIterator m_ConstBeginIterator;
00360 };
00361 
00362 
00363 } // namespace itk
00364 
00365 
00366 #ifndef ITK_MANUAL_INSTANTIATION
00367 #include "itkConstShapedNeighborhoodIterator.txx"
00368 #endif
00369 
00370 #endif
00371 

Generated at Wed Nov 5 20:58:55 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000