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 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

Functions

void swap(dip::ImageSliceIterator& other) noexcept
Swap
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 IsAtEnd() const -> bool
Test to see if the iterator reached past the last plane
auto Coordinate() const -> dip::uint
Return the current position
auto SetCoordinate(dip::uint coord) -> dip::ImageSliceIterator&
Set the iterator to point at a different location in the image
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.

Operators

auto operator*() -> dip::Image&
Dereference
auto operator->() -> dip::Image*
Dereference
auto operator++() -> dip::ImageSliceIterator&
Pre-increment
auto operator++(int ) -> dip::ImageSliceIterator
Post-increment
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&
Increment by n
auto operator+=(dip::uint n) -> dip::ImageSliceIterator&
Increment by n
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::ImageSliceIterator const& it2) const -> dip::ImageSliceIterator::difference_type
Difference between iterators
auto operator==(dip::ImageSliceIterator const& other) const -> bool
Equality comparison
auto operator!=(dip::ImageSliceIterator const& other) const -> bool
Inequality comparison
auto operator>(dip::ImageSliceIterator const& other) const -> bool
Larger than comparison
auto operator<(dip::ImageSliceIterator const& other) const -> bool
Smaller than comparison
auto operator>=(dip::ImageSliceIterator const& other) const -> bool
Not smaller than comparison
auto operator<=(dip::ImageSliceIterator const& other) const -> bool
Not larger than comparison
auto operator bool() const -> bool explicit
Test to see if the iterator is valid and can be dereferenced