ITK  5.4.0
Insight Toolkit
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Attributes | List of all members
itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition > Class Template Reference

#include <itkShapedNeighborhoodIterator.h>

Detailed Description

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
class itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >

A neighborhood iterator which can take on an arbitrary shape.

General Information
The ShapedNeighborhoodIterator is a refinement of NeighborhoodIterator which allows the user to specify which of the neighborhood elements are active and which will be ignored. This is useful for applications which only need to work with a subset of the neighborhood around a pixel such as morphological operations or cellular automata. This iterator can also be used, for example, to specify "cross-shaped" neighborhood where only elements along a spatial axes are significant.
Constructing a shaped neighborhood iterator
A shaped neighborhood iterator is constructed by constructing a list of active neighbor locations. The list is called the ActiveIndexList. The methods ActivateOffset, DeactivateOffset, and ClearActiveList are used to construct the ActiveIndexList. The argument to Activate/DeactivateOffset is an itk::Offset which represents the ND spatial offset from the center of the neighborhood. For example, to activate the center pixel in the neighborhood, you would do the following:
using ImageType = Image<float, 3>;
ShapedNeighborhoodIterator<ImageType> it(radius, image, region);
it.ActivateOffset(offset);

where radius, image, and region are as described in NeighborhoodIterator.

Once a neighborhood location has been activated, iteration (operator++, operator--, operator+=, operator-=) will update the value at the active location. Note that values at inactive locations will NOT be valid if queried.

Accessing elements in a shaped neighborhood.
To access the value at an active neighborhood location, you can use the standard GetPixel, SetPixel methods. SetPixel is not defined for ConstShapedNeighborhoodIterator. The class will not complain if you attempt to access a value at a non-active location, but be aware that the result will be undefined. Error checking is not done in this case for the sake of efficiency.

A second way to access active shaped neighborhood values is through a ShapedNeighborhoodIterator::Iterator or ConstShapedNeighborhoodIterator::ConstIterator. The following example demonstrates the use of these iterators.

using ImageType = Image<float, 3>;
ShapedNeighborhoodIterator<ImageType> it(radius, image, region);
...
it.ActivateOffset(offset1);
it.ActivateOffset(offset2);
it.ActivateOffset(offset3);
// etc..
...
ShapedNeighborhoodIterator<ImageType>::Iterator i;
for (i = it.Begin(); ! i.IsAtEnd(); ++i)
{ i.Set(i.Get() + 1.0); }
// you may also use i != i.End(), but IsAtEnd() may be slightly faster.

You can also iterate backward through the neighborhood active list.

i = it.End();
--i;
while (i != it.Begin())
{
i.Set(i.Get() + 1.0);
--i;
}
i.Set(i.Get() + 1.0);

The Get() Set() syntax was chosen versus defining operator* for these iterators because lvalue vs. rvalue context information is needed to determine whether bounds checking must take place.

See also
Neighborhood
MORE INFORMATION
For a complete description of the ITK Image Iterators and their API, please see the Iterators chapter in the ITK Software Guide. The ITK Software Guide is available in print and as a free .pdf download from https://www.itk.org.
See also
ImageConstIterator
ConditionalConstIterator
ConstNeighborhoodIterator
ConstShapedNeighborhoodIterator
ConstSliceIterator
CorrespondenceDataStructureIterator
FloodFilledFunctionConditionalConstIterator
FloodFilledImageFunctionConditionalConstIterator
FloodFilledImageFunctionConditionalIterator
FloodFilledSpatialFunctionConditionalConstIterator
FloodFilledSpatialFunctionConditionalIterator
ImageConstIterator
ImageConstIteratorWithIndex
ImageIterator
ImageIteratorWithIndex
ImageLinearConstIteratorWithIndex
ImageLinearIteratorWithIndex
ImageRandomConstIteratorWithIndex
ImageRandomIteratorWithIndex
ImageRegionConstIterator
ImageRegionConstIteratorWithIndex
ImageRegionExclusionConstIteratorWithIndex
ImageRegionExclusionIteratorWithIndex
ImageRegionIterator
ImageRegionIteratorWithIndex
ImageRegionReverseConstIterator
ImageRegionReverseIterator
ImageReverseConstIterator
ImageReverseIterator
ImageSliceConstIteratorWithIndex
ImageSliceIteratorWithIndex
NeighborhoodIterator
PathConstIterator
PathIterator
ShapedNeighborhoodIterator
SliceIterator
ImageConstIteratorWithIndex
ShapedImageNeighborhoodRange
ITK Sphinx Examples:

Definition at line 150 of file itkShapedNeighborhoodIterator.h.

+ Inheritance diagram for itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >:
+ Collaboration diagram for itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >:

Classes

struct  Iterator
 

Public Types

using ConstIterator = typename AllocatorType::const_iterator
 
using InternalPixelType = typename TImage::InternalPixelType
 
using OffsetType = Offset< VDimension >
 
using OffsetValueType = typename OffsetType::OffsetValueType
 
using PixelType = typename TImage::PixelType
 
using RadiusType = itk::Size< VDimension >
 
