dip::ImageSliceIterator class

An iterator for slice-by-slice processing of an image. Use it to process a multi-dimensional image as a series of lower-dimensional images.

Dereferencing the iterator yields a reference to an image that encapsulates a plane in the original image. This image has the protected flag set so that it cannot be stripped or reforged.

The iterator can be moved to any arbitrary slice with a non-negative index (so you cannot decrement it below 0, the first slice; if you try nothing will happen), even slices past the last one. If the iterator points at a slice that does not exist, the iterator will test false, but it will still be a valid iterator that can be manipulated. Do not dereference such an iterator!

dip::ImageSliceIterator it( img, 2 );
do {
   // do something with the image *it here.
} while( ++it );

The function dip::ImageSliceEndIterator creates an iterator that points at a slice one past the last, and so is a end iterator. Because it is not possible to decrement below 0, a loop that iterates in reverse order must test the dip::ImageSliceIterator::Coordinate for equality to zero:

dip::ImageSliceEndIterator it( img, 2 );
do {
   --it;
   // do something with the image *it here.
} while( it.Coordinate() != 0 );

Note that when the original image is stripped or reforged, the iterator is still valid and holds on to the original data segment.

Satisfies all the requirements for a mutable ForwardIterator. Additionally, it behaves like a RandomAccessIterator except for the indexing operator [], which would be less efficient in use and therefore it’s better to not offer it.

Constructors, destructors, assignment and conversion operators

ImageSliceIterator() defaulted
Default constructor yields an invalid iterator that cannot be dereferenced or used in any way
ImageSliceIterator(dip::Image const& image, dip::uint procDim)
To construct a useful iterator, provide an image and a processing dimension

Aliases

using difference_type = dip::sint
The type of distances between iterators
using iterator_category = std::forward_iterator_tag
Iterator category
using pointer = dip::Image*
The type of a pointer to value_type
using reference = dip::Image&
The type of a reference to value_type
using value_type = dip::Image
The type obtained when dereferencing the iterator

Functions

auto Coordinate() const -> dip::uint
Return the current position
auto IsAtEnd() const -> bool
Test to see if the iterator reached past the last plane
auto IsValid() const -> bool
Test to see if the iterator is valid (i.e. not default-constructed); it can still be at end, and thus not dereferenceable
auto ProcessingDimension() const -> dip::uint
Return the processing dimension, the direction over which the iterator iterates
auto Reset() -> dip::ImageSliceIterator&
Reset the iterator to the first image plane (as it was when the iterator first was created)
auto Set(dip::uint plane) -> dip::ImageSliceIterator&
Set the iterator to index plane. If plane is outside the image domain, the iterator is still valid, but should not be dereferenced.
auto SetCoordinate(dip::uint coord) -> dip::ImageSliceIterator&
Set the iterator to point at a different location in the image
void swap(dip::ImageSliceIterator& other) noexcept
Swap

Operators

auto operator bool() const -> bool explicit
Test to see if the iterator is valid and can be dereferenced
auto operator!=(dip::ImageSliceIterator const& other) const -> bool
Inequality comparison
auto operator*() -> dip::Image&
Dereference
auto operator++() -> dip::ImageSliceIterator&
Pre-increment
auto operator++(int ) -> dip::ImageSliceIterator
Post-increment
auto operator+=(dip::ImageSliceIterator::difference_type n) -> dip::ImageSliceIterator&
Increment by n
auto operator+=(dip::uint n) -> dip::ImageSliceIterator&
Increment by n
auto operator-(dip::ImageSliceIterator const& it2) const -> dip::ImageSliceIterator::difference_type
Difference between iterators
auto operator--() -> dip::ImageSliceIterator&
Pre-decrement, but never past the first slice
auto operator--(int ) -> dip::ImageSliceIterator
Post-decrement, but never past the first slice
auto operator-=(dip::ImageSliceIterator::difference_type n) -> dip::ImageSliceIterator&
Decrement by n, but never moves the iterator to before the first slice
auto operator-=(dip::uint n) -> dip::ImageSliceIterator&
Decrement by n, but never moves the iterator to before the first slice
auto operator->() -> dip::Image*
Dereference
auto operator<(dip::ImageSliceIterator const& other) const -> bool
Smaller than comparison
auto operator<=(dip::ImageSliceIterator const& other) const -> bool
Not larger than comparison
auto operator==(dip::ImageSliceIterator const& other) const -> bool
Equality comparison
auto operator>(dip::ImageSliceIterator const& other) const -> bool
Larger than comparison
auto operator>=(dip::ImageSliceIterator const& other) const -> bool
Not smaller than comparison

