From 1d73c6e2cd1f629dccfa7986684a5d66b87d962a Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 16 Mar 2021 22:59:23 +0100 Subject: [PATCH 01/10] Remove unnecessary modifiers --- .../java/net/imglib2/type/NativeType.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/imglib2/type/NativeType.java b/src/main/java/net/imglib2/type/NativeType.java index 1e75d3ed2e..90b9d7c1ca 100644 --- a/src/main/java/net/imglib2/type/NativeType.java +++ b/src/main/java/net/imglib2/type/NativeType.java @@ -79,7 +79,7 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * @return the number of storage type entities required to store one pixel * value. */ - public Fraction getEntitiesPerPixel(); + Fraction getEntitiesPerPixel(); /** * Creates a new {@link NativeType} which stores in the same physical array. @@ -88,9 +88,9 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * @return a new {@link NativeType} instance working on the same * {@link NativeImg} */ - public T duplicateTypeOnSameNativeImg(); + T duplicateTypeOnSameNativeImg(); - public NativeTypeFactory< T, ? > getNativeTypeFactory(); + NativeTypeFactory< T, ? > getNativeTypeFactory(); /** * This method is used by an accessor (e.g., a {@link Cursor}) to request an @@ -126,7 +126,7 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * reference to an accessor which can be passed on to the * container (which will know what to do with it). */ - public void updateContainer( Object c ); + void updateContainer( Object c ); /** * Set the index into the current data array. @@ -138,7 +138,7 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * @param i * the new array index */ - public void updateIndex( final int i ); + void updateIndex( final int i ); /** * Get the current index into the current data array. @@ -149,7 +149,7 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * * @return the current index into the underlying data array */ - public int getIndex(); + int getIndex(); /** * Increment the index into the current data array. @@ -158,7 +158,7 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * This is used by accessors (e.g., a {@link Cursor}) to position the * {@link NativeType} in the container. */ - public void incIndex(); + void incIndex(); /** * Increases the index into the current data array by {@code increment} @@ -171,7 +171,7 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * @param increment * how many steps */ - public void incIndex( final int increment ); + void incIndex( final int increment ); /** * Decrement the index into the current data array. @@ -180,7 +180,7 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * This is used by accessors (e.g., a {@link Cursor}) to position the * {@link NativeType} in the container. */ - public void decIndex(); + void decIndex(); /** * Decrease the index into the current data array by {@code decrement} @@ -193,5 +193,5 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * @param decrement * how many steps */ - public void decIndex( final int decrement ); + void decIndex( final int decrement ); } From fe9b873f7789903c0faab86c8dc1705a16a1be6d Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Wed, 17 Mar 2021 23:19:25 +0100 Subject: [PATCH 02/10] Benchmark RandomAccess with multiple Types --- .../img/array/ArrayRandomAccessBenchmark.java | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/test/java/net/imglib2/img/array/ArrayRandomAccessBenchmark.java diff --git a/src/test/java/net/imglib2/img/array/ArrayRandomAccessBenchmark.java b/src/test/java/net/imglib2/img/array/ArrayRandomAccessBenchmark.java new file mode 100644 index 0000000000..8f1d9af425 --- /dev/null +++ b/src/test/java/net/imglib2/img/array/ArrayRandomAccessBenchmark.java @@ -0,0 +1,117 @@ +package net.imglib2.img.array; + +import java.util.concurrent.TimeUnit; +import net.imglib2.RandomAccess; +import net.imglib2.RandomAccessible; +import net.imglib2.img.Img; +import net.imglib2.type.NativeType; +import net.imglib2.type.numeric.RealType; +import net.imglib2.type.numeric.integer.ByteType; +import net.imglib2.type.numeric.integer.IntType; +import net.imglib2.type.numeric.integer.ShortType; +import net.imglib2.type.numeric.integer.UnsignedByteType; +import net.imglib2.type.numeric.integer.UnsignedIntType; +import net.imglib2.type.numeric.integer.UnsignedShortType; +import net.imglib2.type.numeric.real.DoubleType; +import net.imglib2.type.numeric.real.FloatType; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +@State( Scope.Benchmark ) +@Warmup( iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS ) +@Measurement( iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS ) +@BenchmarkMode( Mode.AverageTime ) +@OutputTimeUnit( TimeUnit.MILLISECONDS ) +@Fork( 1 ) +public class ArrayRandomAccessBenchmark +{ + @Param( value = { "false", "true" } ) + private boolean slowdown; + + @Setup + public void setup() + { + if ( slowdown ) + { + spoil( new FloatType() ); + spoil( new DoubleType() ); + spoil( new UnsignedShortType() ); + spoil( new UnsignedByteType() ); + spoil( new ShortType() ); + spoil( new ByteType() ); + spoil( new UnsignedIntType() ); + spoil( new IntType() ); + } + } + + public < T extends NativeType< T > & RealType< T > > double spoil( final T type ) + { + final Img< T > img = new ArrayImgFactory<>( type ).create( 1000, 1000 ); + return doSum1( img ); + } + + private final Img< IntType > img = new ArrayImgFactory<>( new IntType() ).create( 1000, 1000 ); + + @Benchmark + public Object sum() + { + return doSum( img ); + } + + public < T extends RealType< T > > double doSum( RandomAccessible< T > img ) + { + double sum = 0; + RandomAccess< T > ra = img.randomAccess(); + ra.setPosition( 0, 1 ); + for ( int y = 0; y < 1000; y++ ) + { + ra.setPosition( 0, 0 ); + for ( int x = 0; x < 1000; x++ ) + { + sum += ra.get().getRealDouble(); + ra.fwd( 0 ); + } + ra.fwd( 1 ); + } + return sum + ra.getIntPosition( 0 ); + } + + public < T extends RealType< T > > double doSum1( RandomAccessible< T > img ) + { + double sum = 0; + RandomAccess< T > ra = img.randomAccess(); + ra.setPosition( 0, 1 ); + for ( int y = 0; y < 1000; y++ ) + { + ra.setPosition( 0, 0 ); + for ( int x = 0; x < 1000; x++ ) + { + sum += ra.get().getRealDouble(); + ra.fwd( 0 ); + } + ra.fwd( 1 ); + } + return sum + ra.getIntPosition( 0 ); + } + + public static void main( String... args ) throws RunnerException + { + Options options = new OptionsBuilder() + .include( ArrayRandomAccessBenchmark.class.getSimpleName() ) + .build(); + new Runner( options ).run(); + } +} From 0bf381e628097ddb671d0c71f36d543af52e621c Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Fri, 19 Mar 2021 14:05:24 +0100 Subject: [PATCH 03/10] Add Index class and use in NativeType --- src/main/java/net/imglib2/type/Index.java | 36 ++++++++++++++++ .../java/net/imglib2/type/NativeType.java | 42 +++++++++++++++---- 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 src/main/java/net/imglib2/type/Index.java diff --git a/src/main/java/net/imglib2/type/Index.java b/src/main/java/net/imglib2/type/Index.java new file mode 100644 index 0000000000..51eeb91065 --- /dev/null +++ b/src/main/java/net/imglib2/type/Index.java @@ -0,0 +1,36 @@ +package net.imglib2.type; + +public final class Index +{ + private int i = 0; + + public int get() + { + return i; + } + + public void set( final int index) + { + i = index; + } + + public void inc() + { + ++i; + } + + public void inc( final int increment ) + { + i += increment; + } + + public void dec() + { + --i; + } + + public void dec( final int decrement ) + { + i -= decrement; + } +} diff --git a/src/main/java/net/imglib2/type/NativeType.java b/src/main/java/net/imglib2/type/NativeType.java index 90b9d7c1ca..b71a684fd4 100644 --- a/src/main/java/net/imglib2/type/NativeType.java +++ b/src/main/java/net/imglib2/type/NativeType.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 @@ -128,6 +128,8 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > */ void updateContainer( Object c ); + Index index(); + /** * Set the index into the current data array. * @@ -138,7 +140,11 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * @param i * the new array index */ - void updateIndex( final int i ); + @Deprecated + default void updateIndex( final int i ) + { + index().set( i ); + } /** * Get the current index into the current data array. @@ -149,7 +155,11 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * * @return the current index into the underlying data array */ - int getIndex(); + @Deprecated + default int getIndex() + { + return index().get(); + } /** * Increment the index into the current data array. @@ -158,7 +168,11 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * This is used by accessors (e.g., a {@link Cursor}) to position the * {@link NativeType} in the container. */ - void incIndex(); + @Deprecated + default void incIndex() + { + index().inc(); + } /** * Increases the index into the current data array by {@code increment} @@ -171,7 +185,11 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * @param increment * how many steps */ - void incIndex( final int increment ); + @Deprecated + default void incIndex( final int increment ) + { + index().inc( increment ); + } /** * Decrement the index into the current data array. @@ -180,7 +198,11 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * This is used by accessors (e.g., a {@link Cursor}) to position the * {@link NativeType} in the container. */ - void decIndex(); + @Deprecated + default void decIndex() + { + index().dec(); + } /** * Decrease the index into the current data array by {@code decrement} @@ -193,5 +215,9 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > * @param decrement * how many steps */ - void decIndex( final int decrement ); + @Deprecated + default void decIndex( final int decrement ) + { + index().dec( decrement ); + } } From 443d67c09fecff4a8ec9c27381ed8696a38055ec Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sat, 20 Mar 2021 00:23:26 +0100 Subject: [PATCH 04/10] Use Index object instead of int field in NativeType implementations --- .../net/imglib2/type/AbstractBit64Type.java | 6 +- .../net/imglib2/type/AbstractBitType.java | 39 +------ .../net/imglib2/type/AbstractNativeType.java | 35 +----- .../imglib2/type/label/BasePairCharType.java | 6 +- .../java/net/imglib2/type/logic/BitType.java | 54 +++------- .../imglib2/type/logic/NativeBoolType.java | 52 +++------ .../net/imglib2/type/numeric/ARGBType.java | 10 +- .../type/numeric/NativeARGBDoubleType.java | 101 +++++------------- .../numeric/complex/ComplexDoubleType.java | 82 ++++---------- .../numeric/complex/ComplexFloatType.java | 85 ++++----------- .../type/numeric/integer/GenericByteType.java | 56 +++------- .../type/numeric/integer/GenericIntType.java | 60 +++-------- .../type/numeric/integer/GenericLongType.java | 56 +++------- .../numeric/integer/GenericShortType.java | 56 +++------- .../type/numeric/integer/LongType.java | 2 +- .../numeric/integer/Unsigned128BitType.java | 88 ++++++--------- .../numeric/integer/Unsigned12BitType.java | 6 +- .../numeric/integer/Unsigned2BitType.java | 8 +- .../numeric/integer/Unsigned4BitType.java | 8 +- .../numeric/integer/UnsignedLongType.java | 4 +- .../imglib2/type/numeric/real/DoubleType.java | 52 +++------ .../imglib2/type/numeric/real/FloatType.java | 52 +++------ .../AbstractVolatileNativeNumericType.java | 35 +----- .../AbstractVolatileNativeRealType.java | 35 +----- 24 files changed, 262 insertions(+), 726 deletions(-) diff --git a/src/main/java/net/imglib2/type/AbstractBit64Type.java b/src/main/java/net/imglib2/type/AbstractBit64Type.java index 0bd33c8f8b..3f5eb7aa7c 100644 --- a/src/main/java/net/imglib2/type/AbstractBit64Type.java +++ b/src/main/java/net/imglib2/type/AbstractBit64Type.java @@ -79,7 +79,6 @@ else if ( nBits == 64 ) public AbstractBit64Type( final long value, final int nBits ) { this( ( NativeImg< ?, ? extends LongAccess > ) null, nBits ); - updateIndex( 0 ); dataAccess = new LongArray( 1 ); setBits( value ); } @@ -88,7 +87,6 @@ public AbstractBit64Type( final long value, final int nBits ) public AbstractBit64Type( final LongAccess access, final int nBits ) { this( ( NativeImg< ?, ? extends LongAccess > ) null, nBits ); - updateIndex( 0 ); dataAccess = access; } @@ -104,7 +102,7 @@ public AbstractBit64Type( final LongAccess access, final int nBits ) * @return */ protected long getBits() { - final long k = i * nBits; + final long k = i.get() * nBits; final int i1 = (int)(k >>> 6); // k / 64; final long shift = k & 63; // Same as k % 64; final long v = dataAccess.getValue(i1); @@ -134,7 +132,7 @@ protected long getBits() { * @param value */ protected void setBits( final long value ) { - final long k = i * nBits; + final long k = i.get() * nBits; final int i1 = (int)(k >>> 6); // k / 64; final long shift = k & 63; // Same as k % 64; final long safeValue = value & mask; diff --git a/src/main/java/net/imglib2/type/AbstractBitType.java b/src/main/java/net/imglib2/type/AbstractBitType.java index cee43ba078..cf63ed040c 100644 --- a/src/main/java/net/imglib2/type/AbstractBitType.java +++ b/src/main/java/net/imglib2/type/AbstractBitType.java @@ -48,7 +48,7 @@ public abstract class AbstractBitType< T extends AbstractBitType< T > > implements NativeType< T > { // Maximum count is Integer.MAX_VALUE * (64 / getBitsPerPixel()) - protected long i = 0; + protected final Index i; // the number of bits per pixel protected final int nBits; @@ -64,6 +64,7 @@ public AbstractBitType( final NativeImg< ?, ? extends LongAccess > bitStorage, final int nBits ) { + i = new Index(); img = bitStorage; this.nBits = nBits; } @@ -75,43 +76,13 @@ public void updateContainer( final Object c ) } @Override - public abstract NativeTypeFactory< T, LongAccess > getNativeTypeFactory(); - - @Override - public int getIndex() - { - return ( int ) i; - } - - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public void incIndex() + public Index index() { - ++i; + return i; } @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } + public abstract NativeTypeFactory< T, LongAccess > getNativeTypeFactory(); @Override public Fraction getEntitiesPerPixel() diff --git a/src/main/java/net/imglib2/type/AbstractNativeType.java b/src/main/java/net/imglib2/type/AbstractNativeType.java index 0bcccb8c49..2a1b54dab2 100644 --- a/src/main/java/net/imglib2/type/AbstractNativeType.java +++ b/src/main/java/net/imglib2/type/AbstractNativeType.java @@ -36,50 +36,25 @@ /** * TODO - * + * * @author Stephan Preibisch * @author Stephan Saalfeld */ public abstract class AbstractNativeType< T extends AbstractNativeType< T >> implements NativeType< T > { - protected int i = 0; + protected final Index i; - @Override - public void updateIndex( final int j ) + protected AbstractNativeType() { - this.i = j; + i = new Index(); } @Override - public int getIndex() + public Index index() { return i; } - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public abstract String toString(); } diff --git a/src/main/java/net/imglib2/type/label/BasePairCharType.java b/src/main/java/net/imglib2/type/label/BasePairCharType.java index 49fa7476d7..4e5c73bcaf 100644 --- a/src/main/java/net/imglib2/type/label/BasePairCharType.java +++ b/src/main/java/net/imglib2/type/label/BasePairCharType.java @@ -113,12 +113,12 @@ public NativeTypeFactory< BasePairCharType, CharAccess > getNativeTypeFactory() public char getChar() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } public void setChar( final char f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -136,7 +136,7 @@ public Base get() @Override public void set( final BasePairCharType c ) { - dataAccess.setValue( i, c.getChar() ); + dataAccess.setValue( i.get(), c.getChar() ); } @Override diff --git a/src/main/java/net/imglib2/type/logic/BitType.java b/src/main/java/net/imglib2/type/logic/BitType.java index e669f5371c..d4f2dbfda3 100644 --- a/src/main/java/net/imglib2/type/logic/BitType.java +++ b/src/main/java/net/imglib2/type/logic/BitType.java @@ -40,6 +40,7 @@ import net.imglib2.img.basictypeaccess.LongAccess; import net.imglib2.img.basictypeaccess.array.LongArray; import net.imglib2.type.BooleanType; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.type.numeric.IntegerType; @@ -56,7 +57,7 @@ public class BitType extends AbstractIntegerType< BitType > implements BooleanType< BitType >, NativeType< BitType >, IntegerType< BitType > { // Maximum count is Integer.MAX_VALUE * (64 / getBitsPerPixel()) - protected int i = 0; + protected final Index i; final protected NativeImg< ?, ? extends LongAccess > img; @@ -66,6 +67,7 @@ public class BitType extends AbstractIntegerType< BitType > implements BooleanTy // this is the constructor if you want it to read from an array public BitType( final NativeImg< ?, ? extends LongAccess > bitStorage ) { + i = new Index(); img = bitStorage; } @@ -96,6 +98,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public BitType duplicateTypeOnSameNativeImg() { @@ -113,7 +121,8 @@ public NativeTypeFactory< BitType, LongAccess > getNativeTypeFactory() @Override public boolean get() { - return 1 == ( ( dataAccess.getValue( i >>> 6 ) >>> ( ( i & 63 ) ) ) & 1l ); + final int j = i.get(); + return 1 == ( ( dataAccess.getValue( j >>> 6 ) >>> ( ( j & 63 ) ) ) & 1l ); } // Crops value to within mask @@ -125,8 +134,9 @@ public void set( final boolean value ) final long shift = k % 64; */ // Same as above, minus one multiplication, plus one shift to multiply the reminder by 2 - final int i1 = i >>> 6; // Same as i / 64 - final long bit = 1l << (i & 63); + final int j = i.get(); + final int i1 = j >>> 6; // Same as i / 64 + final long bit = 1l << (j & 63); synchronized ( dataAccess ) { // Clear or set the bit @@ -316,42 +326,6 @@ public Fraction getEntitiesPerPixel() return new Fraction(1, 64); } - @Override - public void updateIndex( final int index ) - { - this.i = index; - } - - @Override - public int getIndex() - { - return i; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public int getBitsPerPixel() { diff --git a/src/main/java/net/imglib2/type/logic/NativeBoolType.java b/src/main/java/net/imglib2/type/logic/NativeBoolType.java index 8c27c76f0e..cabc2caff2 100644 --- a/src/main/java/net/imglib2/type/logic/NativeBoolType.java +++ b/src/main/java/net/imglib2/type/logic/NativeBoolType.java @@ -40,6 +40,7 @@ import net.imglib2.img.basictypeaccess.BooleanAccess; import net.imglib2.img.basictypeaccess.array.BooleanArray; import net.imglib2.type.BooleanType; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.type.numeric.integer.AbstractIntegerType; @@ -53,7 +54,7 @@ */ public class NativeBoolType extends AbstractIntegerType< NativeBoolType > implements BooleanType< NativeBoolType >, NativeType< NativeBoolType > { - int i = 0; + final Index i; final protected NativeImg< ?, ? extends BooleanAccess > img; @@ -63,12 +64,14 @@ public class NativeBoolType extends AbstractIntegerType< NativeBoolType > implem // this is the constructor if you want it to read from an array public NativeBoolType( final NativeImg< ?, ? extends BooleanAccess > boolStorage ) { + i = new Index(); img = boolStorage; } // this is the constructor if you want it to be a variable public NativeBoolType( final boolean value ) { + i = new Index(); img = null; dataAccess = new BooleanArray( 1 ); set( value ); @@ -77,6 +80,7 @@ public NativeBoolType( final boolean value ) // this is the constructor if you want to specify the dataAccess public NativeBoolType( final BooleanAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -113,6 +117,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + /** * Returns the primitive boolean value that is used to store this type. * @@ -121,7 +131,7 @@ public void updateContainer( final Object c ) @Override public boolean get() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -130,7 +140,7 @@ public boolean get() @Override public void set( final boolean f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -209,42 +219,6 @@ public String toString() return "" + get(); } - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public int getIndex() - { - return i; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public int getBitsPerPixel() { diff --git a/src/main/java/net/imglib2/type/numeric/ARGBType.java b/src/main/java/net/imglib2/type/numeric/ARGBType.java index 0ec3db9bf4..d83a7e95ca 100644 --- a/src/main/java/net/imglib2/type/numeric/ARGBType.java +++ b/src/main/java/net/imglib2/type/numeric/ARGBType.java @@ -144,12 +144,12 @@ final public static int alpha( final int value ) public int get() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } public void set( final int f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -201,7 +201,7 @@ public void sub( final ARGBType c ) set( rgba( red( value1 ) - red( value2 ), green( value1 ) - green( value2 ), blue( value1 ) - blue( value2 ), alpha( value1 ) - alpha( value2 ) ) ); } - + @Override public void pow( final ARGBType c ) { @@ -212,9 +212,9 @@ public void pow( final ARGBType c ) Math.pow( red( value1 ), red( value2 ) ), Math.pow( green( value1 ), green( value2 ) ), Math.pow( blue( value1 ), blue( value2 ) ), - Math.pow( alpha( value1 ), alpha( value2 ) ) ) ); + Math.pow( alpha( value1 ), alpha( value2 ) ) ) ); } - + @Override public void pow( final double power ) { diff --git a/src/main/java/net/imglib2/type/numeric/NativeARGBDoubleType.java b/src/main/java/net/imglib2/type/numeric/NativeARGBDoubleType.java index 6dcf82b334..ef2cf905c5 100644 --- a/src/main/java/net/imglib2/type/numeric/NativeARGBDoubleType.java +++ b/src/main/java/net/imglib2/type/numeric/NativeARGBDoubleType.java @@ -37,6 +37,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.DoubleAccess; import net.imglib2.img.basictypeaccess.array.DoubleArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.util.Fraction; @@ -47,9 +48,7 @@ */ public class NativeARGBDoubleType extends AbstractARGBDoubleType< NativeARGBDoubleType > implements NativeType< NativeARGBDoubleType > { - private int i = 0; - - private int ai = 0, ri = 1, gi = 2, bi = 3; + private final Index i; final protected NativeImg< ?, ? extends DoubleAccess > img; @@ -57,11 +56,13 @@ public class NativeARGBDoubleType extends AbstractARGBDoubleType< NativeARGBDoub public NativeARGBDoubleType( final NativeImg< ?, ? extends DoubleAccess > img ) { + i = new Index(); this.img = img; } public NativeARGBDoubleType( final double a, final double r, final double g, final double b ) { + i = new Index(); img = null; dataAccess = new DoubleArray( 4 ); set( a, r, g, b ); @@ -69,6 +70,7 @@ public NativeARGBDoubleType( final double a, final double r, final double g, fin public NativeARGBDoubleType( final DoubleAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -84,6 +86,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public NativeARGBDoubleType duplicateTypeOnSameNativeImg() { @@ -101,58 +109,67 @@ public NativeTypeFactory< NativeARGBDoubleType, DoubleAccess > getNativeTypeFact @Override public double getA() { + final int ai = i.get() << 2; return dataAccess.getValue( ai ); } @Override public double getR() { - return dataAccess.getValue( ri ); + final int ai = i.get() << 2; + return dataAccess.getValue( ai + 1 ); } @Override public double getG() { - return dataAccess.getValue( gi ); + final int ai = i.get() << 2; + return dataAccess.getValue( ai + 2 ); } @Override public double getB() { - return dataAccess.getValue( bi ); + final int ai = i.get() << 2; + return dataAccess.getValue( ai + 3 ); } @Override public void setA( final double a ) { + final int ai = i.get() << 2; dataAccess.setValue( ai, a ); } @Override public void setR( final double r ) { - dataAccess.setValue( ri, r ); + final int ai = i.get() << 2; + dataAccess.setValue( ai + 1, r ); } @Override public void setG( final double g ) { - dataAccess.setValue( gi, g ); + final int ai = i.get() << 2; + dataAccess.setValue( ai + 2, g ); } @Override public void setB( final double b ) { - dataAccess.setValue( bi, b ); + final int ai = i.get() << 2; + dataAccess.setValue( ai + 3, b ); } @Override public void set( final double a, final double r, final double g, final double b ) { + final int ai = i.get() << 2; dataAccess.setValue( ai, a ); - dataAccess.setValue( ri, r ); - dataAccess.setValue( gi, g ); - dataAccess.setValue( bi, b ); + dataAccess.setValue( ai + 1, r ); + dataAccess.setValue( ai + 2, g ); + dataAccess.setValue( ai + 3, b ); } public void set( final ARGBDoubleType c ) @@ -177,64 +194,4 @@ public Fraction getEntitiesPerPixel() { return new Fraction( 4, 1 ); } - - @Override - public void updateIndex( final int index ) - { - this.i = index; - ai = i * 4; - ri = ai + 1; - gi = ai + 2; - bi = ai + 3; - } - - @Override - public void incIndex() - { - ++i; - ai += 4; - ri += 4; - gi += 4; - bi += 4; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - - final int inc2 = increment * 4; - ai += inc2; - ri += inc2; - gi += inc2; - bi += inc2; - } - - @Override - public void decIndex() - { - --i; - ai -= 4; - ri -= 4; - gi -= 4; - bi -= 4; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - - final int dec2 = decrement * 4; - ai -= dec2; - ri -= dec2; - gi -= dec2; - bi -= dec2; - } - - @Override - public int getIndex() - { - return i; - } } 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 72d1f667b9..f369e5c7f5 100644 --- a/src/main/java/net/imglib2/type/numeric/complex/ComplexDoubleType.java +++ b/src/main/java/net/imglib2/type/numeric/complex/ComplexDoubleType.java @@ -37,6 +37,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.DoubleAccess; import net.imglib2.img.basictypeaccess.array.DoubleArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.util.Fraction; @@ -49,7 +50,7 @@ */ public class ComplexDoubleType extends AbstractComplexType< ComplexDoubleType > implements NativeType< ComplexDoubleType > { - private int i = 0; + private final Index i; // the indices for real and imaginary value private int realI = 0, imaginaryI = 1; @@ -62,12 +63,14 @@ public class ComplexDoubleType extends AbstractComplexType< ComplexDoubleType > // this is the constructor if you want it to read from an array public ComplexDoubleType( final NativeImg< ?, ? extends DoubleAccess > complexfloatStorage ) { + i = new Index(); img = complexfloatStorage; } // this is the constructor if you want it to be a variable public ComplexDoubleType( final double r, final double i ) { + this.i = new Index(); img = null; dataAccess = new DoubleArray( 2 ); set( r, i ); @@ -76,6 +79,7 @@ public ComplexDoubleType( final double r, final double i ) // this is the constructor if you want to specify the dataAccess public ComplexDoubleType( final DoubleAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -92,6 +96,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public ComplexDoubleType duplicateTypeOnSameNativeImg() { @@ -109,55 +119,56 @@ public NativeTypeFactory< ComplexDoubleType, DoubleAccess > getNativeTypeFactory @Override public float getRealFloat() { - return ( float ) dataAccess.getValue( realI ); + return ( float ) dataAccess.getValue( i.get() << 1 ); } @Override public double getRealDouble() { - return dataAccess.getValue( realI ); + return dataAccess.getValue( i.get() << 1 ); } @Override public float getImaginaryFloat() { - return ( float ) dataAccess.getValue( imaginaryI ); + return ( float ) dataAccess.getValue( ( i.get() << 1 ) + 1 ); } @Override public double getImaginaryDouble() { - return dataAccess.getValue( imaginaryI ); + return dataAccess.getValue( ( i.get() << 1 ) + 1 ); } @Override public void setReal( final float r ) { - dataAccess.setValue( realI, r ); + dataAccess.setValue( i.get() << 1, r ); } @Override public void setReal( final double r ) { - dataAccess.setValue( realI, r ); + dataAccess.setValue( i.get() << 1, r ); } @Override public void setImaginary( final float i ) { - dataAccess.setValue( imaginaryI, i ); + dataAccess.setValue( ( this.i.get() << 1 ) + 1, i ); } @Override public void setImaginary( final double i ) { - dataAccess.setValue( imaginaryI, i ); + dataAccess.setValue( ( this.i.get() << 1 ) + 1, i ); } public void set( final double r, final double i ) { - dataAccess.setValue( realI, r ); - dataAccess.setValue( imaginaryI, i ); + final int j = this.i.get() << 1; + dataAccess.setValue( j, r ); + dataAccess.setValue( j + 1, i ); } @Override @@ -184,53 +195,4 @@ public Fraction getEntitiesPerPixel() { return new Fraction( 2, 1 ); } - - @Override - public void updateIndex( final int index ) - { - this.i = index; - realI = index * 2; - imaginaryI = index * 2 + 1; - } - - @Override - public void incIndex() - { - ++i; - realI += 2; - imaginaryI += 2; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - - final int inc2 = 2 * increment; - realI += inc2; - imaginaryI += inc2; - } - - @Override - public void decIndex() - { - --i; - realI -= 2; - imaginaryI -= 2; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - final int dec2 = 2 * decrement; - realI -= dec2; - imaginaryI -= dec2; - } - - @Override - public int getIndex() - { - return i; - } } 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 6b4615cced..7c0af257ae 100644 --- a/src/main/java/net/imglib2/type/numeric/complex/ComplexFloatType.java +++ b/src/main/java/net/imglib2/type/numeric/complex/ComplexFloatType.java @@ -37,6 +37,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.FloatAccess; import net.imglib2.img.basictypeaccess.array.FloatArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.type.numeric.real.FloatType; @@ -51,10 +52,7 @@ */ public class ComplexFloatType extends AbstractComplexType< ComplexFloatType > implements NativeType< ComplexFloatType > { - private int i = 0; - - // the indices for real and imaginary number - private int realI = 0, imaginaryI = 1; + private final Index i; final protected NativeImg< ?, ? extends FloatAccess > img; @@ -64,12 +62,14 @@ public class ComplexFloatType extends AbstractComplexType< ComplexFloatType > im // this is the constructor if you want it to read from an array public ComplexFloatType( final NativeImg< ?, ? extends FloatAccess > complexfloatStorage ) { + i = new Index(); img = complexfloatStorage; } // this is the constructor if you want it to be a variable public ComplexFloatType( final float r, final float i ) { + this.i = new Index(); img = null; dataAccess = new FloatArray( 2 ); set( r, i ); @@ -78,6 +78,7 @@ public ComplexFloatType( final float r, final float i ) // this is the constructor if you want to specify the dataAccess public ComplexFloatType( final FloatAccess access ) { + this.i = new Index(); img = null; dataAccess = access; } @@ -94,6 +95,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public ComplexFloatType duplicateTypeOnSameNativeImg() { @@ -111,55 +118,56 @@ public NativeTypeFactory< ComplexFloatType, FloatAccess > getNativeTypeFactory() @Override public float getRealFloat() { - return dataAccess.getValue( realI ); + return dataAccess.getValue( i.get() << 1 ); } @Override public double getRealDouble() { - return dataAccess.getValue( realI ); + return dataAccess.getValue( i.get() << 1 ); } @Override public float getImaginaryFloat() { - return dataAccess.getValue( imaginaryI ); + return dataAccess.getValue( ( i.get() << 1 ) + 1 ); } @Override public double getImaginaryDouble() { - return dataAccess.getValue( imaginaryI ); + return dataAccess.getValue( ( i.get() << 1 ) + 1 ); } @Override public void setReal( final float r ) { - dataAccess.setValue( realI, r ); + dataAccess.setValue( i.get() << 1, r ); } @Override public void setReal( final double r ) { - dataAccess.setValue( realI, ( float ) r ); + dataAccess.setValue( i.get() << 1, ( float ) r ); } @Override public void setImaginary( final float i ) { - dataAccess.setValue( imaginaryI, i ); + dataAccess.setValue( ( this.i.get() << 1 ) + 1, i ); } @Override public void setImaginary( final double i ) { - dataAccess.setValue( imaginaryI, ( float ) i ); + dataAccess.setValue( ( this.i.get() << 1 ) + 1, ( float ) i ); } public void set( final float r, final float i ) { - dataAccess.setValue( realI, r ); - dataAccess.setValue( imaginaryI, i ); + final int j = this.i.get() << 1; + dataAccess.setValue( j, r ); + dataAccess.setValue( j + 1, i ); } @Override @@ -241,55 +249,6 @@ public Fraction getEntitiesPerPixel() return new Fraction( 2, 1 ); } - @Override - public void updateIndex( final int index ) - { - this.i = index; - realI = index * 2; - imaginaryI = index * 2 + 1; - } - - @Override - public void incIndex() - { - ++i; - realI += 2; - imaginaryI += 2; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - - final int inc2 = 2 * increment; - realI += inc2; - imaginaryI += inc2; - } - - @Override - public void decIndex() - { - --i; - realI -= 2; - imaginaryI -= 2; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - final int dec2 = 2 * decrement; - realI -= dec2; - imaginaryI -= dec2; - } - - @Override - public int getIndex() - { - return i; - } - @Override public boolean valueEquals( final ComplexFloatType t ) { diff --git a/src/main/java/net/imglib2/type/numeric/integer/GenericByteType.java b/src/main/java/net/imglib2/type/numeric/integer/GenericByteType.java index 9f1d7cc6e7..91d7a4c816 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/GenericByteType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/GenericByteType.java @@ -37,6 +37,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.ByteAccess; import net.imglib2.img.basictypeaccess.array.ByteArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.util.Fraction; @@ -50,7 +51,7 @@ */ public abstract class GenericByteType< T extends GenericByteType< T > > extends AbstractIntegerType< T > implements NativeType< T > { - int i = 0; + final Index i; final protected NativeImg< ?, ? extends ByteAccess > img; @@ -60,12 +61,14 @@ public abstract class GenericByteType< T extends GenericByteType< T > > extends // this is the constructor if you want it to read from an array public GenericByteType( final NativeImg< ?, ? extends ByteAccess > byteStorage ) { + i = new Index(); img = byteStorage; } // this is the constructor if you want it to be a variable public GenericByteType( final byte value ) { + i = new Index(); img = null; dataAccess = new ByteArray( 1 ); setByte( value ); @@ -74,6 +77,7 @@ public GenericByteType( final byte value ) // this is the constructor if you want to specify the dataAccess public GenericByteType( final ByteAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -96,6 +100,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public abstract NativeTypeFactory< T, ByteAccess > getNativeTypeFactory(); @@ -105,7 +115,7 @@ public void updateContainer( final Object c ) @Deprecated protected byte getValue() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -114,7 +124,7 @@ protected byte getValue() @Deprecated protected void setValue( final byte f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } /** @@ -124,7 +134,7 @@ protected void setValue( final byte f ) */ public byte getByte() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -132,7 +142,7 @@ public byte getByte() */ public void setByte( final byte f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -215,42 +225,6 @@ public String toString() return "" + getByte(); } - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public int getIndex() - { - return i; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public int getBitsPerPixel() { diff --git a/src/main/java/net/imglib2/type/numeric/integer/GenericIntType.java b/src/main/java/net/imglib2/type/numeric/integer/GenericIntType.java index d059856620..48864f6bdd 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/GenericIntType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/GenericIntType.java @@ -37,6 +37,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.IntAccess; import net.imglib2.img.basictypeaccess.array.IntArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.util.Fraction; @@ -50,7 +51,7 @@ */ public abstract class GenericIntType< T extends GenericIntType< T > > extends AbstractIntegerType< T > implements NativeType< T > { - int i = 0; + final Index i; final protected NativeImg< ?, ? extends IntAccess > img; @@ -60,12 +61,14 @@ public abstract class GenericIntType< T extends GenericIntType< T > > extends Ab // this is the constructor if you want it to read from an array public GenericIntType( final NativeImg< ?, ? extends IntAccess > intStorage ) { + i = new Index(); img = intStorage; } // this is the constructor if you want it to be a variable public GenericIntType( final int value ) { + i = new Index(); img = null; dataAccess = new IntArray( 1 ); setInt( value ); @@ -74,6 +77,7 @@ public GenericIntType( final int value ) // this is the constructor if you want to specify the dataAccess public GenericIntType( final IntAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -96,6 +100,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public abstract NativeTypeFactory< T, IntAccess > getNativeTypeFactory(); @@ -105,7 +115,7 @@ public void updateContainer( final Object c ) @Deprecated protected int getValue() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -114,7 +124,7 @@ protected int getValue() @Deprecated protected void setValue( final int f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } /** @@ -124,7 +134,7 @@ protected void setValue( final int f ) */ public int getInt() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -132,7 +142,7 @@ public int getInt() */ public void setInt( final int f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -176,14 +186,14 @@ public void sub( final T c ) final int a = getInt(); setInt( a - c.getInt() ); } - + @Override public void pow( final T c ) { final int a = getInt(); setReal( Math.pow( a, c.getInt() ) ); } - + @Override public void pow( final double power ) { @@ -229,42 +239,6 @@ public String toString() return "" + getInt(); } - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public int getIndex() - { - return i; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public int getBitsPerPixel() { diff --git a/src/main/java/net/imglib2/type/numeric/integer/GenericLongType.java b/src/main/java/net/imglib2/type/numeric/integer/GenericLongType.java index 533f087b9f..dab6de2dfe 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/GenericLongType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/GenericLongType.java @@ -36,6 +36,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.LongAccess; import net.imglib2.img.basictypeaccess.array.LongArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.util.Fraction; @@ -48,7 +49,7 @@ */ public abstract class GenericLongType< T extends GenericLongType< T > > extends AbstractIntegerType< T > implements NativeType< T > { - int i = 0; + final Index i; final protected NativeImg< ?, ? extends LongAccess > img; @@ -58,12 +59,14 @@ public abstract class GenericLongType< T extends GenericLongType< T > > extends // this is the constructor if you want it to read from an array public GenericLongType( final NativeImg< ?, ? extends LongAccess > longStorage ) { + i = new Index(); img = longStorage; } // this is the constructor if you want it to be a variable public GenericLongType( final long value ) { + i = new Index(); img = null; dataAccess = new LongArray( 1 ); setLong( value ); @@ -72,6 +75,7 @@ public GenericLongType( final long value ) // this is the constructor if you want to specify the dataAccess public GenericLongType( final LongAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -94,6 +98,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public abstract NativeTypeFactory< T, LongAccess > getNativeTypeFactory(); @@ -103,7 +113,7 @@ public void updateContainer( final Object c ) @Deprecated protected long getValue() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -112,7 +122,7 @@ protected long getValue() @Deprecated protected void setValue( final long f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } /** @@ -122,7 +132,7 @@ protected void setValue( final long f ) */ public long getLong() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -130,7 +140,7 @@ public long getLong() */ public void setLong( final long f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -207,42 +217,6 @@ public String toString() return "" + getLong(); } - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public int getIndex() - { - return i; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public int getBitsPerPixel() { diff --git a/src/main/java/net/imglib2/type/numeric/integer/GenericShortType.java b/src/main/java/net/imglib2/type/numeric/integer/GenericShortType.java index 765532c64c..7d40fd684a 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/GenericShortType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/GenericShortType.java @@ -37,6 +37,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.ShortAccess; import net.imglib2.img.basictypeaccess.array.ShortArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.type.numeric.IntegerType; @@ -54,7 +55,7 @@ public abstract class GenericShortType< T extends GenericShortType< T > > extends AbstractIntegerType< T > implements NativeType< T > { - int i = 0; + final Index i; final protected NativeImg< ?, ? extends ShortAccess > img; @@ -64,12 +65,14 @@ public abstract class GenericShortType< T extends GenericShortType< T > > // this is the constructor if you want it to read from an array public GenericShortType( final NativeImg< ?, ? extends ShortAccess > shortStorage ) { + i = new Index(); img = shortStorage; } // this is the constructor if you want it to be a variable public GenericShortType( final short value ) { + i = new Index(); img = null; dataAccess = new ShortArray( 1 ); setShort( value ); @@ -78,6 +81,7 @@ public GenericShortType( final short value ) // this is the constructor if you want to specify the dataAccess public GenericShortType( final ShortAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -100,6 +104,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public abstract NativeTypeFactory< T, ShortAccess > getNativeTypeFactory(); @@ -109,7 +119,7 @@ public void updateContainer( final Object c ) @Deprecated protected short getValue() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -118,7 +128,7 @@ protected short getValue() @Deprecated protected void setValue( final short f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } /** @@ -128,7 +138,7 @@ protected void setValue( final short f ) */ public short getShort() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -136,7 +146,7 @@ public short getShort() */ public void setShort( final short f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -219,42 +229,6 @@ public String toString() return "" + getShort(); } - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public int getIndex() - { - return i; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public int getBitsPerPixel() { 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 a805b87e77..b6d17befdf 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/LongType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/LongType.java @@ -95,7 +95,7 @@ public long get() public void set( final long f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override 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 daf2ae96b2..5ea3d0ad55 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/Unsigned128BitType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/Unsigned128BitType.java @@ -40,6 +40,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.LongAccess; import net.imglib2.img.basictypeaccess.array.LongArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.type.Type; @@ -59,7 +60,7 @@ */ public class Unsigned128BitType extends AbstractIntegerType< Unsigned128BitType > implements NativeType< Unsigned128BitType > { - private int i = 0; + private final Index i; final protected NativeImg< ?, ? extends LongAccess > img; @@ -72,6 +73,7 @@ public class Unsigned128BitType extends AbstractIntegerType< Unsigned128BitType // this is the constructor if you want it to read from an array public Unsigned128BitType( final NativeImg< ?, ? extends LongAccess > bitStorage ) { + i = new Index(); img = bitStorage; } @@ -110,6 +112,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public Unsigned128BitType duplicateTypeOnSameNativeImg() { @@ -152,7 +160,7 @@ private final void intoBytes( final long lower, final long upper ) */ public void set( final byte[] bytes ) { - final int k = i * 2; + final int k = i.get() * 2; int b = bytes.length - 1; for ( int offset = 0; offset < 2; ++offset ) { @@ -168,7 +176,7 @@ public void set( final byte[] bytes ) public BigInteger get() { - final int k = i * 2; + final int k = i.get() * 2; intoBytes( dataAccess.getValue( k ), dataAccess.getValue( k + 1 ) ); return new BigInteger( bytes ); } @@ -180,7 +188,7 @@ public void set( final BigInteger value ) public void set( final long lower, final long upper ) { - final int k = i * 2; + final int k = i.get() * 2; dataAccess.setValue( k, lower ); dataAccess.setValue( k + 1, upper ); } @@ -189,14 +197,14 @@ public void set( final long lower, final long upper ) @Override public int getInteger() { - return ( int ) ( dataAccess.getValue( i * 2 ) & 0xffffffffL ); + return ( int ) ( dataAccess.getValue( i.get() * 2 ) & 0xffffffffL ); } /** Return the lowest 64 bits, like {@link BigInteger#intValue()}. */ @Override public long getIntegerLong() { - return dataAccess.getValue( i * 2 ); + return dataAccess.getValue( i.get() * 2 ); } @Override @@ -214,7 +222,7 @@ public float getRealFloat() @Override public double getRealDouble() { - final int k = i * 2; + final int k = i.get() * 2; final long lower = dataAccess.getValue( k ); final long upper = dataAccess.getValue( k + 1 ); return UnsignedLongType.unsignedLongToDouble( lower ) + @@ -224,7 +232,7 @@ public double getRealDouble() @Override public void setInteger( final int value ) { - final int k = i * 2; + final int k = i.get() * 2; dataAccess.setValue( k, value ); dataAccess.setValue( k + 1, 0 ); } @@ -232,7 +240,7 @@ public void setInteger( final int value ) @Override public void setInteger( final long value ) { - final int k = i * 2; + final int k = i.get() * 2; dataAccess.setValue( k, value ); dataAccess.setValue( k + 1, 0 ); } @@ -290,42 +298,6 @@ public double getMinValue() return 0; } - @Override - public int getIndex() - { - return i; - } - - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public Unsigned128BitType createVariable() { @@ -336,7 +308,7 @@ public Unsigned128BitType createVariable() public Unsigned128BitType copy() { final Unsigned128BitType copy = new Unsigned128BitType(); - final int k = i * 2; + final int k = i.get() * 2; copy.set( dataAccess.getValue( k ), dataAccess.getValue( k + 1 ) ); return copy; } @@ -356,7 +328,7 @@ public int getBitsPerPixel() @Override public void inc() { - final int k = i * 2; + final int k = i.get() * 2; final long lower = dataAccess.getValue( k ); if ( 0xffffffffffffffffL == lower ) { @@ -380,7 +352,7 @@ public void inc() @Override public void dec() { - final int k = i * 2; + final int k = i.get() * 2; final long lower = dataAccess.getValue( k ); if ( 0 == lower ) { @@ -457,13 +429,13 @@ public void div( final Unsigned128BitType t ) { set( get().divide( t.get() ).toByteArray() ); } - + @Override public void pow( final Unsigned128BitType t ) { throw new UnsupportedOperationException( "pow is not yet supported for Unsigned128BitType" ); } - + @Override public void pow( final double power ) { @@ -473,22 +445,24 @@ public void pow( final double power ) @Override public int compareTo( final Unsigned128BitType t ) { - final long upper1 = dataAccess.getValue( i * 2 + 1 ); - final long upper2 = t.dataAccess.getValue( t.i * 2 + 1 ); + final int j = i.get(); + final int tj = t.i.get(); + final long upper1 = dataAccess.getValue( j * 2 + 1 ); + final long upper2 = t.dataAccess.getValue( tj * 2 + 1 ); final int compareUpper = Long.compareUnsigned( upper1, upper2 ); if ( compareUpper != 0 ) return compareUpper; - final long lower1 = dataAccess.getValue( i * 2 ); - final long lower2 = t.dataAccess.getValue( t.i * 2 ); + final long lower1 = dataAccess.getValue( j * 2 ); + final long lower2 = t.dataAccess.getValue( tj * 2 ); return Long.compareUnsigned( lower1, lower2 ); } @Override public boolean valueEquals( final Unsigned128BitType t ) { - final int k = i * 2; - final int kt = t.i * 2; + final int k = i.get() * 2; + final int kt = t.i.get() * 2; return ( dataAccess.getValue( k ) == t.dataAccess.getValue( kt ) ) && ( dataAccess.getValue( k + 1 ) == t.dataAccess.getValue( kt + 1 ) ); @@ -503,7 +477,7 @@ public boolean equals( final Object obj ) @Override public int hashCode() { - final int k = i * 2; + final int k = i.get() * 2; final int hash1 = Long.hashCode( dataAccess.getValue( k + 1 ) ); final int hash2 = Long.hashCode( dataAccess.getValue( k ) ); return Util.combineHash( hash1, hash2 ); 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 ac3f8a9820..15192e821f 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/Unsigned12BitType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/Unsigned12BitType.java @@ -97,7 +97,8 @@ public NativeTypeFactory< Unsigned12BitType, LongAccess > getNativeTypeFactory() @Override public long get() { - final long k = i * 12; + long j = i.get(); + final long k = j * 12; final int i1 = ( int ) ( k >>> 6 ); // k / 64; final long shift = k & 63; // k % 64; final long v = dataAccess.getValue( i1 ); @@ -121,7 +122,8 @@ public long get() @Override public void set( final long value ) { - final long k = i * 12; + long j = i.get(); + final long k = j * 12; final int i1 = ( int ) ( k >>> 6 ); // k / 64; final long shift = k & 63; // k % 64; final long safeValue = value & mask; 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 421bbe48ee..f3795ae6ba 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/Unsigned2BitType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/Unsigned2BitType.java @@ -104,7 +104,8 @@ public long get() //return (dataAccess.getValue((int)(i >>> 5)) >>> ((i % 32) << 1)) & mask; // Even less operations // div 32 == shr 5 - return ( dataAccess.getValue( ( int ) ( i >>> 5 ) ) >>> ( ( i & 31 ) << 1 ) ) & mask; + final long j = i.get(); + return ( dataAccess.getValue( ( int ) ( j >>> 5 ) ) >>> ( ( j & 31 ) << 1 ) ) & mask; } // Crops value to within mask @@ -117,8 +118,9 @@ public void set( final long value ) final long shift = k % 64; */ // Same as above, minus one multiplication, plus one shift to multiply the reminder by 2 - final int i1 = ( int ) ( i >>> 5 ); // Same as (i * 2) / 64 = (i << 1) >>> 6 - final long shift = ( i << 1 ) & 63; // Same as (i * 2) % 64 + final long j = i.get(); + final int i1 = ( int ) ( j >>> 5 ); // Same as (i * 2) / 64 = (i << 1) >>> 6 + final long shift = ( j << 1 ) & 63; // Same as (i * 2) % 64 // Clear the bits first, then or the masked value final long bitsToRetain = ~( mask << shift ); 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 06473ee771..260cbb5730 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/Unsigned4BitType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/Unsigned4BitType.java @@ -96,7 +96,8 @@ public NativeTypeFactory< Unsigned4BitType, LongAccess > getNativeTypeFactory() @Override public long get() { - return ( dataAccess.getValue( ( int ) ( i >>> 4 ) ) >>> ( ( i & 15 ) << 2 ) ) & mask; + final long j = index().get(); + return ( dataAccess.getValue( ( int ) ( j >>> 4 ) ) >>> ( ( j & 15 ) << 2 ) ) & mask; } // Crops value to within mask @@ -109,8 +110,9 @@ public void set( final long value ) final long shift = k % 64; */ // Same as above minus one multiplication, plus one shift (to multiply by 4) - final int i1 = ( int ) ( i >>> 4 ); // Same as (i * 4) / 64 = ((i << 2) >>> 6) - final long shift = ( i << 2 ) & 63; // Same as (i * 4) % 64 + final long j = index().get(); + final int i1 = ( int ) ( j >>> 4 ); // Same as (i * 4) / 64 = ((i << 2) >>> 6) + final long shift = ( j << 2 ) & 63; // Same as (i * 4) % 64 // Clear the bits first, then or the masked value final long bitsToRetain = ~( mask << shift ); 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 525f0406b9..b0b56f108e 100644 --- a/src/main/java/net/imglib2/type/numeric/integer/UnsignedLongType.java +++ b/src/main/java/net/imglib2/type/numeric/integer/UnsignedLongType.java @@ -218,7 +218,7 @@ public String toString() */ public long get() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } /** @@ -234,7 +234,7 @@ public BigInteger getBigInteger() public void set( final long value ) { - dataAccess.setValue( i, value ); + dataAccess.setValue( i.get(), value ); } @Override 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 c7b4a2c747..94dfe40140 100644 --- a/src/main/java/net/imglib2/type/numeric/real/DoubleType.java +++ b/src/main/java/net/imglib2/type/numeric/real/DoubleType.java @@ -37,6 +37,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.DoubleAccess; import net.imglib2.img.basictypeaccess.array.DoubleArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.util.Fraction; @@ -49,7 +50,7 @@ */ public class DoubleType extends AbstractRealType< DoubleType > implements NativeType< DoubleType > { - private int i = 0; + private final Index i; final protected NativeImg< ?, ? extends DoubleAccess > img; @@ -59,12 +60,14 @@ public class DoubleType extends AbstractRealType< DoubleType > implements Native // this is the constructor if you want it to read from an array public DoubleType( final NativeImg< ?, ? extends DoubleAccess > doubleStorage ) { + i = new Index(); img = doubleStorage; } // this is the constructor if you want it to be a variable public DoubleType( final double value ) { + i = new Index(); img = null; dataAccess = new DoubleArray( 1 ); set( value ); @@ -73,6 +76,7 @@ public DoubleType( final double value ) // this is the constructor if you want to specify the dataAccess public DoubleType( final DoubleAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -89,6 +93,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public DoubleType duplicateTypeOnSameNativeImg() { @@ -105,12 +115,12 @@ public NativeTypeFactory< DoubleType, DoubleAccess > getNativeTypeFactory() public double get() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } public void set( final double f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -173,42 +183,6 @@ public Fraction getEntitiesPerPixel() return new Fraction(); } - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public int getIndex() - { - return i; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public int getBitsPerPixel() { 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 d2bb6d72aa..dc4fe6311d 100644 --- a/src/main/java/net/imglib2/type/numeric/real/FloatType.java +++ b/src/main/java/net/imglib2/type/numeric/real/FloatType.java @@ -37,6 +37,7 @@ import net.imglib2.img.NativeImg; import net.imglib2.img.basictypeaccess.FloatAccess; import net.imglib2.img.basictypeaccess.array.FloatArray; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.util.Fraction; @@ -50,7 +51,7 @@ */ public class FloatType extends AbstractRealType< FloatType > implements NativeType< FloatType > { - private int i = 0; + private final Index i; final protected NativeImg< ?, ? extends FloatAccess > img; @@ -60,12 +61,14 @@ public class FloatType extends AbstractRealType< FloatType > implements NativeTy // this is the constructor if you want it to read from an array public FloatType( final NativeImg< ?, ? extends FloatAccess > floatStorage ) { + i = new Index(); img = floatStorage; } // this is the constructor if you want it to be a variable public FloatType( final float value ) { + i = new Index(); img = null; dataAccess = new FloatArray( 1 ); set( value ); @@ -74,6 +77,7 @@ public FloatType( final float value ) // this is the constructor if you want to specify the dataAccess public FloatType( final FloatAccess access ) { + i = new Index(); img = null; dataAccess = access; } @@ -90,6 +94,12 @@ public void updateContainer( final Object c ) dataAccess = img.update( c ); } + @Override + public Index index() + { + return i; + } + @Override public FloatType duplicateTypeOnSameNativeImg() { @@ -106,12 +116,12 @@ public NativeTypeFactory< FloatType, FloatAccess > getNativeTypeFactory() public float get() { - return dataAccess.getValue( i ); + return dataAccess.getValue( i.get() ); } public void set( final float f ) { - dataAccess.setValue( i, f ); + dataAccess.setValue( i.get(), f ); } @Override @@ -242,42 +252,6 @@ public Fraction getEntitiesPerPixel() return new Fraction(); } - @Override - public void updateIndex( final int index ) - { - i = index; - } - - @Override - public int getIndex() - { - return i; - } - - @Override - public void incIndex() - { - ++i; - } - - @Override - public void incIndex( final int increment ) - { - i += increment; - } - - @Override - public void decIndex() - { - --i; - } - - @Override - public void decIndex( final int decrement ) - { - i -= decrement; - } - @Override public int getBitsPerPixel() { diff --git a/src/main/java/net/imglib2/type/volatiles/AbstractVolatileNativeNumericType.java b/src/main/java/net/imglib2/type/volatiles/AbstractVolatileNativeNumericType.java index 2e3a6cede0..a7c898551d 100644 --- a/src/main/java/net/imglib2/type/volatiles/AbstractVolatileNativeNumericType.java +++ b/src/main/java/net/imglib2/type/volatiles/AbstractVolatileNativeNumericType.java @@ -34,6 +34,7 @@ package net.imglib2.type.volatiles; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.NumericType; import net.imglib2.util.Fraction; @@ -66,38 +67,8 @@ public Fraction getEntitiesPerPixel() } @Override - public void updateIndex( final int i ) + public Index index() { - t.updateIndex( i ); - } - - @Override - public int getIndex() - { - return t.getIndex(); - } - - @Override - public void incIndex() - { - t.incIndex(); - } - - @Override - public void incIndex( final int increment ) - { - t.incIndex( increment ); - } - - @Override - public void decIndex() - { - t.decIndex(); - } - - @Override - public void decIndex( final int decrement ) - { - t.decIndex( decrement ); + return t.index(); } } diff --git a/src/main/java/net/imglib2/type/volatiles/AbstractVolatileNativeRealType.java b/src/main/java/net/imglib2/type/volatiles/AbstractVolatileNativeRealType.java index a52ba6d7cc..9a1595ac1b 100644 --- a/src/main/java/net/imglib2/type/volatiles/AbstractVolatileNativeRealType.java +++ b/src/main/java/net/imglib2/type/volatiles/AbstractVolatileNativeRealType.java @@ -34,6 +34,7 @@ package net.imglib2.type.volatiles; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; import net.imglib2.util.Fraction; @@ -65,38 +66,8 @@ public Fraction getEntitiesPerPixel() } @Override - public void updateIndex( final int i ) + public Index index() { - t.updateIndex( i ); - } - - @Override - public int getIndex() - { - return t.getIndex(); - } - - @Override - public void incIndex() - { - t.incIndex(); - } - - @Override - public void incIndex( final int increment ) - { - t.incIndex( increment ); - } - - @Override - public void decIndex() - { - t.decIndex(); - } - - @Override - public void decIndex( final int decrement ) - { - t.decIndex( decrement ); + return t.index(); } } From a4b9924b2abc751a930e00609540b48a62b80770 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sat, 20 Mar 2021 00:25:06 +0100 Subject: [PATCH 05/10] ArrayRandomAccess: use Index methods for NativeType index manipulation ... instead of deprecated NativeType methods. --- .../imglib2/img/array/ArrayRandomAccess.java | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java b/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java index 92318c3983..eaec85774c 100644 --- a/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java +++ b/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java @@ -37,6 +37,7 @@ import net.imglib2.AbstractLocalizableInt; import net.imglib2.Localizable; import net.imglib2.RandomAccess; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -52,6 +53,8 @@ public class ArrayRandomAccess< T extends NativeType< T > > extends AbstractLoca { protected final T type; + private final Index index; + final ArrayImg< T, ? > img; protected ArrayRandomAccess( final ArrayRandomAccess< T > randomAccess ) @@ -60,16 +63,16 @@ protected ArrayRandomAccess( final ArrayRandomAccess< T > randomAccess ) this.img = randomAccess.img; this.type = img.createLinkedType(); + this.index = type.index(); - int index = 0; + index.set( 0 ); for ( int d = 0; d < n; d++ ) { position[ d ] = randomAccess.position[ d ]; - index += position[ d ] * img.steps[ d ]; + index.inc( position[ d ] * img.steps[ d ] ); } type.updateContainer( this ); - type.updateIndex( index ); } public ArrayRandomAccess( final ArrayImg< T, ? > container ) @@ -78,12 +81,13 @@ public ArrayRandomAccess( final ArrayImg< T, ? > container ) this.img = container; this.type = container.createLinkedType(); + this.index = type.index(); + index.set( 0 ); for ( int d = 0; d < n; d++ ) position[ d ] = 0; type.updateContainer( this ); - type.updateIndex( 0 ); } @Override @@ -95,116 +99,116 @@ public T get() @Override public void fwd( final int d ) { - type.incIndex( img.steps[ d ] ); + index.inc( img.steps[ d ] ); ++position[ d ]; } @Override public void bck( final int d ) { - type.decIndex( img.steps[ d ] ); + index.dec( img.steps[ d ] ); --position[ d ]; } @Override public void move( final int distance, final int d ) { - type.incIndex( img.steps[ d ] * distance ); + index.inc( img.steps[ d ] * distance ); position[ d ] += distance; } @Override public void move( final long distance, final int d ) { - type.incIndex( img.steps[ d ] * ( int ) distance ); + index.inc( img.steps[ d ] * ( int ) distance ); position[ d ] += distance; } @Override public void move( final Localizable localizable ) { - int index = 0; + int move = 0; for ( int d = 0; d < n; ++d ) { final int distance = localizable.getIntPosition( d ); position[ d ] += distance; - index += distance * img.steps[ d ]; + move += distance * img.steps[ d ]; } - type.incIndex( index ); + index.inc( move ); } @Override public void move( final int[] distance ) { - int index = 0; + int move = 0; for ( int d = 0; d < n; ++d ) { position[ d ] += distance[ d ]; - index += distance[ d ] * img.steps[ d ]; + move += distance[ d ] * img.steps[ d ]; } - type.incIndex( index ); + index.inc( move ); } @Override public void move( final long[] distance ) { - int index = 0; + int move = 0; for ( int d = 0; d < n; ++d ) { position[ d ] += distance[ d ]; - index += distance[ d ] * img.steps[ d ]; + move += distance[ d ] * img.steps[ d ]; } - type.incIndex( index ); + index.inc( move ); } @Override public void setPosition( final Localizable localizable ) { - int index = 0; + int i = 0; for ( int d = 0; d < n; ++d ) { position[ d ] = localizable.getIntPosition( d ); - index += position[ d ] * img.steps[ d ]; + i += position[ d ] * img.steps[ d ]; } - type.updateIndex( index ); + index.set( i ); } @Override public void setPosition( final int[] pos ) { - int index = 0; + int i = 0; for ( int d = 0; d < n; ++d ) { position[ d ] = pos[ d ]; - index += pos[ d ] * img.steps[ d ]; + i += pos[ d ] * img.steps[ d ]; } - type.updateIndex( index ); + index.set( i ); } @Override public void setPosition( final long[] pos ) { - int index = 0; + int i = 0; for ( int d = 0; d < n; ++d ) { final int p = ( int ) pos[ d ]; position[ d ] = p; - index += p * img.steps[ d ]; + i += p * img.steps[ d ]; } - type.updateIndex( index ); + index.set( i ); } @Override public void setPosition( final int pos, final int d ) { - type.incIndex( ( pos - position[ d ] ) * img.steps[ d ] ); + index.inc( ( pos - position[ d ] ) * img.steps[ d ] ); position[ d ] = pos; } @Override public void setPosition( final long pos, final int d ) { - type.incIndex( ( ( int ) pos - position[ d ] ) * img.steps[ d ] ); + index.inc( ( ( int ) pos - position[ d ] ) * img.steps[ d ] ); position[ d ] = ( int ) pos; } @@ -227,7 +231,7 @@ public ArrayRandomAccess< T > copyRandomAccess() */ public void fwdDim0() { - type.incIndex(); + index.inc(); ++position[ 0 ]; } @@ -236,7 +240,7 @@ public void fwdDim0() */ public void bckDim0() { - type.decIndex(); + index.dec(); --position[ 0 ]; } @@ -248,7 +252,7 @@ public void bckDim0() */ public void moveDim0( final int distance ) { - type.incIndex( distance ); + index.inc( distance ); position[ 0 ] += distance; } @@ -260,7 +264,7 @@ public void moveDim0( final int distance ) */ public void move( final long distance ) { - type.incIndex( ( int ) distance ); + index.inc( ( int ) distance ); position[ 0 ] += distance; } @@ -275,7 +279,7 @@ public void move( final long distance ) */ public void setPositionDim0( final int pos ) { - type.updateIndex( pos ); + index.set( pos ); position[ 0 ] = pos; } @@ -290,7 +294,7 @@ public void setPositionDim0( final int pos ) */ public void setPositionDim0( final long pos ) { - type.updateIndex( ( int ) pos ); + index.set( ( int ) pos ); position[ 0 ] = ( int ) pos; } } From f96a8e4e8b1bbbb2a4172c9cc915298e193e2c7d Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sat, 20 Mar 2021 00:33:29 +0100 Subject: [PATCH 06/10] Add javadoc --- src/main/java/net/imglib2/type/Index.java | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/main/java/net/imglib2/type/Index.java b/src/main/java/net/imglib2/type/Index.java index 51eeb91065..c80ba6a19a 100644 --- a/src/main/java/net/imglib2/type/Index.java +++ b/src/main/java/net/imglib2/type/Index.java @@ -4,31 +4,69 @@ public final class Index { private int i = 0; + /** + * Get the index. + *

+ * This is used by accessors (e.g., a {@code Cursor}) to position {@code + * NativeType}s in the container, and by {@code NativeType}s to determine + * the offset into the underlying primitive array, where the value of the + * type is stored. + */ public int get() { return i; } + /** + * Set the index to {@code index}. + *

+ * This is used by accessors (e.g., a {@code Cursor}) to position {@code + * NativeType}s in the container. + */ public void set( final int index) { i = index; } + /** + * Increment the index. + *

+ * This is used by accessors (e.g., a {@code Cursor}) to position {@code + * NativeType}s in the container. + */ public void inc() { ++i; } + /** + * Increase the index by {@code decrement} steps. + *

+ * This is used by accessors (e.g., a {@code Cursor}) to position {@code + * NativeType}s in the container. + */ public void inc( final int increment ) { i += increment; } + /** + * Decrement the index. + *

+ * This is used by accessors (e.g., a {@code Cursor}) to position {@code + * NativeType}s in the container. + */ public void dec() { --i; } + /** + * Decrease the index by {@code decrement} steps. + *

+ * This is used by accessors (e.g., a {@code Cursor}) to position {@code + * NativeType}s in the container. + */ public void dec( final int decrement ) { i -= decrement; From 2bcc4a191f3cfc3183ca4054fe4b257608c7120d Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sat, 20 Mar 2021 00:45:23 +0100 Subject: [PATCH 07/10] ArrayCursors: use Index methods for NativeType index manipulation ... instead of deprecated NativeType methods. --- .../img/array/AbstractArrayCursor.java | 19 ++++++++++++------- .../array/AbstractArrayLocalizingCursor.java | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java b/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java index dfad5af992..ca2173c02d 100644 --- a/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java +++ b/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java @@ -36,6 +36,7 @@ import net.imglib2.AbstractCursorInt; import net.imglib2.Cursor; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.util.IntervalIndexer; @@ -68,6 +69,8 @@ public abstract class AbstractArrayCursor< T extends NativeType< T > > extends A */ protected final T type; + private final Index index; + /** * Source image */ @@ -89,11 +92,12 @@ protected AbstractArrayCursor( final AbstractArrayCursor< T > cursor ) this.img = cursor.img; this.type = img.createLinkedType(); + this.index = type.index(); this.offset = cursor.offset; this.size = cursor.size; this.lastIndex = cursor.lastIndex; - type.updateIndex( cursor.type.getIndex() ); + index.set( cursor.index.get() ); type.updateContainer( this ); } @@ -109,6 +113,7 @@ public AbstractArrayCursor( final ArrayImg< T, ? > img, final int offset, final super( img.numDimensions() ); this.type = img.createLinkedType(); + this.index = type.index(); this.img = img; this.lastIndex = offset + size - 1; this.offset = offset; @@ -126,25 +131,25 @@ public T get() @Override public boolean hasNext() { - return type.getIndex() < lastIndex; + return index.get() < lastIndex; } @Override public void jumpFwd( final long steps ) { - type.incIndex( ( int ) steps ); + index.inc( ( int ) steps ); } @Override public void fwd() { - type.incIndex(); + index.inc(); } @Override public void reset() { - type.updateIndex( offset - 1 ); + index.set( offset - 1 ); type.updateContainer( this ); } @@ -157,12 +162,12 @@ public String toString() @Override public int getIntPosition( final int dim ) { - return IntervalIndexer.indexToPosition( type.getIndex(), img.dim, dim ); + return IntervalIndexer.indexToPosition( index.get(), img.dim, dim ); } @Override public void localize( final int[] position ) { - IntervalIndexer.indexToPosition( type.getIndex(), img.dim, position ); + IntervalIndexer.indexToPosition( index.get(), img.dim, position ); } } diff --git a/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java b/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java index 26839e7302..f9b784989b 100644 --- a/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java @@ -36,6 +36,7 @@ import net.imglib2.AbstractLocalizingCursorInt; import net.imglib2.Cursor; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; import net.imglib2.util.IntervalIndexer; @@ -69,6 +70,8 @@ public abstract class AbstractArrayLocalizingCursor< T extends NativeType< T > > */ protected final T type; + private final Index index; + /** * The underlying source {@link ArrayImg}. */ @@ -96,6 +99,7 @@ protected AbstractArrayLocalizingCursor( final AbstractArrayLocalizingCursor< T this.img = cursor.img; this.type = img.createLinkedType(); + this.index = type.index(); this.offset = cursor.offset; this.size = cursor.size; @@ -108,7 +112,7 @@ protected AbstractArrayLocalizingCursor( final AbstractArrayLocalizingCursor< T max[ d ] = cursor.max[ d ]; } - type.updateIndex( cursor.type.getIndex() ); + index.set( cursor.index.get() ); type.updateContainer( this ); } @@ -128,6 +132,7 @@ public AbstractArrayLocalizingCursor( final ArrayImg< T, ? > img, final int offs this.size = size; this.type = img.createLinkedType(); + this.index = type.index(); this.lastIndex = offset + size - 1; max = new int[ n ]; @@ -152,7 +157,7 @@ public T get() @Override public boolean hasNext() { - return type.getIndex() < lastIndex; + return index.get() < lastIndex; } /** @@ -161,7 +166,7 @@ public boolean hasNext() @Override public void fwd() { - type.incIndex(); + index.inc(); // for ( int d = 0; d < n; ++d ) // { @@ -202,8 +207,8 @@ public void fwd() @Override public void jumpFwd( final long steps ) { - type.incIndex( ( int ) steps ); - IntervalIndexer.indexToPosition( type.getIndex(), img.dim, position ); + index.inc( ( int ) steps ); + IntervalIndexer.indexToPosition( index.get(), img.dim, position ); } /** @@ -212,11 +217,11 @@ public void jumpFwd( final long steps ) @Override public void reset() { - type.updateIndex( offset - 1 ); + index.set( offset - 1 ); IntervalIndexer.indexToPosition( offset, img.dim, position ); position[ 0 ]--; - type.updateContainer( this ); + type.updateContainer( this ); // TODO: This is unnecessary. Remove. } } From 1f0f57620904162651622e126b768cb99472d35d Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sat, 20 Mar 2021 23:13:25 +0100 Subject: [PATCH 08/10] Cell/Planar accesses: use Index methods for NativeType index manipulation ... instead of deprecated NativeType methods. --- .../java/net/imglib2/img/cell/CellCursor.java | 13 +++++-- .../img/cell/CellLocalizingCursor.java | 13 +++++-- .../imglib2/img/cell/CellRandomAccess.java | 31 +++++++++------- .../net/imglib2/img/planar/PlanarCursor.java | 15 +++++--- .../imglib2/img/planar/PlanarCursor1D.java | 6 +-- .../imglib2/img/planar/PlanarCursor2D.java | 8 ++-- .../img/planar/PlanarLocalizingCursor.java | 15 +++++--- .../img/planar/PlanarLocalizingCursor1D.java | 4 +- .../img/planar/PlanarLocalizingCursor2D.java | 4 +- .../img/planar/PlanarPlaneSubsetCursor.java | 25 ++++++++----- .../PlanarPlaneSubsetLocalizingCursor.java | 19 ++++++---- .../img/planar/PlanarRandomAccess.java | 37 +++++++++++-------- .../img/planar/PlanarRandomAccess1D.java | 20 +++++----- 13 files changed, 125 insertions(+), 85 deletions(-) diff --git a/src/main/java/net/imglib2/img/cell/CellCursor.java b/src/main/java/net/imglib2/img/cell/CellCursor.java index b97c5a5a96..73b116ef98 100644 --- a/src/main/java/net/imglib2/img/cell/CellCursor.java +++ b/src/main/java/net/imglib2/img/cell/CellCursor.java @@ -36,6 +36,7 @@ import net.imglib2.AbstractCursor; import net.imglib2.Cursor; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -49,6 +50,8 @@ public class CellCursor< T extends NativeType< T >, C extends Cell< ? > > { protected final T type; + protected final Index i; + protected final Cursor< C > cursorOnCells; protected int lastIndexInCell; @@ -69,13 +72,14 @@ protected CellCursor( final CellCursor< T, C > cursor ) super( cursor.numDimensions() ); this.type = cursor.type.duplicateTypeOnSameNativeImg(); + i = type.index(); this.cursorOnCells = cursor.cursorOnCells.copyCursor(); isNotLastCell = cursor.isNotLastCell; lastIndexInCell = cursor.lastIndexInCell; index = cursor.index; type.updateContainer( this ); - type.updateIndex( index ); + i.set( index ); } public CellCursor( final AbstractCellImg< T, ?, C, ? > img ) @@ -83,6 +87,7 @@ public CellCursor( final AbstractCellImg< T, ?, C, ? > img ) super( img.numDimensions() ); this.type = img.createLinkedType(); + i = type.index(); this.cursorOnCells = img.getCells().cursor(); reset(); @@ -130,7 +135,7 @@ public void jumpFwd( final long steps ) lastIndexInCell = ( int ) ( getCell().size() - 1 ); } index = ( int ) newIndex; - type.updateIndex( index ); + i.set( index ); type.updateContainer( this ); } @@ -142,7 +147,7 @@ public void fwd() moveToNextCell(); index = 0; } - type.updateIndex( index ); + i.set( index ); } @Override @@ -150,7 +155,7 @@ public void reset() { cursorOnCells.reset(); moveToNextCell(); - type.updateIndex( index ); + i.set( index ); } @Override diff --git a/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java b/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java index e2d5e64ebc..d21664af4d 100644 --- a/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java @@ -36,6 +36,7 @@ import net.imglib2.AbstractLocalizingCursor; import net.imglib2.Cursor; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -49,6 +50,8 @@ public class CellLocalizingCursor< T extends NativeType< T >, C extends Cell< ? { protected final T type; + protected final Index i; + protected final Cursor< C > cursorOnCells; protected int lastIndexInCell; @@ -73,6 +76,7 @@ protected CellLocalizingCursor( final CellLocalizingCursor< T, C > cursor ) super( cursor.numDimensions() ); this.type = cursor.type.duplicateTypeOnSameNativeImg(); + i = type.index(); this.cursorOnCells = cursor.cursorOnCells.copyCursor(); this.currentCellMin = cursor.currentCellMin; this.currentCellMax = cursor.currentCellMax; @@ -84,7 +88,7 @@ protected CellLocalizingCursor( final CellLocalizingCursor< T, C > cursor ) index = cursor.index; type.updateContainer( this ); - type.updateIndex( index ); + i.set( index ); } public CellLocalizingCursor( final AbstractCellImg< T, ?, C, ? > img ) @@ -92,6 +96,7 @@ public CellLocalizingCursor( final AbstractCellImg< T, ?, C, ? > img ) super( img.numDimensions() ); this.type = img.createLinkedType(); + i = type.index(); this.cursorOnCells = img.getCells().cursor(); this.currentCellMin = null; this.currentCellMax = null; @@ -148,7 +153,7 @@ public void jumpFwd( final long steps ) index = ( int ) newIndex; cell.indexToGlobalPosition( index, position ); - type.updateIndex( index ); + i.set( index ); type.updateContainer( this ); } @@ -160,7 +165,7 @@ public void fwd() moveToNextCell(); index = 0; } - type.updateIndex( index ); + i.set( index ); for ( int d = 0; d < n; ++d ) { @@ -177,7 +182,7 @@ public void reset() cursorOnCells.reset(); moveToNextCell(); index = -1; - type.updateIndex( index ); + i.set( index ); } /** diff --git a/src/main/java/net/imglib2/img/cell/CellRandomAccess.java b/src/main/java/net/imglib2/img/cell/CellRandomAccess.java index e8b6f51052..32fdfdf85c 100644 --- a/src/main/java/net/imglib2/img/cell/CellRandomAccess.java +++ b/src/main/java/net/imglib2/img/cell/CellRandomAccess.java @@ -37,6 +37,7 @@ import net.imglib2.AbstractLocalizable; import net.imglib2.Localizable; import net.imglib2.RandomAccess; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -53,6 +54,8 @@ public class CellRandomAccess< T extends NativeType< T >, C extends Cell< ? > > { protected final T type; + protected final Index i; + protected final CellGrid grid; protected final RandomAccess< C > randomAccessOnCells; @@ -84,6 +87,7 @@ protected CellRandomAccess( final CellRandomAccess< T, C > randomAccess ) super( randomAccess.numDimensions() ); type = randomAccess.type.duplicateTypeOnSameNativeImg(); + i = type.index(); grid = randomAccess.grid; randomAccessOnCells = randomAccess.randomAccessOnCells.copyRandomAccess(); @@ -102,7 +106,7 @@ protected CellRandomAccess( final CellRandomAccess< T, C > randomAccess ) index = randomAccess.index; if ( !isOutOfBounds ) type.updateContainer( this ); - type.updateIndex( index ); + i.set( index ); } public CellRandomAccess( final AbstractCellImg< T, ?, C, ? > img ) @@ -110,6 +114,7 @@ public CellRandomAccess( final AbstractCellImg< T, ?, C, ? > img ) super( img.numDimensions() ); type = img.createLinkedType(); + i = type.index(); grid = img.getCellGrid(); randomAccessOnCells = img.getCells().randomAccess(); @@ -164,7 +169,7 @@ public void fwd( final int d ) randomAccessOnCells.fwd( d ); updatePosition( position[ d ] >= dimensions[ d ] ); } - type.updateIndex( index ); + i.set( index ); } @Override @@ -176,7 +181,7 @@ public void bck( final int d ) randomAccessOnCells.bck( d ); updatePosition( position[ d ] < 0 ); } - type.updateIndex( index ); + i.set( index ); } @Override @@ -189,7 +194,7 @@ public void move( final int distance, final int d ) randomAccessOnCells.setPosition( position[ d ] / cellDims[ d ], d ); updatePosition( position[ d ] < 0 || position[ d ] >= dimensions[ d ] ); } - type.updateIndex( index ); + i.set( index ); } @Override @@ -202,7 +207,7 @@ public void move( final long distance, final int d ) randomAccessOnCells.setPosition( position[ d ] / cellDims[ d ], d ); updatePosition( position[ d ] < 0 || position[ d ] >= dimensions[ d ] ); } - type.updateIndex( index ); + i.set( index ); } @Override @@ -238,7 +243,7 @@ public void move( final Localizable localizable ) } } } - type.updateIndex( index ); + i.set( index ); } @Override @@ -272,7 +277,7 @@ public void move( final int[] distance ) } } } - type.updateIndex( index ); + i.set( index ); } @Override @@ -306,7 +311,7 @@ public void move( final long[] distance ) } } } - type.updateIndex( index ); + i.set( index ); } @Override @@ -319,7 +324,7 @@ public void setPosition( final int pos, final int d ) randomAccessOnCells.setPosition( pos / cellDims[ d ], d ); updatePosition( position[ d ] < 0 || position[ d ] >= dimensions[ d ] ); } - type.updateIndex( index ); + i.set( index ); } @Override @@ -332,7 +337,7 @@ public void setPosition( final long pos, final int d ) randomAccessOnCells.setPosition( pos / cellDims[ d ], d ); updatePosition( position[ d ] < 0 || position[ d ] >= dimensions[ d ] ); } - type.updateIndex( index ); + i.set( index ); } @Override @@ -368,7 +373,7 @@ public void setPosition( final Localizable localizable ) } } } - type.updateIndex( index ); + i.set( index ); } @Override @@ -387,7 +392,7 @@ public void setPosition( final int[] pos ) position[ d ] = pos[ d ]; } } - type.updateIndex( index ); + i.set( index ); } private void setPos2( final int[] pos, final int d0 ) @@ -439,7 +444,7 @@ public void setPosition( final long[] pos ) } } } - type.updateIndex( index ); + i.set( index ); } /** diff --git a/src/main/java/net/imglib2/img/planar/PlanarCursor.java b/src/main/java/net/imglib2/img/planar/PlanarCursor.java index 2cd36013b8..b81dd3c0d7 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarCursor.java @@ -35,6 +35,7 @@ package net.imglib2.img.planar; import net.imglib2.AbstractCursorInt; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -49,6 +50,8 @@ public class PlanarCursor< T extends NativeType< T > > extends AbstractCursorInt { protected final T type; + protected final Index i; + protected final PlanarImg< T, ? > container; protected final int lastIndex, lastSliceIndex; @@ -67,6 +70,7 @@ protected PlanarCursor( final PlanarCursor< T > cursor ) container = cursor.container; this.type = container.createLinkedType(); + i = type.index(); lastIndex = cursor.lastIndex; lastSliceIndex = cursor.lastSliceIndex; @@ -74,7 +78,7 @@ protected PlanarCursor( final PlanarCursor< T > cursor ) index = cursor.index; type.updateContainer( this ); - type.updateIndex( index ); + i.set( index ); } public PlanarCursor( final PlanarImg< T, ? > container ) @@ -82,6 +86,7 @@ public PlanarCursor( final PlanarImg< T, ? > container ) super( container.numDimensions() ); this.type = container.createLinkedType(); + this.i = type.index(); this.container = container; lastIndex = ( ( n > 1 ) ? container.dimensions[ 1 ] : 1 ) * container.dimensions[ 0 ] - 1; @@ -117,7 +122,7 @@ public PlanarCursor< T > copyCursor() /** * Note: This test is fragile in a sense that it returns true for elements * after the last element as well. - * + * * @return false for the last element */ @Override @@ -135,7 +140,7 @@ public void fwd() ++sliceIndex; type.updateContainer( this ); } - type.updateIndex( index ); + i.set( index ); } @Override @@ -150,7 +155,7 @@ public void jumpFwd( final long steps ) type.updateContainer( this ); } index = ( int ) newIndex; - type.updateIndex( index ); + i.set( index ); } @Override @@ -158,7 +163,7 @@ public void reset() { sliceIndex = 0; index = -1; - type.updateIndex( -1 ); + i.set( -1 ); type.updateContainer( this ); } diff --git a/src/main/java/net/imglib2/img/planar/PlanarCursor1D.java b/src/main/java/net/imglib2/img/planar/PlanarCursor1D.java index 7f555c7c19..abd40a1439 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarCursor1D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarCursor1D.java @@ -51,20 +51,20 @@ public PlanarCursor1D( final PlanarImg< T, ? > container ) @Override public boolean hasNext() { - return type.getIndex() < lastIndex; + return i.get() < lastIndex; } @Override public void localize( final int[] position ) { - position[ 0 ] = type.getIndex(); + position[ 0 ] = i.get(); } @Override public int getIntPosition( final int dim ) { if ( dim == 0 ) - return type.getIndex(); + return i.get(); return 0; } } diff --git a/src/main/java/net/imglib2/img/planar/PlanarCursor2D.java b/src/main/java/net/imglib2/img/planar/PlanarCursor2D.java index 206f2776b3..2a0c79cbee 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarCursor2D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarCursor2D.java @@ -53,19 +53,19 @@ public PlanarCursor2D( final PlanarImg< T, ? > container ) @Override public boolean hasNext() { - return type.getIndex() < lastIndex; + return i.get() < lastIndex; } @Override public void fwd() { - type.incIndex(); + i.inc(); } @Override public void localize( final int[] position ) { - final int indexInSlice = type.getIndex(); + final int indexInSlice = i.get(); final int dim0 = container.dimensions[ 0 ]; position[ 1 ] = indexInSlice / dim0; position[ 0 ] = indexInSlice - position[ 1 ] * dim0; @@ -74,7 +74,7 @@ public void localize( final int[] position ) @Override public int getIntPosition( final int dim ) { - final int indexInSlice = type.getIndex(); + final int indexInSlice = i.get(); final int dim0 = container.dimensions[ 0 ]; final int pos1 = indexInSlice / dim0; if ( dim == 0 ) diff --git a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java index 61c476def2..a27cc5f772 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java @@ -35,6 +35,7 @@ package net.imglib2.img.planar; import net.imglib2.AbstractLocalizingCursorInt; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -49,6 +50,8 @@ public class PlanarLocalizingCursor< T extends NativeType< T > > extends Abstrac { protected final T type; + protected final Index i; + protected final PlanarImg< T, ? > container; protected final int lastIndex, lastSliceIndex; @@ -73,6 +76,7 @@ protected PlanarLocalizingCursor( final PlanarLocalizingCursor< T > cursor ) container = cursor.container; this.type = container.createLinkedType(); + i = type.index(); lastIndex = cursor.lastIndex; lastSliceIndex = cursor.lastSliceIndex; @@ -88,7 +92,7 @@ protected PlanarLocalizingCursor( final PlanarLocalizingCursor< T > cursor ) index = cursor.index; type.updateContainer( this ); - type.updateIndex( index ); + i.set( index ); } public PlanarLocalizingCursor( final PlanarImg< T, ? > container ) @@ -96,6 +100,7 @@ public PlanarLocalizingCursor( final PlanarImg< T, ? > container ) super( container.numDimensions() ); this.type = container.createLinkedType(); + i = type.index(); this.container = container; lastIndex = ( ( n > 1 ) ? container.dimensions[ 1 ] : 1 ) * container.dimensions[ 0 ] - 1; @@ -135,7 +140,7 @@ public PlanarLocalizingCursor< T > copyCursor() /** * Note: This test is fragile in a sense that it returns true for elements * after the last element as well. - * + * * @return false for the last element */ @Override @@ -153,7 +158,7 @@ public void fwd() ++sliceIndex; type.updateContainer( this ); } - type.updateIndex( index ); + i.set( index ); for ( int d = 0; d < n; ++d ) { @@ -176,7 +181,7 @@ public void jumpFwd( final long steps ) type.updateContainer( this ); } index = ( int ) newIndex; - type.updateIndex( index ); + i.set( index ); container.indexToGlobalPosition( sliceIndex, index, position ); } @@ -189,7 +194,7 @@ public void reset() sliceIndex = 0; index = -1; - type.updateIndex( -1 ); + i.set( -1 ); type.updateContainer( this ); } } diff --git a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor1D.java b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor1D.java index d8940323e3..614ecd1503 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor1D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor1D.java @@ -61,13 +61,13 @@ public PlanarLocalizingCursor1D< T > copy() @Override public boolean hasNext() { - return type.getIndex() < lastIndex; + return i.get() < lastIndex; } @Override public void fwd() { - type.incIndex(); + i.inc(); ++position[ 0 ]; } } diff --git a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor2D.java b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor2D.java index 6217079146..b593090ce8 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor2D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor2D.java @@ -61,13 +61,13 @@ public PlanarLocalizingCursor2D< T > copy() @Override public boolean hasNext() { - return type.getIndex() < lastIndex; + return i.get() < lastIndex; } @Override public void fwd() { - type.incIndex(); + i.inc(); if ( ++position[ 0 ] > max[ 0 ] ) { diff --git a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java index 06b1bfdb72..592d8f08de 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java @@ -36,6 +36,7 @@ import net.imglib2.AbstractCursorInt; import net.imglib2.Interval; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -55,6 +56,8 @@ public class PlanarPlaneSubsetCursor< T extends NativeType< T >> extends */ private final T type; + private final Index index; + /** * Container */ @@ -77,7 +80,7 @@ public class PlanarPlaneSubsetCursor< T extends NativeType< T >> extends /** * Copy Constructor - * + * * @param cursor - the cursor to copy from. */ protected PlanarPlaneSubsetCursor( final PlanarPlaneSubsetCursor< T > cursor ) @@ -86,18 +89,19 @@ protected PlanarPlaneSubsetCursor( final PlanarPlaneSubsetCursor< T > cursor ) container = cursor.container; this.type = container.createLinkedType(); + index = type.index(); sliceIndex = cursor.sliceIndex; planeSize = cursor.planeSize; lastPlaneIndex = cursor.lastPlaneIndex; type.updateContainer( this ); - type.updateIndex( cursor.type.getIndex() ); + index.set( cursor.index.get() ); } /** * Constructor - * + * * @param container - the container this cursor shall work on. * @param interval - the interval to iterate over. */ @@ -106,12 +110,13 @@ public PlanarPlaneSubsetCursor( final PlanarImg< T, ? > container, final Interva super( container.numDimensions() ); this.type = container.createLinkedType(); + index = type.index(); this.container = container; this.planeSize = ( ( n > 1 ) ? ( int ) interval.dimension( 1 ) : 1 ) * ( int ) interval.dimension( 0 ); - + this.lastPlaneIndex = planeSize - 1; this.sliceIndex = ( int ) ( offset( interval ) / planeSize ); @@ -161,7 +166,7 @@ public PlanarPlaneSubsetCursor< T > copyCursor() @Override public final boolean hasNext() { - return type.getIndex() < lastPlaneIndex; + return index.get() < lastPlaneIndex; } /** @@ -170,7 +175,7 @@ public final boolean hasNext() @Override public final void fwd() { - type.incIndex(); + index.inc(); } /** @@ -179,7 +184,7 @@ public final void fwd() @Override public final void jumpFwd( final long steps ) { - type.incIndex( ( int ) steps ); + index.inc( ( int ) steps ); } /** @@ -189,7 +194,7 @@ public final void jumpFwd( final long steps ) public final void reset() { // Set index inside the slice - type.updateIndex( -1 ); + index.set( -1 ); type.updateContainer( this ); } @@ -208,7 +213,7 @@ public String toString() @Override public final void localize( final int[] position ) { - container.indexToGlobalPosition( sliceIndex, type.getIndex(), position ); + container.indexToGlobalPosition( sliceIndex, index.get(), position ); } /** @@ -217,7 +222,7 @@ public final void localize( final int[] position ) @Override public final int getIntPosition( final int dim ) { - return container.indexToGlobalPosition( sliceIndex, type.getIndex(), dim ); + return container.indexToGlobalPosition( sliceIndex, index.get(), dim ); } private long offset(final Interval interval) { diff --git a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java index 49ccea0cab..412e6b2bbd 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java @@ -35,6 +35,7 @@ import net.imglib2.AbstractLocalizingCursorInt; import net.imglib2.Interval; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -55,6 +56,8 @@ public class PlanarPlaneSubsetLocalizingCursor< T extends NativeType< T > > */ private final T type; + private final Index index; + /** * Container */ @@ -86,6 +89,7 @@ protected PlanarPlaneSubsetLocalizingCursor( final PlanarPlaneSubsetLocalizingCu container = cursor.container; this.type = container.createLinkedType(); + index = type.index(); sliceIndex = cursor.sliceIndex; lastIndexPlane = cursor.lastIndexPlane; @@ -96,7 +100,7 @@ protected PlanarPlaneSubsetLocalizingCursor( final PlanarPlaneSubsetLocalizingCu position[ d ] = cursor.position[ d ]; type.updateContainer( this ); - type.updateIndex( cursor.type.getIndex() ); + index.set( cursor.index.get() ); } /** @@ -112,6 +116,7 @@ public PlanarPlaneSubsetLocalizingCursor( final PlanarImg< T, ? > container, fin super( container.numDimensions() ); this.type = container.createLinkedType(); + index = type.index(); this.container = container; @@ -172,7 +177,7 @@ public PlanarPlaneSubsetLocalizingCursor< T > copyCursor() @Override public final boolean hasNext() { - return type.getIndex() < lastIndexPlane; + return index.get() < lastIndexPlane; } /** @@ -181,7 +186,7 @@ public final boolean hasNext() @Override public final void fwd() { - type.incIndex(); + index.inc(); if ( ++position[ 0 ] > maxX && n > 1 ) { position[ 0 ] = 0; @@ -195,8 +200,8 @@ public final void fwd() @Override public final void jumpFwd( final long steps ) { - type.incIndex( ( int ) steps ); - updatePositionFromIndex( type.getIndex() ); + index.inc( ( int ) steps ); + updatePositionFromIndex( index.get() ); } private void updatePositionFromIndex( final int index ) @@ -217,8 +222,8 @@ private void updatePositionFromIndex( final int index ) @Override public final void reset() { - type.updateIndex( -1 ); - updatePositionFromIndex( type.getIndex() ); + index.set( -1 ); + updatePositionFromIndex( index.get() ); } /** diff --git a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java index 1701fa95af..135784782f 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java +++ b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java @@ -37,6 +37,7 @@ import net.imglib2.AbstractLocalizableInt; import net.imglib2.Localizable; import net.imglib2.RandomAccess; +import net.imglib2.type.Index; import net.imglib2.type.NativeType; /** @@ -56,6 +57,8 @@ public class PlanarRandomAccess< T extends NativeType< T > > extends AbstractLoc final protected T type; + final protected Index index; + protected int sliceIndex; protected PlanarRandomAccess( final PlanarRandomAccess< T > randomAccess ) @@ -70,8 +73,9 @@ protected PlanarRandomAccess( final PlanarRandomAccess< T > randomAccess ) position[ d ] = randomAccess.position[ d ]; type = randomAccess.type.duplicateTypeOnSameNativeImg(); + index = type.index(); type.updateContainer( this ); - type.updateIndex( randomAccess.type.getIndex() ); + index.set( randomAccess.index.get() ); } public PlanarRandomAccess( final PlanarImg< T, ? > container ) @@ -82,7 +86,8 @@ public PlanarRandomAccess( final PlanarImg< T, ? > container ) width = ( int ) container.dimension( 0 ); type = container.createLinkedType(); - type.updateIndex( 0 ); + index = type.index(); + index.set( 0 ); type.updateContainer( this ); } @@ -116,9 +121,9 @@ public void fwd( final int d ) ++position[ d ]; if ( d == 0 ) - type.incIndex(); + index.inc(); else if ( d == 1 ) - type.incIndex( width ); + index.inc( width ); else { sliceIndex += sliceSteps[ d ]; @@ -132,9 +137,9 @@ public void bck( final int d ) --position[ d ]; if ( d == 0 ) - type.decIndex(); + index.dec(); else if ( d == 1 ) - type.decIndex( width ); + index.dec( width ); else { sliceIndex -= sliceSteps[ d ]; @@ -149,11 +154,11 @@ public void move( final int distance, final int d ) if ( d == 0 ) { - type.incIndex( distance ); + index.inc( distance ); } else if ( d == 1 ) { - type.incIndex( distance * width ); + index.inc( distance * width ); } else { @@ -173,7 +178,7 @@ public void move( final Localizable localizable ) { final int d0 = localizable.getIntPosition( 0 ); final int d1 = localizable.getIntPosition( 1 ); - type.incIndex( d0 + d1 * width ); + index.inc( d0 + d1 * width ); position[ 0 ] += d0; position[ 1 ] += d1; @@ -201,7 +206,7 @@ public void move( final Localizable localizable ) @Override public void move( final int[] distance ) { - type.incIndex( distance[ 0 ] + distance[ 1 ] * width ); + index.inc( distance[ 0 ] + distance[ 1 ] * width ); position[ 0 ] += distance[ 0 ]; position[ 1 ] += distance[ 1 ]; @@ -229,7 +234,7 @@ public void move( final int[] distance ) @Override public void move( final long[] distance ) { - type.incIndex( ( int ) distance[ 0 ] + ( int ) distance[ 1 ] * width ); + index.inc( ( int ) distance[ 0 ] + ( int ) distance[ 1 ] * width ); position[ 0 ] += ( int ) distance[ 0 ]; position[ 1 ] += ( int ) distance[ 1 ]; @@ -259,11 +264,11 @@ public void setPosition( final int pos, final int d ) { if ( d == 0 ) { - type.incIndex( pos - position[ 0 ] ); + index.inc( pos - position[ 0 ] ); } else if ( d == 1 ) { - type.incIndex( ( pos - position[ 1 ] ) * width ); + index.inc( ( pos - position[ 1 ] ) * width ); } else { @@ -285,7 +290,7 @@ public void setPosition( final Localizable localizable ) { final int p0 = localizable.getIntPosition( 0 ); final int p1 = localizable.getIntPosition( 1 ); - type.updateIndex( p0 + p1 * width ); + index.set( p0 + p1 * width ); position[ 0 ] = p0; position[ 1 ] = p1; @@ -314,7 +319,7 @@ public void setPosition( final Localizable localizable ) @Override public void setPosition( final int[] pos ) { - type.updateIndex( pos[ 0 ] + pos[ 1 ] * width ); + index.set( pos[ 0 ] + pos[ 1 ] * width ); position[ 0 ] = pos[ 0 ]; position[ 1 ] = pos[ 1 ]; @@ -341,7 +346,7 @@ public void setPosition( final int[] pos ) @Override public void setPosition( final long[] pos ) { - type.updateIndex( ( int ) pos[ 0 ] + ( int ) pos[ 1 ] * width ); + index.set( ( int ) pos[ 0 ] + ( int ) pos[ 1 ] * width ); position[ 0 ] = ( int ) pos[ 0 ]; position[ 1 ] = ( int ) pos[ 1 ]; diff --git a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess1D.java b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess1D.java index fedd9fbaa1..7302634d5f 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess1D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess1D.java @@ -57,21 +57,21 @@ public PlanarRandomAccess1D( final PlanarImg< T, ? > container ) public void fwd( final int dim ) { ++position[ 0 ]; - type.incIndex(); + index.inc(); } @Override public void bck( final int dim ) { --position[ 0 ]; - type.decIndex(); + index.dec(); } @Override public void move( final int distance, final int d ) { position[ 0 ] += distance; - type.incIndex( distance ); + index.inc( distance ); } @Override @@ -79,27 +79,27 @@ public void move( final Localizable localizable ) { final int distance = localizable.getIntPosition( 0 ); position[ 0 ] += distance; - type.incIndex( distance ); + index.inc( distance ); } @Override public void move( final int[] distance ) { position[ 0 ] += distance[ 0 ]; - type.incIndex( distance[ 0 ] ); + index.inc( distance[ 0 ] ); } @Override public void move( final long[] distance ) { position[ 0 ] += ( int ) distance[ 0 ]; - type.incIndex( ( int ) distance[ 0 ] ); + index.inc( ( int ) distance[ 0 ] ); } @Override public void setPosition( final int pos, final int dim ) { - type.updateIndex( pos ); + index.set( pos ); position[ 0 ] = pos; } @@ -107,21 +107,21 @@ public void setPosition( final int pos, final int dim ) public void setPosition( final Localizable localizable ) { final int pos = localizable.getIntPosition( 0 ); - type.updateIndex( pos ); + index.set( pos ); this.position[ 0 ] = pos; } @Override public void setPosition( final int[] position ) { - type.updateIndex( position[ 0 ] ); + index.set( position[ 0 ] ); this.position[ 0 ] = position[ 0 ]; } @Override public void setPosition( final long[] position ) { - type.updateIndex( ( int ) position[ 0 ] ); + index.set( ( int ) position[ 0 ] ); this.position[ 0 ] = ( int ) position[ 0 ]; } } From 56969db9d7a605aa79bec679046b6bc2de7a9d6a Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Sun, 21 Mar 2021 00:19:02 +0100 Subject: [PATCH 09/10] Update javadoc --- .../java/net/imglib2/type/NativeType.java | 51 ++++++------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/imglib2/type/NativeType.java b/src/main/java/net/imglib2/type/NativeType.java index b71a684fd4..84da3df52f 100644 --- a/src/main/java/net/imglib2/type/NativeType.java +++ b/src/main/java/net/imglib2/type/NativeType.java @@ -128,17 +128,16 @@ public interface NativeType< T extends NativeType< T > > extends Type< T > */ void updateContainer( Object c ); + /** + * Get the (modifiable) index into the current data array. The returned + * instance will always be the same for the same Type. + */ Index index(); /** * Set the index into the current data array. - * - *

- * This is used by accessors (e.g., a {@link Cursor}) to position the - * {@link NativeType} in the container. - * - * @param i - * the new array index + * @deprecated Use {@code index().set(int)} instead. If possible, request the + * {@code index()} object only once and re-use it. */ @Deprecated default void updateIndex( final int i ) @@ -148,12 +147,8 @@ default void updateIndex( final int i ) /** * Get the current index into the current data array. - * - *

- * This is used by accessors (e.g., a {@link Cursor}) to position the - * {@link NativeType} in the container. - * - * @return the current index into the underlying data array + * @deprecated Use {@code index().get()} instead. If possible, request the + * {@code index()} object only once and re-use it. */ @Deprecated default int getIndex() @@ -163,10 +158,8 @@ default int getIndex() /** * Increment the index into the current data array. - * - *

- * This is used by accessors (e.g., a {@link Cursor}) to position the - * {@link NativeType} in the container. + * @deprecated Use {@code index().inc()} instead. If possible, request the + * {@code index()} object only once and re-use it. */ @Deprecated default void incIndex() @@ -177,13 +170,8 @@ default void incIndex() /** * Increases the index into the current data array by {@code increment} * steps. - * - *

- * This is used by accessors (e.g., a {@link Cursor}) to position the - * {@link NativeType} in the container. - * - * @param increment - * how many steps + * @deprecated Use {@code index().inc(int)} instead. If possible, request the + * {@code index()} object only once and re-use it. */ @Deprecated default void incIndex( final int increment ) @@ -193,10 +181,8 @@ default void incIndex( final int increment ) /** * Decrement the index into the current data array. - * - *

- * This is used by accessors (e.g., a {@link Cursor}) to position the - * {@link NativeType} in the container. + * @deprecated Use {@code index().dec()} instead. If possible, request the + * {@code index()} object only once and re-use it. */ @Deprecated default void decIndex() @@ -207,13 +193,8 @@ default void decIndex() /** * Decrease the index into the current data array by {@code decrement} * steps. - * - *

- * This is used by accessors (e.g., a {@link Cursor}) to position the - * {@link NativeType} in the container. - * - * @param decrement - * how many steps + * @deprecated Use {@code index().dec(int)} instead. If possible, request the + * {@code index()} object only once and re-use it. */ @Deprecated default void decIndex( final int decrement ) From f413f0b621dd1fbc1883c525570a44ea4e4d93b6 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Wed, 21 Apr 2021 11:54:42 +0200 Subject: [PATCH 10/10] Rename Index fields in accessors to "typeIndex" --- .../img/array/AbstractArrayCursor.java | 20 ++++---- .../array/AbstractArrayLocalizingCursor.java | 18 +++---- .../imglib2/img/array/ArrayRandomAccess.java | 48 +++++++++---------- .../java/net/imglib2/img/cell/CellCursor.java | 28 +++++------ .../img/cell/CellLocalizingCursor.java | 14 +++--- .../imglib2/img/cell/CellRandomAccess.java | 32 ++++++------- .../net/imglib2/img/planar/PlanarCursor.java | 14 +++--- .../imglib2/img/planar/PlanarCursor1D.java | 6 +-- .../imglib2/img/planar/PlanarCursor2D.java | 8 ++-- .../img/planar/PlanarLocalizingCursor.java | 14 +++--- .../img/planar/PlanarLocalizingCursor1D.java | 4 +- .../img/planar/PlanarLocalizingCursor2D.java | 4 +- .../img/planar/PlanarPlaneSubsetCursor.java | 20 ++++---- .../PlanarPlaneSubsetLocalizingCursor.java | 22 ++++----- .../img/planar/PlanarRandomAccess.java | 38 +++++++-------- .../img/planar/PlanarRandomAccess1D.java | 20 ++++---- 16 files changed, 155 insertions(+), 155 deletions(-) diff --git a/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java b/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java index ca2173c02d..8c8611bc18 100644 --- a/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java +++ b/src/main/java/net/imglib2/img/array/AbstractArrayCursor.java @@ -69,7 +69,7 @@ public abstract class AbstractArrayCursor< T extends NativeType< T > > extends A */ protected final T type; - private final Index index; + private final Index typeIndex; /** * Source image @@ -92,12 +92,12 @@ protected AbstractArrayCursor( final AbstractArrayCursor< T > cursor ) this.img = cursor.img; this.type = img.createLinkedType(); - this.index = type.index(); + this.typeIndex = type.index(); this.offset = cursor.offset; this.size = cursor.size; this.lastIndex = cursor.lastIndex; - index.set( cursor.index.get() ); + typeIndex.set( cursor.typeIndex.get() ); type.updateContainer( this ); } @@ -113,7 +113,7 @@ public AbstractArrayCursor( final ArrayImg< T, ? > img, final int offset, final super( img.numDimensions() ); this.type = img.createLinkedType(); - this.index = type.index(); + this.typeIndex = type.index(); this.img = img; this.lastIndex = offset + size - 1; this.offset = offset; @@ -131,25 +131,25 @@ public T get() @Override public boolean hasNext() { - return index.get() < lastIndex; + return typeIndex.get() < lastIndex; } @Override public void jumpFwd( final long steps ) { - index.inc( ( int ) steps ); + typeIndex.inc( ( int ) steps ); } @Override public void fwd() { - index.inc(); + typeIndex.inc(); } @Override public void reset() { - index.set( offset - 1 ); + typeIndex.set( offset - 1 ); type.updateContainer( this ); } @@ -162,12 +162,12 @@ public String toString() @Override public int getIntPosition( final int dim ) { - return IntervalIndexer.indexToPosition( index.get(), img.dim, dim ); + return IntervalIndexer.indexToPosition( typeIndex.get(), img.dim, dim ); } @Override public void localize( final int[] position ) { - IntervalIndexer.indexToPosition( index.get(), img.dim, position ); + IntervalIndexer.indexToPosition( typeIndex.get(), img.dim, position ); } } diff --git a/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java b/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java index f9b784989b..f4f605c4e7 100644 --- a/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/array/AbstractArrayLocalizingCursor.java @@ -70,7 +70,7 @@ public abstract class AbstractArrayLocalizingCursor< T extends NativeType< T > > */ protected final T type; - private final Index index; + private final Index typeIndex; /** * The underlying source {@link ArrayImg}. @@ -99,7 +99,7 @@ protected AbstractArrayLocalizingCursor( final AbstractArrayLocalizingCursor< T this.img = cursor.img; this.type = img.createLinkedType(); - this.index = type.index(); + this.typeIndex = type.index(); this.offset = cursor.offset; this.size = cursor.size; @@ -112,7 +112,7 @@ protected AbstractArrayLocalizingCursor( final AbstractArrayLocalizingCursor< T max[ d ] = cursor.max[ d ]; } - index.set( cursor.index.get() ); + typeIndex.set( cursor.typeIndex.get() ); type.updateContainer( this ); } @@ -132,7 +132,7 @@ public AbstractArrayLocalizingCursor( final ArrayImg< T, ? > img, final int offs this.size = size; this.type = img.createLinkedType(); - this.index = type.index(); + this.typeIndex = type.index(); this.lastIndex = offset + size - 1; max = new int[ n ]; @@ -157,7 +157,7 @@ public T get() @Override public boolean hasNext() { - return index.get() < lastIndex; + return typeIndex.get() < lastIndex; } /** @@ -166,7 +166,7 @@ public boolean hasNext() @Override public void fwd() { - index.inc(); + typeIndex.inc(); // for ( int d = 0; d < n; ++d ) // { @@ -207,8 +207,8 @@ public void fwd() @Override public void jumpFwd( final long steps ) { - index.inc( ( int ) steps ); - IntervalIndexer.indexToPosition( index.get(), img.dim, position ); + typeIndex.inc( ( int ) steps ); + IntervalIndexer.indexToPosition( typeIndex.get(), img.dim, position ); } /** @@ -217,7 +217,7 @@ public void jumpFwd( final long steps ) @Override public void reset() { - index.set( offset - 1 ); + typeIndex.set( offset - 1 ); IntervalIndexer.indexToPosition( offset, img.dim, position ); position[ 0 ]--; diff --git a/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java b/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java index eaec85774c..45946c00e8 100644 --- a/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java +++ b/src/main/java/net/imglib2/img/array/ArrayRandomAccess.java @@ -53,7 +53,7 @@ public class ArrayRandomAccess< T extends NativeType< T > > extends AbstractLoca { protected final T type; - private final Index index; + private final Index typeIndex; final ArrayImg< T, ? > img; @@ -63,13 +63,13 @@ protected ArrayRandomAccess( final ArrayRandomAccess< T > randomAccess ) this.img = randomAccess.img; this.type = img.createLinkedType(); - this.index = type.index(); + this.typeIndex = type.index(); - index.set( 0 ); + typeIndex.set( 0 ); for ( int d = 0; d < n; d++ ) { position[ d ] = randomAccess.position[ d ]; - index.inc( position[ d ] * img.steps[ d ] ); + typeIndex.inc( position[ d ] * img.steps[ d ] ); } type.updateContainer( this ); @@ -81,9 +81,9 @@ public ArrayRandomAccess( final ArrayImg< T, ? > container ) this.img = container; this.type = container.createLinkedType(); - this.index = type.index(); + this.typeIndex = type.index(); - index.set( 0 ); + typeIndex.set( 0 ); for ( int d = 0; d < n; d++ ) position[ d ] = 0; @@ -99,28 +99,28 @@ public T get() @Override public void fwd( final int d ) { - index.inc( img.steps[ d ] ); + typeIndex.inc( img.steps[ d ] ); ++position[ d ]; } @Override public void bck( final int d ) { - index.dec( img.steps[ d ] ); + typeIndex.dec( img.steps[ d ] ); --position[ d ]; } @Override public void move( final int distance, final int d ) { - index.inc( img.steps[ d ] * distance ); + typeIndex.inc( img.steps[ d ] * distance ); position[ d ] += distance; } @Override public void move( final long distance, final int d ) { - index.inc( img.steps[ d ] * ( int ) distance ); + typeIndex.inc( img.steps[ d ] * ( int ) distance ); position[ d ] += distance; } @@ -134,7 +134,7 @@ public void move( final Localizable localizable ) position[ d ] += distance; move += distance * img.steps[ d ]; } - index.inc( move ); + typeIndex.inc( move ); } @Override @@ -146,7 +146,7 @@ public void move( final int[] distance ) position[ d ] += distance[ d ]; move += distance[ d ] * img.steps[ d ]; } - index.inc( move ); + typeIndex.inc( move ); } @Override @@ -158,7 +158,7 @@ public void move( final long[] distance ) position[ d ] += distance[ d ]; move += distance[ d ] * img.steps[ d ]; } - index.inc( move ); + typeIndex.inc( move ); } @Override @@ -170,7 +170,7 @@ public void setPosition( final Localizable localizable ) position[ d ] = localizable.getIntPosition( d ); i += position[ d ] * img.steps[ d ]; } - index.set( i ); + typeIndex.set( i ); } @Override @@ -182,7 +182,7 @@ public void setPosition( final int[] pos ) position[ d ] = pos[ d ]; i += pos[ d ] * img.steps[ d ]; } - index.set( i ); + typeIndex.set( i ); } @Override @@ -195,20 +195,20 @@ public void setPosition( final long[] pos ) position[ d ] = p; i += p * img.steps[ d ]; } - index.set( i ); + typeIndex.set( i ); } @Override public void setPosition( final int pos, final int d ) { - index.inc( ( pos - position[ d ] ) * img.steps[ d ] ); + typeIndex.inc( ( pos - position[ d ] ) * img.steps[ d ] ); position[ d ] = pos; } @Override public void setPosition( final long pos, final int d ) { - index.inc( ( ( int ) pos - position[ d ] ) * img.steps[ d ] ); + typeIndex.inc( ( ( int ) pos - position[ d ] ) * img.steps[ d ] ); position[ d ] = ( int ) pos; } @@ -231,7 +231,7 @@ public ArrayRandomAccess< T > copyRandomAccess() */ public void fwdDim0() { - index.inc(); + typeIndex.inc(); ++position[ 0 ]; } @@ -240,7 +240,7 @@ public void fwdDim0() */ public void bckDim0() { - index.dec(); + typeIndex.dec(); --position[ 0 ]; } @@ -252,7 +252,7 @@ public void bckDim0() */ public void moveDim0( final int distance ) { - index.inc( distance ); + typeIndex.inc( distance ); position[ 0 ] += distance; } @@ -264,7 +264,7 @@ public void moveDim0( final int distance ) */ public void move( final long distance ) { - index.inc( ( int ) distance ); + typeIndex.inc( ( int ) distance ); position[ 0 ] += distance; } @@ -279,7 +279,7 @@ public void move( final long distance ) */ public void setPositionDim0( final int pos ) { - index.set( pos ); + typeIndex.set( pos ); position[ 0 ] = pos; } @@ -294,7 +294,7 @@ public void setPositionDim0( final int pos ) */ public void setPositionDim0( final long pos ) { - index.set( ( int ) pos ); + typeIndex.set( ( int ) pos ); position[ 0 ] = ( int ) pos; } } diff --git a/src/main/java/net/imglib2/img/cell/CellCursor.java b/src/main/java/net/imglib2/img/cell/CellCursor.java index 73b116ef98..157319e51e 100644 --- a/src/main/java/net/imglib2/img/cell/CellCursor.java +++ b/src/main/java/net/imglib2/img/cell/CellCursor.java @@ -60,7 +60,7 @@ public class CellCursor< T extends NativeType< T >, C extends Cell< ? > > * The current index of the type. It is faster to duplicate this here than * to access it through type.getIndex(). */ - protected int index; + protected int typeIndex; /** * Caches cursorOnCells.hasNext(). @@ -76,10 +76,10 @@ protected CellCursor( final CellCursor< T, C > cursor ) this.cursorOnCells = cursor.cursorOnCells.copyCursor(); isNotLastCell = cursor.isNotLastCell; lastIndexInCell = cursor.lastIndexInCell; - index = cursor.index; + typeIndex = cursor.typeIndex; type.updateContainer( this ); - i.set( index ); + i.set( typeIndex ); } public CellCursor( final AbstractCellImg< T, ?, C, ? > img ) @@ -120,13 +120,13 @@ public CellCursor< T, C > copyCursor() @Override public boolean hasNext() { - return ( index < lastIndexInCell ) || isNotLastCell; + return ( typeIndex < lastIndexInCell ) || isNotLastCell; } @Override public void jumpFwd( final long steps ) { - long newIndex = index + steps; + long newIndex = typeIndex + steps; while ( newIndex > lastIndexInCell ) { newIndex -= lastIndexInCell + 1; @@ -134,20 +134,20 @@ public void jumpFwd( final long steps ) isNotLastCell = cursorOnCells.hasNext(); lastIndexInCell = ( int ) ( getCell().size() - 1 ); } - index = ( int ) newIndex; - i.set( index ); + typeIndex = ( int ) newIndex; + i.set( typeIndex ); type.updateContainer( this ); } @Override public void fwd() { - if ( ++index > lastIndexInCell ) + if ( ++typeIndex > lastIndexInCell ) { moveToNextCell(); - index = 0; + typeIndex = 0; } - i.set( index ); + i.set( typeIndex ); } @Override @@ -155,7 +155,7 @@ public void reset() { cursorOnCells.reset(); moveToNextCell(); - i.set( index ); + i.set( typeIndex ); } @Override @@ -167,13 +167,13 @@ public String toString() @Override public long getLongPosition( final int dim ) { - return getCell().indexToGlobalPosition( index, dim ); + return getCell().indexToGlobalPosition( typeIndex, dim ); } @Override public void localize( final long[] position ) { - getCell().indexToGlobalPosition( index, position ); + getCell().indexToGlobalPosition( typeIndex, position ); } /** @@ -185,7 +185,7 @@ private void moveToNextCell() cursorOnCells.fwd(); isNotLastCell = cursorOnCells.hasNext(); lastIndexInCell = ( int ) ( getCell().size() - 1 ); - index = -1; + typeIndex = -1; type.updateContainer( this ); } } diff --git a/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java b/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java index d21664af4d..4908c0e93a 100644 --- a/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/cell/CellLocalizingCursor.java @@ -50,7 +50,7 @@ public class CellLocalizingCursor< T extends NativeType< T >, C extends Cell< ? { protected final T type; - protected final Index i; + protected final Index typeIndex; protected final Cursor< C > cursorOnCells; @@ -76,7 +76,7 @@ protected CellLocalizingCursor( final CellLocalizingCursor< T, C > cursor ) super( cursor.numDimensions() ); this.type = cursor.type.duplicateTypeOnSameNativeImg(); - i = type.index(); + typeIndex = type.index(); this.cursorOnCells = cursor.cursorOnCells.copyCursor(); this.currentCellMin = cursor.currentCellMin; this.currentCellMax = cursor.currentCellMax; @@ -88,7 +88,7 @@ protected CellLocalizingCursor( final CellLocalizingCursor< T, C > cursor ) index = cursor.index; type.updateContainer( this ); - i.set( index ); + typeIndex.set( index ); } public CellLocalizingCursor( final AbstractCellImg< T, ?, C, ? > img ) @@ -96,7 +96,7 @@ public CellLocalizingCursor( final AbstractCellImg< T, ?, C, ? > img ) super( img.numDimensions() ); this.type = img.createLinkedType(); - i = type.index(); + typeIndex = type.index(); this.cursorOnCells = img.getCells().cursor(); this.currentCellMin = null; this.currentCellMax = null; @@ -153,7 +153,7 @@ public void jumpFwd( final long steps ) index = ( int ) newIndex; cell.indexToGlobalPosition( index, position ); - i.set( index ); + typeIndex.set( index ); type.updateContainer( this ); } @@ -165,7 +165,7 @@ public void fwd() moveToNextCell(); index = 0; } - i.set( index ); + typeIndex.set( index ); for ( int d = 0; d < n; ++d ) { @@ -182,7 +182,7 @@ public void reset() cursorOnCells.reset(); moveToNextCell(); index = -1; - i.set( index ); + typeIndex.set( index ); } /** diff --git a/src/main/java/net/imglib2/img/cell/CellRandomAccess.java b/src/main/java/net/imglib2/img/cell/CellRandomAccess.java index 32fdfdf85c..182812a43a 100644 --- a/src/main/java/net/imglib2/img/cell/CellRandomAccess.java +++ b/src/main/java/net/imglib2/img/cell/CellRandomAccess.java @@ -54,7 +54,7 @@ public class CellRandomAccess< T extends NativeType< T >, C extends Cell< ? > > { protected final T type; - protected final Index i; + protected final Index typeIndex; protected final CellGrid grid; @@ -87,7 +87,7 @@ protected CellRandomAccess( final CellRandomAccess< T, C > randomAccess ) super( randomAccess.numDimensions() ); type = randomAccess.type.duplicateTypeOnSameNativeImg(); - i = type.index(); + typeIndex = type.index(); grid = randomAccess.grid; randomAccessOnCells = randomAccess.randomAccessOnCells.copyRandomAccess(); @@ -106,7 +106,7 @@ protected CellRandomAccess( final CellRandomAccess< T, C > randomAccess ) index = randomAccess.index; if ( !isOutOfBounds ) type.updateContainer( this ); - i.set( index ); + typeIndex.set( index ); } public CellRandomAccess( final AbstractCellImg< T, ?, C, ? > img ) @@ -114,7 +114,7 @@ public CellRandomAccess( final AbstractCellImg< T, ?, C, ? > img ) super( img.numDimensions() ); type = img.createLinkedType(); - i = type.index(); + typeIndex = type.index(); grid = img.getCellGrid(); randomAccessOnCells = img.getCells().randomAccess(); @@ -169,7 +169,7 @@ public void fwd( final int d ) randomAccessOnCells.fwd( d ); updatePosition( position[ d ] >= dimensions[ d ] ); } - i.set( index ); + typeIndex.set( index ); } @Override @@ -181,7 +181,7 @@ public void bck( final int d ) randomAccessOnCells.bck( d ); updatePosition( position[ d ] < 0 ); } - i.set( index ); + typeIndex.set( index ); } @Override @@ -194,7 +194,7 @@ public void move( final int distance, final int d ) randomAccessOnCells.setPosition( position[ d ] / cellDims[ d ], d ); updatePosition( position[ d ] < 0 || position[ d ] >= dimensions[ d ] ); } - i.set( index ); + typeIndex.set( index ); } @Override @@ -207,7 +207,7 @@ public void move( final long distance, final int d ) randomAccessOnCells.setPosition( position[ d ] / cellDims[ d ], d ); updatePosition( position[ d ] < 0 || position[ d ] >= dimensions[ d ] ); } - i.set( index ); + typeIndex.set( index ); } @Override @@ -243,7 +243,7 @@ public void move( final Localizable localizable ) } } } - i.set( index ); + typeIndex.set( index ); } @Override @@ -277,7 +277,7 @@ public void move( final int[] distance ) } } } - i.set( index ); + typeIndex.set( index ); } @Override @@ -311,7 +311,7 @@ public void move( final long[] distance ) } } } - i.set( index ); + typeIndex.set( index ); } @Override @@ -324,7 +324,7 @@ public void setPosition( final int pos, final int d ) randomAccessOnCells.setPosition( pos / cellDims[ d ], d ); updatePosition( position[ d ] < 0 || position[ d ] >= dimensions[ d ] ); } - i.set( index ); + typeIndex.set( index ); } @Override @@ -337,7 +337,7 @@ public void setPosition( final long pos, final int d ) randomAccessOnCells.setPosition( pos / cellDims[ d ], d ); updatePosition( position[ d ] < 0 || position[ d ] >= dimensions[ d ] ); } - i.set( index ); + typeIndex.set( index ); } @Override @@ -373,7 +373,7 @@ public void setPosition( final Localizable localizable ) } } } - i.set( index ); + typeIndex.set( index ); } @Override @@ -392,7 +392,7 @@ public void setPosition( final int[] pos ) position[ d ] = pos[ d ]; } } - i.set( index ); + typeIndex.set( index ); } private void setPos2( final int[] pos, final int d0 ) @@ -444,7 +444,7 @@ public void setPosition( final long[] pos ) } } } - i.set( index ); + typeIndex.set( index ); } /** diff --git a/src/main/java/net/imglib2/img/planar/PlanarCursor.java b/src/main/java/net/imglib2/img/planar/PlanarCursor.java index b81dd3c0d7..efa647334b 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarCursor.java @@ -50,7 +50,7 @@ public class PlanarCursor< T extends NativeType< T > > extends AbstractCursorInt { protected final T type; - protected final Index i; + protected final Index typeIndex; protected final PlanarImg< T, ? > container; @@ -70,7 +70,7 @@ protected PlanarCursor( final PlanarCursor< T > cursor ) container = cursor.container; this.type = container.createLinkedType(); - i = type.index(); + typeIndex = type.index(); lastIndex = cursor.lastIndex; lastSliceIndex = cursor.lastSliceIndex; @@ -78,7 +78,7 @@ protected PlanarCursor( final PlanarCursor< T > cursor ) index = cursor.index; type.updateContainer( this ); - i.set( index ); + typeIndex.set( index ); } public PlanarCursor( final PlanarImg< T, ? > container ) @@ -86,7 +86,7 @@ public PlanarCursor( final PlanarImg< T, ? > container ) super( container.numDimensions() ); this.type = container.createLinkedType(); - this.i = type.index(); + this.typeIndex = type.index(); this.container = container; lastIndex = ( ( n > 1 ) ? container.dimensions[ 1 ] : 1 ) * container.dimensions[ 0 ] - 1; @@ -140,7 +140,7 @@ public void fwd() ++sliceIndex; type.updateContainer( this ); } - i.set( index ); + typeIndex.set( index ); } @Override @@ -155,7 +155,7 @@ public void jumpFwd( final long steps ) type.updateContainer( this ); } index = ( int ) newIndex; - i.set( index ); + typeIndex.set( index ); } @Override @@ -163,7 +163,7 @@ public void reset() { sliceIndex = 0; index = -1; - i.set( -1 ); + typeIndex.set( -1 ); type.updateContainer( this ); } diff --git a/src/main/java/net/imglib2/img/planar/PlanarCursor1D.java b/src/main/java/net/imglib2/img/planar/PlanarCursor1D.java index abd40a1439..d04682ffe2 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarCursor1D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarCursor1D.java @@ -51,20 +51,20 @@ public PlanarCursor1D( final PlanarImg< T, ? > container ) @Override public boolean hasNext() { - return i.get() < lastIndex; + return typeIndex.get() < lastIndex; } @Override public void localize( final int[] position ) { - position[ 0 ] = i.get(); + position[ 0 ] = typeIndex.get(); } @Override public int getIntPosition( final int dim ) { if ( dim == 0 ) - return i.get(); + return typeIndex.get(); return 0; } } diff --git a/src/main/java/net/imglib2/img/planar/PlanarCursor2D.java b/src/main/java/net/imglib2/img/planar/PlanarCursor2D.java index 2a0c79cbee..1e51265550 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarCursor2D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarCursor2D.java @@ -53,19 +53,19 @@ public PlanarCursor2D( final PlanarImg< T, ? > container ) @Override public boolean hasNext() { - return i.get() < lastIndex; + return typeIndex.get() < lastIndex; } @Override public void fwd() { - i.inc(); + typeIndex.inc(); } @Override public void localize( final int[] position ) { - final int indexInSlice = i.get(); + final int indexInSlice = typeIndex.get(); final int dim0 = container.dimensions[ 0 ]; position[ 1 ] = indexInSlice / dim0; position[ 0 ] = indexInSlice - position[ 1 ] * dim0; @@ -74,7 +74,7 @@ public void localize( final int[] position ) @Override public int getIntPosition( final int dim ) { - final int indexInSlice = i.get(); + final int indexInSlice = typeIndex.get(); final int dim0 = container.dimensions[ 0 ]; final int pos1 = indexInSlice / dim0; if ( dim == 0 ) diff --git a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java index a27cc5f772..8ac26e1a1a 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor.java @@ -50,7 +50,7 @@ public class PlanarLocalizingCursor< T extends NativeType< T > > extends Abstrac { protected final T type; - protected final Index i; + protected final Index typeIndex; protected final PlanarImg< T, ? > container; @@ -76,7 +76,7 @@ protected PlanarLocalizingCursor( final PlanarLocalizingCursor< T > cursor ) container = cursor.container; this.type = container.createLinkedType(); - i = type.index(); + typeIndex = type.index(); lastIndex = cursor.lastIndex; lastSliceIndex = cursor.lastSliceIndex; @@ -92,7 +92,7 @@ protected PlanarLocalizingCursor( final PlanarLocalizingCursor< T > cursor ) index = cursor.index; type.updateContainer( this ); - i.set( index ); + typeIndex.set( index ); } public PlanarLocalizingCursor( final PlanarImg< T, ? > container ) @@ -100,7 +100,7 @@ public PlanarLocalizingCursor( final PlanarImg< T, ? > container ) super( container.numDimensions() ); this.type = container.createLinkedType(); - i = type.index(); + typeIndex = type.index(); this.container = container; lastIndex = ( ( n > 1 ) ? container.dimensions[ 1 ] : 1 ) * container.dimensions[ 0 ] - 1; @@ -158,7 +158,7 @@ public void fwd() ++sliceIndex; type.updateContainer( this ); } - i.set( index ); + typeIndex.set( index ); for ( int d = 0; d < n; ++d ) { @@ -181,7 +181,7 @@ public void jumpFwd( final long steps ) type.updateContainer( this ); } index = ( int ) newIndex; - i.set( index ); + typeIndex.set( index ); container.indexToGlobalPosition( sliceIndex, index, position ); } @@ -194,7 +194,7 @@ public void reset() sliceIndex = 0; index = -1; - i.set( -1 ); + typeIndex.set( -1 ); type.updateContainer( this ); } } diff --git a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor1D.java b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor1D.java index 614ecd1503..710b642f24 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor1D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor1D.java @@ -61,13 +61,13 @@ public PlanarLocalizingCursor1D< T > copy() @Override public boolean hasNext() { - return i.get() < lastIndex; + return typeIndex.get() < lastIndex; } @Override public void fwd() { - i.inc(); + typeIndex.inc(); ++position[ 0 ]; } } diff --git a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor2D.java b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor2D.java index b593090ce8..fd748afa78 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor2D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarLocalizingCursor2D.java @@ -61,13 +61,13 @@ public PlanarLocalizingCursor2D< T > copy() @Override public boolean hasNext() { - return i.get() < lastIndex; + return typeIndex.get() < lastIndex; } @Override public void fwd() { - i.inc(); + typeIndex.inc(); if ( ++position[ 0 ] > max[ 0 ] ) { diff --git a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java index 592d8f08de..20b28621b1 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetCursor.java @@ -56,7 +56,7 @@ public class PlanarPlaneSubsetCursor< T extends NativeType< T >> extends */ private final T type; - private final Index index; + private final Index typeIndex; /** * Container @@ -89,14 +89,14 @@ protected PlanarPlaneSubsetCursor( final PlanarPlaneSubsetCursor< T > cursor ) container = cursor.container; this.type = container.createLinkedType(); - index = type.index(); + typeIndex = type.index(); sliceIndex = cursor.sliceIndex; planeSize = cursor.planeSize; lastPlaneIndex = cursor.lastPlaneIndex; type.updateContainer( this ); - index.set( cursor.index.get() ); + typeIndex.set( cursor.typeIndex.get() ); } /** @@ -110,7 +110,7 @@ public PlanarPlaneSubsetCursor( final PlanarImg< T, ? > container, final Interva super( container.numDimensions() ); this.type = container.createLinkedType(); - index = type.index(); + typeIndex = type.index(); this.container = container; @@ -166,7 +166,7 @@ public PlanarPlaneSubsetCursor< T > copyCursor() @Override public final boolean hasNext() { - return index.get() < lastPlaneIndex; + return typeIndex.get() < lastPlaneIndex; } /** @@ -175,7 +175,7 @@ public final boolean hasNext() @Override public final void fwd() { - index.inc(); + typeIndex.inc(); } /** @@ -184,7 +184,7 @@ public final void fwd() @Override public final void jumpFwd( final long steps ) { - index.inc( ( int ) steps ); + typeIndex.inc( ( int ) steps ); } /** @@ -194,7 +194,7 @@ public final void jumpFwd( final long steps ) public final void reset() { // Set index inside the slice - index.set( -1 ); + typeIndex.set( -1 ); type.updateContainer( this ); } @@ -213,7 +213,7 @@ public String toString() @Override public final void localize( final int[] position ) { - container.indexToGlobalPosition( sliceIndex, index.get(), position ); + container.indexToGlobalPosition( sliceIndex, typeIndex.get(), position ); } /** @@ -222,7 +222,7 @@ public final void localize( final int[] position ) @Override public final int getIntPosition( final int dim ) { - return container.indexToGlobalPosition( sliceIndex, index.get(), dim ); + return container.indexToGlobalPosition( sliceIndex, typeIndex.get(), dim ); } private long offset(final Interval interval) { diff --git a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java index 412e6b2bbd..d3def6b654 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java +++ b/src/main/java/net/imglib2/img/planar/PlanarPlaneSubsetLocalizingCursor.java @@ -56,7 +56,7 @@ public class PlanarPlaneSubsetLocalizingCursor< T extends NativeType< T > > */ private final T type; - private final Index index; + private final Index typeIndex; /** * Container @@ -79,7 +79,7 @@ public class PlanarPlaneSubsetLocalizingCursor< T extends NativeType< T > > /** * Copy Constructor - * + * * @param cursor * PlanarPlaneSubsetLocalizingCursor to copy from */ @@ -89,7 +89,7 @@ protected PlanarPlaneSubsetLocalizingCursor( final PlanarPlaneSubsetLocalizingCu container = cursor.container; this.type = container.createLinkedType(); - index = type.index(); + typeIndex = type.index(); sliceIndex = cursor.sliceIndex; lastIndexPlane = cursor.lastIndexPlane; @@ -100,7 +100,7 @@ protected PlanarPlaneSubsetLocalizingCursor( final PlanarPlaneSubsetLocalizingCu position[ d ] = cursor.position[ d ]; type.updateContainer( this ); - index.set( cursor.index.get() ); + typeIndex.set( cursor.typeIndex.get() ); } /** @@ -116,7 +116,7 @@ public PlanarPlaneSubsetLocalizingCursor( final PlanarImg< T, ? > container, fin super( container.numDimensions() ); this.type = container.createLinkedType(); - index = type.index(); + typeIndex = type.index(); this.container = container; @@ -177,7 +177,7 @@ public PlanarPlaneSubsetLocalizingCursor< T > copyCursor() @Override public final boolean hasNext() { - return index.get() < lastIndexPlane; + return typeIndex.get() < lastIndexPlane; } /** @@ -186,7 +186,7 @@ public final boolean hasNext() @Override public final void fwd() { - index.inc(); + typeIndex.inc(); if ( ++position[ 0 ] > maxX && n > 1 ) { position[ 0 ] = 0; @@ -200,8 +200,8 @@ public final void fwd() @Override public final void jumpFwd( final long steps ) { - index.inc( ( int ) steps ); - updatePositionFromIndex( index.get() ); + typeIndex.inc( ( int ) steps ); + updatePositionFromIndex( typeIndex.get() ); } private void updatePositionFromIndex( final int index ) @@ -222,8 +222,8 @@ private void updatePositionFromIndex( final int index ) @Override public final void reset() { - index.set( -1 ); - updatePositionFromIndex( index.get() ); + typeIndex.set( -1 ); + updatePositionFromIndex( typeIndex.get() ); } /** diff --git a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java index 135784782f..366bab0a3c 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java +++ b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess.java @@ -57,7 +57,7 @@ public class PlanarRandomAccess< T extends NativeType< T > > extends AbstractLoc final protected T type; - final protected Index index; + final protected Index typeIndex; protected int sliceIndex; @@ -73,9 +73,9 @@ protected PlanarRandomAccess( final PlanarRandomAccess< T > randomAccess ) position[ d ] = randomAccess.position[ d ]; type = randomAccess.type.duplicateTypeOnSameNativeImg(); - index = type.index(); + typeIndex = type.index(); type.updateContainer( this ); - index.set( randomAccess.index.get() ); + typeIndex.set( randomAccess.typeIndex.get() ); } public PlanarRandomAccess( final PlanarImg< T, ? > container ) @@ -86,8 +86,8 @@ public PlanarRandomAccess( final PlanarImg< T, ? > container ) width = ( int ) container.dimension( 0 ); type = container.createLinkedType(); - index = type.index(); - index.set( 0 ); + typeIndex = type.index(); + typeIndex.set( 0 ); type.updateContainer( this ); } @@ -121,9 +121,9 @@ public void fwd( final int d ) ++position[ d ]; if ( d == 0 ) - index.inc(); + typeIndex.inc(); else if ( d == 1 ) - index.inc( width ); + typeIndex.inc( width ); else { sliceIndex += sliceSteps[ d ]; @@ -137,9 +137,9 @@ public void bck( final int d ) --position[ d ]; if ( d == 0 ) - index.dec(); + typeIndex.dec(); else if ( d == 1 ) - index.dec( width ); + typeIndex.dec( width ); else { sliceIndex -= sliceSteps[ d ]; @@ -154,11 +154,11 @@ public void move( final int distance, final int d ) if ( d == 0 ) { - index.inc( distance ); + typeIndex.inc( distance ); } else if ( d == 1 ) { - index.inc( distance * width ); + typeIndex.inc( distance * width ); } else { @@ -178,7 +178,7 @@ public void move( final Localizable localizable ) { final int d0 = localizable.getIntPosition( 0 ); final int d1 = localizable.getIntPosition( 1 ); - index.inc( d0 + d1 * width ); + typeIndex.inc( d0 + d1 * width ); position[ 0 ] += d0; position[ 1 ] += d1; @@ -206,7 +206,7 @@ public void move( final Localizable localizable ) @Override public void move( final int[] distance ) { - index.inc( distance[ 0 ] + distance[ 1 ] * width ); + typeIndex.inc( distance[ 0 ] + distance[ 1 ] * width ); position[ 0 ] += distance[ 0 ]; position[ 1 ] += distance[ 1 ]; @@ -234,7 +234,7 @@ public void move( final int[] distance ) @Override public void move( final long[] distance ) { - index.inc( ( int ) distance[ 0 ] + ( int ) distance[ 1 ] * width ); + typeIndex.inc( ( int ) distance[ 0 ] + ( int ) distance[ 1 ] * width ); position[ 0 ] += ( int ) distance[ 0 ]; position[ 1 ] += ( int ) distance[ 1 ]; @@ -264,11 +264,11 @@ public void setPosition( final int pos, final int d ) { if ( d == 0 ) { - index.inc( pos - position[ 0 ] ); + typeIndex.inc( pos - position[ 0 ] ); } else if ( d == 1 ) { - index.inc( ( pos - position[ 1 ] ) * width ); + typeIndex.inc( ( pos - position[ 1 ] ) * width ); } else { @@ -290,7 +290,7 @@ public void setPosition( final Localizable localizable ) { final int p0 = localizable.getIntPosition( 0 ); final int p1 = localizable.getIntPosition( 1 ); - index.set( p0 + p1 * width ); + typeIndex.set( p0 + p1 * width ); position[ 0 ] = p0; position[ 1 ] = p1; @@ -319,7 +319,7 @@ public void setPosition( final Localizable localizable ) @Override public void setPosition( final int[] pos ) { - index.set( pos[ 0 ] + pos[ 1 ] * width ); + typeIndex.set( pos[ 0 ] + pos[ 1 ] * width ); position[ 0 ] = pos[ 0 ]; position[ 1 ] = pos[ 1 ]; @@ -346,7 +346,7 @@ public void setPosition( final int[] pos ) @Override public void setPosition( final long[] pos ) { - index.set( ( int ) pos[ 0 ] + ( int ) pos[ 1 ] * width ); + typeIndex.set( ( int ) pos[ 0 ] + ( int ) pos[ 1 ] * width ); position[ 0 ] = ( int ) pos[ 0 ]; position[ 1 ] = ( int ) pos[ 1 ]; diff --git a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess1D.java b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess1D.java index 7302634d5f..c1a0fdc767 100644 --- a/src/main/java/net/imglib2/img/planar/PlanarRandomAccess1D.java +++ b/src/main/java/net/imglib2/img/planar/PlanarRandomAccess1D.java @@ -57,21 +57,21 @@ public PlanarRandomAccess1D( final PlanarImg< T, ? > container ) public void fwd( final int dim ) { ++position[ 0 ]; - index.inc(); + typeIndex.inc(); } @Override public void bck( final int dim ) { --position[ 0 ]; - index.dec(); + typeIndex.dec(); } @Override public void move( final int distance, final int d ) { position[ 0 ] += distance; - index.inc( distance ); + typeIndex.inc( distance ); } @Override @@ -79,27 +79,27 @@ public void move( final Localizable localizable ) { final int distance = localizable.getIntPosition( 0 ); position[ 0 ] += distance; - index.inc( distance ); + typeIndex.inc( distance ); } @Override public void move( final int[] distance ) { position[ 0 ] += distance[ 0 ]; - index.inc( distance[ 0 ] ); + typeIndex.inc( distance[ 0 ] ); } @Override public void move( final long[] distance ) { position[ 0 ] += ( int ) distance[ 0 ]; - index.inc( ( int ) distance[ 0 ] ); + typeIndex.inc( ( int ) distance[ 0 ] ); } @Override public void setPosition( final int pos, final int dim ) { - index.set( pos ); + typeIndex.set( pos ); position[ 0 ] = pos; } @@ -107,21 +107,21 @@ public void setPosition( final int pos, final int dim ) public void setPosition( final Localizable localizable ) { final int pos = localizable.getIntPosition( 0 ); - index.set( pos ); + typeIndex.set( pos ); this.position[ 0 ] = pos; } @Override public void setPosition( final int[] position ) { - index.set( position[ 0 ] ); + typeIndex.set( position[ 0 ] ); this.position[ 0 ] = position[ 0 ]; } @Override public void setPosition( final long[] position ) { - index.set( ( int ) position[ 0 ] ); + typeIndex.set( ( int ) position[ 0 ] ); this.position[ 0 ] = ( int ) position[ 0 ]; } }