From eb42ae139fb5e25880f329b331cce640bd6dcff6 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 26 Mar 2024 16:32:47 +0100 Subject: [PATCH] Replace usage of Util.getTypeFromInterval(rai) with rai.getType() --- .../imglib2/converter/RealTypeConverters.java | 7 ++-- src/main/java/net/imglib2/img/ImgView.java | 2 +- .../ClampingNLinearInterpolatorFactory.java | 6 ++-- .../OutOfBoundsMirrorExpWindowing.java | 2 +- .../java/net/imglib2/test/RandomImgs.java | 3 +- src/main/java/net/imglib2/util/Util.java | 2 -- src/main/java/net/imglib2/view/Views.java | 32 +++++++++---------- .../java/net/imglib2/test/RandomImgsTest.java | 3 +- 8 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/main/java/net/imglib2/converter/RealTypeConverters.java b/src/main/java/net/imglib2/converter/RealTypeConverters.java index ffef87658..7c3600157 100644 --- a/src/main/java/net/imglib2/converter/RealTypeConverters.java +++ b/src/main/java/net/imglib2/converter/RealTypeConverters.java @@ -44,7 +44,6 @@ import net.imglib2.type.numeric.integer.UnsignedByteType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Intervals; -import net.imglib2.util.Util; import net.imglib2.view.IntervalView; import net.imglib2.view.Views; @@ -74,8 +73,8 @@ public static void copyFromTo( ) { IntervalView< ? extends RealType< ? > > sourceInterval = Views.interval( source, destination ); - RealType< ? > s = Util.getTypeFromInterval( sourceInterval ); - RealType< ? > d = Util.getTypeFromInterval( destination ); + RealType< ? > s = sourceInterval.getType(); + RealType< ? > d = destination.getType(); Converter< RealType< ? >, RealType< ? > > copy = getConverter( s, d ); boolean useMultiThreading = Intervals.numElements(destination) >= 20_000; LoopBuilder.setImages( sourceInterval, destination ).multiThreaded( useMultiThreading ).forEachPixel( copy::convert ); @@ -102,7 +101,7 @@ public static < T extends RealType< T > > RandomAccessibleInterval< T > convert( RandomAccessibleInterval< ? extends RealType< ? > > image, T pixelType ) { - RealType< ? > in = Util.getTypeFromInterval( image ); + RealType< ? > in = image.getType(); Converter< RealType< ? >, T > converter = getConverter( in, pixelType ); return Converters.convert( image, converter, pixelType ); } diff --git a/src/main/java/net/imglib2/img/ImgView.java b/src/main/java/net/imglib2/img/ImgView.java index b4443a87e..242fb7502 100644 --- a/src/main/java/net/imglib2/img/ImgView.java +++ b/src/main/java/net/imglib2/img/ImgView.java @@ -176,7 +176,7 @@ public static < T extends Type< T > > Img< T > wrap( final RandomAccessibleInter return ( Img< T > ) accessible; else { - final T type = Util.getTypeFromInterval( accessible ); + final T type = accessible.getType(); final ImgFactory< T > factory = Util.getSuitableImgFactory( accessible, type ); return wrap( accessible, factory ); } diff --git a/src/main/java/net/imglib2/interpolation/randomaccess/ClampingNLinearInterpolatorFactory.java b/src/main/java/net/imglib2/interpolation/randomaccess/ClampingNLinearInterpolatorFactory.java index 2c7235f27..18de89013 100644 --- a/src/main/java/net/imglib2/interpolation/randomaccess/ClampingNLinearInterpolatorFactory.java +++ b/src/main/java/net/imglib2/interpolation/randomaccess/ClampingNLinearInterpolatorFactory.java @@ -11,13 +11,13 @@ * %% * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -56,7 +56,7 @@ public class ClampingNLinearInterpolatorFactory< T extends NumericType< T > > im @Override public RealRandomAccess< T > create( final RandomAccessible< T > randomAccessible ) { - final T type = randomAccessible.randomAccess().get(); + final T type = randomAccessible.getType(); if ( type instanceof RealType ) { if ( type instanceof Volatile ) diff --git a/src/main/java/net/imglib2/outofbounds/OutOfBoundsMirrorExpWindowing.java b/src/main/java/net/imglib2/outofbounds/OutOfBoundsMirrorExpWindowing.java index 9dd04e792..e0ca432bd 100644 --- a/src/main/java/net/imglib2/outofbounds/OutOfBoundsMirrorExpWindowing.java +++ b/src/main/java/net/imglib2/outofbounds/OutOfBoundsMirrorExpWindowing.java @@ -81,7 +81,7 @@ public < F extends Interval & RandomAccessible< T > > OutOfBoundsMirrorExpWindow * Sun javac fails to infer return types, so make it explicit, see * https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379 */ - this.type = Util.< T, F >getTypeFromInterval( f ).createVariable(); + this.type = f.getType().createVariable(); this.fadeOutDistance = fadeOutDistance; this.exponent = exponent; this.max = new long[ n ]; diff --git a/src/main/java/net/imglib2/test/RandomImgs.java b/src/main/java/net/imglib2/test/RandomImgs.java index cba5b1277..2c77d4dbd 100644 --- a/src/main/java/net/imglib2/test/RandomImgs.java +++ b/src/main/java/net/imglib2/test/RandomImgs.java @@ -54,7 +54,6 @@ import net.imglib2.type.numeric.real.DoubleType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Intervals; -import net.imglib2.util.Util; import net.imglib2.view.Views; import java.util.Random; @@ -105,7 +104,7 @@ public < T extends NativeType< T > > Img< T > nextImage( final T type, final lon public < I extends RandomAccessibleInterval< T >, T > I randomize( final I image ) { - final T type = Util.getTypeFromInterval( image ); + final T type = image.getType(); Views.iterable( image ).forEach( randomSetter( type ) ); return image; } diff --git a/src/main/java/net/imglib2/util/Util.java b/src/main/java/net/imglib2/util/Util.java index c18484dc4..5a7f3c055 100644 --- a/src/main/java/net/imglib2/util/Util.java +++ b/src/main/java/net/imglib2/util/Util.java @@ -38,12 +38,10 @@ import net.imglib2.Interval; import net.imglib2.IterableInterval; import net.imglib2.Localizable; -import net.imglib2.RandomAccess; import net.imglib2.RandomAccessible; import net.imglib2.RandomAccessibleInterval; import net.imglib2.RealInterval; import net.imglib2.RealLocalizable; -import net.imglib2.RealRandomAccess; import net.imglib2.RealRandomAccessible; import net.imglib2.exception.IncompatibleTypeException; import net.imglib2.img.Img; diff --git a/src/main/java/net/imglib2/view/Views.java b/src/main/java/net/imglib2/view/Views.java index 192a95440..d57ded298 100644 --- a/src/main/java/net/imglib2/view/Views.java +++ b/src/main/java/net/imglib2/view/Views.java @@ -223,7 +223,7 @@ public static < T extends Type< T >, F extends RandomAccessibleInterval< T > > E */ public static < T extends RealType< T >, F extends RandomAccessibleInterval< T > > ExtendedRandomAccessibleInterval< T, F > extendValue( final F source, final float value ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.setReal( value ); return Views.extendValue( source, extension ); } @@ -242,7 +242,7 @@ public static < T extends RealType< T >, F extends RandomAccessibleInterval< T > */ public static < T extends RealType< T >, F extends RandomAccessibleInterval< T > > ExtendedRandomAccessibleInterval< T, F > extendValue( final F source, final double value ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.setReal( value ); return Views.extendValue( source, extension ); } @@ -261,7 +261,7 @@ public static < T extends RealType< T >, F extends RandomAccessibleInterval< T > */ public static < T extends IntegerType< T >, F extends RandomAccessibleInterval< T > > ExtendedRandomAccessibleInterval< T, F > extendValue( final F source, final int value ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.setInteger( value ); return Views.extendValue( source, extension ); } @@ -280,7 +280,7 @@ public static < T extends IntegerType< T >, F extends RandomAccessibleInterval< */ public static < T extends IntegerType< T >, F extends RandomAccessibleInterval< T > > ExtendedRandomAccessibleInterval< T, F > extendValue( final F source, final long value ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.setInteger( value ); return Views.extendValue( source, extension ); } @@ -299,7 +299,7 @@ public static < T extends IntegerType< T >, F extends RandomAccessibleInterval< */ public static < T extends BooleanType< T >, F extends RandomAccessibleInterval< T > > ExtendedRandomAccessibleInterval< T, F > extendValue( final F source, final boolean value ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.set( value ); return Views.extendValue( source, extension ); } @@ -316,7 +316,7 @@ public static < T extends BooleanType< T >, F extends RandomAccessibleInterval< */ public static < T extends NumericType< T >, F extends RandomAccessibleInterval< T > > ExtendedRandomAccessibleInterval< T, F > extendZero( final F source ) { - final T zero = Util.getTypeFromInterval( source ).createVariable(); + final T zero = source.getType().createVariable(); zero.setZero(); return new ExtendedRandomAccessibleInterval<>( source, new OutOfBoundsConstantValueFactory<>( zero ) ); } @@ -337,7 +337,7 @@ public static < T extends NumericType< T >, F extends RandomAccessibleInterval< */ public static < T extends RealType< T >, F extends RandomAccessibleInterval< T > > ExtendedRandomAccessibleInterval< T, F > extendRandom( final F source, final double min, final double max ) { - return new ExtendedRandomAccessibleInterval<>( source, new OutOfBoundsRandomValueFactory<>( Util.getTypeFromInterval( source ), min, max ) ); + return new ExtendedRandomAccessibleInterval<>( source, new OutOfBoundsRandomValueFactory<>( source.getType(), min, max ) ); } /** @@ -838,9 +838,9 @@ public static boolean isZeroMin( final Interval interval ) @SuppressWarnings( "unchecked" ) public static < T > IterableInterval< T > iterable( final RandomAccessibleInterval< T > randomAccessibleInterval ) { - if ( IterableInterval.class.isInstance( randomAccessibleInterval ) ) + if ( randomAccessibleInterval instanceof IterableInterval ) { - final Class< ? > raiType = Util.getTypeFromInterval( randomAccessibleInterval ).getClass(); + final Class< ? > raiType = randomAccessibleInterval.getType().getClass(); final Iterator< ? > iter = ( ( IterableInterval< ? > ) randomAccessibleInterval ).iterator(); final Object o = iter.hasNext() ? iter.next() : null; if ( raiType.isInstance( o ) ) @@ -863,9 +863,9 @@ public static < T > IterableInterval< T > iterable( final RandomAccessibleInterv @SuppressWarnings( "unchecked" ) public static < T > IterableInterval< T > flatIterable( final RandomAccessibleInterval< T > randomAccessibleInterval ) { - if ( IterableInterval.class.isInstance( randomAccessibleInterval ) && FlatIterationOrder.class.isInstance( ( ( IterableInterval< T > ) randomAccessibleInterval ).iterationOrder() ) ) + if ( randomAccessibleInterval instanceof IterableInterval && ( ( IterableInterval< T > ) randomAccessibleInterval ).iterationOrder() instanceof FlatIterationOrder ) { - final Class< ? > raiType = Util.getTypeFromInterval( randomAccessibleInterval ).getClass(); + final Class< ? > raiType = randomAccessibleInterval.getType().getClass(); final Iterator< ? > iter = ( ( IterableInterval< ? > ) randomAccessibleInterval ).iterator(); final Object o = iter.hasNext() ? iter.next() : null; if ( raiType.isInstance( o ) ) @@ -1473,7 +1473,7 @@ public static < T extends Type< T > > IntervalView< T > expandValue( final Rando */ public static < T extends RealType< T > > IntervalView< T > expandValue( final RandomAccessibleInterval< T > source, final float value, final long... border ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.setReal( value ); return Views.expandValue( source, extension, border ); } @@ -1491,7 +1491,7 @@ public static < T extends RealType< T > > IntervalView< T > expandValue( final R */ public static < T extends RealType< T > > IntervalView< T > expandValue( final RandomAccessibleInterval< T > source, final double value, final long... border ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.setReal( value ); return Views.expandValue( source, extension, border ); } @@ -1509,7 +1509,7 @@ public static < T extends RealType< T > > IntervalView< T > expandValue( final R */ public static < T extends IntegerType< T > > IntervalView< T > expandValue( final RandomAccessibleInterval< T > source, final int value, final long... border ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.setInteger( value ); return Views.expandValue( source, extension, border ); } @@ -1527,7 +1527,7 @@ public static < T extends IntegerType< T > > IntervalView< T > expandValue( fina */ public static < T extends IntegerType< T > > IntervalView< T > expandValue( final RandomAccessibleInterval< T > source, final long value, final long... border ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.setInteger( value ); return Views.expandValue( source, extension, border ); } @@ -1545,7 +1545,7 @@ public static < T extends IntegerType< T > > IntervalView< T > expandValue( fina */ public static < T extends BooleanType< T > > IntervalView< T > expandValue( final RandomAccessibleInterval< T > source, final boolean value, final long... border ) { - final T extension = Util.getTypeFromInterval( source ).createVariable(); + final T extension = source.getType().createVariable(); extension.set( value ); return Views.expandValue( source, extension, border ); } diff --git a/src/test/java/net/imglib2/test/RandomImgsTest.java b/src/test/java/net/imglib2/test/RandomImgsTest.java index 6175c4fca..3192870f9 100644 --- a/src/test/java/net/imglib2/test/RandomImgsTest.java +++ b/src/test/java/net/imglib2/test/RandomImgsTest.java @@ -57,7 +57,6 @@ import net.imglib2.type.numeric.real.DoubleType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Intervals; -import net.imglib2.util.Util; import net.imglib2.view.Views; import org.junit.Test; @@ -139,7 +138,7 @@ private < T extends IntegerType< T > & NativeType< T > > void createAndTestInteg private < T extends IntegerType< T > & NativeType< T > > void testIsRandomImageIntegerType( RandomAccessibleInterval< T > image ) { - T type = Util.getTypeFromInterval( image ); + T type = image.getType(); double min = type.getMinValue(); double max = type.getMaxValue(); double actualMin = fold( Double.POSITIVE_INFINITY, Math::min, Views.iterable( image ) );