Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itk::NeighborhoodIterator< TImage, TBoundaryCondition > Class Template Reference
[Image IteratorsOperators]

Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image. More...

#include <itkNeighborhoodIterator.h>

Inheritance diagram for itk::NeighborhoodIterator:

Inheritance graph
[legend]
Collaboration diagram for itk::NeighborhoodIterator< TImage, TBoundaryCondition >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef NeighborhoodIterator Self
typedef ConstNeighborhoodIterator<
TImage > 
Superclass
typedef Superclass::InternalPixelType InternalPixelType
typedef Superclass::PixelType PixelType
typedef Superclass::SizeType SizeType
typedef Superclass::ImageType ImageType
typedef Superclass::RegionType RegionType
typedef Superclass::IndexType IndexType
typedef Superclass::OffsetType OffsetType
typedef OffsetType::OffsetValueType OffsetValueType
typedef Superclass::RadiusType RadiusType
typedef Superclass::NeighborhoodType NeighborhoodType
typedef Superclass::Iterator Iterator
typedef Superclass::ConstIterator ConstIterator
typedef Superclass::ImageBoundaryConditionPointerType ImageBoundaryConditionPointerType

Public Methods

 NeighborhoodIterator ()
 NeighborhoodIterator (const NeighborhoodIterator &n)
 NeighborhoodIterator (const SizeType &radius, ImageType *ptr, const RegionType &region)
virtual void PrintSelf (std::ostream &, Indent) const
InternalPixelTypeGetCenterPointer ()
virtual void SetCenterPixel (const PixelType &p)
virtual void SetNeighborhood (const NeighborhoodType &)
virtual void SetPixel (const unsigned i, const PixelType &v, bool &status)
virtual void SetNext (const unsigned axis, const unsigned i, const PixelType &v)
virtual void SetNext (const unsigned axis, const PixelType &v)
virtual void SetPrevious (const unsigned axis, const unsigned i, const PixelType &v)
virtual void SetPrevious (const unsigned axis, const PixelType &v)
Selfoperator= (const Self &orig)
virtual void SetPixel (const unsigned i, const PixelType &v)
virtual void SetPixel (const OffsetType o, const PixelType &v)

Detailed Description

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
class itk::NeighborhoodIterator< TImage, TBoundaryCondition >

Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.

This class is a loose extension of the Standard Template Library (STL) bi-directional iterator concept to masks of pixel neighborhoods within itk::Image objects. This NeighborhoodIterator base class defines simple forward and reverse iteration of an N-dimensional neighborhood mask across an image. Elements within the mask can be accessed like elements within an array.

NeighborhoodIterators are designed to encapsulate some of the complexity of working with image neighborhoods, complexity that would otherwise have to be managed at the algorithmic level. Use NeighborhoodIterators to simplify writing algorithms that perform geometrically localized operations on images (for example, convolution and morphological operations).

To motivate the discussion of NeighborhoodIterators and their use in Itk, consider the following code that takes directional derivatives at each point in an image.

 itk::NeighborhoodInnerProduct<ImageType> IP;

 itk::DerivativeOperator<ImageType> operator;
  operator->SetOrder(1);
  operator->SetDirection(0);
  operator->CreateDirectional();

 itk::NeighborhoodIterator<ImageType>
   iterator(operator->GetRadius(), myImage, myImage->GetRequestedRegion());

 iterator.SetToBegin();
 while ( ! iterator.IsAtEnd() )
 {
   std::cout << "Derivative at index " << iterator.GetIndex() << is <<
     IP(iterator, operator) << std::endl;
   ++iterator;
 } 

Most of the work for the programmer in the code above is in setting up for the iteration. There are three steps. First an inner product function object is created which will be used to effect convolution with the derivative kernel. Setting up the derivative kernel, DerivativeOperator, involves setting the order and direction of the derivative. Finally, we create an iterator over the RequestedRegion of the itk::Image (see Image) using the radius of the derivative kernel as the size.

Itk iterators only loosely follow STL conventions. Notice that instead of asking myImage for myImage.begin() and myImage.end(), iterator.SetToBegin() and iterator.IsAtEnd() are called. Itk iterators are typically more complex objects than traditional, pointer-style STL iterators, and the increased overhead required to conform to the complete STL API is not always justified.

