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: 2003/02/12 17:13:55 $
00007   Version:   $Revision: 1.24 $
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 #include "itkZeroFluxNeumannBoundaryCondition.h"
00033 
00034 namespace itk {
00035 
00051 template<class TImage,  class TBoundaryCondition
00052                        = ZeroFluxNeumannBoundaryCondition<TImage> >
00053 class ITK_EXPORT ConstNeighborhoodIterator
00054   :  public Neighborhood<ITK_TYPENAME TImage::InternalPixelType *,
00055                          ::itk::GetImageDimension<TImage>::ImageDimension>
00056 {
00057 public:
00059   typedef typename TImage::InternalPixelType InternalPixelType;
00060   typedef typename TImage::PixelType PixelType;
00061     
00063   itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
00064   
00066   typedef ConstNeighborhoodIterator Self;
00067   typedef Neighborhood<InternalPixelType *, itkGetStaticConstMacro(Dimension)> Superclass;
00068 
00070   typedef typename Superclass::OffsetType OffsetType;
00071   typedef typename OffsetType::OffsetValueType OffsetValueType;
00072   typedef typename Superclass::RadiusType RadiusType;  
00073   typedef typename Superclass::SizeType SizeType;
00074   typedef typename Superclass::SizeValueType SizeValueType;
00075   typedef typename Superclass::Iterator Iterator;
00076   typedef typename Superclass::ConstIterator ConstIterator;
00077   
00079   typedef TImage ImageType;
00080   typedef typename TImage::RegionType RegionType;
00081   typedef Index<itkGetStaticConstMacro(Dimension)> IndexType;
00082   typedef typename IndexType::IndexValueType IndexValueType;
00083   typedef Neighborhood<PixelType, itkGetStaticConstMacro(Dimension)> NeighborhoodType;
00084 
00086   typedef TBoundaryCondition BoundaryConditionType;
00087   
00089   typedef ImageBoundaryCondition<ImageType> *ImageBoundaryConditionPointerType;
00090 
00092   ConstNeighborhoodIterator();
00093 
00095   virtual ~ConstNeighborhoodIterator() {}
00096 
00098   ConstNeighborhoodIterator( const ConstNeighborhoodIterator & );
00099 
00102   ConstNeighborhoodIterator(const SizeType &radius,
00103                        const ImageType * ptr,
00104                        const RegionType &region
00105                        )
00106   {
00107     this->Initialize(radius, ptr, region);
00108     for (unsigned int i=0; i < Dimension; i++)
00109       { m_InBounds[i] = false; }
00110     this->ResetBoundaryCondition();
00111   }
00112 
00114   Self &operator=(const Self& orig);
00115 
00117   virtual void PrintSelf(std::ostream &, Indent) const;
00118 
00121   OffsetType ComputeInternalIndex(unsigned int n) const;
00122 
00124   IndexType GetBound() const
00125     {    return m_Bound;   }
00126 
00129   long GetBound(unsigned int n) const
00130     {    return m_Bound[n];  }
00131   
00133   const InternalPixelType *GetCenterPointer() const
00134     {    return (this->operator[]((this->Size())>>1));  }
00135   
00137   PixelType GetCenterPixel() const
00138     {    return *( this->GetCenterPointer() );  }
00139 
00141   const ImageType * GetImagePointer(void) const
00142     { return m_ConstImage; }
00143  
00146   virtual IndexType GetIndex(void) const
00147     { return m_Loop;  }
00148   
00151   virtual NeighborhoodType GetNeighborhood() const;
00152 
00154   virtual PixelType GetPixel(const unsigned i) const;
00155     //    {  return *(this->operator[](i));  }
00156 
00159   virtual PixelType GetPixel(const OffsetType &o) const
00160   { return (this->GetPixel(this->GetNeighborhoodIndex(o))); }
00161     //  { return *(this->operator[](o)); }
00162 
00166   virtual PixelType GetNext(const unsigned axis, const unsigned i) const
00167   {    return (this->GetPixel(this->GetCenterNeighborhoodIndex()
00168                            + (i * this->GetStride(axis)))); }
00169 
00173   virtual PixelType GetNext(const unsigned axis) const
00174   {    return (this->GetPixel(this->GetCenterNeighborhoodIndex()
00175                            + this->GetStride(axis))); }
00176 
00180   virtual PixelType GetPrevious(const unsigned axis, const unsigned i) const
00181   { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
00182                            - (i * this->GetStride(axis)))); }
00183   
00187   virtual PixelType GetPrevious(const unsigned axis) const
00188   { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
00189                            - this->GetStride(axis))); } 
00190   
00193   virtual IndexType GetIndex(const OffsetType &o) const
00194   { return (this->GetIndex() + o); }
00195 
00198   virtual IndexType GetIndex(const unsigned i) const
00199   { return (this->GetIndex() + this->GetOffset(i)); }
00200   
00202   RegionType GetRegion() const
00203     { return m_Region; }
00204   
00207   IndexType GetBeginIndex() const
00208     { return m_BeginIndex; }
00209 
00212   RegionType GetBoundingBoxAsImageRegion() const;
00213   
00215   OffsetType GetWrapOffset() const
00216     {  return m_WrapOffset;  }
00217 
00223   OffsetValueType GetWrapOffset(unsigned int n) const
00224     {    return m_WrapOffset[n];   }
00225 
00229   virtual void GoToBegin();
00230   
00233   virtual void GoToEnd();
00234   
00237   virtual void Initialize(const SizeType &radius, const ImageType *ptr,
00238                           const RegionType &region);
00239 
00242   virtual bool IsAtBegin() const
00243     {    return ( this->GetCenterPointer() == m_Begin );   }
00244   
00247   virtual bool IsAtEnd() const
00248     {
00249       if ( this->GetCenterPointer() > m_End )
00250         {
00251         ExceptionObject e(__FILE__, __LINE__);
00252         OStringStream msg;
00253         msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer()
00254             << " is greater than End = " << m_End
00255             << std::endl
00256             << "  " << *this;
00257         e.SetDescription(msg.str().c_str());
00258         throw e;
00259         }
00260       return ( this->GetCenterPointer() == m_End );
00261     }
00262   
00267   Self &operator++();
00268   
00273   Self &operator--();  
00274  
00278   bool operator==(const Self &it) const 
00279     {   return  it.GetCenterPointer() == this->GetCenterPointer();   }
00280   
00284   bool operator!=(const Self &it) const
00285     {    return  it.GetCenterPointer() != this->GetCenterPointer();  }
00286   
00290   bool operator<(const Self &it) const
00291     {  return  this->GetCenterPointer() < it.GetCenterPointer();  }
00292 
00296   bool operator<=(const Self &it) const
00297     {    return  this->GetCenterPointer() <= it.GetCenterPointer();  }
00298   
00302   bool operator>(const Self &it) const
00303     {    return  this->GetCenterPointer() > it.GetCenterPointer();  }
00304 
00308   bool operator>=(const Self &it) const
00309     {    return  this->GetCenterPointer() >= it.GetCenterPointer();  }
00310 
00315   void SetLocation( const IndexType& position )
00316     {
00317       this->SetLoop(position);
00318       this->SetPixelPointers(position);
00319     }
00320   
00321 
00325   Self &operator+=(const OffsetType &);
00326 
00330   Self &operator-=(const OffsetType &);
00331 
00333   OffsetType operator-(const Self& b)
00334   {  return m_Loop - b.m_Loop;  }
00335 
00339   bool InBounds() const;
00340   
00346   virtual void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
00347     { m_BoundaryCondition = i; }
00348 
00351   virtual void ResetBoundaryCondition()
00352     { m_BoundaryCondition = &m_InternalBoundaryCondition;  }
00353 
00355   void SetBoundaryCondition( const TBoundaryCondition &c )
00356   { m_InternalBoundaryCondition = c; }
00357 
00359   const BoundaryConditionType *GetBoundaryCondition() const
00360   { return dynamic_cast<BoundaryConditionType *>(m_BoundaryCondition); }
00361   
00362 protected:
00363   
00366   virtual void SetLoop( const IndexType& p )
00367     {  m_Loop = p; }
00368   
00372   virtual void SetBound(const SizeType &);
00373 
00378   virtual void SetPixelPointers(const IndexType &);
00379 
00382   virtual void SetBeginIndex( const IndexType& start)
00383     {  m_BeginIndex = start;  }
00384 
00387   virtual void SetEndIndex();
00388   
00391   IndexType m_BeginIndex;
00392 
00394   IndexType m_Bound;
00395 
00397   const InternalPixelType *m_Begin;
00398   
00400   typename ImageType::ConstPointer m_ConstImage;
00401 
00402   /*
00403    * A pointer to one past the last pixel in the iteration region.
00404    */
00405   const InternalPixelType *m_End;
00406 
00409   IndexType m_EndIndex;
00410 
00412   IndexType m_Loop;
00413  
00415   RegionType m_Region;
00416 
00421   OffsetType m_WrapOffset;
00422 
00427   ImageBoundaryConditionPointerType m_BoundaryCondition;
00428 
00431   mutable bool m_InBounds[Dimension];
00432   
00434   IndexType m_InnerBoundsLow;
00435   
00437   IndexType m_InnerBoundsHigh;
00438 
00440   TBoundaryCondition m_InternalBoundaryCondition;
00441 
00443   bool m_NeedToUseBoundaryCondition;
00444 
00445 };
00446 
00447 template<class TImage>
00448 inline ConstNeighborhoodIterator<TImage>
00449 operator+(const ConstNeighborhoodIterator<TImage> &it,
00450           const typename ConstNeighborhoodIterator<TImage>
00451           ::OffsetType &ind)
00452 {
00453   ConstNeighborhoodIterator<TImage> ret;
00454   ret = it;
00455   ret += ind;
00456   return ret;
00457 }
00458 
00459 template<class TImage>
00460 inline ConstNeighborhoodIterator<TImage>
00461 operator+(const typename ConstNeighborhoodIterator<TImage>
00462           ::OffsetType &ind,
00463           const ConstNeighborhoodIterator<TImage> &it)
00464 {  return (it + ind); }
00465 
00466 template<class TImage>
00467 inline ConstNeighborhoodIterator<TImage>
00468 operator-(const ConstNeighborhoodIterator<TImage> &it,
00469           const typename ConstNeighborhoodIterator<TImage>
00470           ::OffsetType &ind)
00471 {
00472   ConstNeighborhoodIterator<TImage> ret;
00473   ret = it;
00474   ret -= ind;
00475   return ret;
00476 }
00477 
00478 
00479 
00480 
00481 
00482 
00483 
00484 
00485 
00486 
00487 
00488 
00489   
00490 } // namespace itk
00491 
00492 
00493 #ifndef ITK_MANUAL_INSTANTIATION
00494 #include "itkConstNeighborhoodIterator.txx"
00495 #endif
00496 
00497 #endif

Generated at Fri May 21 01:14:34 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000