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: 2004/03/22 20:36:04 $
00007   Version:   $Revision: 1.9 $
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::OverrideBoundaryCondition;
00247   Superclass::ResetBoundaryCondition;
00248   Superclass::GetBoundaryCondition;
00249   Superclass::Print;
00250 
00251   Superclass::operator-;
00252  
00253   Superclass::GetPixel;
00254   
00256   Self &operator=(const Self& orig)
00257   {
00258     Superclass::operator=(orig);
00259     m_ActiveIndexList = orig.m_ActiveIndexList;
00260     m_CenterIsActive = orig.m_CenterIsActive;
00261 
00262     // Reset begin and end pointers
00263     m_ConstBeginIterator.GoToBegin();
00264     m_ConstEndIterator.GoToBegin();
00265     return *this;
00266   }
00267 
00269   virtual void PrintSelf(std::ostream &, Indent) const;
00270 
00274   virtual void ActivateOffset(const OffsetType& off)
00275   { this->ActivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
00276   virtual void DeactivateOffset(const OffsetType& off)
00277   { this->DeactivateIndex( Superclass::GetNeighborhoodIndex(off) ); }
00278 
00280   virtual void ClearActiveList()
00281   {
00282     m_ActiveIndexList.clear();
00283     m_ConstBeginIterator.GoToBegin();
00284     m_ConstEndIterator.GoToEnd();
00285     m_CenterIsActive = false;
00286   }
00287   
00289   const IndexListType &GetActiveIndexList() const
00290   { return m_ActiveIndexList; }
00291 
00293   typename IndexListType::size_type GetActiveIndexListSize() const
00294   { return m_ActiveIndexList.size(); }
00295 
00298   Self &operator++();
00299 
00302   Self &operator--();
00303 
00307   Self &operator+=(const OffsetType &);
00308 
00312   Self &operator-=(const OffsetType &);
00313 
00314   // Should be protected, but Borland compiler will not allow it.  A workaround
00315   // must be found.
00316   Superclass::SetPixel;
00317 protected:
00319   ConstShapedNeighborhoodIterator( const ConstShapedNeighborhoodIterator & );
00320   // purposely not implemented
00321 
00322   friend struct ConstIterator;
00323   
00326   //  Superclass::SetPixel;
00327 
00333   virtual void ActivateIndex(const unsigned int);
00334   virtual void DeactivateIndex(const unsigned int);
00335 
00336   bool m_CenterIsActive;
00337   IndexListType m_ActiveIndexList;
00338   ConstIterator m_ConstEndIterator;
00339   ConstIterator m_ConstBeginIterator;
00340 };
00341 
00342 
00343 } // namespace itk
00344 
00345 
00346 #ifndef ITK_MANUAL_INSTANTIATION
00347 #include "itkConstShapedNeighborhoodIterator.txx"
00348 #endif
00349 
00350 #endif
00351 

Generated at Tue Mar 29 23:49:19 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000