From 7f4ac98d7c4207e46435befd1c4ac44ec3b8a025 Mon Sep 17 00:00:00 2001 From: Philipp Hanslovsky Date: Fri, 25 Feb 2022 10:10:46 -0500 Subject: [PATCH 01/19] Add RandomAccessibleInterval.getType Open questions: - We cannot deprecate Utils.getTypeFromInterval because it does not use RAI as argument. We could change the argument to RAI but this would be a breaking change (see comment in JavaDoc for that function) - What about getType in other places like RA, RRA, RRARI? - Name preference getType vs type? --- .../net/imglib2/RandomAccessibleInterval.java | 17 +++++- .../net/imglib2/img/AbstractNativeImg.java | 10 ++++ src/main/java/net/imglib2/util/Util.java | 12 ++++ .../imglib2/RandomAccessibleIntervalTest.java | 59 +++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/test/java/net/imglib2/RandomAccessibleIntervalTest.java diff --git a/src/main/java/net/imglib2/RandomAccessibleInterval.java b/src/main/java/net/imglib2/RandomAccessibleInterval.java index d5a2834ef..bfda69f7f 100644 --- a/src/main/java/net/imglib2/RandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/RandomAccessibleInterval.java @@ -34,6 +34,8 @@ package net.imglib2; +import net.imglib2.util.Intervals; + /** *

* f:{x∈Zn|[min,max]→T} @@ -58,6 +60,19 @@ *

* * @author Stephan Saalfeld + * @author Philipp Hanslovsky */ public interface RandomAccessibleInterval< T > extends RandomAccessible< T >, Interval -{} +{ + /** + * + * Gets an instance of T from the {@link RandomAccessibleInterval}. + * By default, this queries the value at the min coordinate but individual classes + * may choose different implementations for improved performance. + * + * @return - an instance of T + */ + default T getType() { + return getAt( Intervals.minAsLongArray(this) ); + } +} diff --git a/src/main/java/net/imglib2/img/AbstractNativeImg.java b/src/main/java/net/imglib2/img/AbstractNativeImg.java index 3597ffda0..56248c1ce 100644 --- a/src/main/java/net/imglib2/img/AbstractNativeImg.java +++ b/src/main/java/net/imglib2/img/AbstractNativeImg.java @@ -42,6 +42,7 @@ * * @author Stephan Preibisch * @author Stephan Saalfeld + * @author Philipp Hanslovsky */ public abstract class AbstractNativeImg< T extends NativeType< T >, A > extends AbstractImg< T > @@ -77,4 +78,13 @@ public T createLinkedType() return null; } } + + @Override + public T getType() { + try { + return linkedType.createVariable(); + } catch ( final NullPointerException e ) { + return super.getType(); + } + } } diff --git a/src/main/java/net/imglib2/util/Util.java b/src/main/java/net/imglib2/util/Util.java index 09bf3d62d..481128bea 100644 --- a/src/main/java/net/imglib2/util/Util.java +++ b/src/main/java/net/imglib2/util/Util.java @@ -70,6 +70,7 @@ * @author Stephan Preibisch * @author Stephan Saalfeld * @author Curtis Rueden + * @author Philipp Hanslovsky */ public class Util { @@ -780,6 +781,11 @@ final static public long[] int2long( final int[] i ) } /** + * + * This method has been deprecated. + * Use {@link RandomAccessibleInterval#getType()} instead. + * TODO: Cannot deprecate because rai parameter is not actually a RandomAccessibleInterval + * * Gets an instance of T from the {@link RandomAccessibleInterval} by * querying the value at the min coordinate * @@ -789,8 +795,14 @@ final static public long[] int2long( final int[] i ) * - the {@link RandomAccessibleInterval} * @return - an instance of T */ + @Deprecated final public static < T, F extends Interval & RandomAccessible< T > > T getTypeFromInterval( final F rai ) { + if (rai instanceof RandomAccessibleInterval) + return ((RandomAccessibleInterval) rai).getType(); + // TODO can we remove generic parameter F and use + // RandomAccessible rai instead? + // This would be a breaking change, though. // create RandomAccess final RandomAccess< T > randomAccess = rai.randomAccess(); diff --git a/src/test/java/net/imglib2/RandomAccessibleIntervalTest.java b/src/test/java/net/imglib2/RandomAccessibleIntervalTest.java new file mode 100644 index 000000000..384513406 --- /dev/null +++ b/src/test/java/net/imglib2/RandomAccessibleIntervalTest.java @@ -0,0 +1,59 @@ +/* + * #%L + * ImgLib2: a general-purpose, multidimensional image processing library. + * %% + * Copyright (C) 2009 - 2022 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld, + * John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke, + * Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner, + * Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert, + * Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin, + * Jean-Yves Tinevez and Michael Zinsmaier. + * %% + * 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imglib2; + +import net.imglib2.img.array.ArrayImgs; +import net.imglib2.type.numeric.integer.ByteType; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Tests {@link RandomAccessibleInterval}. + * + * @author Philipp Hanslovsky + */ +public class RandomAccessibleIntervalTest +{ + + @Test + public void testGetType() + { + // setup + final RandomAccessibleInterval< ? > rai = ArrayImgs.bytes( 1 ); + // process & test + assertEquals( ByteType.class, rai.getType().getClass() ); + } +} From 12dce9c68b74f0791ae1aa24b3efb92b6916208b Mon Sep 17 00:00:00 2001 From: Philipp Hanslovsky Date: Sun, 27 Feb 2022 22:34:11 -0500 Subject: [PATCH 02/19] Add getType to RA, RRA, RRARI --- src/main/java/net/imglib2/RandomAccessible.java | 12 ++++++++++++ .../net/imglib2/RandomAccessibleInterval.java | 2 +- .../java/net/imglib2/RealRandomAccessible.java | 12 ++++++++++++ .../RealRandomAccessibleRealInterval.java | 16 +++++++++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/imglib2/RandomAccessible.java b/src/main/java/net/imglib2/RandomAccessible.java index 7cfd96bcd..2bf1abc5e 100644 --- a/src/main/java/net/imglib2/RandomAccessible.java +++ b/src/main/java/net/imglib2/RandomAccessible.java @@ -180,4 +180,16 @@ default T getAt( final Localizable position ) { return randomAccess().setPositionAndGet( position ); } + + /** + * + * Gets an instance of T from the {@link RandomAccessible}. + * By default, this queries the value at the default coordinate of {@link RandomAccessible#randomAccess()} + * but individual classes may choose different implementations for improved performance. + * + * @return - an instance of T + */ + default T getType() { + return randomAccess().get(); + } } diff --git a/src/main/java/net/imglib2/RandomAccessibleInterval.java b/src/main/java/net/imglib2/RandomAccessibleInterval.java index bfda69f7f..9b52b9ff7 100644 --- a/src/main/java/net/imglib2/RandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/RandomAccessibleInterval.java @@ -73,6 +73,6 @@ public interface RandomAccessibleInterval< T > extends RandomAccessible< T >, In * @return - an instance of T */ default T getType() { - return getAt( Intervals.minAsLongArray(this) ); + return getAt( Intervals.minAsLongArray( this ) ); } } diff --git a/src/main/java/net/imglib2/RealRandomAccessible.java b/src/main/java/net/imglib2/RealRandomAccessible.java index dfbd56d9f..14a0a8d06 100644 --- a/src/main/java/net/imglib2/RealRandomAccessible.java +++ b/src/main/java/net/imglib2/RealRandomAccessible.java @@ -119,4 +119,16 @@ default T getAt( final RealLocalizable position ) { return realRandomAccess().setPositionAndGet( position ); } + + /** + * + * Gets an instance of T from the {@link RealRandomAccessible}. + * By default, this queries the value at the default coordinate of {@link RealRandomAccessible#realRandomAccess()} ()} + * but individual classes may choose different implementations for improved performance. + * + * @return - an instance of T + */ + default T getType() { + return realRandomAccess().get(); + } } diff --git a/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java index 0388e70f4..f37403ed4 100644 --- a/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java @@ -34,6 +34,8 @@ package net.imglib2; +import net.imglib2.util.Intervals; + /** *

* f:{x∈Rn|[min,max]→T} @@ -60,4 +62,16 @@ * @author Stephan Saalfeld */ public interface RealRandomAccessibleRealInterval< T > extends RealRandomAccessible< T >, RealInterval -{} +{ + /** + * + * Gets an instance of T from the {@link RealRandomAccessibleRealInterval}. + * By default, this queries the value at the min coordinate but individual classes + * may choose different implementations for improved performance. + * + * @return - an instance of T + */ + default T getType() { + return getAt( Intervals.minAsDoubleArray( this ) ); + } +} From d1baade4083b45c227e477071dab567aa7e16477 Mon Sep 17 00:00:00 2001 From: Philipp Hanslovsky Date: Sun, 27 Feb 2022 22:35:31 -0500 Subject: [PATCH 03/19] Override getType for efficiency in some classes In many cases, it may be more efficient to delegate getType to a wrapped source --- .../net/imglib2/view/ExtendedRandomAccessibleInterval.java | 6 ++++++ .../view/ExtendedRealRandomAccessibleRealInterval.java | 6 ++++++ src/main/java/net/imglib2/view/HyperSlice.java | 6 ++++++ src/main/java/net/imglib2/view/IntervalView.java | 6 ++++++ .../net/imglib2/view/IterableRandomAccessibleInterval.java | 6 ++++++ src/main/java/net/imglib2/view/MixedTransformView.java | 6 ++++++ .../view/RandomAccessibleOnRealRandomAccessible.java | 6 ++++++ src/main/java/net/imglib2/view/RandomAccessiblePair.java | 7 +++++++ src/main/java/net/imglib2/view/SubsampleView.java | 6 ++++++ .../java/net/imglib2/view/TransformedRandomAccessible.java | 5 +++++ 10 files changed, 60 insertions(+) diff --git a/src/main/java/net/imglib2/view/ExtendedRandomAccessibleInterval.java b/src/main/java/net/imglib2/view/ExtendedRandomAccessibleInterval.java index bad33a0cb..283f660b0 100644 --- a/src/main/java/net/imglib2/view/ExtendedRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/view/ExtendedRandomAccessibleInterval.java @@ -93,4 +93,10 @@ public F getSource() { return factory; } + + @Override + public T getType() { + // source may have an optimized implementation for getType + return source.getType(); + } } diff --git a/src/main/java/net/imglib2/view/ExtendedRealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/view/ExtendedRealRandomAccessibleRealInterval.java index 4b3ecee0b..fa90b0af3 100644 --- a/src/main/java/net/imglib2/view/ExtendedRealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/view/ExtendedRealRandomAccessibleRealInterval.java @@ -91,4 +91,10 @@ public F getSource() { return factory; } + + @Override + public T getType() { + // source may have an optimized implementation for getType + return source.getType(); + } } diff --git a/src/main/java/net/imglib2/view/HyperSlice.java b/src/main/java/net/imglib2/view/HyperSlice.java index 58760e15d..7b0c0e420 100644 --- a/src/main/java/net/imglib2/view/HyperSlice.java +++ b/src/main/java/net/imglib2/view/HyperSlice.java @@ -302,4 +302,10 @@ public RandomAccess< T > randomAccess( final Interval interval ) return new HyperSliceRandomAccess(); } + @Override + public T getType() { + // source may have an optimized implementation for getType + return source.getType(); + } + } diff --git a/src/main/java/net/imglib2/view/IntervalView.java b/src/main/java/net/imglib2/view/IntervalView.java index 275753e66..c05b4e66e 100644 --- a/src/main/java/net/imglib2/view/IntervalView.java +++ b/src/main/java/net/imglib2/view/IntervalView.java @@ -173,4 +173,10 @@ public Cursor< T > localizingCursor() { return getFullViewIterableInterval().localizingCursor(); } + + @Override + public T getType() { + // source may have an optimized implementation for getType + return source.getType(); + } } diff --git a/src/main/java/net/imglib2/view/IterableRandomAccessibleInterval.java b/src/main/java/net/imglib2/view/IterableRandomAccessibleInterval.java index 8a50755c6..7c9ff17af 100644 --- a/src/main/java/net/imglib2/view/IterableRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/view/IterableRandomAccessibleInterval.java @@ -106,4 +106,10 @@ public RandomAccess< T > randomAccess( final Interval i ) { return sourceInterval.randomAccess( i ); } + + @Override + public T getType() { + // source may have an optimized implementation for getType + return sourceInterval.getType(); + } } diff --git a/src/main/java/net/imglib2/view/MixedTransformView.java b/src/main/java/net/imglib2/view/MixedTransformView.java index e73cf0479..462a67edf 100644 --- a/src/main/java/net/imglib2/view/MixedTransformView.java +++ b/src/main/java/net/imglib2/view/MixedTransformView.java @@ -122,4 +122,10 @@ public RandomAccess< T > randomAccess() fullViewRandomAccessible = TransformBuilder.getEfficientRandomAccessible( null, this ); return fullViewRandomAccessible.randomAccess(); } + + @Override + public T getType() { + // source may have an optimized implementation for getType + return source.getType(); + } } diff --git a/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java b/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java index 17655cf74..f02df3e93 100644 --- a/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java +++ b/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java @@ -229,4 +229,10 @@ public RandomAccess< T > randomAccess( final Interval interval ) { return new RandomAccessOnRealRandomAccessible( source.realRandomAccess( interval ) ); } + + @Override + public T getType() { + // source may have an optimized implementation for getType + return source.getType(); + } } diff --git a/src/main/java/net/imglib2/view/RandomAccessiblePair.java b/src/main/java/net/imglib2/view/RandomAccessiblePair.java index a5ea1663d..09c74bc8c 100644 --- a/src/main/java/net/imglib2/view/RandomAccessiblePair.java +++ b/src/main/java/net/imglib2/view/RandomAccessiblePair.java @@ -37,6 +37,7 @@ import net.imglib2.Localizable; import net.imglib2.RandomAccessible; import net.imglib2.util.Pair; +import net.imglib2.util.ValuePair; /** * A {@link RandomAccessible} over two independent @@ -252,4 +253,10 @@ public RandomAccess randomAccess( final Interval interval ) { return new RandomAccess(); } + + @Override + public Pair getType() { + // sources may have an optimized implementation for getType + return new ValuePair<>( sourceA.getType(), sourceB.getType() ); + } } diff --git a/src/main/java/net/imglib2/view/SubsampleView.java b/src/main/java/net/imglib2/view/SubsampleView.java index 6bf54bc03..fa7967719 100644 --- a/src/main/java/net/imglib2/view/SubsampleView.java +++ b/src/main/java/net/imglib2/view/SubsampleView.java @@ -278,4 +278,10 @@ public long[] getSteps() { return steps.clone(); } + + @Override + public T getType() { + // source may have an optimized implementation for getType + return source.getType(); + } } diff --git a/src/main/java/net/imglib2/view/TransformedRandomAccessible.java b/src/main/java/net/imglib2/view/TransformedRandomAccessible.java index 4b7065b01..774d1f182 100644 --- a/src/main/java/net/imglib2/view/TransformedRandomAccessible.java +++ b/src/main/java/net/imglib2/view/TransformedRandomAccessible.java @@ -69,4 +69,9 @@ public interface TransformedRandomAccessible< T > extends RandomAccessible< T >, * source} coordinates. */ Transform getTransformToSource(); + + default T getType() { + // source may have an optimized implementation for getType + return getSource().getType(); + } } From dc135ca64c8591f2882e010f5ce536a96d3e85f4 Mon Sep 17 00:00:00 2001 From: Philipp Hanslovsky Date: Tue, 1 Mar 2022 23:28:39 -0500 Subject: [PATCH 04/19] Add getType implementations for most of RA/RAI classes. --- .../read/BiConvertedRandomAccessible.java | 6 ++++ .../BiConvertedRandomAccessibleInterval.java | 6 ++++ .../ConvertedRandomAccessibleInterval.java | 6 ++++ .../WriteConvertedRandomAccessible.java | 28 +++++++++++++++++++ ...riteConvertedRandomAccessibleInterval.java | 28 +++++++++++++++++++ .../DiscreteFrequencyDistribution.java | 5 ++++ .../net/imglib2/histogram/Histogram1d.java | 4 +++ .../net/imglib2/histogram/HistogramNd.java | 5 ++++ .../position/FunctionRandomAccessible.java | 5 ++++ .../position/PositionRandomAccessible.java | 5 ++++ .../java/net/imglib2/util/ConstantUtils.java | 5 ++++ src/main/java/net/imglib2/util/Grid.java | 6 ++++ src/main/java/net/imglib2/view/StackView.java | 5 ++++ .../net/imglib2/view/TransformBuilder.java | 20 +++++++++++++ 14 files changed, 134 insertions(+) diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccessible.java b/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccessible.java index a0cf96747..d3ca3b0d1 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccessible.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccessible.java @@ -132,4 +132,10 @@ public C getDestinationType() { return converterSupplier; } + + @Override + public C getType() + { + return convertedSupplier.get(); + } } diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccessibleInterval.java b/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccessibleInterval.java index aab5c1771..33ca1ff0f 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccessibleInterval.java @@ -141,4 +141,10 @@ public C getDestinationType() { return converterSupplier; } + + @Override + public C getType() + { + return convertedSupplier.get(); + } } diff --git a/src/main/java/net/imglib2/converter/read/ConvertedRandomAccessibleInterval.java b/src/main/java/net/imglib2/converter/read/ConvertedRandomAccessibleInterval.java index 6c4606ca8..9e94710d7 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedRandomAccessibleInterval.java @@ -128,4 +128,10 @@ public B getDestinationType() { return converterSupplier; } + + @Override + public B getType() + { + return convertedSupplier.get(); + } } diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessible.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessible.java index 0d9f4f71e..0983c3ba6 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessible.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessible.java @@ -38,6 +38,7 @@ import net.imglib2.Interval; import net.imglib2.RandomAccessible; +import net.imglib2.Sampler; import net.imglib2.converter.AbstractConvertedRandomAccessible; /** @@ -74,4 +75,31 @@ public WriteConvertedRandomAccess< A, B > randomAccess( final Interval interval { return new WriteConvertedRandomAccess< A, B >( source.randomAccess( interval ), converterSupplier ); } + + @Override + public B getType() { + return converterSupplier.get().convert( ( Sampler< ? extends A > ) new ConstantSampler( getSource().getType() ) ); + } + + private static class ConstantSampler< T > implements Sampler< T > + { + + private final T t; + + public ConstantSampler( T t ) { + this.t = t; + } + + @Override + public T get() + { + return t; + } + + @Override + public Sampler< T > copy() + { + return new ConstantSampler<>( t ); + } + } } diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessibleInterval.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessibleInterval.java index 00f6fc42a..211d0ef1d 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessibleInterval.java @@ -39,6 +39,7 @@ import net.imglib2.AbstractWrappedInterval; import net.imglib2.Interval; import net.imglib2.RandomAccessibleInterval; +import net.imglib2.Sampler; /** * TODO @@ -74,4 +75,31 @@ public WriteConvertedRandomAccess< A, B > randomAccess( final Interval interval { return new WriteConvertedRandomAccess< A, B >( sourceInterval.randomAccess( interval ), converterSupplier ); } + + @Override + public B getType() { + return converterSupplier.get().convert( ( Sampler< ? extends A > ) new ConstantSampler( getSource().getType() ) ); + } + + private static class ConstantSampler< T > implements Sampler< T > + { + + private final T t; + + public ConstantSampler( T t ) { + this.t = t; + } + + @Override + public T get() + { + return t; + } + + @Override + public Sampler< T > copy() + { + return new ConstantSampler<>( t ); + } + } } diff --git a/src/main/java/net/imglib2/histogram/DiscreteFrequencyDistribution.java b/src/main/java/net/imglib2/histogram/DiscreteFrequencyDistribution.java index 67c23cc71..30f402c61 100644 --- a/src/main/java/net/imglib2/histogram/DiscreteFrequencyDistribution.java +++ b/src/main/java/net/imglib2/histogram/DiscreteFrequencyDistribution.java @@ -366,4 +366,9 @@ public DiscreteFrequencyDistribution copy() return new DiscreteFrequencyDistribution( counts.copy() ); } + @Override + public LongType getType() { + return new LongType(); + } + } diff --git a/src/main/java/net/imglib2/histogram/Histogram1d.java b/src/main/java/net/imglib2/histogram/Histogram1d.java index df763b7e4..c6ce51171 100644 --- a/src/main/java/net/imglib2/histogram/Histogram1d.java +++ b/src/main/java/net/imglib2/histogram/Histogram1d.java @@ -721,6 +721,10 @@ public Histogram1d< T > copy() return new Histogram1d< T >( this ); } + public LongType getType() { + return new LongType(); + } + // -- helpers -- private void reset() diff --git a/src/main/java/net/imglib2/histogram/HistogramNd.java b/src/main/java/net/imglib2/histogram/HistogramNd.java index f9826fc4a..2710ee9f8 100644 --- a/src/main/java/net/imglib2/histogram/HistogramNd.java +++ b/src/main/java/net/imglib2/histogram/HistogramNd.java @@ -1020,6 +1020,11 @@ public HistogramNd< T > copy() return new HistogramNd< T >( this ); } + @Override + public LongType getType() { + return new LongType(); + } + // -- helpers -- private void reset() diff --git a/src/main/java/net/imglib2/position/FunctionRandomAccessible.java b/src/main/java/net/imglib2/position/FunctionRandomAccessible.java index ebab8dce2..7cd157cdb 100644 --- a/src/main/java/net/imglib2/position/FunctionRandomAccessible.java +++ b/src/main/java/net/imglib2/position/FunctionRandomAccessible.java @@ -103,4 +103,9 @@ public FunctionRandomAccess randomAccess( final Interval interval ) { return randomAccess(); } + + @Override + public T getType() { + return super.typeSupplier.get(); + } } diff --git a/src/main/java/net/imglib2/position/PositionRandomAccessible.java b/src/main/java/net/imglib2/position/PositionRandomAccessible.java index 9f24aaa8a..a8ec1555e 100644 --- a/src/main/java/net/imglib2/position/PositionRandomAccessible.java +++ b/src/main/java/net/imglib2/position/PositionRandomAccessible.java @@ -102,4 +102,9 @@ public RandomAccess< LongType > randomAccess( final Interval interval ) { return randomAccess(); } + + @Override + public LongType getType() { + return new LongType(); + } } diff --git a/src/main/java/net/imglib2/util/ConstantUtils.java b/src/main/java/net/imglib2/util/ConstantUtils.java index a054aa375..d79c69375 100644 --- a/src/main/java/net/imglib2/util/ConstantUtils.java +++ b/src/main/java/net/imglib2/util/ConstantUtils.java @@ -88,6 +88,11 @@ public RandomAccess< T > randomAccess( final Interval interval ) { return randomAccess(); } + + @Override + public T getType() { + return constant; + } }; } diff --git a/src/main/java/net/imglib2/util/Grid.java b/src/main/java/net/imglib2/util/Grid.java index 00574c0bc..5c72cddad 100644 --- a/src/main/java/net/imglib2/util/Grid.java +++ b/src/main/java/net/imglib2/util/Grid.java @@ -550,6 +550,12 @@ public FlatIterationOrder iterationOrder() { return new FlatIterationOrder( this ); } + + @Override + public Interval getType() + { + return firstElement(); + } } private final CellIntervals cellIntervals; diff --git a/src/main/java/net/imglib2/view/StackView.java b/src/main/java/net/imglib2/view/StackView.java index 8ef7a1dc0..343cfeb1a 100644 --- a/src/main/java/net/imglib2/view/StackView.java +++ b/src/main/java/net/imglib2/view/StackView.java @@ -147,6 +147,11 @@ public RandomAccess< T > randomAccess( final Interval interval ) new DefaultRA< T >( slices, interval ); } + @Override + public T getType() { + return slices.length > 0 ? slices[0].getType() : null; + } + /** * Get the source slices that are stacked in this {@link StackView}. These * are {@code (numDimensions() - 1)} dimensional diff --git a/src/main/java/net/imglib2/view/TransformBuilder.java b/src/main/java/net/imglib2/view/TransformBuilder.java index db7b0d897..75350d82e 100644 --- a/src/main/java/net/imglib2/view/TransformBuilder.java +++ b/src/main/java/net/imglib2/view/TransformBuilder.java @@ -388,6 +388,11 @@ public RandomAccess< T > randomAccess( final Interval interval ) { return new TransformRandomAccess< T >( s.randomAccess(), t ); } + + @Override + public T getType() { + return s.getType(); + } }; } @@ -417,6 +422,11 @@ public RandomAccess< T > randomAccess( final Interval interval ) return new FullSourceMapMixedRandomAccess< T >( s.randomAccess(), t ); return new MixedRandomAccess< T >( s.randomAccess(), t ); } + + @Override + public T getType() { + return s.getType(); + } }; } @@ -441,6 +451,11 @@ public TranslationRandomAccess< T > randomAccess( final Interval interval ) { return new TranslationRandomAccess< T >( s.randomAccess(), t ); } + + @Override + public T getType() { + return s.getType(); + } }; } @@ -470,6 +485,11 @@ public RandomAccess< T > randomAccess( final Interval interval ) return new FullSourceMapSlicingRandomAccess< T >( s.randomAccess(), t ); return new SlicingRandomAccess< T >( s.randomAccess(), t ); } + + @Override + public T getType() { + return s.getType(); + } }; } } From c8517ac7f2ff2c1fe18d4a10537ee10476a9da4c Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sun, 15 Oct 2023 17:15:37 +0200 Subject: [PATCH 05/19] formatting and javadoc changes --- .../java/net/imglib2/RandomAccessible.java | 18 ++++++++++++------ .../net/imglib2/RandomAccessibleInterval.java | 18 ++++++++++++------ .../java/net/imglib2/RealRandomAccessible.java | 18 ++++++++++++------ .../RealRandomAccessibleRealInterval.java | 18 ++++++++++++------ 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/imglib2/RandomAccessible.java b/src/main/java/net/imglib2/RandomAccessible.java index 2bf1abc5e..fb00a2e9b 100644 --- a/src/main/java/net/imglib2/RandomAccessible.java +++ b/src/main/java/net/imglib2/RandomAccessible.java @@ -182,14 +182,20 @@ default T getAt( final Localizable position ) } /** + * Get an instance of {@code T}. + *

+ * It should not be assumed that the returned {@code T} instance is an + * independent copy. In particular, repeated calls to {@code getType()} may + * return the same instance. + *

+ * The default implementation queries the value at the default coordinate of + * {@link RandomAccessible#randomAccess()}. Derived classes may choose + * different implementations for improved performance. * - * Gets an instance of T from the {@link RandomAccessible}. - * By default, this queries the value at the default coordinate of {@link RandomAccessible#randomAccess()} - * but individual classes may choose different implementations for improved performance. - * - * @return - an instance of T + * @return an instance of {@code T} */ - default T getType() { + default T getType() + { return randomAccess().get(); } } diff --git a/src/main/java/net/imglib2/RandomAccessibleInterval.java b/src/main/java/net/imglib2/RandomAccessibleInterval.java index 9b52b9ff7..8babf7ac8 100644 --- a/src/main/java/net/imglib2/RandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/RandomAccessibleInterval.java @@ -65,14 +65,20 @@ public interface RandomAccessibleInterval< T > extends RandomAccessible< T >, Interval { /** + * Get an instance of {@code T}. + *

+ * It should not be assumed that the returned {@code T} instance is an + * independent copy. In particular, repeated calls to {@code getType()} may + * return the same instance. + *

+ * The default implementation queries the value at the min coordinate of + * this interval. Derived classes may choose different implementations for + * improved performance. * - * Gets an instance of T from the {@link RandomAccessibleInterval}. - * By default, this queries the value at the min coordinate but individual classes - * may choose different implementations for improved performance. - * - * @return - an instance of T + * @return an instance of {@code T} */ - default T getType() { + default T getType() + { return getAt( Intervals.minAsLongArray( this ) ); } } diff --git a/src/main/java/net/imglib2/RealRandomAccessible.java b/src/main/java/net/imglib2/RealRandomAccessible.java index 14a0a8d06..eeefee029 100644 --- a/src/main/java/net/imglib2/RealRandomAccessible.java +++ b/src/main/java/net/imglib2/RealRandomAccessible.java @@ -121,14 +121,20 @@ default T getAt( final RealLocalizable position ) } /** + * Get an instance of {@code T}. + *

+ * It should not be assumed that the returned {@code T} instance is an + * independent copy. In particular, repeated calls to {@code getType()} may + * return the same instance. + *

+ * The default implementation queries the value at the default coordinate of + * {@link RealRandomAccessible#realRandomAccess()}. Derived classes + * may choose different implementations for improved performance. * - * Gets an instance of T from the {@link RealRandomAccessible}. - * By default, this queries the value at the default coordinate of {@link RealRandomAccessible#realRandomAccess()} ()} - * but individual classes may choose different implementations for improved performance. - * - * @return - an instance of T + * @return an instance of {@code T} */ - default T getType() { + default T getType() + { return realRandomAccess().get(); } } diff --git a/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java index f37403ed4..be2ba1246 100644 --- a/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java @@ -64,14 +64,20 @@ public interface RealRandomAccessibleRealInterval< T > extends RealRandomAccessible< T >, RealInterval { /** + * Get an instance of {@code T}. + *

+ * It should not be assumed that the returned {@code T} instance is an + * independent copy. In particular, repeated calls to {@code getType()} may + * return the same instance. + *

+ * The default implementation queries the value at the min coordinate of + * this interval. Derived classes may choose different implementations for + * improved performance. * - * Gets an instance of T from the {@link RealRandomAccessibleRealInterval}. - * By default, this queries the value at the min coordinate but individual classes - * may choose different implementations for improved performance. - * - * @return - an instance of T + * @return an instance of {@code T} */ - default T getType() { + default T getType() + { return getAt( Intervals.minAsDoubleArray( this ) ); } } From 67cd27c86c4d9d9ed08bc182db721a4bb12436f4 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sun, 15 Oct 2023 17:28:51 +0200 Subject: [PATCH 06/19] Introduce Typed interface to support IterableRealInterval.getType() IterableRealInterval and RandomAccessible cannot both have default getType() implementations, otherwise we run into a bug with generic bounds: https://bugs.openjdk.org/browse/JDK-7120669 Therefore we implement getType for all IterableRealInterval implementations. For the same reason, the getType() method must be inherited from a common super-type. Possibly it is possible to avoid this by not having a default implementation at all. Something to try. On the other hand, a Typed interface is probably a good idea. --- .../java/net/imglib2/IterableRealInterval.java | 12 +++++++++++- src/main/java/net/imglib2/KDTree.java | 6 ++++++ src/main/java/net/imglib2/PointSampleList.java | 6 ++++++ src/main/java/net/imglib2/RandomAccessible.java | 2 +- .../java/net/imglib2/RealPointSampleList.java | 6 ++++++ src/main/java/net/imglib2/Typed.java | 15 +++++++++++++++ .../AbstractConvertedIterableInterval.java | 6 ++++++ .../AbstractConvertedIterableRealInterval.java | 6 ++++++ .../view/iteration/IterableTransformBuilder.java | 12 ++++++++++++ .../view/iteration/SubIntervalIterable.java | 3 ++- 10 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/imglib2/Typed.java diff --git a/src/main/java/net/imglib2/IterableRealInterval.java b/src/main/java/net/imglib2/IterableRealInterval.java index 51ea63cd2..9bf0b5d1c 100644 --- a/src/main/java/net/imglib2/IterableRealInterval.java +++ b/src/main/java/net/imglib2/IterableRealInterval.java @@ -60,7 +60,7 @@ * * @author Stephan Saalfeld */ -public interface IterableRealInterval< T > extends RealInterval, Iterable< T > +public interface IterableRealInterval< T > extends RealInterval, Iterable< T >, Typed< T > { /** *

@@ -118,6 +118,16 @@ default T firstElement() // TODO: fix places where it is not necessary to implem return iterator().next(); } + /* + * NB: We cannot have a default implementation here because of + * https://bugs.openjdk.org/browse/JDK-7120669 + */ +// @Override +// default T getType() +// { +// return firstElement(); +// } + /** * Returns the iteration order of this {@link IterableRealInterval}. If the * returned object equals ({@link Object#equals(Object)}) the iteration diff --git a/src/main/java/net/imglib2/KDTree.java b/src/main/java/net/imglib2/KDTree.java index fb338c832..0647c06a2 100644 --- a/src/main/java/net/imglib2/KDTree.java +++ b/src/main/java/net/imglib2/KDTree.java @@ -182,6 +182,12 @@ public KDTreeNode< T > getRoot() return new KDTreeNode<>( this ).setNodeIndex( impl.root() ); } + @Override + public T getType() + { + return treeData.getType(); + } + @Override public int numDimensions() { diff --git a/src/main/java/net/imglib2/PointSampleList.java b/src/main/java/net/imglib2/PointSampleList.java index 23b200b5f..612db0d0f 100644 --- a/src/main/java/net/imglib2/PointSampleList.java +++ b/src/main/java/net/imglib2/PointSampleList.java @@ -228,4 +228,10 @@ public long size() { return samples.size(); } + + @Override + public T getType() + { + return samples.get( 0 ); + } } diff --git a/src/main/java/net/imglib2/RandomAccessible.java b/src/main/java/net/imglib2/RandomAccessible.java index fb00a2e9b..1dcc9048e 100644 --- a/src/main/java/net/imglib2/RandomAccessible.java +++ b/src/main/java/net/imglib2/RandomAccessible.java @@ -62,7 +62,7 @@ * @author Stephan Saalfeld * @author Tobias Pietzsch */ -public interface RandomAccessible< T > extends EuclideanSpace +public interface RandomAccessible< T > extends EuclideanSpace, Typed< T > { /** * Create a random access sampler for integer coordinates. diff --git a/src/main/java/net/imglib2/RealPointSampleList.java b/src/main/java/net/imglib2/RealPointSampleList.java index 2abde52f8..092d16540 100644 --- a/src/main/java/net/imglib2/RealPointSampleList.java +++ b/src/main/java/net/imglib2/RealPointSampleList.java @@ -212,6 +212,12 @@ public long size() return samples.size(); } + @Override + public T getType() + { + return samples.get( 0 ); + } + @Override public double realMax( final int d ) { diff --git a/src/main/java/net/imglib2/Typed.java b/src/main/java/net/imglib2/Typed.java new file mode 100644 index 000000000..429646338 --- /dev/null +++ b/src/main/java/net/imglib2/Typed.java @@ -0,0 +1,15 @@ +package net.imglib2; + +public interface Typed< T > +{ + /** + * Get an instance of {@code T}. + *

+ * It should not be assumed that the returned {@code T} instance is an + * independent copy. In particular, repeated calls to {@code getType()} may + * return the same instance. + * + * @return an instance of {@code T} + */ + T getType(); +} diff --git a/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java b/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java index 7f9b9dff2..3cb52a701 100644 --- a/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java +++ b/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java @@ -68,4 +68,10 @@ public Object iterationOrder() @Override abstract public AbstractConvertedCursor< A, B > localizingCursor(); + + @Override + public B getType() + { + return firstElement(); // TODO GET-TYPE: Probably cursor().getType() is better? Or something else entirely? + } } diff --git a/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java b/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java index 2c379f3a4..6f5f2bd7d 100644 --- a/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java +++ b/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java @@ -68,4 +68,10 @@ public Object iterationOrder() @Override abstract public AbstractConvertedRealCursor< A, B > localizingCursor(); + + @Override + public B getType() + { + return firstElement(); // TODO GET-TYPE: Probably cursor().getType() is better? Or something else entirely? + } } diff --git a/src/main/java/net/imglib2/view/iteration/IterableTransformBuilder.java b/src/main/java/net/imglib2/view/iteration/IterableTransformBuilder.java index 1442d4598..69ae48fee 100644 --- a/src/main/java/net/imglib2/view/iteration/IterableTransformBuilder.java +++ b/src/main/java/net/imglib2/view/iteration/IterableTransformBuilder.java @@ -145,6 +145,12 @@ public Cursor< T > localizingCursor() { return iterableSource.localizingCursor( interval ); } + + @Override + public T getType() + { + return iterableSource.getType(); + } } /** @@ -195,6 +201,12 @@ public Cursor< T > localizingCursor() { return new SlicingCursor< T >( iterableSource.localizingCursor( sourceInterval ), transformToSource ); } + + @Override + public T getType() + { + return iterableSource.getType(); + } } /** diff --git a/src/main/java/net/imglib2/view/iteration/SubIntervalIterable.java b/src/main/java/net/imglib2/view/iteration/SubIntervalIterable.java index d85c5eaa0..efd7160c4 100644 --- a/src/main/java/net/imglib2/view/iteration/SubIntervalIterable.java +++ b/src/main/java/net/imglib2/view/iteration/SubIntervalIterable.java @@ -35,6 +35,7 @@ import net.imglib2.Cursor; import net.imglib2.Interval; +import net.imglib2.IterableInterval; import net.imglib2.IterableRealInterval; /** @@ -43,7 +44,7 @@ * * @author Tobias Pietzsch */ -public interface SubIntervalIterable< T > +public interface SubIntervalIterable< T > extends IterableInterval< T > { /** * Determine whether a {@link Cursor} can be created that iterates the given From 452f0b7008b7f95be2a3f2b9b1b6bec8a274e035 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 17 Oct 2023 17:41:54 +0200 Subject: [PATCH 07/19] Remove default RandomAccessible[Interval]::getType implementations Instead, implement getType() in all RandomAccessible[Interval] implementations --- .../java/net/imglib2/RandomAccessible.java | 11 +++--- .../net/imglib2/RandomAccessibleInterval.java | 11 +++--- .../read/ConvertedRandomAccessible.java | 5 +++ ...ertedIterableRandomAccessibleInterval.java | 37 ++++++++++++++++--- .../net/imglib2/img/AbstractNativeImg.java | 9 ++--- .../java/net/imglib2/img/cell/CellGrid.java | 6 +++ .../net/imglib2/img/cell/LazyCellImg.java | 25 +++++++++++-- .../java/net/imglib2/img/list/ListImg.java | 37 +++++++++++++------ .../java/net/imglib2/util/Localizables.java | 6 +++ .../java/net/imglib2/view/BundleView.java | 6 +++ .../java/net/imglib2/view/FunctionView.java | 6 +++ .../net/imglib2/view/HyperSlicesView.java | 6 ++- .../imglib2/view/composite/CompositeView.java | 6 +++ .../imglib2/view/composite/InflateView.java | 6 +++ .../view/composite/InterleaveView.java | 6 +++ ...ConvertedRandomAccessibleIntervalTest.java | 5 +++ 16 files changed, 150 insertions(+), 38 deletions(-) diff --git a/src/main/java/net/imglib2/RandomAccessible.java b/src/main/java/net/imglib2/RandomAccessible.java index 1dcc9048e..c36681c1a 100644 --- a/src/main/java/net/imglib2/RandomAccessible.java +++ b/src/main/java/net/imglib2/RandomAccessible.java @@ -181,7 +181,7 @@ default T getAt( final Localizable position ) return randomAccess().setPositionAndGet( position ); } - /** + /* * Get an instance of {@code T}. *

* It should not be assumed that the returned {@code T} instance is an @@ -194,8 +194,9 @@ default T getAt( final Localizable position ) * * @return an instance of {@code T} */ - default T getType() - { - return randomAccess().get(); - } +// @Override +// default T getType() +// { +// return randomAccess().get(); +// } } diff --git a/src/main/java/net/imglib2/RandomAccessibleInterval.java b/src/main/java/net/imglib2/RandomAccessibleInterval.java index 8babf7ac8..864ff34a0 100644 --- a/src/main/java/net/imglib2/RandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/RandomAccessibleInterval.java @@ -64,7 +64,7 @@ */ public interface RandomAccessibleInterval< T > extends RandomAccessible< T >, Interval { - /** + /* * Get an instance of {@code T}. *

* It should not be assumed that the returned {@code T} instance is an @@ -77,8 +77,9 @@ public interface RandomAccessibleInterval< T > extends RandomAccessible< T >, In * * @return an instance of {@code T} */ - default T getType() - { - return getAt( Intervals.minAsLongArray( this ) ); - } +// @Override +// default T getType() +// { +// return getAt( Intervals.minAsLongArray( this ) ); +// } } diff --git a/src/main/java/net/imglib2/converter/read/ConvertedRandomAccessible.java b/src/main/java/net/imglib2/converter/read/ConvertedRandomAccessible.java index b0cd812c2..53fce0d9a 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedRandomAccessible.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedRandomAccessible.java @@ -102,6 +102,11 @@ public B getDestinationType() return convertedSupplier; } + @Override + public B getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link Converter}. If the diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRandomAccessibleInterval.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRandomAccessibleInterval.java index a2e5489fc..76a512ce9 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRandomAccessibleInterval.java @@ -49,42 +49,69 @@ public class WriteConvertedIterableRandomAccessibleInterval< A, B, S extends Ran { private final Supplier< SamplerConverter< ? super A, B > > converterSupplier; + private final Supplier< B > typeSupplier; + public WriteConvertedIterableRandomAccessibleInterval( final S source, final Supplier< SamplerConverter< ? super A, B > > converterSupplier ) { super( source ); this.converterSupplier = converterSupplier; + this.typeSupplier = () -> cursor().next(); } public WriteConvertedIterableRandomAccessibleInterval( final S source, - final SamplerConverter< ? super A, B > converter ) + final Supplier< SamplerConverter< ? super A, B > > converterSupplier, + final Supplier< B > typeSupplier ) + { + super( source ); + this.converterSupplier = converterSupplier; + this.typeSupplier = typeSupplier; + } + + public WriteConvertedIterableRandomAccessibleInterval( + final S source, + final SamplerConverter< ? super A, B > converter) { this( source, () -> converter ); } + public WriteConvertedIterableRandomAccessibleInterval( + final S source, + final SamplerConverter< ? super A, B > converter, + final B type ) + { + this( source, () -> converter, () -> type ); + } + @Override public WriteConvertedRandomAccess< A, B > randomAccess() { - return new WriteConvertedRandomAccess< A, B >( sourceInterval.randomAccess(), converterSupplier ); + return new WriteConvertedRandomAccess<>( sourceInterval.randomAccess(), converterSupplier ); } @Override public WriteConvertedRandomAccess< A, B > randomAccess( final Interval interval ) { - return new WriteConvertedRandomAccess< A, B >( sourceInterval.randomAccess( interval ), converterSupplier ); + return new WriteConvertedRandomAccess<>( sourceInterval.randomAccess( interval ), converterSupplier ); } @Override public WriteConvertedCursor< A, B > cursor() { - return new WriteConvertedCursor< A, B >( sourceInterval.cursor(), converterSupplier ); + return new WriteConvertedCursor<>( sourceInterval.cursor(), converterSupplier ); } @Override public WriteConvertedCursor< A, B > localizingCursor() { - return new WriteConvertedCursor< A, B >( sourceInterval.localizingCursor(), converterSupplier ); + return new WriteConvertedCursor<>( sourceInterval.localizingCursor(), converterSupplier ); + } + + @Override + public B getType() + { + return typeSupplier.get(); } } diff --git a/src/main/java/net/imglib2/img/AbstractNativeImg.java b/src/main/java/net/imglib2/img/AbstractNativeImg.java index 56248c1ce..2f446479c 100644 --- a/src/main/java/net/imglib2/img/AbstractNativeImg.java +++ b/src/main/java/net/imglib2/img/AbstractNativeImg.java @@ -80,11 +80,8 @@ public T createLinkedType() } @Override - public T getType() { - try { - return linkedType.createVariable(); - } catch ( final NullPointerException e ) { - return super.getType(); - } + public T getType() + { + return linkedType; } } diff --git a/src/main/java/net/imglib2/img/cell/CellGrid.java b/src/main/java/net/imglib2/img/cell/CellGrid.java index 6292ddbbc..96ce2bac8 100644 --- a/src/main/java/net/imglib2/img/cell/CellGrid.java +++ b/src/main/java/net/imglib2/img/cell/CellGrid.java @@ -759,6 +759,12 @@ public FlatIterationOrder iterationOrder() { return new FlatIterationOrder( this ); } + + @Override + public Interval getType() + { + return new FinalInterval(); + } } private final CellIntervals cellIntervals; diff --git a/src/main/java/net/imglib2/img/cell/LazyCellImg.java b/src/main/java/net/imglib2/img/cell/LazyCellImg.java index 87d95c959..af5fba1ec 100644 --- a/src/main/java/net/imglib2/img/cell/LazyCellImg.java +++ b/src/main/java/net/imglib2/img/cell/LazyCellImg.java @@ -65,7 +65,7 @@ public interface Get< T > public LazyCellImg( final CellGrid grid, final T type, final Get< Cell< A > > get ) { - super( grid, new LazyCells<>( grid.getGridDimensions(), get ), type.getEntitiesPerPixel() ); + super( grid, new LazyCells<>( grid.getGridDimensions(), get, typeCell() ), type.getEntitiesPerPixel() ); @SuppressWarnings( "unchecked" ) final NativeTypeFactory< T, ? super A > typeFactory = ( NativeTypeFactory< T, ? super A > ) type.getNativeTypeFactory(); @@ -74,7 +74,15 @@ public LazyCellImg( final CellGrid grid, final T type, final Get< Cell< A > > ge public LazyCellImg( final CellGrid grid, final Fraction entitiesPerPixel, final Get< Cell< A > > get ) { - super( grid, new LazyCells<>( grid.getGridDimensions(), get ), entitiesPerPixel ); + super( grid, new LazyCells<>( grid.getGridDimensions(), get, typeCell() ), entitiesPerPixel ); + } + + /** + * Create a dummy Cell instance to be returned by {@code LazyCells.getType()}. + */ + private static < A > Cell< A > typeCell() + { + return new Cell<>( new int[] { 0 }, new long[] { 0 }, null ); } @Override @@ -89,14 +97,17 @@ public Img< T > copy() throw new UnsupportedOperationException( "not implemented yet" ); } - public static final class LazyCells< T > extends AbstractLongListImg< T > + public static final class LazyCells< T extends Cell< ? > > extends AbstractLongListImg< T > { private final Get< T > get; - public LazyCells( final long[] dimensions, final Get< T > get ) + private final T type; + + public LazyCells( final long[] dimensions, final Get< T > get, final T type ) { super( dimensions ); this.get = get; + this.type = type; } @Override @@ -105,6 +116,12 @@ protected T get( final long index ) return get.get( index ); } + @Override + public T getType() + { + return type; + } + @Override protected void set( final long index, final T value ) { diff --git a/src/main/java/net/imglib2/img/list/ListImg.java b/src/main/java/net/imglib2/img/list/ListImg.java index 0801cf091..cbb85b0cc 100644 --- a/src/main/java/net/imglib2/img/list/ListImg.java +++ b/src/main/java/net/imglib2/img/list/ListImg.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 @@ -46,7 +46,7 @@ * pixel is stored as an individual object, so {@link ListImg} should only be * used for images with relatively few pixels. In principle, the number of * entities stored is limited to {@link Integer#MAX_VALUE}. - * + * * @param * The value type of the pixels. You can us {@link Type}s or * arbitrary {@link Object}s. If you use non-{@link Type} pixels, @@ -55,18 +55,21 @@ * {@link ListCursor#set(Object)} and * {@link ListRandomAccess#set(Object)} methods to alter the * underlying {@link ArrayList}. - * + * * @author Stephan Preibisch * @author Stephan Saalfeld * @author Tobias Pietzsch */ public class ListImg< T > extends AbstractListImg< T > { - final private List< T > pixels; + private final List< T > pixels; + + private final T type; public ListImg( final long[] dim, final T type ) { super( dim ); + this.type = type; pixels = new ArrayList< T >( ( int ) numPixels ); if ( type instanceof Type< ? > ) @@ -84,14 +87,19 @@ public ListImg( final long[] dim, final T type ) } } - public ListImg( final Collection< T > collection, final long... dim ) + public ListImg( final T type, final Collection< T > collection, final long... dim ) { super( dim ); assert numPixels == collection.size() : "Dimensions do not match number of pixels."; - pixels = new ArrayList< T >( ( int ) numPixels ); - pixels.addAll( collection ); + this.type = type; + pixels = new ArrayList<>( collection ); + } + + public ListImg( final Collection< T > collection, final long... dim ) + { + this( collection.iterator().next(), collection, dim ); } @Override @@ -100,6 +108,12 @@ protected T get( final int index ) return pixels.get( index ); } + @Override + public T getType() + { + return type; + } + @Override protected void set( final int index, final T value ) { @@ -108,7 +122,7 @@ protected void set( final int index, final T value ) private static < A extends Type< A > > ListImg< A > copyWithType( final ListImg< A > img ) { - final ListImg< A > copy = new ListImg< A >( img.dimension, img.firstElement().createVariable() ); + final ListImg< A > copy = new ListImg<>( img.dimension, img.type ); final ListCursor< A > source = img.cursor(); final ListCursor< A > target = copy.cursor(); @@ -123,19 +137,18 @@ private static < A extends Type< A > > ListImg< A > copyWithType( final ListImg< @Override public ListImg< T > copy() { - final T type = firstElement(); if ( type instanceof Type< ? > ) { final ListImg< ? > copy = copyWithType( ( ListImg< Type > ) this ); return ( ListImg< T > ) copy; } - return new ListImg< T >( this.pixels, dimension ); + return new ListImg<>( this.type, this.pixels, dimension ); } private ListImg( final List< T > pixels, final boolean dummy, final long... dim ) { super( dim ); - + this.type = pixels.isEmpty() ? null : pixels.get( 0 ); assert numPixels == pixels.size() : "Dimensions do not match number of pixels."; this.pixels = pixels; } diff --git a/src/main/java/net/imglib2/util/Localizables.java b/src/main/java/net/imglib2/util/Localizables.java index c3b8296c1..54b726dac 100644 --- a/src/main/java/net/imglib2/util/Localizables.java +++ b/src/main/java/net/imglib2/util/Localizables.java @@ -197,6 +197,12 @@ public RandomAccess< Localizable > randomAccess( final Interval interval ) { return randomAccess(); } + + @Override + public Localizable getType() + { + return randomAccess(); + } } /** diff --git a/src/main/java/net/imglib2/view/BundleView.java b/src/main/java/net/imglib2/view/BundleView.java index 7d1faf8c6..3dce2213a 100644 --- a/src/main/java/net/imglib2/view/BundleView.java +++ b/src/main/java/net/imglib2/view/BundleView.java @@ -102,4 +102,10 @@ public BundleRandomAccess randomAccess( final Interval interval ) { return new BundleRandomAccess( source.randomAccess( interval ) ); } + + @Override + public RandomAccess< T > getType() + { + return source.randomAccess(); + } } diff --git a/src/main/java/net/imglib2/view/FunctionView.java b/src/main/java/net/imglib2/view/FunctionView.java index f34578178..f40cc13ec 100644 --- a/src/main/java/net/imglib2/view/FunctionView.java +++ b/src/main/java/net/imglib2/view/FunctionView.java @@ -89,4 +89,10 @@ public RandomAccess< B > randomAccess( final Interval interval ) { return new FunctionRandomAccess( source.randomAccess( interval ) ); } + + @Override + public B getType() + { + return randomAccess().get(); // TODO GET-TYPE: should be getType(); + } } diff --git a/src/main/java/net/imglib2/view/HyperSlicesView.java b/src/main/java/net/imglib2/view/HyperSlicesView.java index 9131d2db4..c30d28750 100644 --- a/src/main/java/net/imglib2/view/HyperSlicesView.java +++ b/src/main/java/net/imglib2/view/HyperSlicesView.java @@ -123,5 +123,9 @@ public HyperSlicesViewRandomAccess randomAccess( final Interval interval ) return randomAccess(); } - + @Override + public HyperSlice< T > getType() + { + return randomAccess().get(); // TODO GET-TYPE: should be getType(); + } } diff --git a/src/main/java/net/imglib2/view/composite/CompositeView.java b/src/main/java/net/imglib2/view/composite/CompositeView.java index 75e12788e..2e9105b52 100644 --- a/src/main/java/net/imglib2/view/composite/CompositeView.java +++ b/src/main/java/net/imglib2/view/composite/CompositeView.java @@ -247,4 +247,10 @@ public CompositeRandomAccess randomAccess( final Interval interval ) return randomAccess(); } + @Override + public C getType() + { + return randomAccess().get(); // TODO GET-TYPE: should be .getType() when that is available + } + } diff --git a/src/main/java/net/imglib2/view/composite/InflateView.java b/src/main/java/net/imglib2/view/composite/InflateView.java index 4e77f35c5..3340a2502 100644 --- a/src/main/java/net/imglib2/view/composite/InflateView.java +++ b/src/main/java/net/imglib2/view/composite/InflateView.java @@ -313,4 +313,10 @@ public InflateRandomAccess randomAccess( final Interval interval ) { return randomAccess(); } + + @Override + public T getType() + { + return source.getType().get( 0 ); + } } diff --git a/src/main/java/net/imglib2/view/composite/InterleaveView.java b/src/main/java/net/imglib2/view/composite/InterleaveView.java index 0eccd1401..02a533762 100644 --- a/src/main/java/net/imglib2/view/composite/InterleaveView.java +++ b/src/main/java/net/imglib2/view/composite/InterleaveView.java @@ -289,6 +289,12 @@ public InterleaveView( final RandomAccessible< ? extends Composite< T > > source n = source.numDimensions() + 1; } + @Override + public T getType() + { + return source.getType().get( 0 ); + } + @Override public int numDimensions() { diff --git a/src/test/java/net/imglib2/converter/AbstractConvertedRandomAccessibleIntervalTest.java b/src/test/java/net/imglib2/converter/AbstractConvertedRandomAccessibleIntervalTest.java index 84c170c41..f32b52cdc 100644 --- a/src/test/java/net/imglib2/converter/AbstractConvertedRandomAccessibleIntervalTest.java +++ b/src/test/java/net/imglib2/converter/AbstractConvertedRandomAccessibleIntervalTest.java @@ -100,6 +100,11 @@ public AbstractConvertedRandomAccess< DoubleType, DoubleType > randomAccess( fin return randomAccess(); } + @Override + public DoubleType getType() + { + return new DoubleType(); + } }; for ( final Cursor< Pair< DoubleType, DoubleType > > c = Views.interval( Views.pair( data, converted ), data ).cursor(); c.hasNext(); ) From 2c14cf1f5dfe6346fa683c3afd2689affa13d19a Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Mon, 16 Oct 2023 18:14:15 +0200 Subject: [PATCH 08/19] Let Sampler extend Typed Implement getType() in all Sampler implementations --- src/main/java/net/imglib2/KDTree.java | 12 +++++ src/main/java/net/imglib2/KDTreeNode.java | 6 +++ src/main/java/net/imglib2/PointSample.java | 6 +++ .../java/net/imglib2/PointSampleList.java | 6 +++ .../java/net/imglib2/RealPointSample.java | 6 +++ .../java/net/imglib2/RealPointSampleList.java | 6 +++ src/main/java/net/imglib2/Sampler.java | 7 ++- .../converter/read/BiConvertedCursor.java | 6 +++ .../read/BiConvertedRandomAccess.java | 6 +++ .../converter/read/BiConvertedRealCursor.java | 6 +++ .../read/BiConvertedRealRandomAccess.java | 6 +++ .../converter/read/ConvertedCursor.java | 6 +++ .../converter/read/ConvertedRandomAccess.java | 6 +++ .../converter/read/ConvertedRealCursor.java | 6 +++ .../read/ConvertedRealRandomAccess.java | 6 +++ .../converter/readwrite/TypeUtils.java | 45 +++++++++++++++++++ .../readwrite/WriteConvertedCursor.java | 6 +++ .../readwrite/WriteConvertedRandomAccess.java | 6 +++ .../WriteConvertedRandomAccessible.java | 26 +---------- ...riteConvertedRandomAccessibleInterval.java | 26 +---------- .../readwrite/WriteConvertedRealCursor.java | 6 +++ .../projector/sampler/IntervalSampler.java | 6 +++ .../projector/sampler/SelectiveSampler.java | 6 +++ .../img/array/AbstractArrayCursor.java | 6 +++ .../array/AbstractArrayLocalizingCursor.java | 6 +++ .../img/array/ArrayLocalizingSpliterator.java | 6 +++ .../imglib2/img/array/ArrayRandomAccess.java | 6 +++ .../imglib2/img/array/ArraySpliterator.java | 5 +++ .../java/net/imglib2/img/cell/CellCursor.java | 6 +++ .../java/net/imglib2/img/cell/CellGrid.java | 6 +++ .../img/cell/CellLocalizingCursor.java | 6 +++ .../imglib2/img/cell/CellRandomAccess.java | 6 +++ .../net/imglib2/img/cell/CellSpliterator.java | 6 +++ .../imglib2/img/list/AbstractLongListImg.java | 18 ++++++++ .../java/net/imglib2/img/list/ListCursor.java | 6 +++ .../java/net/imglib2/img/list/ListImg.java | 5 +-- .../img/list/ListLocalizingCursor.java | 6 +++ .../imglib2/img/list/ListRandomAccess.java | 6 +++ .../net/imglib2/img/planar/PlanarCursor.java | 6 +++ .../img/planar/PlanarLocalizingCursor.java | 6 +++ .../img/planar/PlanarPlaneSubsetCursor.java | 6 +++ .../PlanarPlaneSubsetLocalizingCursor.java | 6 +++ .../img/planar/PlanarRandomAccess.java | 6 +++ .../imglib2/img/planar/PlanarSpliterator.java | 5 +++ .../net/imglib2/img/sparse/NtreeCursor.java | 6 +++ .../imglib2/img/sparse/NtreeRandomAccess.java | 6 +++ .../InverseDistanceWeightingInterpolator.java | 6 +++ .../NearestNeighborSearchInterpolator.java | 6 +++ .../randomaccess/FloorInterpolator.java | 6 +++ .../randomaccess/LanczosInterpolator.java | 6 +++ .../randomaccess/NLinearInterpolator.java | 6 +++ .../NearestNeighborInterpolator.java | 6 +++ ...RealRandomAccessibleStackInterpolator.java | 6 +++ .../AbstractOutOfBoundsMirror.java | 6 +++ .../outofbounds/AbstractOutOfBoundsValue.java | 6 +++ .../outofbounds/OutOfBoundsBorder.java | 6 +++ .../outofbounds/OutOfBoundsPeriodic.java | 6 +++ .../RealOutOfBoundsRealRandomAccess.java | 6 +++ .../position/FunctionRandomAccessible.java | 6 +++ .../FunctionRealRandomAccessible.java | 6 +++ .../position/PositionRandomAccessible.java | 6 +++ .../RealPositionRealRandomAccessible.java | 6 +++ .../net/imglib2/stream/CursorSpliterator.java | 6 +++ .../stream/LocalizableSamplerWrapper.java | 6 +++ .../imglib2/stream/RealCursorSpliterator.java | 6 +++ .../stream/RealLocalizableSamplerWrapper.java | 6 +++ .../java/net/imglib2/util/ConstantUtils.java | 12 +++++ src/main/java/net/imglib2/util/Grid.java | 6 +++ .../java/net/imglib2/util/Localizables.java | 12 +++++ .../java/net/imglib2/view/BundleView.java | 6 +++ .../view/FullSourceMapMixedRandomAccess.java | 6 +++ .../FullSourceMapSlicingRandomAccess.java | 6 +++ .../java/net/imglib2/view/FunctionView.java | 6 +++ .../java/net/imglib2/view/HyperSlice.java | 6 +++ .../net/imglib2/view/HyperSlicesView.java | 6 +++ .../net/imglib2/view/MixedRandomAccess.java | 6 +++ .../view/RandomAccessibleIntervalCursor.java | 6 +++ ...andomAccessibleOnRealRandomAccessible.java | 6 +++ .../imglib2/view/RandomAccessiblePair.java | 6 +++ .../net/imglib2/view/SlicingRandomAccess.java | 6 +++ src/main/java/net/imglib2/view/StackView.java | 12 +++++ .../java/net/imglib2/view/SubsampleView.java | 6 +++ .../imglib2/view/TransformRandomAccess.java | 10 ++++- .../imglib2/view/TranslationRandomAccess.java | 6 +++ .../imglib2/view/composite/CompositeView.java | 6 +++ .../imglib2/view/composite/InflateView.java | 6 +++ .../view/composite/InterleaveView.java | 6 +++ .../imglib2/view/iteration/SlicingCursor.java | 6 +++ ...ConvertedRandomAccessibleIntervalTest.java | 6 +++ 89 files changed, 596 insertions(+), 55 deletions(-) create mode 100644 src/main/java/net/imglib2/converter/readwrite/TypeUtils.java diff --git a/src/main/java/net/imglib2/KDTree.java b/src/main/java/net/imglib2/KDTree.java index 0647c06a2..861931f5a 100644 --- a/src/main/java/net/imglib2/KDTree.java +++ b/src/main/java/net/imglib2/KDTree.java @@ -136,6 +136,12 @@ public Cursor copy() { return new Cursor( source.copy() ); } + + @Override + public RealLocalizable getType() + { + return source; + } } @Override @@ -238,6 +244,12 @@ public boolean hasNext() return nodeIndex() < impl.size() - 1; } + @Override + public T getType() + { + return treeData.getType(); + } + @Override public KDTreeCursor copy() { diff --git a/src/main/java/net/imglib2/KDTreeNode.java b/src/main/java/net/imglib2/KDTreeNode.java index 5d643fca7..a393118ee 100644 --- a/src/main/java/net/imglib2/KDTreeNode.java +++ b/src/main/java/net/imglib2/KDTreeNode.java @@ -151,6 +151,12 @@ public T get() return values.apply( nodeIndex ); } + @Override + public T getType() + { + return tree.getType(); + } + @Override public KDTreeNode< T > copy() { diff --git a/src/main/java/net/imglib2/PointSample.java b/src/main/java/net/imglib2/PointSample.java index e2342d909..367ace36d 100644 --- a/src/main/java/net/imglib2/PointSample.java +++ b/src/main/java/net/imglib2/PointSample.java @@ -275,6 +275,12 @@ public T get() return sampleSupplier.get(); } + @Override + public T getType() + { + return get(); + } + @Override public PointSample< T > copy() { diff --git a/src/main/java/net/imglib2/PointSampleList.java b/src/main/java/net/imglib2/PointSampleList.java index 612db0d0f..035f07ffb 100644 --- a/src/main/java/net/imglib2/PointSampleList.java +++ b/src/main/java/net/imglib2/PointSampleList.java @@ -124,6 +124,12 @@ public T get() return sample; } + @Override + public T getType() + { + return sample; + } + @Override public void fwd() { diff --git a/src/main/java/net/imglib2/RealPointSample.java b/src/main/java/net/imglib2/RealPointSample.java index 1d4d934ab..5da65a2bd 100644 --- a/src/main/java/net/imglib2/RealPointSample.java +++ b/src/main/java/net/imglib2/RealPointSample.java @@ -333,6 +333,12 @@ public T get() return sampleSupplier.get(); } + @Override + public T getType() + { + return get(); + } + @Override public RealPointSample< T > copy() { diff --git a/src/main/java/net/imglib2/RealPointSampleList.java b/src/main/java/net/imglib2/RealPointSampleList.java index 092d16540..976dd529b 100644 --- a/src/main/java/net/imglib2/RealPointSampleList.java +++ b/src/main/java/net/imglib2/RealPointSampleList.java @@ -99,6 +99,12 @@ public T get() return sample; } + @Override + public T getType() + { + return sample; + } + @Override public void fwd() { diff --git a/src/main/java/net/imglib2/Sampler.java b/src/main/java/net/imglib2/Sampler.java index cc5bbf6a5..9908fa713 100644 --- a/src/main/java/net/imglib2/Sampler.java +++ b/src/main/java/net/imglib2/Sampler.java @@ -53,7 +53,7 @@ * @author Stephan Preibisch * @author Stephan Saalfeld */ -public interface Sampler< T > +public interface Sampler< T > extends Typed< T > { /** * Access the actual T instance providing access to a pixel, @@ -73,4 +73,9 @@ public interface Sampler< T > * {@link ArrayCursor} for example) */ Sampler< T > copy(); + +// @Override default T getType() // TODO GET-TYPE: do we want a default implementation here? +// { +// return get(); +// } } diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedCursor.java b/src/main/java/net/imglib2/converter/read/BiConvertedCursor.java index 8d525a149..c55476833 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedCursor.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedCursor.java @@ -95,6 +95,12 @@ public C get() return converted; } + @Override + public C getType() + { + return converted; + } + @Override public void jumpFwd( final long steps ) { diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccess.java b/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccess.java index 072bed266..5b0ef9ed7 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccess.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedRandomAccess.java @@ -172,6 +172,12 @@ public C get() return converted; } + @Override + public C getType() + { + return converted; + } + @Override public BiConvertedRandomAccess< A, B, C > copy() { diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedRealCursor.java b/src/main/java/net/imglib2/converter/read/BiConvertedRealCursor.java index 69504c317..2f7b37247 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedRealCursor.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedRealCursor.java @@ -105,6 +105,12 @@ public C get() return converted; } + @Override + public C getType() + { + return converted; + } + @Override public void jumpFwd( final long steps ) { diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccess.java b/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccess.java index 8bfd2885a..3a9a91e3b 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccess.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccess.java @@ -88,6 +88,12 @@ public C get() return converted; } + @Override + public C getType() + { + return converted; + } + @Override public void fwd( final int d ) { diff --git a/src/main/java/net/imglib2/converter/read/ConvertedCursor.java b/src/main/java/net/imglib2/converter/read/ConvertedCursor.java index 368f87ce2..bc2144aa6 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedCursor.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedCursor.java @@ -93,6 +93,12 @@ public B get() return converted; } + @Override + public B getType() + { + return converted; + } + @Override public ConvertedCursor< A, B > copy() { diff --git a/src/main/java/net/imglib2/converter/read/ConvertedRandomAccess.java b/src/main/java/net/imglib2/converter/read/ConvertedRandomAccess.java index 16de74a21..c9aed77b8 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedRandomAccess.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedRandomAccess.java @@ -95,6 +95,12 @@ public B get() return converted; } + @Override + public B getType() + { + return converted; + } + @Override public ConvertedRandomAccess< A, B > copy() { diff --git a/src/main/java/net/imglib2/converter/read/ConvertedRealCursor.java b/src/main/java/net/imglib2/converter/read/ConvertedRealCursor.java index e45afc602..e72fffd95 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedRealCursor.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedRealCursor.java @@ -97,6 +97,12 @@ public B get() return converted; } + @Override + public B getType() + { + return converted; + } + @Override public ConvertedRealCursor< A, B > copy() { diff --git a/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccess.java b/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccess.java index 4ff54732a..d69593d0c 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccess.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccess.java @@ -89,6 +89,12 @@ public B get() return converted; } + @Override + public B getType() + { + return converted; + } + @Override public ConvertedRealRandomAccess< A, B > copy() { diff --git a/src/main/java/net/imglib2/converter/readwrite/TypeUtils.java b/src/main/java/net/imglib2/converter/readwrite/TypeUtils.java new file mode 100644 index 000000000..1960e2190 --- /dev/null +++ b/src/main/java/net/imglib2/converter/readwrite/TypeUtils.java @@ -0,0 +1,45 @@ +package net.imglib2.converter.readwrite; + +import java.util.function.Supplier; + +import net.imglib2.Sampler; + +/** + * Helper method for implementing Typed::getType + */ +class TypeUtils +{ + public static < A, B > B getConvertedType( A sourceType, Supplier< SamplerConverter< ? super A, B > > converterSupplier ) + { + return converterSupplier.get().convert( new ConstantSampler<>( sourceType ) ); + } + + private static class ConstantSampler< T > implements Sampler< T > + { + + private final T t; + + public ConstantSampler( T t ) + { + this.t = t; + } + + @Override + public T get() + { + return t; + } + + @Override + public T getType() // TODO GET-TYPE: just use default implementation + { + return t; + } + + @Override + public Sampler< T > copy() + { + return new ConstantSampler<>( t ); + } + } +} diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedCursor.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedCursor.java index 053ad440f..3436a10eb 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedCursor.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedCursor.java @@ -74,6 +74,12 @@ public B get() return converted; } + @Override + public B getType() + { + return converted; + } + @Override public WriteConvertedCursor< A, B > copy() { diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccess.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccess.java index 0d920f784..77fcd3c71 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccess.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccess.java @@ -74,6 +74,12 @@ public B get() return converted; } + @Override + public B getType() + { + return converted; + } + @Override public WriteConvertedRandomAccess< A, B > copy() { diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessible.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessible.java index 0983c3ba6..fccbd38b0 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessible.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessible.java @@ -38,7 +38,6 @@ import net.imglib2.Interval; import net.imglib2.RandomAccessible; -import net.imglib2.Sampler; import net.imglib2.converter.AbstractConvertedRandomAccessible; /** @@ -77,29 +76,8 @@ public WriteConvertedRandomAccess< A, B > randomAccess( final Interval interval } @Override - public B getType() { - return converterSupplier.get().convert( ( Sampler< ? extends A > ) new ConstantSampler( getSource().getType() ) ); - } - - private static class ConstantSampler< T > implements Sampler< T > + public B getType() { - - private final T t; - - public ConstantSampler( T t ) { - this.t = t; - } - - @Override - public T get() - { - return t; - } - - @Override - public Sampler< T > copy() - { - return new ConstantSampler<>( t ); - } + return TypeUtils.getConvertedType( getSource().getType(), converterSupplier ); } } diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessibleInterval.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessibleInterval.java index 211d0ef1d..4df4b7329 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRandomAccessibleInterval.java @@ -39,7 +39,6 @@ import net.imglib2.AbstractWrappedInterval; import net.imglib2.Interval; import net.imglib2.RandomAccessibleInterval; -import net.imglib2.Sampler; /** * TODO @@ -77,29 +76,8 @@ public WriteConvertedRandomAccess< A, B > randomAccess( final Interval interval } @Override - public B getType() { - return converterSupplier.get().convert( ( Sampler< ? extends A > ) new ConstantSampler( getSource().getType() ) ); - } - - private static class ConstantSampler< T > implements Sampler< T > + public B getType() { - - private final T t; - - public ConstantSampler( T t ) { - this.t = t; - } - - @Override - public T get() - { - return t; - } - - @Override - public Sampler< T > copy() - { - return new ConstantSampler<>( t ); - } + return TypeUtils.getConvertedType( getSource().getType(), converterSupplier ); } } diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRealCursor.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRealCursor.java index 153d4f502..eaf185239 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRealCursor.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedRealCursor.java @@ -74,6 +74,12 @@ public B get() return converted; } + @Override + public B getType() + { + return converted; + } + @Override public WriteConvertedRealCursor< A, B > copy() { diff --git a/src/main/java/net/imglib2/display/projector/sampler/IntervalSampler.java b/src/main/java/net/imglib2/display/projector/sampler/IntervalSampler.java index 92683a9e7..21a94b6ec 100644 --- a/src/main/java/net/imglib2/display/projector/sampler/IntervalSampler.java +++ b/src/main/java/net/imglib2/display/projector/sampler/IntervalSampler.java @@ -88,6 +88,12 @@ public T get() return m_source.get(); } + @Override + public T getType() + { + return m_source.getType(); + } + @Override public Sampler< T > copy() { diff --git a/src/main/java/net/imglib2/display/projector/sampler/SelectiveSampler.java b/src/main/java/net/imglib2/display/projector/sampler/SelectiveSampler.java index 46919509a..02fd19ae9 100644 --- a/src/main/java/net/imglib2/display/projector/sampler/SelectiveSampler.java +++ b/src/main/java/net/imglib2/display/projector/sampler/SelectiveSampler.java @@ -93,6 +93,12 @@ public T get() return m_source.get(); } + @Override + public T getType() + { + return m_source.getType(); + } + @Override public Sampler< T > copy() { diff --git a/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java b/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java index dbf5ccd66..465043968 100644 --- a/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java +++ b/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java @@ -128,6 +128,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public boolean hasNext() { diff --git a/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java b/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java index c0ae1cf52..1cf4422fd 100644 --- a/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java @@ -151,6 +151,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + /** * {@inheritDoc} */ diff --git a/src/main/java/net/imglib2/img/array/ArrayLocalizingSpliterator.java b/src/main/java/net/imglib2/img/array/ArrayLocalizingSpliterator.java index ef763c4fc..343193464 100644 --- a/src/main/java/net/imglib2/img/array/ArrayLocalizingSpliterator.java +++ b/src/main/java/net/imglib2/img/array/ArrayLocalizingSpliterator.java @@ -178,4 +178,10 @@ public T get() { return type; } + + @Override + public T getType() + { + return type; + } } diff --git a/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java b/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java index b397d2fa3..9220c7dc9 100644 --- a/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java +++ b/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java @@ -96,6 +96,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public void fwd( final int d ) { diff --git a/src/main/java/net/imglib2/img/array/ArraySpliterator.java b/src/main/java/net/imglib2/img/array/ArraySpliterator.java index 027822f51..a411ae1c2 100644 --- a/src/main/java/net/imglib2/img/array/ArraySpliterator.java +++ b/src/main/java/net/imglib2/img/array/ArraySpliterator.java @@ -135,6 +135,11 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } // ----------------------------------------------------------- diff --git a/src/main/java/net/imglib2/img/cell/CellCursor.java b/src/main/java/net/imglib2/img/cell/CellCursor.java index fbc7a261e..1805feffc 100644 --- a/src/main/java/net/imglib2/img/cell/CellCursor.java +++ b/src/main/java/net/imglib2/img/cell/CellCursor.java @@ -111,6 +111,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public CellCursor< T, C > copy() { diff --git a/src/main/java/net/imglib2/img/cell/CellGrid.java b/src/main/java/net/imglib2/img/cell/CellGrid.java index 96ce2bac8..3456a5b9a 100644 --- a/src/main/java/net/imglib2/img/cell/CellGrid.java +++ b/src/main/java/net/imglib2/img/cell/CellGrid.java @@ -685,6 +685,12 @@ public Interval get() return interval; } + @Override + public Interval getType() + { + return interval; + } + CellIntervalsRA() { super( CellGrid.this.n ); diff --git a/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java b/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java index 046ea3903..0cbb9929c 100644 --- a/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java @@ -116,6 +116,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public CellLocalizingCursor< T, C > copy() { diff --git a/src/main/java/net/imglib2/img/cell/CellRandomAccess.java b/src/main/java/net/imglib2/img/cell/CellRandomAccess.java index e419df79c..4e39a9cba 100644 --- a/src/main/java/net/imglib2/img/cell/CellRandomAccess.java +++ b/src/main/java/net/imglib2/img/cell/CellRandomAccess.java @@ -139,6 +139,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public CellRandomAccess< T, C > copy() { diff --git a/src/main/java/net/imglib2/img/cell/CellSpliterator.java b/src/main/java/net/imglib2/img/cell/CellSpliterator.java index 1d4a67ad5..10286d6ee 100644 --- a/src/main/java/net/imglib2/img/cell/CellSpliterator.java +++ b/src/main/java/net/imglib2/img/cell/CellSpliterator.java @@ -221,6 +221,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public String toString() { diff --git a/src/main/java/net/imglib2/img/list/AbstractLongListImg.java b/src/main/java/net/imglib2/img/list/AbstractLongListImg.java index 1f3c34658..c861c5058 100644 --- a/src/main/java/net/imglib2/img/list/AbstractLongListImg.java +++ b/src/main/java/net/imglib2/img/list/AbstractLongListImg.java @@ -98,6 +98,12 @@ public T get() return AbstractLongListImg.this.get( i ); } + @Override + public T getType() + { + return AbstractLongListImg.this.getType(); + } + public void set( final T t ) { AbstractLongListImg.this.set( i, t ); @@ -223,6 +229,12 @@ public T get() return AbstractLongListImg.this.get( i ); } + @Override + public T getType() + { + return AbstractLongListImg.this.getType(); + } + public void set( final T t ) { AbstractLongListImg.this.set( i, t ); @@ -262,6 +274,12 @@ public T get() return AbstractLongListImg.this.get( i ); } + @Override + public T getType() + { + return AbstractLongListImg.this.getType(); + } + public void set( final T t ) { AbstractLongListImg.this.set( i, t ); diff --git a/src/main/java/net/imglib2/img/list/ListCursor.java b/src/main/java/net/imglib2/img/list/ListCursor.java index f96a86523..ed8087769 100644 --- a/src/main/java/net/imglib2/img/list/ListCursor.java +++ b/src/main/java/net/imglib2/img/list/ListCursor.java @@ -82,6 +82,12 @@ public T get() return img.get( i ); } + @Override + public T getType() + { + return img.getType(); + } + public void set( final T t ) { img.set( i, t ); diff --git a/src/main/java/net/imglib2/img/list/ListImg.java b/src/main/java/net/imglib2/img/list/ListImg.java index cbb85b0cc..52ad73738 100644 --- a/src/main/java/net/imglib2/img/list/ListImg.java +++ b/src/main/java/net/imglib2/img/list/ListImg.java @@ -71,7 +71,6 @@ public ListImg( final long[] dim, final T type ) super( dim ); this.type = type; pixels = new ArrayList< T >( ( int ) numPixels ); - if ( type instanceof Type< ? > ) { final Type< ? > t = ( Type< ? > ) type; @@ -90,10 +89,8 @@ public ListImg( final long[] dim, final T type ) public ListImg( final T type, final Collection< T > collection, final long... dim ) { super( dim ); - - assert numPixels == collection.size() : "Dimensions do not match number of pixels."; - this.type = type; + assert numPixels == collection.size() : "Dimensions do not match number of pixels."; pixels = new ArrayList<>( collection ); } diff --git a/src/main/java/net/imglib2/img/list/ListLocalizingCursor.java b/src/main/java/net/imglib2/img/list/ListLocalizingCursor.java index c16f00723..c72f496dc 100644 --- a/src/main/java/net/imglib2/img/list/ListLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/list/ListLocalizingCursor.java @@ -129,6 +129,12 @@ public T get() return img.get( i ); } + @Override + public T getType() + { + return img.getType(); + } + public void set( final T t ) { img.set( i, t ); diff --git a/src/main/java/net/imglib2/img/list/ListRandomAccess.java b/src/main/java/net/imglib2/img/list/ListRandomAccess.java index 692cbb5e1..e5983624a 100644 --- a/src/main/java/net/imglib2/img/list/ListRandomAccess.java +++ b/src/main/java/net/imglib2/img/list/ListRandomAccess.java @@ -81,6 +81,12 @@ public T get() return img.get( i ); } + @Override + public T getType() + { + return img.getType(); + } + public void set( final T t ) { img.set( i, t ); diff --git a/src/main/java/net/imglib2/img/planar/PlanarCursor.java b/src/main/java/net/imglib2/img/planar/PlanarCursor.java index ca22cef76..97d616b30 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarCursor.java @@ -107,6 +107,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public PlanarCursor< T > copy() { diff --git a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java index fc1c08ea7..602cefca5 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java @@ -125,6 +125,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public PlanarLocalizingCursor< T > copy() { diff --git a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java index 5d4f2644f..c1526d428 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java @@ -142,6 +142,12 @@ public final T get() return type; } + @Override + public T getType() + { + return type; + } + /** * {@inheritDoc} */ diff --git a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java index bcb1f96bd..a664c7be4 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java @@ -153,6 +153,12 @@ public final T get() return type; } + @Override + public T getType() + { + return type; + } + /** * {@inheritDoc} */ diff --git a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java index f6f273fc0..cf4f0e3c2 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java +++ b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java @@ -103,6 +103,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public PlanarRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/img/planar/PlanarSpliterator.java b/src/main/java/net/imglib2/img/planar/PlanarSpliterator.java index bd9339438..915dc4816 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarSpliterator.java +++ b/src/main/java/net/imglib2/img/planar/PlanarSpliterator.java @@ -209,6 +209,11 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } diff --git a/src/main/java/net/imglib2/img/sparse/NtreeCursor.java b/src/main/java/net/imglib2/img/sparse/NtreeCursor.java index 28e587db5..afb431e68 100644 --- a/src/main/java/net/imglib2/img/sparse/NtreeCursor.java +++ b/src/main/java/net/imglib2/img/sparse/NtreeCursor.java @@ -83,6 +83,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public NtreeCursor< T > copy() { diff --git a/src/main/java/net/imglib2/img/sparse/NtreeRandomAccess.java b/src/main/java/net/imglib2/img/sparse/NtreeRandomAccess.java index 457d58d46..c88a1df30 100644 --- a/src/main/java/net/imglib2/img/sparse/NtreeRandomAccess.java +++ b/src/main/java/net/imglib2/img/sparse/NtreeRandomAccess.java @@ -125,6 +125,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public NtreeRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/interpolation/neighborsearch/InverseDistanceWeightingInterpolator.java b/src/main/java/net/imglib2/interpolation/neighborsearch/InverseDistanceWeightingInterpolator.java index 2d98ed3b6..e1622964c 100644 --- a/src/main/java/net/imglib2/interpolation/neighborsearch/InverseDistanceWeightingInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/neighborsearch/InverseDistanceWeightingInterpolator.java @@ -121,6 +121,12 @@ public T get() return value; } + @Override + public T getType() + { + return value; + } + protected double computeWeight( final double squareDistance ) { return 1.0 / Math.pow( squareDistance, p2 ); diff --git a/src/main/java/net/imglib2/interpolation/neighborsearch/NearestNeighborSearchInterpolator.java b/src/main/java/net/imglib2/interpolation/neighborsearch/NearestNeighborSearchInterpolator.java index 745835a8e..0c4f05ce8 100644 --- a/src/main/java/net/imglib2/interpolation/neighborsearch/NearestNeighborSearchInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/neighborsearch/NearestNeighborSearchInterpolator.java @@ -62,6 +62,12 @@ public T get() return search.getSampler().get(); } + @Override + public T getType() + { + return search.getSampler().getType(); // TODO GET-TYPE: getSampler() might return null, it would be better if NearestNeighborSearch had getType() + } + @Override public NearestNeighborSearchInterpolator< T > copy() { diff --git a/src/main/java/net/imglib2/interpolation/randomaccess/FloorInterpolator.java b/src/main/java/net/imglib2/interpolation/randomaccess/FloorInterpolator.java index f13662290..23d39ce82 100644 --- a/src/main/java/net/imglib2/interpolation/randomaccess/FloorInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/randomaccess/FloorInterpolator.java @@ -79,6 +79,12 @@ public T get() return target.get(); } + @Override + public T getType() + { + return get(); + } + @Override public FloorInterpolator< T > copy() { diff --git a/src/main/java/net/imglib2/interpolation/randomaccess/LanczosInterpolator.java b/src/main/java/net/imglib2/interpolation/randomaccess/LanczosInterpolator.java index e6f0eb13a..3cd1e26a0 100644 --- a/src/main/java/net/imglib2/interpolation/randomaccess/LanczosInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/randomaccess/LanczosInterpolator.java @@ -208,6 +208,12 @@ else if ( convolved > maxValue ) return interpolatedValue; } + @Override + public T getType() + { + return interpolatedValue; + } + private static final double lanczos( final double x, final double a ) { if ( x == 0 ) diff --git a/src/main/java/net/imglib2/interpolation/randomaccess/NLinearInterpolator.java b/src/main/java/net/imglib2/interpolation/randomaccess/NLinearInterpolator.java index 1ab544d70..3a6f328db 100644 --- a/src/main/java/net/imglib2/interpolation/randomaccess/NLinearInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/randomaccess/NLinearInterpolator.java @@ -208,6 +208,12 @@ public T get() return accumulator; } + @Override + public T getType() + { + return accumulator; + } + @Override public NLinearInterpolator< T > copy() { diff --git a/src/main/java/net/imglib2/interpolation/randomaccess/NearestNeighborInterpolator.java b/src/main/java/net/imglib2/interpolation/randomaccess/NearestNeighborInterpolator.java index b5815f358..60c20bc3b 100644 --- a/src/main/java/net/imglib2/interpolation/randomaccess/NearestNeighborInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/randomaccess/NearestNeighborInterpolator.java @@ -82,6 +82,12 @@ public T get() return target.get(); } + @Override + public T getType() + { + return get(); + } + @Override public NearestNeighborInterpolator< T > copy() { diff --git a/src/main/java/net/imglib2/interpolation/stack/NearestNeighborRealRandomAccessibleStackInterpolator.java b/src/main/java/net/imglib2/interpolation/stack/NearestNeighborRealRandomAccessibleStackInterpolator.java index bc00e372e..872c38f8f 100644 --- a/src/main/java/net/imglib2/interpolation/stack/NearestNeighborRealRandomAccessibleStackInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/stack/NearestNeighborRealRandomAccessibleStackInterpolator.java @@ -490,6 +490,12 @@ public T get() return sliceAccess.get(); } + @Override + public T getType() + { + return sliceAccesses[ 0 ].getType(); + } + @Override public NearestNeighborRealRandomAccessibleStackInterpolator< T > copy() { diff --git a/src/main/java/net/imglib2/outofbounds/AbstractOutOfBoundsMirror.java b/src/main/java/net/imglib2/outofbounds/AbstractOutOfBoundsMirror.java index d5cc54b9e..5d57170a7 100644 --- a/src/main/java/net/imglib2/outofbounds/AbstractOutOfBoundsMirror.java +++ b/src/main/java/net/imglib2/outofbounds/AbstractOutOfBoundsMirror.java @@ -162,6 +162,12 @@ public T get() return outOfBoundsRandomAccess.get(); } + @Override + public T getType() + { + return outOfBoundsRandomAccess.getType(); + } + @Override abstract public AbstractOutOfBoundsMirror< T > copy(); diff --git a/src/main/java/net/imglib2/outofbounds/AbstractOutOfBoundsValue.java b/src/main/java/net/imglib2/outofbounds/AbstractOutOfBoundsValue.java index b788288f0..c679de8bf 100644 --- a/src/main/java/net/imglib2/outofbounds/AbstractOutOfBoundsValue.java +++ b/src/main/java/net/imglib2/outofbounds/AbstractOutOfBoundsValue.java @@ -90,6 +90,12 @@ public < F extends Interval & RandomAccessible< T > > AbstractOutOfBoundsValue( dimIsOutOfBounds = new boolean[ n ]; } + @Override + public T getType() + { + return sampler.getType(); + } + final private void checkOutOfBounds() { for ( int d = 0; d < n; ++d ) diff --git a/src/main/java/net/imglib2/outofbounds/OutOfBoundsBorder.java b/src/main/java/net/imglib2/outofbounds/OutOfBoundsBorder.java index e595e73ff..d7369462d 100644 --- a/src/main/java/net/imglib2/outofbounds/OutOfBoundsBorder.java +++ b/src/main/java/net/imglib2/outofbounds/OutOfBoundsBorder.java @@ -137,6 +137,12 @@ public T get() return outOfBoundsRandomAccess.get(); } + @Override + public T getType() + { + return outOfBoundsRandomAccess.getType(); + } + @Override final public OutOfBoundsBorder< T > copy() { diff --git a/src/main/java/net/imglib2/outofbounds/OutOfBoundsPeriodic.java b/src/main/java/net/imglib2/outofbounds/OutOfBoundsPeriodic.java index 953459331..009d81bfc 100644 --- a/src/main/java/net/imglib2/outofbounds/OutOfBoundsPeriodic.java +++ b/src/main/java/net/imglib2/outofbounds/OutOfBoundsPeriodic.java @@ -160,6 +160,12 @@ public T get() return outOfBoundsRandomAccess.get(); } + @Override + public T getType() + { + return outOfBoundsRandomAccess.getType(); + } + @Override final public OutOfBoundsPeriodic< T > copy() { diff --git a/src/main/java/net/imglib2/outofbounds/RealOutOfBoundsRealRandomAccess.java b/src/main/java/net/imglib2/outofbounds/RealOutOfBoundsRealRandomAccess.java index d2ef7e1e8..0b0c9116b 100644 --- a/src/main/java/net/imglib2/outofbounds/RealOutOfBoundsRealRandomAccess.java +++ b/src/main/java/net/imglib2/outofbounds/RealOutOfBoundsRealRandomAccess.java @@ -91,6 +91,12 @@ public T get() return outOfBounds.get(); } + @Override + public T getType() + { + return outOfBounds.getType(); + } + @Override public RealOutOfBoundsRealRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/position/FunctionRandomAccessible.java b/src/main/java/net/imglib2/position/FunctionRandomAccessible.java index 7cd157cdb..025a820b0 100644 --- a/src/main/java/net/imglib2/position/FunctionRandomAccessible.java +++ b/src/main/java/net/imglib2/position/FunctionRandomAccessible.java @@ -85,6 +85,12 @@ public T get() return t; } + @Override + public T getType() + { + return t; + } + @Override public FunctionRandomAccess copy() { diff --git a/src/main/java/net/imglib2/position/FunctionRealRandomAccessible.java b/src/main/java/net/imglib2/position/FunctionRealRandomAccessible.java index 867d59641..1fc6daa4f 100644 --- a/src/main/java/net/imglib2/position/FunctionRealRandomAccessible.java +++ b/src/main/java/net/imglib2/position/FunctionRealRandomAccessible.java @@ -84,6 +84,12 @@ public T get() return t; } + @Override + public T getType() + { + return t; + } + @Override public RealFunctionRealRandomAccess copy() { diff --git a/src/main/java/net/imglib2/position/PositionRandomAccessible.java b/src/main/java/net/imglib2/position/PositionRandomAccessible.java index a8ec1555e..49dfaaf82 100644 --- a/src/main/java/net/imglib2/position/PositionRandomAccessible.java +++ b/src/main/java/net/imglib2/position/PositionRandomAccessible.java @@ -78,6 +78,12 @@ public LongType get() return t; } + @Override + public LongType getType() + { + return t; + } + @Override public PositionRandomAccess copy() { diff --git a/src/main/java/net/imglib2/position/RealPositionRealRandomAccessible.java b/src/main/java/net/imglib2/position/RealPositionRealRandomAccessible.java index 34f231272..095ef162e 100644 --- a/src/main/java/net/imglib2/position/RealPositionRealRandomAccessible.java +++ b/src/main/java/net/imglib2/position/RealPositionRealRandomAccessible.java @@ -78,6 +78,12 @@ public DoubleType get() return t; } + @Override + public DoubleType getType() + { + return t; + } + @Override public RealPositionRealRandomAccess copy() { diff --git a/src/main/java/net/imglib2/stream/CursorSpliterator.java b/src/main/java/net/imglib2/stream/CursorSpliterator.java index f60f8f47f..725bd1f64 100644 --- a/src/main/java/net/imglib2/stream/CursorSpliterator.java +++ b/src/main/java/net/imglib2/stream/CursorSpliterator.java @@ -139,6 +139,12 @@ public T get() return cursor.get(); } + @Override + public T getType() + { + return cursor.getType(); + } + @Override public CursorSpliterator< T > copy() { diff --git a/src/main/java/net/imglib2/stream/LocalizableSamplerWrapper.java b/src/main/java/net/imglib2/stream/LocalizableSamplerWrapper.java index c501a3fe7..0298136d1 100644 --- a/src/main/java/net/imglib2/stream/LocalizableSamplerWrapper.java +++ b/src/main/java/net/imglib2/stream/LocalizableSamplerWrapper.java @@ -69,6 +69,12 @@ public T get() return delegate.get(); } + @Override + public T getType() + { + return delegate.getType(); + } + @Override public LocalizableSamplerWrapper< T > copy() { diff --git a/src/main/java/net/imglib2/stream/RealCursorSpliterator.java b/src/main/java/net/imglib2/stream/RealCursorSpliterator.java index 31dc76260..58088a592 100644 --- a/src/main/java/net/imglib2/stream/RealCursorSpliterator.java +++ b/src/main/java/net/imglib2/stream/RealCursorSpliterator.java @@ -137,6 +137,12 @@ public T get() return cursor.get(); } + @Override + public T getType() + { + return cursor.getType(); + } + @Override public RealCursorSpliterator< T > copy() { diff --git a/src/main/java/net/imglib2/stream/RealLocalizableSamplerWrapper.java b/src/main/java/net/imglib2/stream/RealLocalizableSamplerWrapper.java index bbee16526..59dbc3670 100644 --- a/src/main/java/net/imglib2/stream/RealLocalizableSamplerWrapper.java +++ b/src/main/java/net/imglib2/stream/RealLocalizableSamplerWrapper.java @@ -68,6 +68,12 @@ public T get() return delegate.get(); } + @Override + public T getType() + { + return delegate.getType(); + } + @Override public RealLocalizableSamplerWrapper< T > copy() { diff --git a/src/main/java/net/imglib2/util/ConstantUtils.java b/src/main/java/net/imglib2/util/ConstantUtils.java index d79c69375..e36437e72 100644 --- a/src/main/java/net/imglib2/util/ConstantUtils.java +++ b/src/main/java/net/imglib2/util/ConstantUtils.java @@ -70,6 +70,12 @@ public T get() return constant; } + @Override + public T getType() + { + return constant; + } + @Override public ConstantRandomAccess copy() { @@ -130,6 +136,12 @@ public T get() return constant; } + @Override + public T getType() + { + return constant; + } + @Override public ConstantRealRandomAccess copy() { diff --git a/src/main/java/net/imglib2/util/Grid.java b/src/main/java/net/imglib2/util/Grid.java index 5c72cddad..cb66b7d19 100644 --- a/src/main/java/net/imglib2/util/Grid.java +++ b/src/main/java/net/imglib2/util/Grid.java @@ -476,6 +476,12 @@ public Interval get() return interval; } + @Override + public Interval getType() + { + return interval; + } + CellIntervalsRA() { super( Grid.this.n ); diff --git a/src/main/java/net/imglib2/util/Localizables.java b/src/main/java/net/imglib2/util/Localizables.java index 54b726dac..bb93cff4b 100644 --- a/src/main/java/net/imglib2/util/Localizables.java +++ b/src/main/java/net/imglib2/util/Localizables.java @@ -226,6 +226,12 @@ public Localizable get() return this; } + @Override + public Localizable getType() + { + return this; + } + @Override public RandomAccess< Localizable > copy() { @@ -274,6 +280,12 @@ public RealLocationRealRandomAccess get() return this; } + @Override + public RealLocalizable getType() + { + return this; + } + @Override public RealLocationRealRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/BundleView.java b/src/main/java/net/imglib2/view/BundleView.java index 3dce2213a..cf521554e 100644 --- a/src/main/java/net/imglib2/view/BundleView.java +++ b/src/main/java/net/imglib2/view/BundleView.java @@ -73,6 +73,12 @@ public RandomAccess< T > get() return source; } + @Override + public RandomAccess< T > getType() + { + return source; + } + @Override public BundleRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/FullSourceMapMixedRandomAccess.java b/src/main/java/net/imglib2/view/FullSourceMapMixedRandomAccess.java index 92d0e9be4..6344da24d 100644 --- a/src/main/java/net/imglib2/view/FullSourceMapMixedRandomAccess.java +++ b/src/main/java/net/imglib2/view/FullSourceMapMixedRandomAccess.java @@ -368,6 +368,12 @@ public T get() return s.get(); } + @Override + public T getType() + { + return s.getType(); + } + @Override public FullSourceMapMixedRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/view/FullSourceMapSlicingRandomAccess.java b/src/main/java/net/imglib2/view/FullSourceMapSlicingRandomAccess.java index 4de89a070..5f0767c55 100644 --- a/src/main/java/net/imglib2/view/FullSourceMapSlicingRandomAccess.java +++ b/src/main/java/net/imglib2/view/FullSourceMapSlicingRandomAccess.java @@ -310,6 +310,12 @@ public T get() return s.get(); } + @Override + public T getType() + { + return s.getType(); + } + @Override public FullSourceMapSlicingRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/view/FunctionView.java b/src/main/java/net/imglib2/view/FunctionView.java index f40cc13ec..5dec47476 100644 --- a/src/main/java/net/imglib2/view/FunctionView.java +++ b/src/main/java/net/imglib2/view/FunctionView.java @@ -59,6 +59,12 @@ public B get() return function.apply( source.get() ); } + @Override + public B getType() + { + return get(); // TODO GET-TYPE: It looks like there is no good solution here. + } + @Override public FunctionRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/HyperSlice.java b/src/main/java/net/imglib2/view/HyperSlice.java index 7b0c0e420..6607b3e07 100644 --- a/src/main/java/net/imglib2/view/HyperSlice.java +++ b/src/main/java/net/imglib2/view/HyperSlice.java @@ -241,6 +241,12 @@ public T get() return sourceAccess.get(); } + @Override + public T getType() + { + return sourceAccess.getType(); + } + @Override public HyperSliceRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/HyperSlicesView.java b/src/main/java/net/imglib2/view/HyperSlicesView.java index c30d28750..18186b501 100644 --- a/src/main/java/net/imglib2/view/HyperSlicesView.java +++ b/src/main/java/net/imglib2/view/HyperSlicesView.java @@ -78,6 +78,12 @@ public HyperSlice< T > get() return new HyperSlice<>( source, accessAxes, position ); } + @Override + public HyperSlice< T > getType() + { + return new HyperSlice< T >( source, accessAxes, new long[ source.numDimensions() ] ); + } + @Override public HyperSlicesViewRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/MixedRandomAccess.java b/src/main/java/net/imglib2/view/MixedRandomAccess.java index cfa060c08..cc4b66723 100644 --- a/src/main/java/net/imglib2/view/MixedRandomAccess.java +++ b/src/main/java/net/imglib2/view/MixedRandomAccess.java @@ -364,6 +364,12 @@ public T get() return s.get(); } + @Override + public T getType() + { + return s.getType(); + } + @Override public MixedRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/view/RandomAccessibleIntervalCursor.java b/src/main/java/net/imglib2/view/RandomAccessibleIntervalCursor.java index 99baaece2..2cf7c7156 100644 --- a/src/main/java/net/imglib2/view/RandomAccessibleIntervalCursor.java +++ b/src/main/java/net/imglib2/view/RandomAccessibleIntervalCursor.java @@ -96,6 +96,12 @@ public T get() return randomAccess.get(); } + @Override + public T getType() + { + return randomAccess.getType(); + } + @Override public void jumpFwd( final long steps ) { diff --git a/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java b/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java index f02df3e93..3d58f4156 100644 --- a/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java +++ b/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java @@ -194,6 +194,12 @@ public T get() return sourceAccess.get(); } + @Override + public T getType() + { + return sourceAccess.getType(); + } + @Override public RandomAccessOnRealRandomAccessible copy() { diff --git a/src/main/java/net/imglib2/view/RandomAccessiblePair.java b/src/main/java/net/imglib2/view/RandomAccessiblePair.java index 09c74bc8c..0fe2d1af2 100644 --- a/src/main/java/net/imglib2/view/RandomAccessiblePair.java +++ b/src/main/java/net/imglib2/view/RandomAccessiblePair.java @@ -219,6 +219,12 @@ public RandomAccess get() return this; } + @Override + public RandomAccess getType() + { + return this; + } + @Override public RandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/SlicingRandomAccess.java b/src/main/java/net/imglib2/view/SlicingRandomAccess.java index a9dab2aa6..99e18945a 100644 --- a/src/main/java/net/imglib2/view/SlicingRandomAccess.java +++ b/src/main/java/net/imglib2/view/SlicingRandomAccess.java @@ -298,6 +298,12 @@ public T get() return s.get(); } + @Override + public T getType() + { + return s.getType(); + } + @Override public SlicingRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/view/StackView.java b/src/main/java/net/imglib2/view/StackView.java index 343cfeb1a..98019cbfa 100644 --- a/src/main/java/net/imglib2/view/StackView.java +++ b/src/main/java/net/imglib2/view/StackView.java @@ -440,6 +440,12 @@ public T get() return sliceAccess.get(); } + @Override + public T getType() + { + return sliceAccess.getType(); + } + @Override public DefaultRA< T > copy() { @@ -715,6 +721,12 @@ public T get() return sliceAccesses[ slice ].get(); } + @Override + public T getType() + { + return sliceAccesses[ 0 ].getType(); + } + @Override public MoveAllSlicesRA< T > copy() { diff --git a/src/main/java/net/imglib2/view/SubsampleView.java b/src/main/java/net/imglib2/view/SubsampleView.java index fa7967719..d2c67189a 100644 --- a/src/main/java/net/imglib2/view/SubsampleView.java +++ b/src/main/java/net/imglib2/view/SubsampleView.java @@ -225,6 +225,12 @@ public T get() return sourceRandomAccess.get(); } + @Override + public T getType() + { + return sourceRandomAccess.getType(); + } + @Override public SubsampleRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/TransformRandomAccess.java b/src/main/java/net/imglib2/view/TransformRandomAccess.java index 0abef5106..73fd91481 100644 --- a/src/main/java/net/imglib2/view/TransformRandomAccess.java +++ b/src/main/java/net/imglib2/view/TransformRandomAccess.java @@ -184,11 +184,17 @@ public void setPosition( final long pos, final int d ) @Override public T get() { - transformToSource.apply( position, tmp ); - source.setPosition( tmp ); + transformToSource.apply( position, tmp ); + source.setPosition( tmp ); return source.get(); } + @Override + public T getType() + { + return source.getType(); + } + @Override public TransformRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/view/TranslationRandomAccess.java b/src/main/java/net/imglib2/view/TranslationRandomAccess.java index c5cfabcff..84f7c825b 100644 --- a/src/main/java/net/imglib2/view/TranslationRandomAccess.java +++ b/src/main/java/net/imglib2/view/TranslationRandomAccess.java @@ -223,6 +223,12 @@ public T get() return s.get(); } + @Override + public T getType() + { + return s.getType(); + } + @Override public TranslationRandomAccess< T > copy() { diff --git a/src/main/java/net/imglib2/view/composite/CompositeView.java b/src/main/java/net/imglib2/view/composite/CompositeView.java index 2e9105b52..6d54ba0a8 100644 --- a/src/main/java/net/imglib2/view/composite/CompositeView.java +++ b/src/main/java/net/imglib2/view/composite/CompositeView.java @@ -215,6 +215,12 @@ public C get() return composite; } + @Override + public C getType() + { + return composite; + } + @Override public CompositeRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/composite/InflateView.java b/src/main/java/net/imglib2/view/composite/InflateView.java index 3340a2502..5048ec2c4 100644 --- a/src/main/java/net/imglib2/view/composite/InflateView.java +++ b/src/main/java/net/imglib2/view/composite/InflateView.java @@ -282,6 +282,12 @@ public T get() return composite.get( compositePosition ); } + @Override + public T getType() + { + return composite.get( 0 ); // TODO GET-TYPE: should we add Composite.getType() ? + } + @Override public InflateRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/composite/InterleaveView.java b/src/main/java/net/imglib2/view/composite/InterleaveView.java index 02a533762..d13857df0 100644 --- a/src/main/java/net/imglib2/view/composite/InterleaveView.java +++ b/src/main/java/net/imglib2/view/composite/InterleaveView.java @@ -276,6 +276,12 @@ public T get() return composite.get( compositePosition ); } + @Override + public T getType() + { + return composite.get( 0 ); // TODO GET-TYPE: should we add Composite.getType() ? + } + @Override public InterleaveRandomAccess copy() { diff --git a/src/main/java/net/imglib2/view/iteration/SlicingCursor.java b/src/main/java/net/imglib2/view/iteration/SlicingCursor.java index 323118371..092d4d875 100644 --- a/src/main/java/net/imglib2/view/iteration/SlicingCursor.java +++ b/src/main/java/net/imglib2/view/iteration/SlicingCursor.java @@ -197,6 +197,12 @@ public T get() return s.get(); } + @Override + public T getType() + { + return s.getType(); + } + /** * {@inheritDoc} */ diff --git a/src/test/java/net/imglib2/converter/AbstractConvertedRandomAccessibleIntervalTest.java b/src/test/java/net/imglib2/converter/AbstractConvertedRandomAccessibleIntervalTest.java index f32b52cdc..1ae1b2801 100644 --- a/src/test/java/net/imglib2/converter/AbstractConvertedRandomAccessibleIntervalTest.java +++ b/src/test/java/net/imglib2/converter/AbstractConvertedRandomAccessibleIntervalTest.java @@ -86,6 +86,12 @@ public DoubleType get() return t; } + @Override + public DoubleType getType() + { + return t; + } + @Override public AbstractConvertedRandomAccess< DoubleType, DoubleType > copy() { From 62054610b00bb99a4e40d7f63c7b5a2e5e8a287b Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 2 Apr 2024 21:49:59 +0200 Subject: [PATCH 09/19] Remove default getType in Real..Accessibles Instead implement it in all Real...Accessible implementation --- src/main/java/net/imglib2/KDTree.java | 7 ++++++- src/main/java/net/imglib2/RealRandomAccessible.java | 11 ++++++----- .../net/imglib2/RealRandomAccessibleRealInterval.java | 9 +++++---- .../converter/AbstractConvertedIterableInterval.java | 10 +++++----- .../AbstractConvertedIterableRealInterval.java | 10 +++++----- .../converter/read/BiConvertedIterableInterval.java | 5 +++++ .../read/BiConvertedIterableRealInterval.java | 5 +++++ .../read/BiConvertedRealRandomAccessible.java | 5 +++++ .../BiConvertedRealRandomAccessibleRealInterval.java | 5 +++++ .../converter/read/ConvertedIterableInterval.java | 5 +++++ .../converter/read/ConvertedIterableRealInterval.java | 5 +++++ .../converter/read/ConvertedRealRandomAccessible.java | 5 +++++ .../ConvertedRealRandomAccessibleRealInterval.java | 5 +++++ .../readwrite/WriteConvertedIterableInterval.java | 6 ++++++ .../readwrite/WriteConvertedIterableRealInterval.java | 6 ++++++ .../java/net/imglib2/interpolation/Interpolant.java | 6 ++++++ .../position/FunctionRealRandomAccessible.java | 6 ++++++ .../position/RealPositionRealRandomAccessible.java | 6 ++++++ src/main/java/net/imglib2/util/ConstantUtils.java | 6 ++++++ src/main/java/net/imglib2/util/Localizables.java | 6 ++++++ 20 files changed, 109 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/imglib2/KDTree.java b/src/main/java/net/imglib2/KDTree.java index 861931f5a..cd0730dfb 100644 --- a/src/main/java/net/imglib2/KDTree.java +++ b/src/main/java/net/imglib2/KDTree.java @@ -117,7 +117,6 @@ private static < A > Iterable< RealLocalizable > positionsIterable( IterableReal { return new AbstractConvertedIterableRealInterval< A, RealLocalizable >( sourceInterval ) { - class Cursor extends AbstractConvertedRealCursor< A, RealLocalizable > { Cursor( final RealCursor< A > source ) @@ -144,6 +143,12 @@ public RealLocalizable getType() } } + @Override + public RealLocalizable getType() + { + return firstElement(); + } + @Override public AbstractConvertedRealCursor< A, RealLocalizable > cursor() { diff --git a/src/main/java/net/imglib2/RealRandomAccessible.java b/src/main/java/net/imglib2/RealRandomAccessible.java index eeefee029..f1e3a5d04 100644 --- a/src/main/java/net/imglib2/RealRandomAccessible.java +++ b/src/main/java/net/imglib2/RealRandomAccessible.java @@ -55,7 +55,7 @@ * * @author Stephan Saalfeld */ -public interface RealRandomAccessible< T > extends EuclideanSpace +public interface RealRandomAccessible< T > extends EuclideanSpace, Typed< T > { /** * Create a random access sampler for real coordinates. @@ -133,8 +133,9 @@ default T getAt( final RealLocalizable position ) * * @return an instance of {@code T} */ - default T getType() - { - return realRandomAccess().get(); - } +// @Override +// default T getType() +// { +// return realRandomAccess().get(); +// } } diff --git a/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java index be2ba1246..12a764d77 100644 --- a/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java @@ -76,8 +76,9 @@ public interface RealRandomAccessibleRealInterval< T > extends RealRandomAccessi * * @return an instance of {@code T} */ - default T getType() - { - return getAt( Intervals.minAsDoubleArray( this ) ); - } +// @Override +// default T getType() +// { +// return getAt( Intervals.minAsDoubleArray( this ) ); +// } } diff --git a/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java b/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java index 3cb52a701..f136100cf 100644 --- a/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java +++ b/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java @@ -69,9 +69,9 @@ public Object iterationOrder() @Override abstract public AbstractConvertedCursor< A, B > localizingCursor(); - @Override - public B getType() - { - return firstElement(); // TODO GET-TYPE: Probably cursor().getType() is better? Or something else entirely? - } +// @Override +// public B getType() +// { +// return firstElement(); // TODO GET-TYPE: Probably cursor().getType() is better? Or something else entirely? +// } } diff --git a/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java b/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java index 6f5f2bd7d..5bbf097aa 100644 --- a/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java +++ b/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java @@ -69,9 +69,9 @@ public Object iterationOrder() @Override abstract public AbstractConvertedRealCursor< A, B > localizingCursor(); - @Override - public B getType() - { - return firstElement(); // TODO GET-TYPE: Probably cursor().getType() is better? Or something else entirely? - } +// @Override +// public B getType() +// { +// return firstElement(); // TODO GET-TYPE: Probably cursor().getType() is better? Or something else entirely? +// } } diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedIterableInterval.java b/src/main/java/net/imglib2/converter/read/BiConvertedIterableInterval.java index 42f715fe8..7c2b1a203 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedIterableInterval.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedIterableInterval.java @@ -137,6 +137,11 @@ public C getDestinationType() return convertedSupplier; } + @Override + public C getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link BiConverter}. If the diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedIterableRealInterval.java b/src/main/java/net/imglib2/converter/read/BiConvertedIterableRealInterval.java index 4f40c84e3..7f4a30379 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedIterableRealInterval.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedIterableRealInterval.java @@ -127,6 +127,11 @@ public C getDestinationType() return convertedSupplier; } + @Override + public C getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link BiConverter}. If the diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccessible.java b/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccessible.java index ffb04aec5..97ba1c98b 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccessible.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccessible.java @@ -115,6 +115,11 @@ public C getDestinationType() return convertedSupplier; } + @Override + public C getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link BiConverter}. If the diff --git a/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccessibleRealInterval.java index 2b16881cc..663a7f440 100644 --- a/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/converter/read/BiConvertedRealRandomAccessibleRealInterval.java @@ -116,6 +116,11 @@ public C getDestinationType() return convertedSupplier; } + @Override + public C getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link BiConverter}. If the diff --git a/src/main/java/net/imglib2/converter/read/ConvertedIterableInterval.java b/src/main/java/net/imglib2/converter/read/ConvertedIterableInterval.java index 3230f7490..9cb531043 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedIterableInterval.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedIterableInterval.java @@ -113,6 +113,11 @@ public B getDestinationType() return convertedSupplier; } + @Override + public B getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link Converter}. If the diff --git a/src/main/java/net/imglib2/converter/read/ConvertedIterableRealInterval.java b/src/main/java/net/imglib2/converter/read/ConvertedIterableRealInterval.java index 25e5d87ba..49847583e 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedIterableRealInterval.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedIterableRealInterval.java @@ -114,6 +114,11 @@ public B getDestinationType() return convertedSupplier; } + @Override + public B getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link Converter}. If the diff --git a/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccessible.java b/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccessible.java index b50500601..3591a489d 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccessible.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccessible.java @@ -102,6 +102,11 @@ public B getDestinationType() return convertedSupplier; } + @Override + public B getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link Converter}. If the diff --git a/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccessibleRealInterval.java index 1eb7c28b6..0e78f0203 100644 --- a/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/converter/read/ConvertedRealRandomAccessibleRealInterval.java @@ -103,6 +103,11 @@ public B getDestinationType() return convertedSupplier; } + @Override + public B getType() + { + return convertedSupplier.get(); + } /** * Returns an instance of the {@link Converter}. If the diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableInterval.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableInterval.java index 70ed5a3cf..85202974f 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableInterval.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableInterval.java @@ -71,4 +71,10 @@ public WriteConvertedCursor< A, B > localizingCursor() { return new WriteConvertedCursor< A, B >( sourceInterval.localizingCursor(), converterSupplier ); } + + @Override + public B getType() + { + return TypeUtils.getConvertedType( getSource().getType(), converterSupplier ); + } } diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRealInterval.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRealInterval.java index 5a02af6a7..9118139b0 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRealInterval.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRealInterval.java @@ -73,4 +73,10 @@ public WriteConvertedRealCursor< A, B > localizingCursor() { return new WriteConvertedRealCursor< A, B >( sourceInterval.localizingCursor(), converterSupplier ); } + + @Override + public B getType() + { + return TypeUtils.getConvertedType( getSource().getType(), converterSupplier ); + } } diff --git a/src/main/java/net/imglib2/interpolation/Interpolant.java b/src/main/java/net/imglib2/interpolation/Interpolant.java index 7d3724b1e..e2b6eb3ee 100644 --- a/src/main/java/net/imglib2/interpolation/Interpolant.java +++ b/src/main/java/net/imglib2/interpolation/Interpolant.java @@ -109,6 +109,12 @@ public F getSource() return source; } + @Override + public T getType() + { + return realRandomAccess().getType(); // TODO: this could be better, if InterpolatorFactory would implement getType() + } + /** * @return {@link InterpolatorFactory} used for interpolation */ diff --git a/src/main/java/net/imglib2/position/FunctionRealRandomAccessible.java b/src/main/java/net/imglib2/position/FunctionRealRandomAccessible.java index 1fc6daa4f..5b3eafc53 100644 --- a/src/main/java/net/imglib2/position/FunctionRealRandomAccessible.java +++ b/src/main/java/net/imglib2/position/FunctionRealRandomAccessible.java @@ -97,6 +97,12 @@ public RealFunctionRealRandomAccess copy() } } + @Override + public T getType() + { + return typeSupplier.get(); + } + @Override public RealFunctionRealRandomAccess realRandomAccess() { diff --git a/src/main/java/net/imglib2/position/RealPositionRealRandomAccessible.java b/src/main/java/net/imglib2/position/RealPositionRealRandomAccessible.java index 095ef162e..236be9ab1 100644 --- a/src/main/java/net/imglib2/position/RealPositionRealRandomAccessible.java +++ b/src/main/java/net/imglib2/position/RealPositionRealRandomAccessible.java @@ -108,4 +108,10 @@ public RealPositionRealRandomAccess realRandomAccess( final RealInterval interva { return realRandomAccess(); } + + @Override + public DoubleType getType() + { + return new DoubleType(); + } } diff --git a/src/main/java/net/imglib2/util/ConstantUtils.java b/src/main/java/net/imglib2/util/ConstantUtils.java index e36437e72..1c5c56470 100644 --- a/src/main/java/net/imglib2/util/ConstantUtils.java +++ b/src/main/java/net/imglib2/util/ConstantUtils.java @@ -149,6 +149,12 @@ public ConstantRealRandomAccess copy() } } + @Override + public T getType() + { + return constant; + } + @Override public ConstantRealRandomAccess realRandomAccess() { diff --git a/src/main/java/net/imglib2/util/Localizables.java b/src/main/java/net/imglib2/util/Localizables.java index bb93cff4b..1cfa9d150 100644 --- a/src/main/java/net/imglib2/util/Localizables.java +++ b/src/main/java/net/imglib2/util/Localizables.java @@ -257,6 +257,12 @@ public RealLocationRealRandomAccess realRandomAccess( final RealInterval interva { return realRandomAccess(); } + + @Override + public RealLocalizable getType() + { + return realRandomAccess(); + } } /** From 14a5b101e8df62af3c8660ac7f11f3d43c90072f Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 26 Mar 2024 15:53:47 +0100 Subject: [PATCH 10/19] clean up --- .../AbstractConvertedIterableInterval.java | 6 ---- ...AbstractConvertedIterableRealInterval.java | 6 ---- ...ertedIterableRandomAccessibleInterval.java | 33 ++++--------------- .../randomaccess/FloorInterpolator.java | 2 +- .../NearestNeighborInterpolator.java | 2 +- .../java/net/imglib2/util/ConstantUtils.java | 3 +- src/main/java/net/imglib2/util/Util.java | 26 +++------------ .../java/net/imglib2/view/FunctionView.java | 2 +- .../net/imglib2/view/HyperSlicesView.java | 2 +- .../imglib2/view/composite/CompositeView.java | 2 +- .../imglib2/view/composite/InflateView.java | 2 +- .../view/composite/InterleaveView.java | 2 +- 12 files changed, 20 insertions(+), 68 deletions(-) diff --git a/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java b/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java index f136100cf..7f9b9dff2 100644 --- a/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java +++ b/src/main/java/net/imglib2/converter/AbstractConvertedIterableInterval.java @@ -68,10 +68,4 @@ public Object iterationOrder() @Override abstract public AbstractConvertedCursor< A, B > localizingCursor(); - -// @Override -// public B getType() -// { -// return firstElement(); // TODO GET-TYPE: Probably cursor().getType() is better? Or something else entirely? -// } } diff --git a/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java b/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java index 5bbf097aa..2c379f3a4 100644 --- a/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java +++ b/src/main/java/net/imglib2/converter/AbstractConvertedIterableRealInterval.java @@ -68,10 +68,4 @@ public Object iterationOrder() @Override abstract public AbstractConvertedRealCursor< A, B > localizingCursor(); - -// @Override -// public B getType() -// { -// return firstElement(); // TODO GET-TYPE: Probably cursor().getType() is better? Or something else entirely? -// } } diff --git a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRandomAccessibleInterval.java b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRandomAccessibleInterval.java index 76a512ce9..ddfb63fe8 100644 --- a/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/converter/readwrite/WriteConvertedIterableRandomAccessibleInterval.java @@ -49,69 +49,48 @@ public class WriteConvertedIterableRandomAccessibleInterval< A, B, S extends Ran { private final Supplier< SamplerConverter< ? super A, B > > converterSupplier; - private final Supplier< B > typeSupplier; - public WriteConvertedIterableRandomAccessibleInterval( final S source, final Supplier< SamplerConverter< ? super A, B > > converterSupplier ) { super( source ); this.converterSupplier = converterSupplier; - this.typeSupplier = () -> cursor().next(); } public WriteConvertedIterableRandomAccessibleInterval( final S source, - final Supplier< SamplerConverter< ? super A, B > > converterSupplier, - final Supplier< B > typeSupplier ) - { - super( source ); - this.converterSupplier = converterSupplier; - this.typeSupplier = typeSupplier; - } - - public WriteConvertedIterableRandomAccessibleInterval( - final S source, - final SamplerConverter< ? super A, B > converter) + final SamplerConverter< ? super A, B > converter ) { this( source, () -> converter ); } - public WriteConvertedIterableRandomAccessibleInterval( - final S source, - final SamplerConverter< ? super A, B > converter, - final B type ) - { - this( source, () -> converter, () -> type ); - } - @Override public WriteConvertedRandomAccess< A, B > randomAccess() { - return new WriteConvertedRandomAccess<>( sourceInterval.randomAccess(), converterSupplier ); + return new WriteConvertedRandomAccess< A, B >( sourceInterval.randomAccess(), converterSupplier ); } @Override public WriteConvertedRandomAccess< A, B > randomAccess( final Interval interval ) { - return new WriteConvertedRandomAccess<>( sourceInterval.randomAccess( interval ), converterSupplier ); + return new WriteConvertedRandomAccess< A, B >( sourceInterval.randomAccess( interval ), converterSupplier ); } @Override public WriteConvertedCursor< A, B > cursor() { - return new WriteConvertedCursor<>( sourceInterval.cursor(), converterSupplier ); + return new WriteConvertedCursor< A, B >( sourceInterval.cursor(), converterSupplier ); } @Override public WriteConvertedCursor< A, B > localizingCursor() { - return new WriteConvertedCursor<>( sourceInterval.localizingCursor(), converterSupplier ); + return new WriteConvertedCursor< A, B >( sourceInterval.localizingCursor(), converterSupplier ); } @Override public B getType() { - return typeSupplier.get(); + return TypeUtils.getConvertedType( getSource().getType(), converterSupplier ); } } diff --git a/src/main/java/net/imglib2/interpolation/randomaccess/FloorInterpolator.java b/src/main/java/net/imglib2/interpolation/randomaccess/FloorInterpolator.java index 23d39ce82..ca804b7f3 100644 --- a/src/main/java/net/imglib2/interpolation/randomaccess/FloorInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/randomaccess/FloorInterpolator.java @@ -82,7 +82,7 @@ public T get() @Override public T getType() { - return get(); + return target.getType(); } @Override diff --git a/src/main/java/net/imglib2/interpolation/randomaccess/NearestNeighborInterpolator.java b/src/main/java/net/imglib2/interpolation/randomaccess/NearestNeighborInterpolator.java index 60c20bc3b..b2ce92339 100644 --- a/src/main/java/net/imglib2/interpolation/randomaccess/NearestNeighborInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/randomaccess/NearestNeighborInterpolator.java @@ -85,7 +85,7 @@ public T get() @Override public T getType() { - return get(); + return target.getType(); } @Override diff --git a/src/main/java/net/imglib2/util/ConstantUtils.java b/src/main/java/net/imglib2/util/ConstantUtils.java index 1c5c56470..06811d9b6 100644 --- a/src/main/java/net/imglib2/util/ConstantUtils.java +++ b/src/main/java/net/imglib2/util/ConstantUtils.java @@ -96,7 +96,8 @@ public RandomAccess< T > randomAccess( final Interval interval ) } @Override - public T getType() { + public T getType() + { return constant; } }; diff --git a/src/main/java/net/imglib2/util/Util.java b/src/main/java/net/imglib2/util/Util.java index 481128bea..c18484dc4 100644 --- a/src/main/java/net/imglib2/util/Util.java +++ b/src/main/java/net/imglib2/util/Util.java @@ -796,20 +796,9 @@ final static public long[] int2long( final int[] i ) * @return - an instance of T */ @Deprecated - final public static < T, F extends Interval & RandomAccessible< T > > T getTypeFromInterval( final F rai ) + public static < T, F extends Interval & RandomAccessible< T > > T getTypeFromInterval( final F rai ) { - if (rai instanceof RandomAccessibleInterval) - return ((RandomAccessibleInterval) rai).getType(); - // TODO can we remove generic parameter F and use - // RandomAccessible rai instead? - // This would be a breaking change, though. - // create RandomAccess - final RandomAccess< T > randomAccess = rai.randomAccess(); - - // place it at the first pixel - rai.min( randomAccess ); - - return randomAccess.get(); + return rai.getType(); } /** @@ -822,15 +811,10 @@ final public static < T, F extends Interval & RandomAccessible< T > > T getTypeF * - the {@link RandomAccessibleInterval} * @return - an instance of T */ - final public static < T, F extends RealInterval & RealRandomAccessible< T >> T getTypeFromRealInterval( final F rai ) + @Deprecated + public static < T, F extends RealInterval & RealRandomAccessible< T >> T getTypeFromRealInterval( final F rai ) { - // create RealRandomAccess - final RealRandomAccess< T > realRandomAccess = rai.realRandomAccess(); - - // place it at the first pixel - rai.realMin( realRandomAccess ); - - return realRandomAccess.get(); + return rai.getType(); } /** diff --git a/src/main/java/net/imglib2/view/FunctionView.java b/src/main/java/net/imglib2/view/FunctionView.java index 5dec47476..4f5880fd8 100644 --- a/src/main/java/net/imglib2/view/FunctionView.java +++ b/src/main/java/net/imglib2/view/FunctionView.java @@ -99,6 +99,6 @@ public RandomAccess< B > randomAccess( final Interval interval ) @Override public B getType() { - return randomAccess().get(); // TODO GET-TYPE: should be getType(); + return randomAccess().getType(); } } diff --git a/src/main/java/net/imglib2/view/HyperSlicesView.java b/src/main/java/net/imglib2/view/HyperSlicesView.java index 18186b501..aacaf9cc6 100644 --- a/src/main/java/net/imglib2/view/HyperSlicesView.java +++ b/src/main/java/net/imglib2/view/HyperSlicesView.java @@ -132,6 +132,6 @@ public HyperSlicesViewRandomAccess randomAccess( final Interval interval ) @Override public HyperSlice< T > getType() { - return randomAccess().get(); // TODO GET-TYPE: should be getType(); + return randomAccess().getType(); } } diff --git a/src/main/java/net/imglib2/view/composite/CompositeView.java b/src/main/java/net/imglib2/view/composite/CompositeView.java index 6d54ba0a8..0780aba55 100644 --- a/src/main/java/net/imglib2/view/composite/CompositeView.java +++ b/src/main/java/net/imglib2/view/composite/CompositeView.java @@ -256,7 +256,7 @@ public CompositeRandomAccess randomAccess( final Interval interval ) @Override public C getType() { - return randomAccess().get(); // TODO GET-TYPE: should be .getType() when that is available + return randomAccess().getType(); } } diff --git a/src/main/java/net/imglib2/view/composite/InflateView.java b/src/main/java/net/imglib2/view/composite/InflateView.java index 5048ec2c4..796bf3dd3 100644 --- a/src/main/java/net/imglib2/view/composite/InflateView.java +++ b/src/main/java/net/imglib2/view/composite/InflateView.java @@ -285,7 +285,7 @@ public T get() @Override public T getType() { - return composite.get( 0 ); // TODO GET-TYPE: should we add Composite.getType() ? + return composite.get( 0 ); } @Override diff --git a/src/main/java/net/imglib2/view/composite/InterleaveView.java b/src/main/java/net/imglib2/view/composite/InterleaveView.java index d13857df0..1e1c817c2 100644 --- a/src/main/java/net/imglib2/view/composite/InterleaveView.java +++ b/src/main/java/net/imglib2/view/composite/InterleaveView.java @@ -279,7 +279,7 @@ public T get() @Override public T getType() { - return composite.get( 0 ); // TODO GET-TYPE: should we add Composite.getType() ? + return composite.get( 0 ); } @Override From 9d61a64a5341031b436a194efb98c455a04d3cc0 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 26 Mar 2024 16:04:02 +0100 Subject: [PATCH 11/19] formatting --- .../view/ExtendedRandomAccessibleInterval.java | 3 ++- .../ExtendedRealRandomAccessibleRealInterval.java | 3 ++- src/main/java/net/imglib2/view/HyperSlice.java | 4 ++-- src/main/java/net/imglib2/view/IntervalView.java | 3 ++- .../view/IterableRandomAccessibleInterval.java | 3 ++- .../java/net/imglib2/view/MixedTransformView.java | 3 ++- .../view/RandomAccessibleOnRealRandomAccessible.java | 7 ++++--- .../java/net/imglib2/view/RandomAccessiblePair.java | 3 ++- src/main/java/net/imglib2/view/StackView.java | 5 +++-- src/main/java/net/imglib2/view/SubsampleView.java | 3 ++- src/main/java/net/imglib2/view/TransformBuilder.java | 12 ++++++++---- .../imglib2/view/TransformedRandomAccessible.java | 3 ++- 12 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/imglib2/view/ExtendedRandomAccessibleInterval.java b/src/main/java/net/imglib2/view/ExtendedRandomAccessibleInterval.java index 283f660b0..7afd0ab2c 100644 --- a/src/main/java/net/imglib2/view/ExtendedRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/view/ExtendedRandomAccessibleInterval.java @@ -95,7 +95,8 @@ public F getSource() } @Override - public T getType() { + public T getType() + { // source may have an optimized implementation for getType return source.getType(); } diff --git a/src/main/java/net/imglib2/view/ExtendedRealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/view/ExtendedRealRandomAccessibleRealInterval.java index fa90b0af3..d793d9bef 100644 --- a/src/main/java/net/imglib2/view/ExtendedRealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/view/ExtendedRealRandomAccessibleRealInterval.java @@ -93,7 +93,8 @@ public F getSource() } @Override - public T getType() { + public T getType() + { // source may have an optimized implementation for getType return source.getType(); } diff --git a/src/main/java/net/imglib2/view/HyperSlice.java b/src/main/java/net/imglib2/view/HyperSlice.java index 6607b3e07..11fd1a438 100644 --- a/src/main/java/net/imglib2/view/HyperSlice.java +++ b/src/main/java/net/imglib2/view/HyperSlice.java @@ -309,9 +309,9 @@ public RandomAccess< T > randomAccess( final Interval interval ) } @Override - public T getType() { + public T getType() + { // source may have an optimized implementation for getType return source.getType(); } - } diff --git a/src/main/java/net/imglib2/view/IntervalView.java b/src/main/java/net/imglib2/view/IntervalView.java index c05b4e66e..eef92cbba 100644 --- a/src/main/java/net/imglib2/view/IntervalView.java +++ b/src/main/java/net/imglib2/view/IntervalView.java @@ -175,7 +175,8 @@ public Cursor< T > localizingCursor() } @Override - public T getType() { + public T getType() + { // source may have an optimized implementation for getType return source.getType(); } diff --git a/src/main/java/net/imglib2/view/IterableRandomAccessibleInterval.java b/src/main/java/net/imglib2/view/IterableRandomAccessibleInterval.java index 7c9ff17af..ea652cc61 100644 --- a/src/main/java/net/imglib2/view/IterableRandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/view/IterableRandomAccessibleInterval.java @@ -108,7 +108,8 @@ public RandomAccess< T > randomAccess( final Interval i ) } @Override - public T getType() { + public T getType() + { // source may have an optimized implementation for getType return sourceInterval.getType(); } diff --git a/src/main/java/net/imglib2/view/MixedTransformView.java b/src/main/java/net/imglib2/view/MixedTransformView.java index 462a67edf..ae7fd75f3 100644 --- a/src/main/java/net/imglib2/view/MixedTransformView.java +++ b/src/main/java/net/imglib2/view/MixedTransformView.java @@ -124,7 +124,8 @@ public RandomAccess< T > randomAccess() } @Override - public T getType() { + public T getType() + { // source may have an optimized implementation for getType return source.getType(); } diff --git a/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java b/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java index 3d58f4156..592efc0bc 100644 --- a/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java +++ b/src/main/java/net/imglib2/view/RandomAccessibleOnRealRandomAccessible.java @@ -57,9 +57,9 @@ public class RandomAccessibleOnRealRandomAccessible< T > extends AbstractEuclide { final protected RealRandomAccessible< T > source; - final protected class RandomAccessOnRealRandomAccessible implements RandomAccess< T > + private final class RandomAccessOnRealRandomAccessible implements RandomAccess< T > { - final protected RealRandomAccess< T > sourceAccess; + private final RealRandomAccess< T > sourceAccess; public RandomAccessOnRealRandomAccessible( final RealRandomAccess< T > sourceAccess ) { @@ -237,7 +237,8 @@ public RandomAccess< T > randomAccess( final Interval interval ) } @Override - public T getType() { + public T getType() + { // source may have an optimized implementation for getType return source.getType(); } diff --git a/src/main/java/net/imglib2/view/RandomAccessiblePair.java b/src/main/java/net/imglib2/view/RandomAccessiblePair.java index 0fe2d1af2..6858b52a4 100644 --- a/src/main/java/net/imglib2/view/RandomAccessiblePair.java +++ b/src/main/java/net/imglib2/view/RandomAccessiblePair.java @@ -261,7 +261,8 @@ public RandomAccess randomAccess( final Interval interval ) } @Override - public Pair getType() { + public Pair< A, B > getType() + { // sources may have an optimized implementation for getType return new ValuePair<>( sourceA.getType(), sourceB.getType() ); } diff --git a/src/main/java/net/imglib2/view/StackView.java b/src/main/java/net/imglib2/view/StackView.java index 98019cbfa..392fdf436 100644 --- a/src/main/java/net/imglib2/view/StackView.java +++ b/src/main/java/net/imglib2/view/StackView.java @@ -148,8 +148,9 @@ public RandomAccess< T > randomAccess( final Interval interval ) } @Override - public T getType() { - return slices.length > 0 ? slices[0].getType() : null; + public T getType() + { + return slices.length > 0 ? slices[ 0 ].getType() : null; } /** diff --git a/src/main/java/net/imglib2/view/SubsampleView.java b/src/main/java/net/imglib2/view/SubsampleView.java index d2c67189a..528a8ffb7 100644 --- a/src/main/java/net/imglib2/view/SubsampleView.java +++ b/src/main/java/net/imglib2/view/SubsampleView.java @@ -286,7 +286,8 @@ public long[] getSteps() } @Override - public T getType() { + public T getType() + { // source may have an optimized implementation for getType return source.getType(); } diff --git a/src/main/java/net/imglib2/view/TransformBuilder.java b/src/main/java/net/imglib2/view/TransformBuilder.java index 75350d82e..a883bdeb0 100644 --- a/src/main/java/net/imglib2/view/TransformBuilder.java +++ b/src/main/java/net/imglib2/view/TransformBuilder.java @@ -390,7 +390,8 @@ public RandomAccess< T > randomAccess( final Interval interval ) } @Override - public T getType() { + public T getType() + { return s.getType(); } }; @@ -424,7 +425,8 @@ public RandomAccess< T > randomAccess( final Interval interval ) } @Override - public T getType() { + public T getType() + { return s.getType(); } }; @@ -453,7 +455,8 @@ public TranslationRandomAccess< T > randomAccess( final Interval interval ) } @Override - public T getType() { + public T getType() + { return s.getType(); } }; @@ -487,7 +490,8 @@ public RandomAccess< T > randomAccess( final Interval interval ) } @Override - public T getType() { + public T getType() + { return s.getType(); } }; diff --git a/src/main/java/net/imglib2/view/TransformedRandomAccessible.java b/src/main/java/net/imglib2/view/TransformedRandomAccessible.java index 774d1f182..224790ac5 100644 --- a/src/main/java/net/imglib2/view/TransformedRandomAccessible.java +++ b/src/main/java/net/imglib2/view/TransformedRandomAccessible.java @@ -70,7 +70,8 @@ public interface TransformedRandomAccessible< T > extends RandomAccessible< T >, */ Transform getTransformToSource(); - default T getType() { + default T getType() + { // source may have an optimized implementation for getType return getSource().getType(); } From c60ce48a83ac49fe62c7f86eb2ed4b02601e6bcc Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 26 Mar 2024 16:32:47 +0100 Subject: [PATCH 12/19] 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 ) ); From 857d48f32d8691a5a4c3032b3aa1353c52ee8fc2 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 26 Mar 2024 19:26:12 +0100 Subject: [PATCH 13/19] Add default getType impl for Sampler and IterableRealInterval --- src/main/java/net/imglib2/IterableRealInterval.java | 10 +++++----- src/main/java/net/imglib2/KDTree.java | 7 +------ src/main/java/net/imglib2/Sampler.java | 9 +++++---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/imglib2/IterableRealInterval.java b/src/main/java/net/imglib2/IterableRealInterval.java index 9bf0b5d1c..deef5aa38 100644 --- a/src/main/java/net/imglib2/IterableRealInterval.java +++ b/src/main/java/net/imglib2/IterableRealInterval.java @@ -122,11 +122,11 @@ default T firstElement() // TODO: fix places where it is not necessary to implem * NB: We cannot have a default implementation here because of * https://bugs.openjdk.org/browse/JDK-7120669 */ -// @Override -// default T getType() -// { -// return firstElement(); -// } + @Override + default T getType() + { + return firstElement(); + } /** * Returns the iteration order of this {@link IterableRealInterval}. If the diff --git a/src/main/java/net/imglib2/KDTree.java b/src/main/java/net/imglib2/KDTree.java index cd0730dfb..861931f5a 100644 --- a/src/main/java/net/imglib2/KDTree.java +++ b/src/main/java/net/imglib2/KDTree.java @@ -117,6 +117,7 @@ private static < A > Iterable< RealLocalizable > positionsIterable( IterableReal { return new AbstractConvertedIterableRealInterval< A, RealLocalizable >( sourceInterval ) { + class Cursor extends AbstractConvertedRealCursor< A, RealLocalizable > { Cursor( final RealCursor< A > source ) @@ -143,12 +144,6 @@ public RealLocalizable getType() } } - @Override - public RealLocalizable getType() - { - return firstElement(); - } - @Override public AbstractConvertedRealCursor< A, RealLocalizable > cursor() { diff --git a/src/main/java/net/imglib2/Sampler.java b/src/main/java/net/imglib2/Sampler.java index 9908fa713..d0270e734 100644 --- a/src/main/java/net/imglib2/Sampler.java +++ b/src/main/java/net/imglib2/Sampler.java @@ -74,8 +74,9 @@ public interface Sampler< T > extends Typed< T > */ Sampler< T > copy(); -// @Override default T getType() // TODO GET-TYPE: do we want a default implementation here? -// { -// return get(); -// } + @Override + default T getType() + { + return get(); + } } From e4f0eef4ce59c1b16081e140771c65fe05714cf6 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Thu, 28 Mar 2024 12:23:50 +0100 Subject: [PATCH 14/19] javadoc fixes --- .../java/net/imglib2/IterableRealInterval.java | 14 +++++++++++--- src/main/java/net/imglib2/RandomAccessible.java | 13 ++----------- .../net/imglib2/RandomAccessibleInterval.java | 13 ++----------- .../java/net/imglib2/RealRandomAccessible.java | 15 +++------------ .../imglib2/RealRandomAccessibleRealInterval.java | 15 +++------------ 5 files changed, 21 insertions(+), 49 deletions(-) diff --git a/src/main/java/net/imglib2/IterableRealInterval.java b/src/main/java/net/imglib2/IterableRealInterval.java index deef5aa38..6650e9676 100644 --- a/src/main/java/net/imglib2/IterableRealInterval.java +++ b/src/main/java/net/imglib2/IterableRealInterval.java @@ -118,9 +118,17 @@ default T firstElement() // TODO: fix places where it is not necessary to implem return iterator().next(); } - /* - * NB: We cannot have a default implementation here because of - * https://bugs.openjdk.org/browse/JDK-7120669 + /** + * Get an instance of {@code T}. + *

+ * It should not be assumed that the returned {@code T} instance is an + * independent copy. In particular, repeated calls to {@code getType()} may + * return the same instance. + *

+ * The default implementation returns {@link #firstElement}. Derived classes + * may choose different implementations for improved performance. + * + * @return an instance of {@code T} */ @Override default T getType() diff --git a/src/main/java/net/imglib2/RandomAccessible.java b/src/main/java/net/imglib2/RandomAccessible.java index c36681c1a..e42768a23 100644 --- a/src/main/java/net/imglib2/RandomAccessible.java +++ b/src/main/java/net/imglib2/RandomAccessible.java @@ -182,17 +182,8 @@ default T getAt( final Localizable position ) } /* - * Get an instance of {@code T}. - *

- * It should not be assumed that the returned {@code T} instance is an - * independent copy. In particular, repeated calls to {@code getType()} may - * return the same instance. - *

- * The default implementation queries the value at the default coordinate of - * {@link RandomAccessible#randomAccess()}. Derived classes may choose - * different implementations for improved performance. - * - * @return an instance of {@code T} + * NB: We cannot have a default implementation here because of + * https://bugs.openjdk.org/browse/JDK-7120669 */ // @Override // default T getType() diff --git a/src/main/java/net/imglib2/RandomAccessibleInterval.java b/src/main/java/net/imglib2/RandomAccessibleInterval.java index 864ff34a0..84371aeb9 100644 --- a/src/main/java/net/imglib2/RandomAccessibleInterval.java +++ b/src/main/java/net/imglib2/RandomAccessibleInterval.java @@ -65,17 +65,8 @@ public interface RandomAccessibleInterval< T > extends RandomAccessible< T >, Interval { /* - * Get an instance of {@code T}. - *

- * It should not be assumed that the returned {@code T} instance is an - * independent copy. In particular, repeated calls to {@code getType()} may - * return the same instance. - *

- * The default implementation queries the value at the min coordinate of - * this interval. Derived classes may choose different implementations for - * improved performance. - * - * @return an instance of {@code T} + * NB: We cannot have a default implementation here because of + * https://bugs.openjdk.org/browse/JDK-7120669 */ // @Override // default T getType() diff --git a/src/main/java/net/imglib2/RealRandomAccessible.java b/src/main/java/net/imglib2/RealRandomAccessible.java index f1e3a5d04..0825ea62f 100644 --- a/src/main/java/net/imglib2/RealRandomAccessible.java +++ b/src/main/java/net/imglib2/RealRandomAccessible.java @@ -120,18 +120,9 @@ default T getAt( final RealLocalizable position ) return realRandomAccess().setPositionAndGet( position ); } - /** - * Get an instance of {@code T}. - *

- * It should not be assumed that the returned {@code T} instance is an - * independent copy. In particular, repeated calls to {@code getType()} may - * return the same instance. - *

- * The default implementation queries the value at the default coordinate of - * {@link RealRandomAccessible#realRandomAccess()}. Derived classes - * may choose different implementations for improved performance. - * - * @return an instance of {@code T} + /* + * NB: We cannot have a default implementation here because of + * https://bugs.openjdk.org/browse/JDK-7120669 */ // @Override // default T getType() diff --git a/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java b/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java index 12a764d77..0c45b77c1 100644 --- a/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java +++ b/src/main/java/net/imglib2/RealRandomAccessibleRealInterval.java @@ -63,18 +63,9 @@ */ public interface RealRandomAccessibleRealInterval< T > extends RealRandomAccessible< T >, RealInterval { - /** - * Get an instance of {@code T}. - *

- * It should not be assumed that the returned {@code T} instance is an - * independent copy. In particular, repeated calls to {@code getType()} may - * return the same instance. - *

- * The default implementation queries the value at the min coordinate of - * this interval. Derived classes may choose different implementations for - * improved performance. - * - * @return an instance of {@code T} + /* + * NB: We cannot have a default implementation here because of + * https://bugs.openjdk.org/browse/JDK-7120669 */ // @Override // default T getType() From c1b45766d1b69b47df402f256929fa8118f0f92b Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Wed, 3 Apr 2024 13:46:47 +0200 Subject: [PATCH 15/19] Util.getTypeFromInterval returns getType().createVariable() is possible See https://github.com/imglib/imglib2/pull/312#issuecomment-2034171700 --- src/main/java/net/imglib2/util/Util.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/imglib2/util/Util.java b/src/main/java/net/imglib2/util/Util.java index 5a7f3c055..09253ba6b 100644 --- a/src/main/java/net/imglib2/util/Util.java +++ b/src/main/java/net/imglib2/util/Util.java @@ -796,7 +796,8 @@ final static public long[] int2long( final int[] i ) @Deprecated public static < T, F extends Interval & RandomAccessible< T > > T getTypeFromInterval( final F rai ) { - return rai.getType(); + final T type = rai.getType(); + return type instanceof Type ? ( T ) ( ( Type ) type ).createVariable() : type; } /** @@ -810,9 +811,10 @@ public static < T, F extends Interval & RandomAccessible< T > > T getTypeFromInt * @return - an instance of T */ @Deprecated - public static < T, F extends RealInterval & RealRandomAccessible< T >> T getTypeFromRealInterval( final F rai ) + public static < T, F extends RealInterval & RealRandomAccessible< T > > T getTypeFromRealInterval( final F rai ) { - return rai.getType(); + final T type = rai.getType(); + return type instanceof Type ? ( T ) ( ( Type ) type ).createVariable() : type; } /** From 96c8315813f3c5b95fc6ad8e3b2a6872e96e5d3a Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Wed, 3 Apr 2024 13:48:29 +0200 Subject: [PATCH 16/19] Replace calls of Type.copy() that should actually be createVariable() --- .../net/imglib2/converter/Converters.java | 54 +++++++++---------- .../InverseDistanceWeightingInterpolator.java | 2 +- .../outofbounds/OutOfBoundsRandomValue.java | 2 +- .../OutOfBoundsRandomValueFactory.java | 2 +- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/imglib2/converter/Converters.java b/src/main/java/net/imglib2/converter/Converters.java index b4a818c95..af10bab10 100644 --- a/src/main/java/net/imglib2/converter/Converters.java +++ b/src/main/java/net/imglib2/converter/Converters.java @@ -106,7 +106,7 @@ public static < A, B extends Type< B > > RandomAccessible< B > convert( final Converter< ? super A, ? super B > converter, final B b ) { - return convert2( source, converter, () -> b.copy() ); + return convert2( source, converter, () -> b.createVariable() ); } /** @@ -156,7 +156,7 @@ public static < A, B extends Type< B > > RandomAccessible< B > convert( final Supplier< Converter< ? super A, ? super B > > converterSupplier, final B b ) { - return convert2( source, converterSupplier, () -> b.copy() ); + return convert2( source, converterSupplier, () -> b.createVariable() ); } /** @@ -239,7 +239,7 @@ public static < A, B extends Type< B > > RandomAccessibleInterval< B > convert( final Converter< ? super A, ? super B > converter, final B b ) { - return convert2( source, converter, () -> b.copy() ); + return convert2( source, converter, () -> b.createVariable() ); } /** @@ -290,7 +290,7 @@ public static < A, B extends Type< B > > RandomAccessibleInterval< B > convert( final Supplier< Converter< ? super A, ? super B > > converterSupplier, final B b ) { - return convert2( source, converterSupplier, () -> b.copy() ); + return convert2( source, converterSupplier, () -> b.createVariable() ); } /** @@ -514,7 +514,7 @@ public static < A, B extends Type< B > > IterableRealInterval< B > convert( final Converter< ? super A, ? super B > converter, final B b ) { - return convert2( source, converter, () -> b.copy() ); + return convert2( source, converter, () -> b.createVariable() ); } /** @@ -562,7 +562,7 @@ public static < A, B extends Type< B > > IterableRealInterval< B > convert( final Supplier< Converter< ? super A, ? super B > > converterSupplier, final B b ) { - return convert2( source, converterSupplier, () -> b.copy() ); + return convert2( source, converterSupplier, () -> b.createVariable() ); } /** @@ -631,7 +631,7 @@ public static < A, B extends Type< B > > IterableInterval< B > convert( final Converter< ? super A, ? super B > converter, final B b ) { - return convert2( source, converter, () -> b.copy() ); + return convert2( source, converter, () -> b.createVariable() ); } /** @@ -679,7 +679,7 @@ public static < A, B extends Type< B > > IterableInterval< B > convert( final Supplier< Converter< ? super A, ? super B > > converterSupplier, final B b ) { - return convert2( source, converterSupplier, () -> b.copy() ); + return convert2( source, converterSupplier, () -> b.createVariable() ); } /** @@ -816,7 +816,7 @@ public static < A, B extends Type< B > > RealRandomAccessibleRealInterval< B > c final Converter< ? super A, ? super B > converter, final B b ) { - return convert2( source, converter, () -> b.copy() ); + return convert2( source, converter, () -> b.createVariable() ); } /** @@ -866,7 +866,7 @@ public static < A, B extends Type< B > > RealRandomAccessibleRealInterval< B > c final Supplier< Converter< ? super A, ? super B > > converterSupplier, final B b ) { - return convert2( source, converterSupplier, () -> b.copy() ); + return convert2( source, converterSupplier, () -> b.createVariable() ); } /** @@ -913,7 +913,7 @@ public static < A, B extends Type< B > > RealRandomAccessible< B > convert( final Converter< ? super A, ? super B > converter, final B b ) { - return convert2( source, converter, () -> b.copy() ); + return convert2( source, converter, () -> b.createVariable() ); } /** @@ -963,7 +963,7 @@ public static < A, B extends Type< B > > RealRandomAccessible< B > convert( final Supplier< Converter< ? super A, ? super B > > converterSupplier, final B b ) { - return convert2( source, converterSupplier, () -> b.copy() ); + return convert2( source, converterSupplier, () -> b.createVariable() ); } /** @@ -1132,7 +1132,7 @@ public static < A extends RealType< A >, B extends Type< B > > RandomAccessibleI return composeReal2( components, composer, - () -> targetType.copy() ); + () -> targetType.createVariable() ); } /** @@ -1181,7 +1181,7 @@ public static < A extends NumericType< A >, B extends Type< B > > RandomAccessib return composeNumeric2( components, composer, - () -> targetType.copy() ); + () -> targetType.createVariable() ); } /** @@ -1230,7 +1230,7 @@ public static < A, B extends Type< B > > RandomAccessibleInterval< B > compose( return compose2( components, composer, - () -> targetType.copy() ); + () -> targetType.createVariable() ); } /** @@ -1282,7 +1282,7 @@ public static < A, B, C extends Type< C > > RandomAccessible< C > convert( final BiConverter< ? super A, ? super B, ? super C > converter, final C c ) { - return convert2( sourceA, sourceB, converter, () -> c.copy() ); + return convert2( sourceA, sourceB, converter, () -> c.createVariable() ); } /** @@ -1337,7 +1337,7 @@ public static < A, B, C extends Type< C > > RandomAccessible< C > convert( final Supplier< BiConverter< ? super A, ? super B, ? super C > > converterSupplier, final C c ) { - return convert2( sourceA, sourceB, converterSupplier, () -> c.copy() ); + return convert2( sourceA, sourceB, converterSupplier, () -> c.createVariable() ); } /** @@ -1392,7 +1392,7 @@ public static < A, B, C extends Type< C > > RandomAccessibleInterval< C > conver final BiConverter< ? super A, ? super B, ? super C > converter, final C c ) { - return convert2( sourceA, sourceB, converter, () -> c.copy() ); + return convert2( sourceA, sourceB, converter, () -> c.createVariable() ); } /** @@ -1447,7 +1447,7 @@ public static < A, B, C extends Type< C > > RandomAccessibleInterval< C > conver final Supplier< BiConverter< ? super A, ? super B, ? super C > > converterSupplier, final C c ) { - return convert2( sourceA, sourceB, converterSupplier, () -> c.copy() ); + return convert2( sourceA, sourceB, converterSupplier, () -> c.createVariable() ); } /** @@ -1635,7 +1635,7 @@ public static < A, B, C extends Type< C > > IterableInterval< C > convert( final BiConverter< ? super A, ? super B, ? super C > converter, final C c ) { - return convert2( sourceA, sourceB, converter, () -> c.copy() ); + return convert2( sourceA, sourceB, converter, () -> c.createVariable() ); } /** @@ -1688,7 +1688,7 @@ public static < A, B, C extends Type< C > > IterableInterval< C > convert( final Supplier< BiConverter< ? super A, ? super B, ? super C > > converterSupplier, final C c ) { - return convert2( sourceA, sourceB, converterSupplier, () -> c.copy() ); + return convert2( sourceA, sourceB, converterSupplier, () -> c.createVariable() ); } /** @@ -1741,7 +1741,7 @@ public static < A, B, C extends Type< C > > IterableRealInterval< C > convert( final BiConverter< ? super A, ? super B, ? super C > converter, final C c ) { - return convert2( sourceA, sourceB, converter, () -> c.copy() ); + return convert2( sourceA, sourceB, converter, () -> c.createVariable() ); } /** @@ -1794,7 +1794,7 @@ public static < A, B, C extends Type< C > > IterableRealInterval< C > convert( final Supplier< BiConverter< ? super A, ? super B, ? super C > > converterSupplier, final C c ) { - return convert2( sourceA, sourceB, converterSupplier, () -> c.copy() ); + return convert2( sourceA, sourceB, converterSupplier, () -> c.createVariable() ); } /** @@ -1848,7 +1848,7 @@ public static < A, B, C extends Type< C > > RealRandomAccessibleRealInterval< C final BiConverter< ? super A, ? super B, ? super C > converter, final C c ) { - return convert2( sourceA, sourceB, converter, () -> c.copy() ); + return convert2( sourceA, sourceB, converter, () -> c.createVariable() ); } /** @@ -1903,7 +1903,7 @@ public static < A, B, C extends Type< C > > RealRandomAccessibleRealInterval< C final Supplier< BiConverter< ? super A, ? super B, ? super C > > converterSupplier, final C c ) { - return convert2( sourceA, sourceB, converterSupplier, () -> c.copy() ); + return convert2( sourceA, sourceB, converterSupplier, () -> c.createVariable() ); } /** @@ -1958,7 +1958,7 @@ public static < A, B, C extends Type< C > > RealRandomAccessible< C > convert( final BiConverter< ? super A, ? super B, ? super C > converter, final C c ) { - return convert2( sourceA, sourceB, converter, () -> c.copy() ); + return convert2( sourceA, sourceB, converter, () -> c.createVariable() ); } /** @@ -2013,7 +2013,7 @@ public static < A, B, C extends Type< C > > RealRandomAccessible< C > convert( final Supplier< BiConverter< ? super A, ? super B, ? super C > > converterSupplier, final C c ) { - return convert2( sourceA, sourceB, converterSupplier, () -> c.copy() ); + return convert2( sourceA, sourceB, converterSupplier, () -> c.createVariable() ); } /** diff --git a/src/main/java/net/imglib2/interpolation/neighborsearch/InverseDistanceWeightingInterpolator.java b/src/main/java/net/imglib2/interpolation/neighborsearch/InverseDistanceWeightingInterpolator.java index e1622964c..4890de540 100644 --- a/src/main/java/net/imglib2/interpolation/neighborsearch/InverseDistanceWeightingInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/neighborsearch/InverseDistanceWeightingInterpolator.java @@ -84,7 +84,7 @@ public InverseDistanceWeightingInterpolator( final KNearestNeighborSearch< T > s p2 = p / 2.0; search.search( this ); - this.value = search.getSampler( 0 ).get().copy(); + this.value = search.getSampler( 0 ).getType().createVariable(); this.numNeighbors = search.getK(); } diff --git a/src/main/java/net/imglib2/outofbounds/OutOfBoundsRandomValue.java b/src/main/java/net/imglib2/outofbounds/OutOfBoundsRandomValue.java index 1a50c28cf..2f0f644d0 100644 --- a/src/main/java/net/imglib2/outofbounds/OutOfBoundsRandomValue.java +++ b/src/main/java/net/imglib2/outofbounds/OutOfBoundsRandomValue.java @@ -60,7 +60,7 @@ protected OutOfBoundsRandomValue( final OutOfBoundsRandomValue< T > outOfBounds { super( outOfBounds ); - this.value = outOfBounds.value.copy(); + this.value = outOfBounds.value.createVariable(); this.minValue = outOfBounds.minValue; this.maxValue = outOfBounds.maxValue; this.range = outOfBounds.range; diff --git a/src/main/java/net/imglib2/outofbounds/OutOfBoundsRandomValueFactory.java b/src/main/java/net/imglib2/outofbounds/OutOfBoundsRandomValueFactory.java index b8f11f7db..51bf5877f 100644 --- a/src/main/java/net/imglib2/outofbounds/OutOfBoundsRandomValueFactory.java +++ b/src/main/java/net/imglib2/outofbounds/OutOfBoundsRandomValueFactory.java @@ -78,6 +78,6 @@ public void setRandom( final Random rnd ) @Override public OutOfBoundsRandomValue< T > create( final F f ) { - return new OutOfBoundsRandomValue< T >( f, value.copy(), rnd, min, max ); + return new OutOfBoundsRandomValue< T >( f, value.createVariable(), rnd, min, max ); } } From 05e77c12bf78c656dd2c1af73ab22a86d30682f3 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Wed, 3 Apr 2024 13:50:10 +0200 Subject: [PATCH 17/19] Fix circular call to LanczosInterpolator.copy() --- .../imglib2/interpolation/randomaccess/LanczosInterpolator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/imglib2/interpolation/randomaccess/LanczosInterpolator.java b/src/main/java/net/imglib2/interpolation/randomaccess/LanczosInterpolator.java index 3cd1e26a0..333e63620 100644 --- a/src/main/java/net/imglib2/interpolation/randomaccess/LanczosInterpolator.java +++ b/src/main/java/net/imglib2/interpolation/randomaccess/LanczosInterpolator.java @@ -232,6 +232,6 @@ final private double lookUpLanczos( final double x ) @Override public RealRandomAccess< T > copy() { - return copy(); + return new LanczosInterpolator<>( this ); } } From d10e744066876226a34531853497ccfd8952701f Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Wed, 3 Apr 2024 14:04:50 +0200 Subject: [PATCH 18/19] POM: Bump version to 7.0.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e4eef919f..75b464d20 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.imglib2 imglib2 - 6.4.1-SNAPSHOT + 7.0.0-SNAPSHOT ImgLib2 Core Library A multidimensional, type-agnostic image processing library. From 60aff89ea7b67515be8aad41a619b6f05405ad2c Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sat, 20 Apr 2024 10:40:38 +0200 Subject: [PATCH 19/19] Be defensive in NativeType.copy() methods: Act like createVariable() if no dataAccess is set --- src/main/java/net/imglib2/type/label/BasePairBitType.java | 5 ++++- src/main/java/net/imglib2/type/label/BasePairCharType.java | 5 ++++- src/main/java/net/imglib2/type/logic/BitType.java | 2 +- src/main/java/net/imglib2/type/logic/NativeBoolType.java | 2 +- src/main/java/net/imglib2/type/numeric/ARGBType.java | 2 +- .../net/imglib2/type/numeric/NativeARGBDoubleType.java | 5 ++++- .../imglib2/type/numeric/complex/ComplexDoubleType.java | 5 ++++- .../net/imglib2/type/numeric/complex/ComplexFloatType.java | 5 ++++- .../java/net/imglib2/type/numeric/integer/ByteType.java | 2 +- .../java/net/imglib2/type/numeric/integer/IntType.java | 2 +- .../java/net/imglib2/type/numeric/integer/LongType.java | 2 +- .../java/net/imglib2/type/numeric/integer/ShortType.java | 2 +- .../imglib2/type/numeric/integer/Unsigned128BitType.java | 7 +++++-- .../imglib2/type/numeric/integer/Unsigned12BitType.java | 2 +- .../net/imglib2/type/numeric/integer/Unsigned2BitType.java | 2 +- .../net/imglib2/type/numeric/integer/Unsigned4BitType.java | 2 +- .../net/imglib2/type/numeric/integer/UnsignedByteType.java | 2 +- .../net/imglib2/type/numeric/integer/UnsignedIntType.java | 2 +- .../net/imglib2/type/numeric/integer/UnsignedLongType.java | 2 +- .../imglib2/type/numeric/integer/UnsignedShortType.java | 2 +- .../numeric/integer/UnsignedVariableBitLengthType.java | 5 ++++- .../java/net/imglib2/type/numeric/real/DoubleType.java | 2 +- src/main/java/net/imglib2/type/numeric/real/FloatType.java | 2 +- 23 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/imglib2/type/label/BasePairBitType.java b/src/main/java/net/imglib2/type/label/BasePairBitType.java index 72d139369..104730ab5 100644 --- a/src/main/java/net/imglib2/type/label/BasePairBitType.java +++ b/src/main/java/net/imglib2/type/label/BasePairBitType.java @@ -179,7 +179,10 @@ public BasePairBitType createVariable() @Override public BasePairBitType copy() { - return new BasePairBitType( this.get() ); + if ( dataAccess != null ) + return new BasePairBitType( this.get() ); + else + return createVariable(); } @Override diff --git a/src/main/java/net/imglib2/type/label/BasePairCharType.java b/src/main/java/net/imglib2/type/label/BasePairCharType.java index 2c29bf392..4f5c9c0c7 100644 --- a/src/main/java/net/imglib2/type/label/BasePairCharType.java +++ b/src/main/java/net/imglib2/type/label/BasePairCharType.java @@ -184,7 +184,10 @@ public BasePairCharType createVariable() @Override public BasePairCharType copy() { - return new BasePairCharType( get() ); + if ( dataAccess != null ) + return new BasePairCharType( get() ); + else + return createVariable(); } @Override diff --git a/src/main/java/net/imglib2/type/logic/BitType.java b/src/main/java/net/imglib2/type/logic/BitType.java index 4bbd212e3..721cc2784 100644 --- a/src/main/java/net/imglib2/type/logic/BitType.java +++ b/src/main/java/net/imglib2/type/logic/BitType.java @@ -309,7 +309,7 @@ public BitType createVariable() @Override public BitType copy() { - return new BitType( get() ); + return new BitType( dataAccess != null ? get() : false ); } @Override diff --git a/src/main/java/net/imglib2/type/logic/NativeBoolType.java b/src/main/java/net/imglib2/type/logic/NativeBoolType.java index 1eefb0ce0..9ad2b4df4 100644 --- a/src/main/java/net/imglib2/type/logic/NativeBoolType.java +++ b/src/main/java/net/imglib2/type/logic/NativeBoolType.java @@ -269,7 +269,7 @@ public NativeBoolType createVariable() @Override public NativeBoolType copy() { - return new NativeBoolType( get() ); + return new NativeBoolType( dataAccess != null ? get() : false ); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/ARGBType.java b/src/main/java/net/imglib2/type/numeric/ARGBType.java index 1ce2cd270..f92212cce 100644 --- a/src/main/java/net/imglib2/type/numeric/ARGBType.java +++ b/src/main/java/net/imglib2/type/numeric/ARGBType.java @@ -254,7 +254,7 @@ public ARGBType createVariable() @Override public ARGBType copy() { - return new ARGBType( get() ); + return new ARGBType( dataAccess != null ? get() : 0 ); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/NativeARGBDoubleType.java b/src/main/java/net/imglib2/type/numeric/NativeARGBDoubleType.java index 2bd30ab18..418249638 100644 --- a/src/main/java/net/imglib2/type/numeric/NativeARGBDoubleType.java +++ b/src/main/java/net/imglib2/type/numeric/NativeARGBDoubleType.java @@ -186,7 +186,10 @@ public NativeARGBDoubleType createVariable() @Override public NativeARGBDoubleType copy() { - return new NativeARGBDoubleType( getA(), getR(), getG(), getB() ); + if ( dataAccess != null ) + return new NativeARGBDoubleType( getA(), getR(), getG(), getB() ); + else + return createVariable(); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/complex/ComplexDoubleType.java b/src/main/java/net/imglib2/type/numeric/complex/ComplexDoubleType.java index 16b0daeda..8d7d46abe 100644 --- a/src/main/java/net/imglib2/type/numeric/complex/ComplexDoubleType.java +++ b/src/main/java/net/imglib2/type/numeric/complex/ComplexDoubleType.java @@ -187,7 +187,10 @@ public ComplexDoubleType createVariable() @Override public ComplexDoubleType copy() { - return new ComplexDoubleType( getRealFloat(), getImaginaryFloat() ); + if ( dataAccess != null ) + return new ComplexDoubleType( getRealFloat(), getImaginaryFloat() ); + else + return createVariable(); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/complex/ComplexFloatType.java b/src/main/java/net/imglib2/type/numeric/complex/ComplexFloatType.java index f6d053281..076ed22f5 100644 --- a/src/main/java/net/imglib2/type/numeric/complex/ComplexFloatType.java +++ b/src/main/java/net/imglib2/type/numeric/complex/ComplexFloatType.java @@ -240,7 +240,10 @@ public ComplexFloatType createVariable() @Override public ComplexFloatType copy() { - return new ComplexFloatType( getRealFloat(), getImaginaryFloat() ); + if ( dataAccess != null ) + return new ComplexFloatType( getRealFloat(), getImaginaryFloat() ); + else + return createVariable(); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/integer/ByteType.java b/src/main/java/net/imglib2/type/numeric/integer/ByteType.java index 509213547..13eb846bd 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/ByteType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/ByteType.java @@ -153,6 +153,6 @@ public ByteType createVariable() @Override public ByteType copy() { - return new ByteType( getByte() ); + return new ByteType( dataAccess != null ? get() : 0 ); } } diff --git a/src/main/java/net/imglib2/type/numeric/integer/IntType.java b/src/main/java/net/imglib2/type/numeric/integer/IntType.java index 0bba38c72..9dc6599ed 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/IntType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/IntType.java @@ -153,6 +153,6 @@ public IntType createVariable() @Override public IntType copy() { - return new IntType( getInt() ); + return new IntType( dataAccess != null ? get() : 0 ); } } diff --git a/src/main/java/net/imglib2/type/numeric/integer/LongType.java b/src/main/java/net/imglib2/type/numeric/integer/LongType.java index 4cfc41d90..387797577 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/LongType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/LongType.java @@ -161,6 +161,6 @@ public LongType createVariable() @Override public LongType copy() { - return new LongType( get() ); + return new LongType( dataAccess != null ? get() : 0 ); } } diff --git a/src/main/java/net/imglib2/type/numeric/integer/ShortType.java b/src/main/java/net/imglib2/type/numeric/integer/ShortType.java index 999a8ea80..acc8dbec7 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/ShortType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/ShortType.java @@ -153,6 +153,6 @@ public ShortType createVariable() @Override public ShortType copy() { - return new ShortType( getShort() ); + return new ShortType( dataAccess != null ? get() : 0 ); } } diff --git a/src/main/java/net/imglib2/type/numeric/integer/Unsigned128BitType.java b/src/main/java/net/imglib2/type/numeric/integer/Unsigned128BitType.java index 4945970f6..f1242bbdd 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/Unsigned128BitType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/Unsigned128BitType.java @@ -308,8 +308,11 @@ public Unsigned128BitType createVariable() public Unsigned128BitType copy() { final Unsigned128BitType copy = new Unsigned128BitType(); - final int k = i.get() * 2; - copy.set( dataAccess.getValue( k ), dataAccess.getValue( k + 1 ) ); + if ( dataAccess != null ) + { + final int k = i.get() * 2; + copy.set( dataAccess.getValue( k ), dataAccess.getValue( k + 1 ) ); + } return copy; } diff --git a/src/main/java/net/imglib2/type/numeric/integer/Unsigned12BitType.java b/src/main/java/net/imglib2/type/numeric/integer/Unsigned12BitType.java index fd2bdce29..0a7fbf6a2 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/Unsigned12BitType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/Unsigned12BitType.java @@ -171,6 +171,6 @@ public Unsigned12BitType createVariable() @Override public Unsigned12BitType copy() { - return new Unsigned12BitType( get() ); + return new Unsigned12BitType( dataAccess != null ? get() : 0 ); } } diff --git a/src/main/java/net/imglib2/type/numeric/integer/Unsigned2BitType.java b/src/main/java/net/imglib2/type/numeric/integer/Unsigned2BitType.java index 2f5ac7485..ada05deec 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/Unsigned2BitType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/Unsigned2BitType.java @@ -140,6 +140,6 @@ public Unsigned2BitType createVariable() @Override public Unsigned2BitType copy() { - return new Unsigned2BitType( get() ); + return new Unsigned2BitType( dataAccess != null ? get() : 0 ); } } diff --git a/src/main/java/net/imglib2/type/numeric/integer/Unsigned4BitType.java b/src/main/java/net/imglib2/type/numeric/integer/Unsigned4BitType.java index 0d3a5ea9f..ca5d3027d 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/Unsigned4BitType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/Unsigned4BitType.java @@ -132,6 +132,6 @@ public Unsigned4BitType createVariable() @Override public Unsigned4BitType copy() { - return new Unsigned4BitType( get() ); + return new Unsigned4BitType( dataAccess != null ? get() : 0 ); } } diff --git a/src/main/java/net/imglib2/type/numeric/integer/UnsignedByteType.java b/src/main/java/net/imglib2/type/numeric/integer/UnsignedByteType.java index d55b41611..8da8bd778 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/UnsignedByteType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/UnsignedByteType.java @@ -213,7 +213,7 @@ public UnsignedByteType createVariable() @Override public UnsignedByteType copy() { - return new UnsignedByteType( get() ); + return new UnsignedByteType( dataAccess != null ? get() : 0 ); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/integer/UnsignedIntType.java b/src/main/java/net/imglib2/type/numeric/integer/UnsignedIntType.java index 5725931d7..d30b618eb 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/UnsignedIntType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/UnsignedIntType.java @@ -248,7 +248,7 @@ public UnsignedIntType createVariable() @Override public UnsignedIntType copy() { - return new UnsignedIntType( get() ); + return new UnsignedIntType( dataAccess != null ? get() : 0 ); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/integer/UnsignedLongType.java b/src/main/java/net/imglib2/type/numeric/integer/UnsignedLongType.java index 357565cf1..139893a89 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/UnsignedLongType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/UnsignedLongType.java @@ -345,7 +345,7 @@ public UnsignedLongType createVariable() @Override public UnsignedLongType copy() { - return new UnsignedLongType( get() ); + return new UnsignedLongType( dataAccess != null ? get() : 0 ); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/integer/UnsignedShortType.java b/src/main/java/net/imglib2/type/numeric/integer/UnsignedShortType.java index b60b841bf..93a1e54ca 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/UnsignedShortType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/UnsignedShortType.java @@ -222,7 +222,7 @@ public UnsignedShortType createVariable() @Override public UnsignedShortType copy() { - return new UnsignedShortType( get() ); + return new UnsignedShortType( dataAccess != null ? get() : 0 ); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/integer/UnsignedVariableBitLengthType.java b/src/main/java/net/imglib2/type/numeric/integer/UnsignedVariableBitLengthType.java index 06829430e..9e8a1e5cf 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/UnsignedVariableBitLengthType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/UnsignedVariableBitLengthType.java @@ -121,7 +121,10 @@ public UnsignedVariableBitLengthType createVariable() @Override public UnsignedVariableBitLengthType copy() { - return new UnsignedVariableBitLengthType( getBits(), nBits ); + if ( dataAccess != null ) + return new UnsignedVariableBitLengthType( getBits(), nBits ); + else + return createVariable(); } /** @see UnsignedLongType#divide(long, long) */ diff --git a/src/main/java/net/imglib2/type/numeric/real/DoubleType.java b/src/main/java/net/imglib2/type/numeric/real/DoubleType.java index 77375ba08..8dbcf22f1 100644 --- a/src/main/java/net/imglib2/type/numeric/real/DoubleType.java +++ b/src/main/java/net/imglib2/type/numeric/real/DoubleType.java @@ -178,7 +178,7 @@ public DoubleType createVariable() @Override public DoubleType copy() { - return new DoubleType( get() ); + return new DoubleType( dataAccess != null ? get() : 0 ); } @Override diff --git a/src/main/java/net/imglib2/type/numeric/real/FloatType.java b/src/main/java/net/imglib2/type/numeric/real/FloatType.java index 2c1cdf0e7..aa20b1490 100644 --- a/src/main/java/net/imglib2/type/numeric/real/FloatType.java +++ b/src/main/java/net/imglib2/type/numeric/real/FloatType.java @@ -247,7 +247,7 @@ public FloatType createVariable() @Override public FloatType copy() { - return new FloatType( get() ); + return new FloatType( dataAccess != null ? get() : 0 ); } @Override