Alias documentation

using iterator_category = std::forward_iterator_tag

Iterator category

using value_type = dip::Image

The type obtained when dereferencing the iterator

using difference_type = dip::sint

The type of distances between iterators

using reference = dip::Image&

The type of a reference to value_type

using pointer = dip::Image*

The type of a pointer to value_type

Function documentation

ImageSliceIterator( ) defaulted

Default constructor yields an invalid iterator that cannot be dereferenced or used in any way

ImageSliceIterator( dip::Image const& image, dip::uint procDim)

To construct a useful iterator, provide an image and a processing dimension

void swap( dip::ImageSliceIterator& other) noexcept

Swap

bool IsValid( ) const

Test to see if the iterator is valid (i.e. not default-constructed); it can still be at end, and thus not dereferenceable

bool IsAtEnd( ) const

Test to see if the iterator reached past the last plane

dip::uint Coordinate( ) const

Return the current position

dip::ImageSliceIterator& SetCoordinate( dip::uint coord)

Set the iterator to point at a different location in the image

dip::uint ProcessingDimension( ) const

Return the processing dimension, the direction over which the iterator iterates

dip::ImageSliceIterator& Reset( )

Reset the iterator to the first image plane (as it was when the iterator first was created)

dip::ImageSliceIterator& Set( dip::uint plane)

Set the iterator to index plane. If plane is outside the image domain, the iterator is still valid, but should not be dereferenced.

dip::Image& operator*( )

Dereference

dip::Image* operator->( )

Dereference

dip::ImageSliceIterator operator++( int )

Post-increment

dip::ImageSliceIterator& operator--( )

Pre-decrement, but never past the first slice

dip::ImageSliceIterator operator--( int )

Post-decrement, but never past the first slice

dip::ImageSliceIterator& operator-=( dip::ImageSliceIterator::difference_type n)

Decrement by n, but never moves the iterator to before the first slice

dip::ImageSliceIterator& operator-=( dip::uint n)

Decrement by n, but never moves the iterator to before the first slice

dip::ImageSliceIterator::difference_type operator-( dip::ImageSliceIterator const& it2) const

Difference between iterators

bool operator==( dip::ImageSliceIterator const& other) const

Equality comparison

bool operator!=( dip::ImageSliceIterator const& other) const

Inequality comparison

bool operator>( dip::ImageSliceIterator const& other) const

Larger than comparison

bool operator<( dip::ImageSliceIterator const& other) const

Smaller than comparison

bool operator>=( dip::ImageSliceIterator const& other) const

Not smaller than comparison

bool operator<=( dip::ImageSliceIterator const& other) const

Not larger than comparison

bool operator bool( ) const explicit

Test to see if the iterator is valid and can be dereferenced

dip::ImageSliceIterator dip::operator+( dip::ImageSliceIterator it, dip::sint n)

Increment an image slice iterator by n

dip::ImageSliceIterator dip::operator+( dip::ImageSliceIterator it, dip::uint n)

Increment an image slice iterator by n

dip::ImageSliceIterator dip::operator-( dip::ImageSliceIterator it, dip::sint n)

Decrement an image slice iterator by n, but never moves the iterator to before the first slide

dip::ImageSliceIterator dip::operator-( dip::ImageSliceIterator it, dip::uint n)

Decrement an image slice iterator by n, but never moves the iterator to before the first slide

dip::ImageSliceIterator dip::ImageSliceEndIterator( dip::Image const& image, dip::uint procDim)

Constructs an end iterator corresponding to a dip::ImageSliceIterator