Support types module
#include "diplib.h"
dip::Range struct

Used in indexing to indicate a regular subset of pixels along one image dimension.

dip::Range{ start, stop } generates a range of pixels where start and stop are the first and last indices in the range. That is, stop is included in the range. dip::Range{ start } generates a range for a single pixel. For example, dip::Range{ 0 } is the first pixel, and is equivalent to dip::Range{ 0, 0 }. dip::Range{ 0, N - 1 } is a range of the first N pixels.

dip::Range{ start, stop, step } generates a range of pixels where step is the number of pixels between subsequent indices. The pixels indexed are the ones generated by the following loop:

offset = start;
do {
   // use this offset
   offset += step;
} while( offset <= stop );

That is, it is possible that the range does not include stop, if the step would make the range step over stop.

Negative start and stop values indicate offset from the end (-1 is the last pixel, -2 the second to last, etc.): dip::Range{ 5, -6 } indicates a range that skips the first and last five pixels. dip::Range{ -1, -1, 1 } (or simply dip::Range{ -1 } indicates the last pixel only.

dip::Range{ 0, -1 } is equivalent to dip::Range{}, and indicates all pixels.

The dip::Range::Fix method converts the negative start and stop values to actual offsets:

dip::Range r{ 5, -6 };
r.fix( 50 );
// now r.stop == 50 - 6

If stop comes before start, then the range generates pixel indices in the reverse order. That is, negative steps are taken to go from start to stop. step is always a positive integer, the direction of the steps is given solely by the ordering of start and stop.

The begin and end methods yield an iterator that dereferences to the indices defined by the range.

Constructors, destructors, assignment and conversion operators

Range() defaulted
Create a range that indicates all pixels
Range(dip::sint i) explicit
Create a range that indicates a single pixel
Range(dip::sint i, dip::sint j, dip::uint s = 1)
Create a range using two or three values; it indicates all pixels between i and j, both inclusive. The step size defaults to 1.

Classes

class Iterator
An iterator for the range

Functions

void Fix(dip::uint size)
Modify a range so that negative values are assigned correct values according to the given size. Throws if the range falls out of bounds.
auto Size() const -> dip::uint
Get the number of pixels addressed by the range (must be fixed first!).
auto Offset() const -> dip::uint
Get the offset for the range (must be fixed first!).
auto Last() const -> dip::uint
Get the last index in the range (must be fixed first!).
auto Step() const -> dip::sint
Get the signed step size for the range (must be fixed first!).
auto begin() const -> dip::Range::Iterator
Get an iterator to the beginning of the range (must be fixed first!).
auto end() const -> dip::Range::Iterator
Get an iterator to the end of the range (must be fixed first!). This iterator points one past the stop value, as is usual for the end iterator.

Variables

dip::sint start
First index included in range
dip::sint stop
Last index included in range
dip::uint step
Step size when going from start to stop