ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkConstNeighborhoodIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkConstNeighborhoodIterator_h
19 #define itkConstNeighborhoodIterator_h
20 
21 #include <vector>
22 #include <cstring>
23 #include <iostream>
24 #include "itkImage.h"
25 #include "itkNeighborhood.h"
26 #include "itkMacro.h"
28 
29 namespace itk
30 {
49 template< typename TImage, typename TBoundaryCondition =
52  public Neighborhood< typename TImage::InternalPixelType *,
53  TImage::ImageDimension >
54 {
55 public:
57  typedef typename TImage::InternalPixelType InternalPixelType;
58  typedef typename TImage::PixelType PixelType;
59 
61  typedef unsigned int DimensionValueType;
62 
64  itkStaticConstMacro(Dimension, DimensionValueType, TImage::ImageDimension);
65 
69  itkGetStaticConstMacro(Dimension) > Superclass;
70 
74  typedef typename Superclass::SizeType SizeType;
75  typedef typename Superclass::Iterator Iterator;
77 
79  typedef TImage ImageType;
80  typedef typename TImage::RegionType RegionType;
85 
88 
92  typedef typename ImageType::NeighborhoodAccessorFunctorType
94 
96  typedef TBoundaryCondition BoundaryConditionType;
97 
102 
105 
108 
111 
115  const ImageType *ptr,
116  const RegionType & region)
117  {
118  this->Initialize(radius, ptr, region);
119  for ( DimensionValueType i = 0; i < Dimension; i++ )
120  { m_InBounds[i] = false; }
121  this->ResetBoundaryCondition();
122  m_NeighborhoodAccessorFunctor = ptr->GetNeighborhoodAccessor();
123  m_NeighborhoodAccessorFunctor.SetBegin( ptr->GetBufferPointer() );
124  }
126 
128  Self & operator=(const Self & orig);
129 
131  virtual void PrintSelf(std::ostream &, Indent) const;
132 
136 
139  { return m_Bound; }
140 
144  { return m_Bound[n]; }
145 
148  { return ( this->operator[]( ( this->Size() ) >> 1 ) ); }
149 
153  { return m_NeighborhoodAccessorFunctor.Get( this->GetCenterPointer() ); }
154 
156  const ImageType * GetImagePointer(void) const
157  { return m_ConstImage; }
158 
161  virtual IndexType GetIndex(void) const
162  { return m_Loop; }
163 
165  { return m_Loop + o; }
166 
169  virtual NeighborhoodType GetNeighborhood() const;
170 
173  {
175  {
176  return ( m_NeighborhoodAccessorFunctor.Get( this->operator[](i) ) );
177  }
178  bool inbounds;
179  return this->GetPixel(i, inbounds);
180  }
182 
188  virtual PixelType GetPixel(NeighborIndexType i, bool & IsInBounds) const;
189 
192  virtual PixelType GetPixel(const OffsetType & o) const
193  {
194  bool inbounds;
195 
196  return ( this->GetPixel(this->GetNeighborhoodIndex(o), inbounds) );
197  }
198 
204  virtual PixelType GetPixel(const OffsetType & o,
205  bool & IsInBounds) const
206  { return ( this->GetPixel(this->GetNeighborhoodIndex(o), IsInBounds) ); }
207 
211  virtual PixelType GetNext(const unsigned axis, NeighborIndexType i) const
212  {
213  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
214  + ( i * this->GetStride(axis) ) ) );
215  }
216 
220  virtual PixelType GetNext(const unsigned axis) const
221  {
222  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
223  + this->GetStride(axis) ) );
224  }
225 
229  virtual PixelType GetPrevious(const unsigned axis, NeighborIndexType i) const
230  {
231  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
232  - ( i * this->GetStride(axis) ) ) );
233  }
234 
238  virtual PixelType GetPrevious(const unsigned axis) const
239  {
240  return ( this->GetPixel( this->GetCenterNeighborhoodIndex()
241  - this->GetStride(axis) ) );
242  }
243 
246  virtual IndexType GetIndex(const OffsetType & o) const
247  { return ( this->GetIndex() + o ); }
248 
252  { return ( this->GetIndex() + this->GetOffset(i) ); }
253 
256  { return m_Region; }
257 
261  { return m_BeginIndex; }
262 
266 
269  { return m_WrapOffset; }
270 
277  { return m_WrapOffset[n]; }
278 
282  virtual void GoToBegin();
283 
286  virtual void GoToEnd();
287 
290  virtual void Initialize(const SizeType & radius, const ImageType *ptr,
291  const RegionType & region);
292 
295  virtual bool IsAtBegin() const
296  { return ( this->GetCenterPointer() == m_Begin ); }
297 
300  virtual bool IsAtEnd() const
301  {
302  if ( this->GetCenterPointer() > m_End )
303  {
304  ExceptionObject e(__FILE__, __LINE__);
305  std::ostringstream msg;
306  msg << "In method IsAtEnd, CenterPointer = " << this->GetCenterPointer()
307  << " is greater than End = " << m_End
308  << std::endl
309  << " " << *this;
310  e.SetDescription( msg.str().c_str() );
311  throw e;
312  }
313  return ( this->GetCenterPointer() == m_End );
314  }
316 
321  Self & operator++();
322 
327  Self & operator--();
328 
332  bool operator==(const Self & it) const
333  { return it.GetCenterPointer() == this->GetCenterPointer(); }
334 
338  bool operator!=(const Self & it) const
339  { return it.GetCenterPointer() != this->GetCenterPointer(); }
340 
344  bool operator<(const Self & it) const
345  { return this->GetCenterPointer() < it.GetCenterPointer(); }
346 
350  bool operator<=(const Self & it) const
351  { return this->GetCenterPointer() <= it.GetCenterPointer(); }
352 
356  bool operator>(const Self & it) const
357  { return this->GetCenterPointer() > it.GetCenterPointer(); }
358 
362  bool operator>=(const Self & it) const
363  { return this->GetCenterPointer() >= it.GetCenterPointer(); }
364 
369  void SetLocation(const IndexType & position)
370  {
371  this->SetLoop(position);
372  this->SetPixelPointers(position);
373  }
375 
379  Self & operator+=(const OffsetType &);
380 
384  Self & operator-=(const OffsetType &);
385 
388  { return m_Loop - b.m_Loop; }
389 
393  bool InBounds() const;
394 
406  bool IndexInBounds(const NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset ) const;
407 
410  bool IndexInBounds(const NeighborIndexType n ) const;
411 
417  virtual void OverrideBoundaryCondition(const
419  { m_BoundaryCondition = i; }
420 
423  virtual void ResetBoundaryCondition()
425 
427  void SetBoundaryCondition(const TBoundaryCondition & c)
429 
432  { return m_BoundaryCondition; }
433 
436  {
437  this->SetNeedToUseBoundaryCondition(true);
438  }
439 
441  {
442  this->SetNeedToUseBoundaryCondition(false);
443  }
444 
446  {
448  }
449 
451  {
453  }
454 
456  virtual void SetRegion(const RegionType & region);
457 
458 protected:
459 
462  virtual void SetLoop(const IndexType & p)
463  { m_Loop = p; m_IsInBoundsValid = false; }
464 
468  virtual void SetBound(const SizeType &);
469 
474  virtual void SetPixelPointers(const IndexType &);
475 
478  virtual void SetBeginIndex(const IndexType & start)
479  { m_BeginIndex = start; }
480 
483  virtual void SetEndIndex();
484 
488 
491 
494 
496  typename ImageType::ConstWeakPointer m_ConstImage;
497 
500 
504 
507 
510 
517 
523 
526  mutable bool m_InBounds[Dimension];
527 
529  mutable bool m_IsInBounds;
530 
534  mutable bool m_IsInBoundsValid;
535 
538 
541 
543  TBoundaryCondition m_InternalBoundaryCondition;
544 
547 
550 };
551 
552 template< typename TImage >
556 {
558  ret += ind;
559  return ret;
560 }
561 
562 template< typename TImage >
566 { return ( it + ind ); }
567 
568 template< typename TImage >
572  ::OffsetType & ind)
573 {
575  ret -= ind;
576  return ret;
577 }
578 } // namespace itk
579 
580 #ifndef ITK_MANUAL_INSTANTIATION
581 #include "itkConstNeighborhoodIterator.hxx"
582 #endif
583 
584 #endif
virtual IndexType GetIndex(void) const
OffsetValueType GetWrapOffset(NeighborIndexType n) const
NeighborhoodAccessorFunctorType m_NeighborhoodAccessorFunctor
typedef::itk::Size< VDimension > RadiusType
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
virtual void SetDescription(const std::string &s)
Neighborhood< PixelType, itkGetStaticConstMacro(Dimension) > NeighborhoodType
virtual PixelType GetNext(const unsigned axis) const
signed long OffsetValueType
Definition: itkIntTypes.h:154
virtual PixelType GetPixel(NeighborIndexType i) const
virtual void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
A light-weight container object for storing an N-dimensional neighborhood of values.
signed long IndexValueType
Definition: itkIntTypes.h:150
virtual void PrintSelf(std::ostream &, Indent) const
bool IndexInBounds(const NeighborIndexType n, OffsetType &internalIndex, OffsetType &offset) const
NeighborhoodType::NeighborIndexType NeighborIndexType
virtual NeighborIndexType GetNeighborhoodIndex(const OffsetType &) const
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:47
virtual PixelType GetPixel(const OffsetType &o, bool &IsInBounds) const
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
virtual PixelType GetPrevious(const unsigned axis, NeighborIndexType i) const
IndexType GetFastIndexPlusOffset(const OffsetType &o) const
ImageBoundaryCondition< ImageType > * ImageBoundaryConditionPointerType
IndexValueType GetBound(NeighborIndexType n) const
virtual PixelType GetNext(const unsigned axis, NeighborIndexType i) const
virtual void SetPixelPointers(const IndexType &)
ConstNeighborhoodIterator(const SizeType &radius, const ImageType *ptr, const RegionType &region)
ImageType::ConstWeakPointer m_ConstImage
Self & operator=(const Self &orig)
ImageBoundaryConditionPointerType m_BoundaryCondition
void SetLocation(const IndexType &position)
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
typedef::itk::Size< VDimension > SizeType
virtual IndexType GetIndex(const OffsetType &o) const
Standard exception handling object.
virtual void SetRegion(const RegionType &region)
Neighborhood< InternalPixelType *, itkGetStaticConstMacro(Dimension) > Superclass
virtual void SetLoop(const IndexType &p)
virtual void SetBeginIndex(const IndexType &start)
virtual PixelType GetPrevious(const unsigned axis) const
ImageType::NeighborhoodAccessorFunctorType NeighborhoodAccessorFunctorType
Self & operator+=(const OffsetType &)
const ImageType * GetImagePointer(void) const
Index< itkGetStaticConstMacro(Dimension) > IndexType
Self & operator-=(const OffsetType &)
AllocatorType::iterator Iterator
ImageBoundaryCondition< ImageType > const * ImageBoundaryConditionConstPointerType
RegionType GetBoundingBoxAsImageRegion() const
const InternalPixelType * GetCenterPointer() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void SetBound(const SizeType &)
AllocatorType::const_iterator ConstIterator
OffsetType ComputeInternalIndex(const NeighborIndexType n) const
virtual NeighborhoodType GetNeighborhood() const
static const DimensionValueType Dimension
ImageBoundaryConditionPointerType GetBoundaryCondition() const
void SetBoundaryCondition(const TBoundaryCondition &c)
virtual IndexType GetIndex(NeighborIndexType i) const
virtual PixelType GetPixel(const OffsetType &o) const
TImage::InternalPixelType InternalPixelType
virtual void Initialize(const SizeType &radius, const ImageType *ptr, const RegionType &region)
SizeValueType NeighborIndexType