Skip to content

Commit

Permalink
bugfix: Do not use Views methods in IterableTransformBuilder.
Browse files Browse the repository at this point in the history
This caused infinite recursion in IntervalView.size()
  • Loading branch information
tpietzsch committed May 7, 2024
1 parent 0ed5e33 commit 8dcb1d1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}
}

0 comments on commit 8dcb1d1

Please sign in to comment.