00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00050 template<class TImage, class TBoundaryCondition
00051 = ZeroFluxNeumannBoundaryCondition<TImage> >
00052 class ITK_EXPORT ConstNeighborhoodIterator
00053 : public Neighborhood<ITK_TYPENAME TImage::InternalPixelType *,
00054 ::itk::GetImageDimension<TImage>::ImageDimension>
00055 {
00056 public:
00058 typedef typename TImage::InternalPixelType InternalPixelType;
00059 typedef typename TImage::PixelType PixelType;
00060
00062 itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
00063
00065 typedef ConstNeighborhoodIterator Self;
00066 typedef Neighborhood<InternalPixelType *, itkGetStaticConstMacro(Dimension)> Superclass;
00067
00069 typedef typename Superclass::OffsetType OffsetType;
00070 typedef typename OffsetType::OffsetValueType OffsetValueType;
00071 typedef typename Superclass::RadiusType RadiusType;
00072 typedef typename Superclass::SizeType SizeType;
00073 typedef typename Superclass::SizeValueType SizeValueType;
00074 typedef typename Superclass::Iterator Iterator;
00075 typedef typename Superclass::ConstIterator ConstIterator;
00076
00078 typedef TImage ImageType;
00079 typedef typename TImage::RegionType RegionType;
00080 typedef Index<itkGetStaticConstMacro(Dimension)> IndexType;
00081 typedef typename IndexType::IndexValueType IndexValueType;
00082 typedef Neighborhood<PixelType, itkGetStaticConstMacro(Dimension)> NeighborhoodType;
00083
00085 typedef TBoundaryCondition BoundaryConditionType;
00086
00088 typedef ImageBoundaryCondition<ImageType> *ImageBoundaryConditionPointerType;
00089 typedef ImageBoundaryCondition<ImageType> const *ImageBoundaryConditionConstPointerType;
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 ®ion
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 { bool inbounds; return this->GetPixel(i, inbounds); }
00156
00162 virtual PixelType GetPixel(const unsigned i, bool& IsInBounds) const;
00163
00166 virtual PixelType GetPixel(const OffsetType &o) const
00167 { bool inbounds; return (this->GetPixel(this->GetNeighborhoodIndex(o), inbounds)); }
00168
00174 virtual PixelType GetPixel(const OffsetType &o,
00175 bool& IsInBounds) const
00176 { return (this->GetPixel(this->GetNeighborhoodIndex(o), IsInBounds)); }
00177
00181 virtual PixelType GetNext(const unsigned axis, const unsigned i) const
00182 { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
00183 + (i * this->GetStride(axis)))); }
00184
00188 virtual PixelType GetNext(const unsigned axis) const
00189 { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
00190 + this->GetStride(axis))); }
00191
00195 virtual PixelType GetPrevious(const unsigned axis, const unsigned i) const
00196 { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
00197 - (i * this->GetStride(axis)))); }
00198
00202 virtual PixelType GetPrevious(const unsigned axis) const
00203 { return (this->GetPixel(this->GetCenterNeighborhoodIndex()
00204 - this->GetStride(axis))); }
00205
00208 virtual IndexType GetIndex(const OffsetType &o) const
00209 { return (this->GetIndex() + o); }
00210
00213 virtual IndexType GetIndex(const unsigned i) const
00214 { return (this->GetIndex() + this->GetOffset(i)); }
00215
00217 RegionType GetRegion() const
00218 { return m_Region; }
00219
00222 IndexType GetBeginIndex() const
00223 { return m_BeginIndex; }
00224
00227 RegionType GetBoundingBoxAsImageRegion() const;
00228
00230 OffsetType GetWrapOffset() const
00231 { return m_WrapOffset; }
00232
00238 OffsetValueType GetWrapOffset(unsigned int n) const
00239 { return m_WrapOffset[n]; }
00240
00244 virtual void GoToBegin();
00245
00248 virtual void GoToEnd();
00249
00252 virtual void Initialize(const SizeType &radius, const ImageType *ptr,
00253 const RegionType ®ion);
00254
00257 virtual bool IsAtBegin() const
00258 { return ( this->GetCenterPointer() == m_Begin ); }
00259
00262 virtual bool IsAtEnd() const
00263 {
00264 if ( this->GetCenterPointer() > m_End )
00265 {
00266 ExceptionObject e(__FILE__, __LINE__);
00267 OStringStream msg;
00268 msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer()
00269 << " is greater than End = " << m_End
00270 << std::endl
00271 << " " << *this;
00272 e.SetDescription(msg.str().c_str());
00273 throw e;
00274 }
00275 return ( this->GetCenterPointer() == m_End );
00276 }
00277
00282 Self &operator++();
00283
00288 Self &operator--();
00289
00293 bool operator==(const Self &it) const
00294 { return it.GetCenterPointer() == this->GetCenterPointer(); }
00295
00299 bool operator!=(const Self &it) const
00300 { return it.GetCenterPointer() != this->GetCenterPointer(); }
00301
00305 bool operator<(const Self &it) const
00306 { return this->GetCenterPointer() < it.GetCenterPointer(); }
00307
00311 bool operator<=(const Self &it) const
00312 { return this->GetCenterPointer() <= it.GetCenterPointer(); }
00313
00317 bool operator>(const Self &it) const
00318 { return this->GetCenterPointer() > it.GetCenterPointer(); }
00319
00323 bool operator>=(const Self &it) const
00324 { return this->GetCenterPointer() >= it.GetCenterPointer(); }
00325
00330 void SetLocation( const IndexType& position )
00331 {
00332 this->SetLoop(position);
00333 this->SetPixelPointers(position);
00334 }
00335
00336
00340 Self &operator+=(const OffsetType &);
00341
00345 Self &operator-=(const OffsetType &);
00346
00348 OffsetType operator-(const Self& b)
00349 { return m_Loop - b.m_Loop; }
00350
00354 bool InBounds() const;
00355
00361 virtual void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
00362 { m_BoundaryCondition = i; }
00363
00366 virtual void ResetBoundaryCondition()
00367 { m_BoundaryCondition = &m_InternalBoundaryCondition; }
00368
00370 void SetBoundaryCondition( const TBoundaryCondition &c )
00371 { m_InternalBoundaryCondition = c; }
00372
00374 const BoundaryConditionType *GetBoundaryCondition() const
00375 { return dynamic_cast<BoundaryConditionType *>(m_BoundaryCondition); }
00376
00378 void NeedToUseBoundaryConditionOn()
00379 {
00380 this->SetNeedToUseBoundaryCondition(true);
00381 }
00382 void NeedToUseBoundaryConditionOff()
00383 {
00384 this->SetNeedToUseBoundaryCondition(false);
00385 }
00386 void SetNeedToUseBoundaryCondition(bool b)
00387 {
00388 m_NeedToUseBoundaryCondition = b;
00389 }
00390 bool GetNeedToUseBoundaryCondition() const
00391 {
00392 return m_NeedToUseBoundaryCondition;
00393 }
00394
00395
00396 protected:
00397
00400 virtual void SetLoop( const IndexType& p )
00401 { m_Loop = p; }
00402
00406 virtual void SetBound(const SizeType &);
00407
00412 virtual void SetPixelPointers(const IndexType &);
00413
00416 virtual void SetBeginIndex( const IndexType& start)
00417 { m_BeginIndex = start; }
00418
00421 virtual void SetEndIndex();
00422
00425 IndexType m_BeginIndex;
00426
00428 IndexType m_Bound;
00429
00431 const InternalPixelType *m_Begin;
00432
00434 typename ImageType::ConstWeakPointer m_ConstImage;
00435
00436
00437
00438
00439 const InternalPixelType *m_End;
00440
00443 IndexType m_EndIndex;
00444
00446 IndexType m_Loop;
00447
00449 RegionType m_Region;
00450
00455 OffsetType m_WrapOffset;
00456
00461 ImageBoundaryConditionPointerType m_BoundaryCondition;
00462
00465 mutable bool m_InBounds[Dimension];
00466
00468 IndexType m_InnerBoundsLow;
00469
00471 IndexType m_InnerBoundsHigh;
00472
00474 TBoundaryCondition m_InternalBoundaryCondition;
00475
00477 bool m_NeedToUseBoundaryCondition;
00478
00479 };
00480
00481 template<class TImage>
00482 inline ConstNeighborhoodIterator<TImage>
00483 operator+(const ConstNeighborhoodIterator<TImage> &it,
00484 const typename ConstNeighborhoodIterator<TImage>
00485 ::OffsetType &ind)
00486 {
00487 ConstNeighborhoodIterator<TImage> ret;
00488 ret = it;
00489 ret += ind;
00490 return ret;
00491 }
00492
00493 template<class TImage>
00494 inline ConstNeighborhoodIterator<TImage>
00495 operator+(const typename ConstNeighborhoodIterator<TImage>
00496 ::OffsetType &ind,
00497 const ConstNeighborhoodIterator<TImage> &it)
00498 { return (it + ind); }
00499
00500 template<class TImage>
00501 inline ConstNeighborhoodIterator<TImage>
00502 operator-(const ConstNeighborhoodIterator<TImage> &it,
00503 const typename ConstNeighborhoodIterator<TImage>
00504 ::OffsetType &ind)
00505 {
00506 ConstNeighborhoodIterator<TImage> ret;
00507 ret = it;
00508 ret -= ind;
00509 return ret;
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524 }
00525
00526
00527 #ifndef ITK_MANUAL_INSTANTIATION
00528 #include "itkConstNeighborhoodIterator.txx"
00529 #endif
00530
00531 #endif