The API for creating and manipulating a NeighborhoodIterator mimics that of the itk::ImageIterators. Like the itk::ImageIterator, a ConstNeighborhoodIterator is defined on a region of interest in an itk::Image. Iteration is constrained within that region of interest.

A NeighborhoodIterator is constructed as a container of pointers (offsets) to a geometric neighborhood of image pixels. As the central pixel position in the mask is moved around the image, the neighboring pixel pointers (offsets) are moved accordingly.

A pixel neighborhood is defined as a central pixel location and an N-dimensional radius extending outward from that location.

Pixels in a neighborhood can be accessed through a NeighborhoodIterator like elements in an array. For example, a 2D neighborhood with radius 2x1 has indices:

 0  1  2  3  4
 5  6  7  8  9
 10 11 12 13 14

Now suppose a NeighborhoodIterator with the above dimensions is constructed and positioned over a neighborhood of values in an Image:

 1.2 1.3 1.8 1.4 1.1
 1.8 1.1 0.7 1.0 1.0
 2.1 1.9 1.7 1.4 2.0

Shown below is some sample pixel access code and the values that it returns.

 ::size_t c = (::size_t) (iterator.Size() / 2); // get offset of center pixel
 ::size_t s = iterator.GetStride(1);            // y-dimension step size

 std::cout << iterator.GetPixel(7)      << std::endl;
 std::cout << iterator.GetCenterPixel() << std::endl;
 std::cout << iterator.GetPixel(c)      << std::endl;
 std::cout << iterator.GetPixel(c-1)    << std::endl;
 std::cout << iterator.GetPixel(c-s)    << std::endl;
 std::cout << iterator.GetPixel(c-s-1)  << std::endl; 
 std::cout << *iterator[c]              << std::endl;

Results:

 0.7
 0.7
 0.7
 1.1
 1.8
 1.3
 0.7

Use of GetPixel() is preferred over the *iterator[] form, and can be used without loss of efficiency in most cases. Some variations (subclasses) of NeighborhoodIterators may exist which do not support the latter API. Corresponding SetPixel() methods exist to modify pixel values in non-const NeighborhoodIterators.

NeighborhoodIterators are "bidirectional iterators". They move only in two directions through the data set. These directions correspond to the layout of the image data in memory and not to spatial directions of the N-dimensional itk::Image. Iteration always proceeds along the fastest increasing dimension (as defined by the layout of the image data) . For itk::Image this is the first dimension specified (i.e. for 3-dimensional (x,y,z) NeighborhoodIterator proceeds along the x-dimension) (For random access iteration through N-dimensional indicies, use RandomAccessNeighborhoodIterator.)

Each subclass of a ConstNeighborhoodIterator may also define its own mechanism for iteration through an image. In general, the Iterator does not directly keep track of its spatial location in the image, but uses a set of internal loop variables and offsets to trigger wraps at itk::Image region boundaries, and to identify the end of the itk::Image region.

NeighborhoodIterator does not perform bounds checking before dereferencing it pixels. It is up to the user to make sure the iteration region is sufficiently padded for the neighborhood radius. See SmartNeighborhoodIterator for a way to automatically handle bounds conditions.

Todo:
Better support for regions with negative indicies.

Add Begin() and End() methods?

See also:
DerivativeOperator , NeighborhoodInnerProduct , Image , Neighborhood , ImageIterator , NeighborhoodIterator , SmartNeighborhoodIterator , RandomAccessNeighborhoodIterator

Definition at line 193 of file itkNeighborhoodIterator.h.


Member Typedef Documentation

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::ConstIterator itk::NeighborhoodIterator< TImage, TBoundaryCondition >::ConstIterator
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 213 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::ImageBoundaryConditionPointerType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::ImageBoundaryConditionPointerType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 215 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::ImageType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::ImageType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 205 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::IndexType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::IndexType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 207 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::InternalPixelType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::InternalPixelType
 

