17 #ifndef __itkConstNeighborhoodIterator_h
18 #define __itkConstNeighborhoodIterator_h
50 template<
class TImage,
class TBoundaryCondition
51 = ZeroFluxNeumannBoundaryCondition<TImage> >
53 :
public Neighborhood<ITK_TYPENAME TImage::InternalPixelType *,
54 ::itk::GetImageDimension<TImage>::ImageDimension>
62 itkStaticConstMacro(Dimension,
unsigned int, TImage::ImageDimension);
89 typedef typename ImageType::NeighborhoodAccessorFunctorType
113 const RegionType ®ion)
115 this->Initialize(radius, ptr, region);
116 for (
unsigned int i=0; i < Dimension; i++)
117 { m_InBounds[i] =
false; }
118 this->ResetBoundaryCondition();
119 m_NeighborhoodAccessorFunctor = ptr->GetNeighborhoodAccessor();
120 m_NeighborhoodAccessorFunctor.SetBegin( ptr->GetBufferPointer() );
124 Self &operator=(
const Self& orig);
127 virtual void PrintSelf(std::ostream &,
Indent)
const;
131 OffsetType ComputeInternalIndex(
unsigned int n)
const;
139 long GetBound(
unsigned int n)
const
140 {
return m_Bound[n]; }
143 const InternalPixelType *GetCenterPointer()
const
144 {
return (this->
operator[]((this->
Size())>>1)); }
149 {
return m_NeighborhoodAccessorFunctor.Get( this->GetCenterPointer() );}
153 {
return m_ConstImage; }
162 virtual NeighborhoodType GetNeighborhood()
const;
167 if( !m_NeedToUseBoundaryCondition )
169 return ( m_NeighborhoodAccessorFunctor.Get( this->operator[]( i ) ) );
172 return this->GetPixel( i, inbounds );
180 virtual PixelType GetPixel(
const unsigned i,
bool& IsInBounds)
const;
187 return (this->GetPixel(this->GetNeighborhoodIndex(o), inbounds));
196 bool& IsInBounds)
const
197 {
return (this->
GetPixel(this->GetNeighborhoodIndex(o), IsInBounds)); }
202 virtual PixelType GetNext(
const unsigned axis,
const unsigned i)
const
203 {
return (this->GetPixel(this->GetCenterNeighborhoodIndex()
204 + (i * this->GetStride(axis)))); }
210 {
return (this->GetPixel(this->GetCenterNeighborhoodIndex()
211 + this->GetStride(axis))); }
216 virtual PixelType GetPrevious(
const unsigned axis,
const unsigned i)
const
217 {
return (this->GetPixel(this->GetCenterNeighborhoodIndex()
218 - (i * this->GetStride(axis)))); }
223 virtual PixelType GetPrevious(
const unsigned axis)
const
224 {
return (this->GetPixel(this->GetCenterNeighborhoodIndex()
225 - this->GetStride(axis))); }
235 {
return (this->
GetIndex() + this->GetOffset(i)); }
238 RegionType GetRegion()
const
244 {
return m_BeginIndex; }
248 RegionType GetBoundingBoxAsImageRegion()
const;
252 {
return m_WrapOffset; }
260 {
return m_WrapOffset[n]; }
265 virtual void GoToBegin();
269 virtual void GoToEnd();
273 virtual void Initialize(
const SizeType &radius,
const ImageType *ptr,
274 const RegionType ®ion);
278 virtual bool IsAtBegin()
const
279 {
return ( this->GetCenterPointer() == m_Begin ); }
283 virtual bool IsAtEnd()
const
285 if ( this->GetCenterPointer() > m_End )
289 msg <<
"In method IsAtEnd, CenterPointer = " << this->GetCenterPointer()
290 <<
" is greater than End = " << m_End
296 return ( this->GetCenterPointer() == m_End );
332 bool operator<=(
const Self &it)
const
338 bool operator>(
const Self &it)
const
344 bool operator>=(
const Self &it)
const
353 this->SetLoop(position);
354 this->SetPixelPointers(position);
361 Self &operator+=(
const OffsetType &);
366 Self &operator-=(
const OffsetType &);
370 {
return m_Loop - b.
m_Loop; }
375 bool InBounds()
const;
382 virtual void OverrideBoundaryCondition(
const
384 { m_BoundaryCondition = i; }
388 virtual void ResetBoundaryCondition()
389 { m_BoundaryCondition = &m_InternalBoundaryCondition; }
392 void SetBoundaryCondition(
const TBoundaryCondition &c )
393 { m_InternalBoundaryCondition = c; }
400 void NeedToUseBoundaryConditionOn()
402 this->SetNeedToUseBoundaryCondition(
true);
404 void NeedToUseBoundaryConditionOff()
406 this->SetNeedToUseBoundaryCondition(
false);
408 void SetNeedToUseBoundaryCondition(
bool b)
410 m_NeedToUseBoundaryCondition = b;
412 bool GetNeedToUseBoundaryCondition()
const
414 return m_NeedToUseBoundaryCondition;
422 { m_Loop = p; m_IsInBoundsValid =
false;}
427 virtual void SetBound(
const SizeType &);
433 virtual void SetPixelPointers(
const IndexType &);
438 { m_BeginIndex = start; }
442 virtual void SetEndIndex();
485 mutable bool m_InBounds[Dimension];
512 template<
class TImage>
524 template<
class TImage>
525 inline ConstNeighborhoodIterator<TImage>
529 {
return (it + ind); }
531 template<
class TImage>
532 inline ConstNeighborhoodIterator<TImage>
546 #define ITK_TEMPLATE_ConstNeighborhoodIterator(_, EXPORT, x, y) namespace itk { \
547 _(2(class EXPORT ConstNeighborhoodIterator< ITK_TEMPLATE_2 x >)) \
548 namespace Templates { typedef ConstNeighborhoodIterator< ITK_TEMPLATE_2 x > \
549 ConstNeighborhoodIterator##y; } \
552 #if ITK_TEMPLATE_EXPLICIT
553 # include "Templates/itkConstNeighborhoodIterator+-.h"