using Self = ShapedNeighborhoodIterator
 
using SizeType = itk::Size< VDimension >
 
using SizeValueType = typename SizeType::SizeValueType
 
using Superclass = ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >
 
- Public Types inherited from itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >
using BoundaryConditionType = TBoundaryCondition
 
using ImageBoundaryConditionPointerType = ImageBoundaryCondition< ImageType > *
 
using ImageType = TImage
 
using IndexListConstIterator = typename IndexListType::const_iterator
 
using IndexListIterator = typename IndexListType::iterator
 
using IndexListType = std::list< NeighborIndexType >
 
using IndexType = Index< Self::Dimension >
 
using IndexValueType = typename IndexType::IndexValueType
 
using InternalPixelType = typename TImage::InternalPixelType
 
using NeighborhoodType = Neighborhood< PixelType, Self::Dimension >
 
using NeighborIndexType = typename NeighborhoodType::NeighborIndexType
 
using OffsetType = Offset< VDimension >
 
using OffsetValueType = typename OffsetType::OffsetValueType
 
using PixelType = typename TImage::PixelType
 
using RadiusType = itk::Size< VDimension >
 
using RegionType = typename TImage::RegionType
 
using Self = ConstShapedNeighborhoodIterator
 
using SizeType = itk::Size< VDimension >
 
using SizeValueType = typename SizeType::SizeValueType
 
using Superclass = NeighborhoodIterator< TImage, TBoundaryCondition >
 

Public Member Functions

Iterator Begin ()
 
ConstIterator Begin () const
 
Iterator End ()
 
ConstIterator End () const
 
 ShapedNeighborhoodIterator ()=default
 
 ShapedNeighborhoodIterator (const ShapedNeighborhoodIterator &o)=delete
 
 ShapedNeighborhoodIterator (const SizeType &radius, const ImageType *ptr, const RegionType &region)
 
 ~ShapedNeighborhoodIterator () override=default
 
Selfoperator= (const Self &orig)
 
Iterator Begin ()
 
Iterator End ()
 
- Public Member Functions inherited from itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >
const IndexListTypeGetActiveIndexList () const
 
IndexListType::size_type GetActiveIndexListSize () const
 
Selfoperator++ ()
 
Selfoperator+= (const OffsetType &)
 
Selfoperator-- ()
 
Selfoperator-= (const OffsetType &)
 
void PrintSelf (std::ostream &, Indent) const override
 
ConstIterator Begin () const
 
ConstIterator End () const
 
 ConstShapedNeighborhoodIterator ()=default
 
 ~ConstShapedNeighborhoodIterator () override=default
 
 ConstShapedNeighborhoodIterator (const SizeType &radius, const ImageType *ptr, const RegionType &region)
 
 ConstShapedNeighborhoodIterator (const ConstShapedNeighborhoodIterator &)=delete
 
Selfoperator= (const Self &orig)
 
const SizeType GetRadius () const
 
SizeValueType GetRadius (DimensionValueType n) const
 
virtual NeighborIndexType GetNeighborhoodIndex (const OffsetType &) const
 
NeighborIndexType GetCenterNeighborhoodIndex () const
 
OffsetType GetOffset (NeighborIndexType i) const
 
bool operator== (const Self &other) const
 
TPixel & GetElement (NeighborIndexType i)
 
void Print (std::ostream &os) const
 
ITK_ITERATOR_VIRTUAL void ActivateOffset (const OffsetType &off) ITK_ITERATOR_FINAL
 
ITK_ITERATOR_VIRTUAL void DeactivateOffset (const OffsetType &off) ITK_ITERATOR_FINAL
 
template<typename TOffsets >
void ActivateOffsets (const TOffsets &offsets)
 
ITK_ITERATOR_VIRTUAL void ClearActiveList () ITK_ITERATOR_FINAL
 
template<typename TNeighborPixel >
void CreateActiveListFromNeighborhood (const Neighborhood< TNeighborPixel, Self::Dimension > &)
 
void CreateActiveListFromNeighborhood (const NeighborhoodType &neighborhood)
 

Static Public Attributes

static constexpr unsigned int Dimension = TImage::ImageDimension
 
- Static Public Attributes inherited from itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >
static constexpr unsigned int Dimension = TImage::ImageDimension
 

Protected Types

using NeighborIndexType = SizeValueType
 

Protected Attributes

friend Superclass
 
- Protected Attributes inherited from itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >
IndexListType m_ActiveIndexList {}
 
bool m_CenterIsActive { false }
 

Additional Inherited Members

- Protected Member Functions inherited from itk::ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >
ITK_ITERATOR_VIRTUAL void ActivateIndex (NeighborIndexType) ITK_ITERATOR_FINAL
 
ITK_ITERATOR_VIRTUAL void DeactivateIndex (NeighborIndexType) ITK_ITERATOR_FINAL
 

Member Typedef Documentation

◆ ConstIterator

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::Neighborhood< TPixel, VDimension, TAllocator >::ConstIterator = typename AllocatorType::const_iterator

Definition at line 76 of file itkNeighborhood.h.

