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

itkConstNeighborhoodIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkConstNeighborhoodIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2002/09/11 19:39:03 $
00007   Version:   $Revision: 1.18 $
00008 
00009   Copyright (c) 2002 Insight 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 __itkConstNeighborhoodIterator_h
00018 #define __itkConstNeighborhoodIterator_h
00019 
00020 #include <vector>
00021 #include <string.h>
00022 #include <iostream>
00023 #include "itkImage.h"
00024 #include "itkIndex.h"
00025 #include "itkOffset.h"
00026 #include "itkSize.h"
00027 #include "itkImageRegion.h"
00028 #include "itkMacro.h"
00029 #include "itkNeighborhood.h"
00030 #include "itkImageBoundaryCondition.h"
00031 #include "itkExceptionObject.h"
00032 
00033 namespace itk {
00034 
00050 template<class TImage>
00051 class ITK_EXPORT ConstNeighborhoodIterator
00052   :  public Neighborhood<ITK_TYPENAME TImage::InternalPixelType *,
00053                          ::itk::GetImageDimension<TImage>::ImageDimension>
00054 {
00055 public:
00057   typedef typename TImage::InternalPixelType InternalPixelType;
00058   typedef typename TImage::PixelType PixelType;
00059     
00061   itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
00062   
00064   typedef ConstNeighborhoodIterator Self;
00065   typedef Neighborhood<InternalPixelType *, itkGetStaticConstMacro(Dimension)> Superclass;
00066   
00068   typedef typename Superclass::SizeType SizeType;
00069   typedef typename Superclass::SizeValueType SizeValueType;
00070   typedef TImage ImageType;
00071   typedef typename TImage::RegionType RegionType;
00072   typedef Index<itkGetStaticConstMacro(Dimension)> IndexType;
00073   typedef typename IndexType::IndexValueType IndexValueType;
00074   typedef Offset<itkGetStaticConstMacro(Dimension)> OffsetType;
00075   typedef typename OffsetType::OffsetValueType OffsetValueType;
00076   typedef typename Superclass::RadiusType RadiusType;
00077   typedef Neighborhood<PixelType, itkGetStaticConstMacro(Dimension)> NeighborhoodType;
00078   typedef typename Superclass::Iterator Iterator;
00079     
00082   typedef typename Superclass::ConstIterator ConstIterator;
00083 
00085   typedef ImageBoundaryCondition<ImageType> *ImageBoundaryConditionPointerType;
00086 
00088   ConstNeighborhoodIterator();
00089 
00091   virtual ~ConstNeighborhoodIterator() {}
00092   
00094   ConstNeighborhoodIterator( const ConstNeighborhoodIterator & );
00095   
00098   ConstNeighborhoodIterator(const SizeType &radius,
00099                        const ImageType * ptr,
00100                        const RegionType &region
00101                        )
00102     {      this->Initialize(radius, ptr, region);  }
00103 
00105   Self &operator=(const Self& orig);
00106   
00108   virtual void PrintSelf(std::ostream &, Indent) const;
00109 
00112   OffsetType ComputeInternalIndex(unsigned int n) const;
00113   
00115   IndexType GetBound() const
00116     {    return m_Bound;   }
00117 
00120   long GetBound(unsigned int n) const
00121     {    return m_Bound[n];  }
00122   
00124   const InternalPixelType *GetCenterPointer() const
00125     {    return (this->operator[]((this->Size())>>1));  }
00126   
00128   PixelType GetCenterPixel() const
00129     {    return *( this->GetCenterPointer() );  }
00130 
00132   const ImageType * GetImagePointer(void)
00133     { return m_ConstImage; }
00134  
00137   virtual IndexType GetIndex(void) const
00138     { return m_Loop;  }
00139   
00142   virtual NeighborhoodType GetNeighborhood() const;
00143 
00147   InternalPixelType *GetOutputBuffer() const
00148     {    return m_OutputBuffer;  }
00149   
00152   OffsetType GetOutputWrapOffsetModifier() const
00153     {  return m_OutputWrapOffsetModifier;  }
00154 
00156   virtual PixelType GetPixel(const unsigned long i) const
00157     {  return *(this->operator[](i));  }
00158 
00160   RegionType GetRegion() const
00161     { return m_Region; }
00162   
00165   IndexType GetBeginIndex() const
00166     { return m_BeginIndex; }
00167   
00169   OffsetType GetWrapOffset() const
00170     {  return m_WrapOffset;  }
00171 
00177   OffsetValueType GetWrapOffset(unsigned int n) const
00178     {    return m_WrapOffset[n];   }
00179 
00183   virtual void GoToBegin();
00184   
00187   virtual void GoToEnd();
00188   
00191   virtual void Initialize(const SizeType &radius, const ImageType *ptr,
00192                           const RegionType &region);
00193 
00196   virtual bool IsAtBegin() const
00197     {    return ( this->GetCenterPointer() == m_Begin );   }
00198   
00201   virtual bool IsAtEnd() const
00202     {
00203       if ( this->GetCenterPointer() > m_End )
00204         {
00205         ExceptionObject e(__FILE__, __LINE__);
00206         OStringStream msg;
00207         msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer()
00208             << " is greater than End = " << m_End
00209             << std::endl
00210             << "  " << *this;
00211         e.SetDescription(msg.str().c_str());
00212         throw e;
00213         }
00214       return ( this->GetCenterPointer() == m_End );
00215     }
00216   
00221   virtual const Self &operator++();
00222   
00227   virtual const Self &operator--();  
00228  
00232   bool operator==(const Self &it) const 
00233     {   return  it.GetCenterPointer() == this->GetCenterPointer();   }
00234   
00238   bool operator!=(const Self &it) const
00239     {    return  it.GetCenterPointer() != this->GetCenterPointer();  }
00240   
00244   bool operator<(const Self &it) const
00245     {  return  this->GetCenterPointer() < it.GetCenterPointer();  }
00246 
00250   bool operator<=(const Self &it) const
00251     {    return  this->GetCenterPointer() <= it.GetCenterPointer();  }
00252   
00256   bool operator>(const Self &it) const
00257     {    return  this->GetCenterPointer() > it.GetCenterPointer();  }
00258 
00262   bool operator>=(const Self &it) const
00263     {    return  this->GetCenterPointer() >= it.GetCenterPointer();  }
00264 
00273   virtual void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType)
00274     { /* default case is do nothing */ }
00275  
00280   void SetLocation( const IndexType& position )
00281     {
00282       this->SetLoop(position);
00283       this->SetPixelPointers(position);
00284     }
00285   
00291   void SetOutputBuffer(InternalPixelType *i)
00292     {    m_OutputBuffer = i;   }
00293 
00296   void SetOutputWrapOffsetModifier( const OffsetType &modifiers);
00297 
00300   virtual void ResetBoundaryCondition()
00301     { /* default case is do nothing */ }
00302  
00303 protected:
00305   void ComputeStrideTable()
00306     {
00307       for (unsigned int i = 0; i < Dimension; ++i)
00308         { m_StrideTable[i] = this->GetStride(i); }
00309     }
00310   
00313   virtual void SetLoop( const IndexType& p )
00314     {  m_Loop = p; }
00315   
00319   virtual void SetBound(const SizeType &);
00320 
00325   virtual void SetPixelPointers(const IndexType &);
00326 
00329   virtual void SetBeginIndex( const IndexType& start)
00330     {  m_BeginIndex = start;  }
00331 
00334   virtual void SetEndIndex();
00335   
00338   IndexType m_BeginIndex;
00339 
00341   IndexType m_Bound;
00342 
00344   const InternalPixelType *m_Begin;
00345   
00347   typename ImageType::ConstPointer m_ConstImage;
00348 
00349   /*
00350    * A pointer to one past the last pixel in the iteration region.
00351    */
00352   const InternalPixelType *m_End;
00353 
00356   IndexType m_EndIndex;
00357 
00359   IndexType m_Loop;
00360  
00367   InternalPixelType *m_OutputBuffer;
00368   
00373   OffsetType m_OutputWrapOffsetModifier;
00374   
00376   RegionType m_Region;
00377 
00380   unsigned long m_StrideTable[Dimension];
00381 
00386   OffsetType m_WrapOffset;
00387 };
00388 
00389 } // namespace itk
00390 
00391 
00392 #ifndef ITK_MANUAL_INSTANTIATION
00393 #include "itkConstNeighborhoodIterator.txx"
00394 #endif
00395 
00396 #endif

Generated at Wed Mar 12 01:12:51 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000