Class IntervalIterator

All Implemented Interfaces:
Dimensions, EuclideanSpace, Interval, Iterator, Localizable, RealInterval, RealLocalizable
Direct Known Subclasses:
LocalizingIntervalIterator, OffsetableIntervalIterator, ZeroMinIntervalIterator

public class IntervalIterator extends AbstractInterval implements Iterator, Localizable
Use this class to iterate a virtual Interval in flat order, that is: row by row, plane by plane, cube by cube, ... This is useful for iterating an arbitrary interval in a defined order. For that, connect an IntervalIterator to a Positionable.

 ...
 IntervalIterator i = new IntervalIterator(image);
 RandomAccess<T> s = image.randomAccess();
 while (i.hasNext()) {
   i.fwd();
   s.setPosition(i);
   s.get().performOperation(...);
   ...
 }
 ...
 
Note that IntervalIterator is the right choice in situations where not for each pixel you want to localize and/or set the Positionable [Sampler], that is in a sparse sampling situation. For localizing at each iteration step (as in the simplified example above), use LocalizingIntervalIterator instead.
Author:
Stephan Preibisch, Stephan Saalfeld
  • Field Details

    • dimensions

      protected final long[] dimensions
    • steps

      protected final long[] steps
    • lastIndex

      protected final long lastIndex
    • index

      protected long index
  • Constructor Details

    • IntervalIterator

      public IntervalIterator(long[] dimensions)
      Iterates an Interval of the given dimensions with min= 0n
      Parameters:
      dimensions -
    • IntervalIterator

      public IntervalIterator(int[] dimensions)
      Iterates an Interval of the given dimensions with min= 0n
      Parameters:
      dimensions -
    • IntervalIterator

      public IntervalIterator(long[] min, long[] max)
      Iterates an Interval with given min and max.
      Parameters:
      min -
      max -
    • IntervalIterator

      public IntervalIterator(int[] min, int[] max)
      Iterates an Interval with given min and max.
      Parameters:
      min -
      max -
    • IntervalIterator

      public IntervalIterator(Interval interval)
      Iterates a given Interval.
      Parameters:
      interval -
  • Method Details

    • create

      public static IntervalIterator create(Interval interval)
    • jumpFwd

      public void jumpFwd(long i)
      Description copied from interface: Iterator
      Move steps × forward.
      Specified by:
      jumpFwd in interface Iterator
      Parameters:
      i - number of steps to move forward
    • fwd

      public void fwd()
      Description copied from interface: Iterator
      Move forward.
      Specified by:
      fwd in interface Iterator
    • reset

      public void reset()
      Description copied from interface: Iterator
      Reset the Iterator, that is put it to where it would be if newly created.
      Specified by:
      reset in interface Iterator
    • hasNext

      public boolean hasNext()
      Description copied from interface: Iterator
      Returns true if another step forward is possible.
      Specified by:
      hasNext in interface Iterator
      Returns:
      true, if there is another step forward is possible, otherwise false
    • getIndex

      public long getIndex()
      Returns:
      - the current iteration index
    • getLongPosition

      public long getLongPosition(int dim)
      Description copied from interface: Localizable
      Return the current position in a given dimension.
      Specified by:
      getLongPosition in interface Localizable
      Parameters:
      dim - dimension
      Returns:
      dimension of current position
    • localize

      public void localize(long[] position)
      Description copied from interface: Localizable
      Write the current position into the passed array.
      Specified by:
      localize in interface Localizable
      Parameters:
      position - receives current position
    • getIntPosition

      public int getIntPosition(int dim)
      Description copied from interface: Localizable
      Return the current position in a given dimension.
      Specified by:
      getIntPosition in interface Localizable
      Parameters:
      dim - dimension
      Returns:
      dimension of current position
    • localize

      public void localize(int[] position)
      Description copied from interface: Localizable
      Write the current position into the passed array.
      Specified by:
      localize in interface Localizable
      Parameters:
      position - receives current position
    • getDoublePosition

      public double getDoublePosition(int dim)
      Description copied from interface: RealLocalizable
      Return the current position in a given dimension.
      Specified by:
      getDoublePosition in interface RealLocalizable
      Parameters:
      dim - dimension
      Returns:
      dimension of current position
    • getFloatPosition

      public float getFloatPosition(int dim)
      Description copied from interface: RealLocalizable
      Return the current position in a given dimension.
      Specified by:
      getFloatPosition in interface RealLocalizable
      Parameters:
      dim - dimension
      Returns:
      dimension of current position
    • localize

      public void localize(float[] position)
      Description copied from interface: RealLocalizable
      Write the current position into the passed array.
      Specified by:
      localize in interface RealLocalizable
      Parameters:
      position - receives current position
    • localize

      public void localize(double[] position)
      Description copied from interface: RealLocalizable
      Write the current position into the passed array.
      Specified by:
      localize in interface RealLocalizable
      Parameters:
      position - receives current position
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • dimension

      public long dimension(int d)
      Description copied from interface: Dimensions
      Get the number of pixels in a given dimension d.
      Specified by:
      dimension in interface Dimensions
      Overrides:
      dimension in class AbstractInterval
    • dimensions

      public void dimensions(long[] dim)
      Description copied from interface: Dimensions
      Write the number of pixels in each dimension into long[].
      Specified by:
      dimensions in interface Dimensions
      Overrides:
      dimensions in class AbstractInterval