◆ InternalPixelType

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::InternalPixelType = typename TImage::InternalPixelType

Extract image type information.

Definition at line 155 of file itkShapedNeighborhoodIterator.h.

◆ NeighborIndexType

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::Neighborhood< TPixel, VDimension, TAllocator >::NeighborIndexType = SizeValueType
protected

Type used to refer to the elements of the pixel list that are part of the neighborhood.

Definition at line 96 of file itkNeighborhood.h.

◆ OffsetType

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::Neighborhood< TPixel, VDimension, TAllocator >::OffsetType = Offset<VDimension>

Offset type used to reference neighbor locations

Definition at line 86 of file itkNeighborhood.h.

◆ OffsetValueType

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::OffsetValueType = typename OffsetType::OffsetValueType

Definition at line 167 of file itkShapedNeighborhoodIterator.h.

◆ PixelType

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::PixelType = typename TImage::PixelType

Definition at line 156 of file itkShapedNeighborhoodIterator.h.

◆ RadiusType

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::Neighborhood< TPixel, VDimension, TAllocator >::RadiusType = itk::Size<VDimension>

Radius type alias support

Definition at line 83 of file itkNeighborhood.h.

◆ Self

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::Self = ShapedNeighborhoodIterator

Standard class type aliases.

Definition at line 162 of file itkShapedNeighborhoodIterator.h.

◆ SizeType

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::Neighborhood< TPixel, VDimension, TAllocator >::SizeType = itk::Size<VDimension>

Size and value type alias support

Definition at line 79 of file itkNeighborhood.h.

◆ SizeValueType

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::Neighborhood< TPixel, VDimension, TAllocator >::SizeValueType = typename SizeType::SizeValueType

Definition at line 80 of file itkNeighborhood.h.

◆ Superclass

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
using itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::Superclass = ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition>

Definition at line 163 of file itkShapedNeighborhoodIterator.h.

Constructor & Destructor Documentation

◆ ShapedNeighborhoodIterator() [1/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::ShapedNeighborhoodIterator ( )
default

Default constructor

◆ ~ShapedNeighborhoodIterator()

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::~ShapedNeighborhoodIterator ( )
overridedefault

Virtual destructor

◆ ShapedNeighborhoodIterator() [2/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::ShapedNeighborhoodIterator ( const ShapedNeighborhoodIterator< TImage, TBoundaryCondition > &  o)
delete

Copy constructor

◆ ShapedNeighborhoodIterator() [3/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::ShapedNeighborhoodIterator ( const SizeType radius,
const ImageType ptr,
const RegionType region 
)
inline

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

Definition at line 223 of file itkShapedNeighborhoodIterator.h.

Member Function Documentation

◆ Begin() [1/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
Iterator itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::Begin ( )
inline

Returns a const iterator for the neighborhood which points to the first pixel in the neighborhood.

Definition at line 245 of file itkShapedNeighborhoodIterator.h.

◆ Begin() [2/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
Iterator itk::Neighborhood< TPixel, VDimension, TAllocator >::Begin
inline

Definition at line 173 of file itkNeighborhood.h.

◆ Begin() [3/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
ConstIterator itk::Neighborhood< TPixel, VDimension, TAllocator >::Begin
inline

Definition at line 183 of file itkNeighborhood.h.

◆ End() [1/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
Iterator itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::End ( )
inline

Returns a const iterator for the neighborhood which points to the first pixel in the neighborhood.

Definition at line 250 of file itkShapedNeighborhoodIterator.h.

◆ End() [2/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
Iterator itk::Neighborhood< TPixel, VDimension, TAllocator >::End
inline

STL-style iterator support.

Definition at line 168 of file itkNeighborhood.h.

◆ End() [3/3]

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
ConstIterator itk::Neighborhood< TPixel, VDimension, TAllocator >::End
inline

Definition at line 178 of file itkNeighborhood.h.

◆ operator=()

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
Self& itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::operator= ( const Self orig)
inline

Assignment operator

Definition at line 235 of file itkShapedNeighborhoodIterator.h.

Member Data Documentation

◆ Dimension

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
constexpr unsigned int itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::Dimension = TImage::ImageDimension
staticconstexpr

Save the image dimension.

Definition at line 159 of file itkShapedNeighborhoodIterator.h.

◆ Superclass

template<typename TImage, typename TBoundaryCondition = ZeroFluxNeumannBoundaryCondition<TImage>>
friend itk::ShapedNeighborhoodIterator< TImage, TBoundaryCondition >::Superclass
protected

Definition at line 260 of file itkShapedNeighborhoodIterator.h.


The documentation for this class was generated from the following file:
itk::ConstShapedNeighborhoodIterator::ImageType
TImage ImageType
Definition: itkConstShapedNeighborhoodIterator.h:94
itk::Neighborhood< TImage::InternalPixelType *, TImage::ImageDimension >::Iterator
typename AllocatorType::iterator Iterator
Definition: itkNeighborhood.h:75
itk::ShapedNeighborhoodIterator< ImageType >::OffsetType
Offset< VDimension > OffsetType
Definition: itkNeighborhood.h:86