Class IntervalIterator
java.lang.Object
net.imglib2.AbstractEuclideanSpace
net.imglib2.AbstractInterval
net.imglib2.iterator.IntervalIterator
- All Implemented Interfaces:
Dimensions, EuclideanSpace, Interval, Iterator, Localizable, RealInterval, RealLocalizable
- Direct Known Subclasses:
LocalizingIntervalIterator, OffsetableIntervalIterator, ZeroMinIntervalIterator
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.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final long[]protected longprotected final longprotected final long[]Fields inherited from class AbstractInterval
max, minFields inherited from class AbstractEuclideanSpace
n -
Constructor Summary
ConstructorsConstructorDescriptionIntervalIterator(int[] dimensions) Iterates anIntervalof the given dimensions with min= 0nIntervalIterator(int[] min, int[] max) Iterates anIntervalwith given min and max.IntervalIterator(long[] dimensions) Iterates anIntervalof the given dimensions with min= 0nIntervalIterator(long[] min, long[] max) Iterates anIntervalwith given min and max.IntervalIterator(Interval interval) Iterates a givenInterval. -
Method Summary
Modifier and TypeMethodDescriptionstatic IntervalIteratorlongdimension(int d) Default implementation ofDimensions.dimension(int).voiddimensions(long[] dim) Write the number of pixels in each dimension into long[].voidfwd()Move forward.doublegetDoublePosition(int dim) Return the current position in a given dimension.floatgetFloatPosition(int dim) Return the current position in a given dimension.longgetIndex()intgetIntPosition(int dim) Return the current position in a given dimension.longgetLongPosition(int dim) Return the current position in a given dimension.booleanhasNext()Returns true if another step forward is possible.voidjumpFwd(long i) Move steps × forward.voidlocalize(double[] position) Write the current position into the passed array.voidlocalize(float[] position) Write the current position into the passed array.voidlocalize(int[] position) Write the current position into the passed array.voidlocalize(long[] position) Write the current position into the passed array.voidreset()Reset theIterator, that is put it to where it would be if newly created.toString()Methods inherited from class AbstractInterval
max, max, max, min, min, min, realMax, realMax, realMax, realMin, realMin, realMinMethods inherited from class AbstractEuclideanSpace
numDimensionsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Dimensions
dimensions, dimensionsAsLongArray, dimensionsAsPointMethods inherited from interface EuclideanSpace
numDimensionsMethods inherited from interface Interval
maxAsLongArray, maxAsPoint, minAsLongArray, minAsPointMethods inherited from interface Localizable
localize, localize, positionAsLongArray, positionAsPointMethods inherited from interface RealInterval
maxAsDoubleArray, maxAsRealPoint, minAsDoubleArray, minAsRealPointMethods inherited from interface RealLocalizable
positionAsDoubleArray, positionAsRealPoint
-
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 anIntervalof the given dimensions with min= 0n- Parameters:
dimensions-
-
IntervalIterator
public IntervalIterator(int[] dimensions) Iterates anIntervalof the given dimensions with min= 0n- Parameters:
dimensions-
-
IntervalIterator
public IntervalIterator(long[] min, long[] max) Iterates anIntervalwith given min and max.- Parameters:
min-max-
-
IntervalIterator
public IntervalIterator(int[] min, int[] max) Iterates anIntervalwith given min and max.- Parameters:
min-max-
-
IntervalIterator
-
-
Method Details
-
create
-
jumpFwd
-
fwd
-
reset
-
hasNext
-
getIndex
public long getIndex()- Returns:
- - the current iteration index
-
getLongPosition
public long getLongPosition(int dim) Description copied from interface:LocalizableReturn the current position in a given dimension.- Specified by:
getLongPositionin interfaceLocalizable- Parameters:
dim- dimension- Returns:
- dimension of current position
-
localize
public void localize(long[] position) Description copied from interface:LocalizableWrite the current position into the passed array.- Specified by:
localizein interfaceLocalizable- Parameters:
position- receives current position, length must be ≥EuclideanSpace.numDimensions()
-
getIntPosition
public int getIntPosition(int dim) Description copied from interface:LocalizableReturn the current position in a given dimension.- Specified by:
getIntPositionin interfaceLocalizable- Parameters:
dim- dimension- Returns:
- dimension of current position
-
localize
public void localize(int[] position) Description copied from interface:LocalizableWrite the current position into the passed array.- Specified by:
localizein interfaceLocalizable- Parameters:
position- receives current position, length must be ≥EuclideanSpace.numDimensions()
-
getDoublePosition
public double getDoublePosition(int dim) Description copied from interface:RealLocalizableReturn the current position in a given dimension.- Specified by:
getDoublePositionin interfaceLocalizable- Specified by:
getDoublePositionin interfaceRealLocalizable- Parameters:
dim- dimension- Returns:
- dimension of current position
-
getFloatPosition
public float getFloatPosition(int dim) Description copied from interface:RealLocalizableReturn the current position in a given dimension.- Specified by:
getFloatPositionin interfaceLocalizable- Specified by:
getFloatPositionin interfaceRealLocalizable- Parameters:
dim- dimension- Returns:
- dimension of current position
-
localize
public void localize(float[] position) Description copied from interface:RealLocalizableWrite the current position into the passed array.- Specified by:
localizein interfaceRealLocalizable- Parameters:
position- receives current position, length must be ≥EuclideanSpace.numDimensions()
-
localize
public void localize(double[] position) Description copied from interface:RealLocalizableWrite the current position into the passed array.- Specified by:
localizein interfaceRealLocalizable- Parameters:
position- receives current position, length must be ≥EuclideanSpace.numDimensions()
-
toString
- Overrides:
toStringin classAbstractInterval
-
dimension
public long dimension(int d) Description copied from interface:IntervalDefault implementation ofDimensions.dimension(int).- Specified by:
dimensionin interfaceDimensions- Specified by:
dimensionin interfaceInterval- Overrides:
dimensionin classAbstractInterval- Parameters:
d-
-
dimensions
public void dimensions(long[] dim) Description copied from interface:DimensionsWrite the number of pixels in each dimension into long[].- Specified by:
dimensionsin interfaceDimensions- Overrides:
dimensionsin classAbstractInterval- Parameters:
dim-
-