Skip to content

Commit

Permalink
Replace usage of Util.getTypeFromInterval(rai) with rai.getType()
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietzsch committed May 7, 2024
1 parent d23dae8 commit eb42ae1
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 31 deletions.
7 changes: 3 additions & 4 deletions src/main/java/net/imglib2/converter/RealTypeConverters.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/img/ImgView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/imglib2/test/RandomImgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/imglib2/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/net/imglib2/view/Views.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 ) );
}
Expand All @@ -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 ) );
}

/**
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/net/imglib2/test/RandomImgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ) );
Expand Down

0 comments on commit eb42ae1

Please sign in to comment.