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
00156
00159 virtual
PixelType GetPixel(const
OffsetType &o)
const
00160
{
return (this->GetPixel(this->GetNeighborhoodIndex(o))); }
00161
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 ®ion);
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
00363
void NeedToUseBoundaryConditionOn()
00364 {
00365 this->SetNeedToUseBoundaryCondition(
true);
00366 }
00367
void NeedToUseBoundaryConditionOff()
00368 {
00369 this->SetNeedToUseBoundaryCondition(
false);
00370 }
00371
void SetNeedToUseBoundaryCondition(
bool b)
00372 {
00373 m_NeedToUseBoundaryCondition = b;
00374 }
00375
bool GetNeedToUseBoundaryCondition()
const
00376
{
00377 return m_NeedToUseBoundaryCondition;
00378 }
00379
00380
00381 protected:
00382
00385
virtual void SetLoop(
const IndexType& p )
00386 { m_Loop = p; }
00387
00391
virtual void SetBound(
const SizeType &);
00392
00397
virtual void SetPixelPointers(
const IndexType &);
00398
00401
virtual void SetBeginIndex(
const IndexType& start)
00402 { m_BeginIndex = start; }
00403
00406
virtual void SetEndIndex();
00407
00410 IndexType m_BeginIndex;
00411
00413 IndexType m_Bound;
00414
00416
const InternalPixelType *m_Begin;
00417
00419
typename ImageType::ConstPointer m_ConstImage;
00420
00421
00422
00423
00424
const InternalPixelType *m_End;
00425
00428
IndexType m_EndIndex;
00429
00431 IndexType m_Loop;
00432
00434
RegionType m_Region;
00435
00440
OffsetType m_WrapOffset;
00441
00446
ImageBoundaryConditionPointerType m_BoundaryCondition;
00447
00450
mutable bool m_InBounds[Dimension];
00451
00453 IndexType m_InnerBoundsLow;
00454
00456
IndexType m_InnerBoundsHigh;
00457
00459 TBoundaryCondition m_InternalBoundaryCondition;
00460
00462
bool m_NeedToUseBoundaryCondition;
00463
00464 };
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
template<
class TImage>
00479
inline ConstNeighborhoodIterator<TImage>
00480
operator+(
const typename ConstNeighborhoodIterator<TImage>
00481 ::OffsetType &ind,
00482
const ConstNeighborhoodIterator<TImage> &it)
00483 {
return (it + ind); }
00484
00485
template<
class TImage>
00486
inline ConstNeighborhoodIterator<TImage>
00487 operator-(
const ConstNeighborhoodIterator<TImage> &it,
00488
const typename ConstNeighborhoodIterator<TImage>
00489 ::OffsetType &ind)
00490 {
00491
ConstNeighborhoodIterator<TImage> ret;
00492 ret = it;
00493 ret -= ind;
00494 return ret;
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 }
00510
00511
00512
#ifndef ITK_MANUAL_INSTANTIATION
00513
#include "itkConstNeighborhoodIterator.txx"
00514
#endif
00515
00516
#endif