diff --git a/src/main/java/net/imglib2/view/RandomAccessibleIntervalCursor.java b/src/main/java/net/imglib2/view/RandomAccessibleIntervalCursor.java index 2cf7c7156..c340b8a18 100644 --- a/src/main/java/net/imglib2/view/RandomAccessibleIntervalCursor.java +++ b/src/main/java/net/imglib2/view/RandomAccessibleIntervalCursor.java @@ -66,9 +66,14 @@ public final class RandomAccessibleIntervalCursor< T > extends AbstractInterval private long maxIndexOnLine; public < I extends RandomAccessible< T > & Interval > RandomAccessibleIntervalCursor( final I interval ) + { + this( interval, interval ); + } + + public RandomAccessibleIntervalCursor( final RandomAccessible< T > randomAccessible, final Interval interval ) { super( interval ); - randomAccess = interval.randomAccess(); + randomAccess = randomAccessible.randomAccess(); dimensions = new long[ n ]; dimensions( dimensions ); tmp = new long[ n ]; diff --git a/src/main/java/net/imglib2/view/iteration/IterableTransformBuilder.java b/src/main/java/net/imglib2/view/iteration/IterableTransformBuilder.java index 69ae48fee..495c862f9 100644 --- a/src/main/java/net/imglib2/view/iteration/IterableTransformBuilder.java +++ b/src/main/java/net/imglib2/view/iteration/IterableTransformBuilder.java @@ -46,8 +46,8 @@ import net.imglib2.transform.integer.SlicingTransform; import net.imglib2.util.Intervals; import net.imglib2.view.IterableRandomAccessibleInterval; +import net.imglib2.view.RandomAccessibleIntervalCursor; import net.imglib2.view.TransformBuilder; -import net.imglib2.view.Views; /** * Simplifies View cascades to provide the most efficient {@link Cursor}. @@ -209,6 +209,44 @@ public T getType() } } + private class IterableIntervalView extends AbstractWrappedInterval< Interval > implements IterableInterval< T > + { + private final RandomAccessible< T > randomAccessible; + + private final long size; + + public IterableIntervalView( final RandomAccessible< T > randomAccessible, final Interval interval ) + { + super( interval ); + this.randomAccessible = randomAccessible; + size = Intervals.numElements( interval ); + } + + @Override + public long size() + { + return size; + } + + @Override + public FlatIterationOrder iterationOrder() + { + return new FlatIterationOrder( sourceInterval ); + } + + @Override + public Cursor< T > cursor() + { + return new RandomAccessibleIntervalCursor<>( randomAccessible, sourceInterval ); + } + + @Override + public Cursor< T > localizingCursor() + { + return cursor(); + } + } + /** * Create an {@link IterableInterval} on the {@link Interval} specified in * the constructor of the {@link RandomAccessible} specified in the @@ -272,6 +310,7 @@ else if ( transforms.size() == 1 && SlicingTransform.class.isInstance( transform } } } - return new IterableRandomAccessibleInterval< T >( Views.interval( build(), interval ) ); + + return new IterableIntervalView( build(), interval ); } }