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: 2005/10/20 13:25:24 $
00007   Version:   $Revision: 1.11 $
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 
00067 template<class TImage,  class TBoundaryCondition
00068                        = ZeroFluxNeumannBoundaryCondition<TImage> >
00069 class ITK_EXPORT ConstShapedNeighborhoodIterator
00070   :  private NeighborhoodIterator<TImage, TBoundaryCondition>
00071 {
00072 public:
00074   typedef typename TImage::InternalPixelType InternalPixelType;
00075   typedef typename TImage::PixelType PixelType;
00076     
00078   itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
00079   
00081   typedef ConstShapedNeighborhoodIterator Self;
00082   typedef NeighborhoodIterator<TImage, TBoundaryCondition> Superclass;
00083 
00085   typedef typename Superclass::OffsetType OffsetType;
00086   typedef typename OffsetType::OffsetValueType OffsetValueType;
00087   typedef typename Superclass::RadiusType RadiusType;  
00088   typedef typename Superclass::SizeType SizeType;
00089   typedef typename Superclass::SizeValueType SizeValueType;
00090   
00092   typedef TImage ImageType;
00093   typedef typename TImage::RegionType RegionType;
00094   typedef Index<itkGetStaticConstMacro(Dimension)> IndexType;
00095   typedef typename IndexType::IndexValueType IndexValueType;
00096   typedef Neighborhood<PixelType, itkGetStaticConstMacro(Dimension)> NeighborhoodType;
00097 
00100   typedef std::list<unsigned int> IndexListType;
00101 
00103   typedef TBoundaryCondition BoundaryConditionType;
00104   
00106   typedef ImageBoundaryCondition<ImageType> *ImageBoundaryConditionPointerType;
00107 
00109   struct ConstIterator
00110   {
00111     ConstIterator() { m_NeighborhoodIterator = 0; }
00112     ConstIterator(Self *s)
00113     {
00114       m_NeighborhoodIterator = s;
00115       this->GoToBegin();
00116     }
00117     ~ConstIterator() {}
00118     const ConstIterator &operator=(const ConstIterator &o)
00119     {
00120       m_NeighborhoodIterator = o.m_NeighborhoodIterator;
00121       m_ListIterator = o.m_ListIterator;
00122       return *this;
00123     }
00124     
00125     ConstIterator(const ConstIterator &o)
00126     {
00127       m_NeighborhoodIterator = o.m_NeighborhoodIterator;
00128       m_ListIterator = o.m_ListIterator;
00129     }
00130 
00131     void operator++(int)
00132     { m_ListIterator++; }
00133 
00134     void operator--(int)
00135     { m_ListIterator--; }
00136     
00137     const ConstIterator &operator++()
00138     {
00139       m_ListIterator++;
00140       return *this;
00141     }
00142     const ConstIterator &operator--()
00143     {
00144       m_ListIterator--;
00145       return *this;
00146     }
00147     
00148     bool operator!=(const ConstIterator &o) const
00149     { return m_ListIterator.operator!=(o.m_ListIterator); }
00150     bool operator==(const ConstIterator &o) const
00151     { return m_ListIterator.operator==(o.m_ListIterator); }
00152 
00153     bool IsAtEnd() const
00154     {
00155       if (m_ListIterator == m_NeighborhoodIterator->GetActiveIndexList().end())
00156         { return true; }
00157       else { return false; }
00158     }
00159 
00160     void GoToBegin()
00161     {
00162       m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().begin();
00163     }
00164 
00165     void GoToEnd()
00166     {
00167       m_ListIterator = m_NeighborhoodIterator->GetActiveIndexList().end();
00168     }
00169 
00170     PixelType Get() const
00171     { return m_NeighborhoodIterator->GetPixel(*m_ListIterator); }
00172 
00173     OffsetType GetNeighborhoodOffset() const
00174     { return m_NeighborhoodIterator->GetOffset(*m_ListIterator); }
00175 
00176     typename IndexListType::value_type GetNeighborhoodIndex() const
00177     { return *m_ListIterator; }
00178 
00179   protected:
00180     Self *m_NeighborhoodIterator;
00181     typename IndexListType::const_iterator m_ListIterator;
00182 
00183     void ProtectedSet(const PixelType &v) const
00184     { m_NeighborhoodIterator->SetPixel(*m_ListIterator, v); } 
00185   };
00186 
00189   const ConstIterator &Begin() const
00190   {    return m_ConstBeginIterator;  }
00191 
00194   const ConstIterator &End() const
00195   {    return m_ConstEndIterator;  }
00196   
00198   ConstShapedNeighborhoodIterator()
00199   {
00200     m_ConstBeginIterator = ConstIterator(this);
00201     m_ConstEndIterator = ConstIterator(this);
00202     m_ConstEndIterator.GoToEnd();
00203     m_CenterIsActive = false;
00204   }
00205 
00207   virtual ~ConstShapedNeighborhoodIterator()  { }
00208 
00211   ConstShapedNeighborhoodIterator(const SizeType &radius,
00212                        const ImageType * ptr,
00213                        const RegionType &region
00214                                   ) : Superclass (radius, const_cast<ImageType*>(ptr),
00215                                                   region)
00216   {
00217     m_ConstBeginIterator = ConstIterator(this);
00218     m_ConstEndIterator = ConstIterator(this);
00219     m_ConstEndIterator.GoToEnd();
00220     m_CenterIsActive = false;
00221   }
00222   
00223   // Expose the following methods from the superclass.  This is a restricted
00224   // subset of the methods available for ConstNeighborhoodIterator.
00225   Superclass::GetImagePointer;
00226   Superclass::GetRadius;
00227   Superclass::GetIndex;
00228   Superclass::GetNeighborhoodIndex;
00229   Superclass::GetCenterNeighborhoodIndex;
00230   Superclass::GetRegion;
00231   Superclass::GetBeginIndex;
00232   Superclass::GoToBegin;
00233   Superclass::GoToEnd;
00234   Superclass::IsAtBegin;
00235   Superclass::IsAtEnd;
00236   Superclass::GetOffset;
00237   Superclass::operator==;
00238   Superclass::operator!=;
00239   Superclass::operator<;
00240   Superclass::operator>;
00241   Superclass::operator>=;
00242   Superclass::operator<=;
00243   Superclass::operator[];
00244   Superclass::GetElement;
00245   Superclass::SetLocation;
00246   Superclass::GetCenterPointer;
00247   Superclass::GetCenterPixel;
00248   Superclass::OverrideBoundaryCondition;
00249   Superclass::ResetBoundaryCondition;
00250   Superclass::GetBoundaryCondition;
00251   Superclass::Print;
00252   Superclass::operator-;
00253  
00254   Superclass::GetPixel;
00255   
00257   Self &operator=(const Self& orig)
00258   {
00259     Superclass::operator=(orig);
00260     m_ActiveIndexList = orig.m_ActiveIndexList;
00261     m_CenterIsActive = orig.m_CenterIsActive;
00262 
00263     // Reset begin and end pointers
00264     m_ConstBeginIterator.GoToBegin();
00265     m_ConstEndIterator.GoToBegin();
00266     return *this;
00267   }
00268 
00270   virtual void PrintSelf(std::ostream &, Indent) const;
00271 
00275   virtual void ActivateOffset(const OffsetType& off)
00276   { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
00277   virtual void DeactivateOffset(const OffsetType& off)
00278   { this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
00279 
00281   virtual void ClearActiveList()
00282   {
00283     m_ActiveIndexList.clear();
00284     m_ConstBeginIterator.GoToBegin();
00285     m_ConstEndIterator.GoToEnd();
00286     m_CenterIsActive = false;
00287   }
00288   
00290   const IndexListType &GetActiveIndexList() const
00291   { return m_ActiveIndexList; }
00292 
00294   typename IndexListType::size_type GetActiveIndexListSize() const
00295   { return m_ActiveIndexList.size(); }
00296 
00299   Self &operator++();
00300 
00303   Self &operator--();
00304 
00308   Self &operator+=(const OffsetType &);
00309 
00313   Self &operator-=(const OffsetType &);
00314 
00315   // Should be protected, but Borland compiler will not allow it.  A workaround
00316   // must be found.
00317   Superclass::SetPixel;
00318   Superclass::SetCenterPixel;
00319 protected:
00321   ConstShapedNeighborhoodIterator( const ConstShapedNeighborhoodIterator & );
00322   // purposely not implemented
00323 
00324   friend struct ConstIterator;
00325   
00328   //  Superclass::SetPixel;
00329   //  Superclass::SetCenterPixel;
00330 
00336   virtual void ActivateIndex(const unsigned int);
00337   virtual void DeactivateIndex(const unsigned int);
00338 
00339   bool m_CenterIsActive;
00340   IndexListType m_ActiveIndexList;
00341   ConstIterator m_ConstEndIterator;
00342   ConstIterator m_ConstBeginIterator;
00343 };
00344 
00345 
00346 } // namespace itk
00347 
00348 
00349 #ifndef ITK_MANUAL_INSTANTIATION
00350 #include "itkConstShapedNeighborhoodIterator.txx"
00351 #endif
00352 
00353 #endif
00354 

Generated at Wed May 24 22:59:41 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000