Extract typedefs from superclass.

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 202 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::Iterator itk::NeighborhoodIterator< TImage, TBoundaryCondition >::Iterator
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 212 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::NeighborhoodType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::NeighborhoodType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 211 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::OffsetType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::OffsetType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 208 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef OffsetType::OffsetValueType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::OffsetValueType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 209 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::PixelType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::PixelType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 203 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::RadiusType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::RadiusType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 210 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::RegionType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::RegionType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 206 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef NeighborhoodIterator itk::NeighborhoodIterator< TImage, TBoundaryCondition >::Self
 

Standard class typedefs.

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 198 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef Superclass::SizeType itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SizeType
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 204 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
typedef ConstNeighborhoodIterator<TImage> itk::NeighborhoodIterator< TImage, TBoundaryCondition >::Superclass
 

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 199 of file itkNeighborhoodIterator.h.


Constructor & Destructor Documentation

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
itk::NeighborhoodIterator< TImage, TBoundaryCondition >::NeighborhoodIterator   [inline]
 

Default constructor.

Definition at line 218 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
itk::NeighborhoodIterator< TImage, TBoundaryCondition >::NeighborhoodIterator const NeighborhoodIterator< TImage, TBoundaryCondition > &    n [inline]
 

Copy constructor

Definition at line 221 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
itk::NeighborhoodIterator< TImage, TBoundaryCondition >::NeighborhoodIterator const SizeType   radius,
ImageType   ptr,
const RegionType   region
[inline]
 

Constructor which establishes the region size, neighborhood, and image over which to walk.

Definition at line 234 of file itkNeighborhoodIterator.h.


Member Function Documentation

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
InternalPixelType* itk::NeighborhoodIterator< TImage, TBoundaryCondition >::GetCenterPointer   [inline]
 

Returns the central memory pointer of the neighborhood.

Definition at line 242 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
Self& itk::NeighborhoodIterator< TImage, TBoundaryCondition >::operator= const Self   orig [inline]
 

Assignment operator

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::SmartNeighborhoodIterator< TImage, TBoundaryCondition >.

Definition at line 225 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::PrintSelf std::ostream &   ,
Indent   
const [virtual]
 

Standard print method

Reimplemented from itk::ConstNeighborhoodIterator< TImage >.

Reimplemented in itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >, and itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetCenterPixel const PixelType   p [inline, virtual]
 

Returns the central pixel of the neighborhood.

Definition at line 246 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetNeighborhood const NeighborhoodType   [virtual]
 

Virtual function that replaces the pixel values in the image neighborhood that are pointed to by this NeighborhoodIterator with the pixel values contained in a Neighborhood.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetNext const unsigned    axis,
const PixelType   v
[inline, virtual]
 

Sets the pixel value located one pixel distant from the neighborhood center in the specifed positive axis direction. No bounds checking is done on the size of the neighborhood.

Definition at line 282 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetNext const unsigned    axis,
const unsigned    i,
const PixelType   v
[inline, virtual]
 

Sets the pixel value located i pixels distant from the neighborhood center in the positive specified ``axis'' direction. No bounds checking is done on the size of the neighborhood.

Definition at line 273 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetPixel const OffsetType    o,
const PixelType   v
[inline, virtual]
 

Set the pixel at offset o from the neighborhood center

Definition at line 265 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetPixel const unsigned    i,
const PixelType   v
[virtual]
 

Set the pixel at the ith location.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetPixel const unsigned    i,
const PixelType   v,
bool &    status
[virtual]
 

Special SetPixel method which quietly ignores out-of-bounds attempts. Sets status TRUE if pixel has been set, FALSE otherwise.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetPrevious const unsigned    axis,
const PixelType   v
[inline, virtual]
 

Sets the pixel value located one pixel distant from the neighborhood center in the specifed negative axis direction. No bounds checking is done on the size of the neighborhood.

Definition at line 298 of file itkNeighborhoodIterator.h.

template<class TImage, class TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
virtual void itk::NeighborhoodIterator< TImage, TBoundaryCondition >::SetPrevious const unsigned    axis,
const unsigned    i,
const PixelType   v
[inline, virtual]
 

Sets the pixel value located i pixels distant from the neighborhood center in the negative specified ``axis'' direction. No bounds checking is done on the size of the neighborhood.

Definition at line 289 of file itkNeighborhoodIterator.h.


The documentation for this class was generated from the following file:
Generated at Fri May 21 01:34:47 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000