diff --git a/src/main/java/net/imglib2/blocks/PrimitiveBlocksUtils.java b/src/main/java/net/imglib2/blocks/PrimitiveBlocksUtils.java index 117e9c2dc..51fec5cd9 100644 --- a/src/main/java/net/imglib2/blocks/PrimitiveBlocksUtils.java +++ b/src/main/java/net/imglib2/blocks/PrimitiveBlocksUtils.java @@ -35,15 +35,11 @@ import java.util.Arrays; import java.util.function.Supplier; -import net.imglib2.Interval; -import net.imglib2.Point; -import net.imglib2.RandomAccessible; import net.imglib2.img.array.ArrayImg; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.img.basictypeaccess.array.ArrayDataAccess; import net.imglib2.transform.integer.MixedTransform; import net.imglib2.type.NativeType; -import net.imglib2.type.Type; import net.imglib2.util.CloseableThreadLocal; class PrimitiveBlocksUtils @@ -86,15 +82,6 @@ static < T extends NativeType< T > > Object extractOobValue( final T type, final return null; } - // TODO replace with ra.getType() when that is available in imglib2 core - static < T extends Type< T > > T getType( RandomAccessible< T > ra ) - { - final Point p = new Point( ra.numDimensions() ); - if ( ra instanceof Interval ) - ( ( Interval ) ra ).min( p ); - return ra.getAt( p ).createVariable(); - } - /** * Computes the inverse of (@code transform}. The {@code MixedTransform * transform} is a pure axis permutation followed by inversion of some axes, diff --git a/src/main/java/net/imglib2/blocks/ViewAnalyzer.java b/src/main/java/net/imglib2/blocks/ViewAnalyzer.java index 10cbb8019..802a47aba 100644 --- a/src/main/java/net/imglib2/blocks/ViewAnalyzer.java +++ b/src/main/java/net/imglib2/blocks/ViewAnalyzer.java @@ -54,13 +54,12 @@ import net.imglib2.transform.integer.MixedTransform; import net.imglib2.type.NativeType; import net.imglib2.type.Type; +import net.imglib2.util.Cast; import net.imglib2.util.Intervals; import net.imglib2.view.ExtendedRandomAccessibleInterval; import net.imglib2.view.IntervalView; import net.imglib2.view.MixedTransformView; -import static net.imglib2.blocks.PrimitiveBlocksUtils.getType; - class ViewAnalyzer { /** @@ -90,7 +89,7 @@ private ViewAnalyzer( final RandomAccessible< ? > ra ) */ private < T extends Type< T > > boolean checkViewTypeSupported() { - final T type = getType( ( RandomAccessible< T > ) ra ); + final T type = Cast.unchecked( ra.getType() ); if ( type instanceof NativeType && ( ( NativeType ) type ).getEntitiesPerPixel().getRatio() == 1 ) { @@ -589,16 +588,16 @@ private boolean splitTransform() private < T extends NativeType< T >, R extends NativeType< R > > ViewProperties< T, R > getViewProperties() { - final T viewType = getType( ( RandomAccessible< T > ) ra ); - final NativeImg< R, ? > root = ( NativeImg< R, ? > ) nodes.get( nodes.size() - 1 ).view(); + final T viewType = Cast.unchecked( ra.getType() ); + final NativeImg< R, ? > root = Cast.unchecked( nodes.get( nodes.size() - 1 ).view() ); final R rootType = root.createLinkedType(); return new ViewProperties<>( viewType, root, rootType, oobExtension, transform, permuteInvertTransform, converterSupplier ); } private < T extends NativeType< T > > FallbackProperties< T > getFallbackProperties() { - final RandomAccessible< T > view = ( RandomAccessible< T > ) ra; - return new FallbackProperties<>( getType( view ), view ); + final RandomAccessible< T > view = Cast.unchecked( ra ); + return new FallbackProperties<>( view.getType(), view ); } public static < T extends NativeType< T >, R extends NativeType< R > > ViewPropertiesOrError< T, R > getViewProperties( RandomAccessible< T > view )