From 0abf3009f39c350c2f116514ffed8cc776a70c53 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Fri, 2 Jun 2023 12:33:13 +0200 Subject: [PATCH 1/7] Add convenience method AccessOptions.accessFlags(Set) to set both DIRTY and VOLATIL --- .../net/imglib2/cache/img/optional/AccessOptions.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/net/imglib2/cache/img/optional/AccessOptions.java b/src/main/java/net/imglib2/cache/img/optional/AccessOptions.java index 546d5b0..276f457 100644 --- a/src/main/java/net/imglib2/cache/img/optional/AccessOptions.java +++ b/src/main/java/net/imglib2/cache/img/optional/AccessOptions.java @@ -33,8 +33,10 @@ */ package net.imglib2.cache.img.optional; +import java.util.Set; import java.util.function.BiConsumer; import net.imglib2.Dirty; +import net.imglib2.img.basictypeaccess.AccessFlags; import org.scijava.optional.Options; import org.scijava.optional.Values; @@ -67,6 +69,13 @@ default T volatileAccesses( final boolean volatil ) return setValue( "volatileAccesses", volatil ); } + default T accessFlags( final Set< AccessFlags > flags ) + { + final boolean dirty = flags.contains( AccessFlags.DIRTY ); + final boolean volatil = flags.contains( AccessFlags.VOLATILE ); + return ( ( AccessOptions< T > ) dirtyAccesses( dirty ) ).volatileAccesses( volatil ); + } + interface Val extends Values { default void forEach( BiConsumer< String, Object > action ) From 26d533e259aebae4b91f77df5719ce113e9b128c Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Wed, 31 Jan 2024 14:41:21 +0100 Subject: [PATCH 2/7] remove unnecessary null check --- src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java b/src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java index f598e19..cc55df0 100644 --- a/src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java +++ b/src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java @@ -143,7 +143,7 @@ public static < T extends NativeType< T >, A extends ArrayDataAccess< A > > Load { final A creator = ArrayDataAccessFactory.get( primitiveType, flags ); final ArrayDataAccessWrapper< A, ? > wrapper = getWrapper( primitiveType, flags ); - return creator == null ? null : new LoadedCellCacheLoader<>( grid, type, creator, wrapper, loader ); + return new LoadedCellCacheLoader<>( grid, type, creator, wrapper, loader ); } @SuppressWarnings( "unchecked" ) From 46b40a190857547a3803b8121f2bd8f5a2c83933 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 7 May 2024 14:20:29 +0200 Subject: [PATCH 3/7] POM: Update parent to pom-scijava-37.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6bd3a84..0dfcf7c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.scijava pom-scijava - 34.0.0 + 37.0.0 From f93ad8608c2432b5ebb7629b7da7c27b9791cfc6 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Tue, 7 May 2024 14:20:35 +0200 Subject: [PATCH 4/7] POM: Bump dependency version imglib2-7.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0dfcf7c..2fa9aed 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,7 @@ Jean-Yves Tinevez and Michael Zinsmaier. sign,deploy-to-scijava - 6.1.0 + 7.0.0 From ff89608a33b792392405483e6d85c0439a42bdb3 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Mon, 25 Mar 2024 12:35:01 +0100 Subject: [PATCH 5/7] Implement Sampler.getType() --- .../imglib2/cache/img/SingleCellArrayImg.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/net/imglib2/cache/img/SingleCellArrayImg.java b/src/main/java/net/imglib2/cache/img/SingleCellArrayImg.java index 74c3925..c3bd14b 100644 --- a/src/main/java/net/imglib2/cache/img/SingleCellArrayImg.java +++ b/src/main/java/net/imglib2/cache/img/SingleCellArrayImg.java @@ -178,6 +178,12 @@ public RandomAccess< T > randomAccess( final Interval interval ) return randomAccess(); } + @Override + public T getType() + { + return linkedType; + } + class CellArrayRandomAccess extends AbstractLocalizable implements RandomAccess< T > { final T type; @@ -208,6 +214,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public void fwd( final int d ) { @@ -363,6 +375,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public boolean hasNext() { @@ -450,6 +468,12 @@ public T get() return type; } + @Override + public T getType() + { + return type; + } + @Override public void fwd() { From 8b1882b5d2c1864974e5db0ca5c49b2c5b0f4628 Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Thu, 1 Feb 2024 14:12:32 +0100 Subject: [PATCH 6/7] javadoc --- src/main/java/net/imglib2/cache/IoSync.java | 2 +- .../imglib2/cache/ref/GuardedStrongRefLoaderRemoverCache.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/imglib2/cache/IoSync.java b/src/main/java/net/imglib2/cache/IoSync.java index 896bdf9..49f7301 100644 --- a/src/main/java/net/imglib2/cache/IoSync.java +++ b/src/main/java/net/imglib2/cache/IoSync.java @@ -75,7 +75,7 @@ * @param * value type * @param - * value data type + * value data type, see {@link CacheRemover} * * @author Tobias Pietzsch */ diff --git a/src/main/java/net/imglib2/cache/ref/GuardedStrongRefLoaderRemoverCache.java b/src/main/java/net/imglib2/cache/ref/GuardedStrongRefLoaderRemoverCache.java index 5475c45..8e8ef71 100644 --- a/src/main/java/net/imglib2/cache/ref/GuardedStrongRefLoaderRemoverCache.java +++ b/src/main/java/net/imglib2/cache/ref/GuardedStrongRefLoaderRemoverCache.java @@ -72,6 +72,8 @@ * key type * @param * value type + * @param + * value data type, see {@link CacheRemover} * * @author Tobias Pietzsch */ From e23e78ae55ae2e6e497339cf12a97620bd77f8cb Mon Sep 17 00:00:00 2001 From: tpietzsch Date: Thu, 1 Feb 2024 14:13:44 +0100 Subject: [PATCH 7/7] Use CellGrid.CellDimensionsAndSteps --- .../net/imglib2/cache/img/DiskCellCache.java | 16 +++++++--------- .../imglib2/cache/img/EmptyCellCacheLoader.java | 9 ++++----- .../imglib2/cache/img/LoadedCellCacheLoader.java | 10 +++++----- .../cache/img/RandomAccessibleCacheLoader.java | 14 ++++++-------- .../util/IntervalKeyLoaderAsLongKeyLoader.java | 12 ++++++------ 5 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/main/java/net/imglib2/cache/img/DiskCellCache.java b/src/main/java/net/imglib2/cache/img/DiskCellCache.java index fc7bef5..464d252 100644 --- a/src/main/java/net/imglib2/cache/img/DiskCellCache.java +++ b/src/main/java/net/imglib2/cache/img/DiskCellCache.java @@ -55,6 +55,7 @@ import net.imglib2.cache.IoSync; import net.imglib2.img.cell.Cell; import net.imglib2.img.cell.CellGrid; +import net.imglib2.img.cell.CellGrid.CellDimensionsAndSteps; import net.imglib2.util.Fraction; import net.imglib2.util.Intervals; @@ -125,16 +126,14 @@ public Cell< A > get( final Long key ) throws Exception if ( new File( filename ).exists() ) { final long[] cellMin = new long[ n ]; - final int[] cellDims = new int[ n ]; - grid.getCellDimensions( index, cellMin, cellDims ); - final long numEntities = entitiesPerPixel.mulCeil( Intervals.numElements( cellDims ) ); + final CellDimensionsAndSteps dimsAndSteps = grid.getCellDimensions( index, cellMin ); + final long numEntities = entitiesPerPixel.mulCeil( dimsAndSteps.numPixels() ); final long bytesize = numEntities * accessIo.getBytesPerElement(); - try ( - final RandomAccessFile mmFile = new RandomAccessFile( filename, "r" ); ) + try ( final RandomAccessFile mmFile = new RandomAccessFile( filename, "r" ) ) { final MappedByteBuffer in = mmFile.getChannel().map( MapMode.READ_ONLY, 0, bytesize ); final A access = accessIo.load( in, ( int ) numEntities ); - return new Cell<>( cellDims, cellMin, access ); + return new Cell<>( dimsAndSteps, cellMin, access ); } } else @@ -154,9 +153,8 @@ public Cell< A > reconstruct( final Long key, final A valueData ) { final long index = key; final long[] cellMin = new long[ n ]; - final int[] cellDims = new int[ n ]; - grid.getCellDimensions( index, cellMin, cellDims ); - return new Cell<>( cellDims, cellMin, valueData ); + final CellDimensionsAndSteps dimsAndSteps = grid.getCellDimensions( index, cellMin ); + return new Cell<>( dimsAndSteps, cellMin, valueData ); } @Override diff --git a/src/main/java/net/imglib2/cache/img/EmptyCellCacheLoader.java b/src/main/java/net/imglib2/cache/img/EmptyCellCacheLoader.java index 06c6ed0..9a65fa2 100644 --- a/src/main/java/net/imglib2/cache/img/EmptyCellCacheLoader.java +++ b/src/main/java/net/imglib2/cache/img/EmptyCellCacheLoader.java @@ -41,10 +41,10 @@ import net.imglib2.img.basictypeaccess.array.ArrayDataAccess; import net.imglib2.img.cell.Cell; import net.imglib2.img.cell.CellGrid; +import net.imglib2.img.cell.CellGrid.CellDimensionsAndSteps; import net.imglib2.type.NativeType; import net.imglib2.type.PrimitiveType; import net.imglib2.util.Fraction; -import net.imglib2.util.Intervals; /** * A {@link CacheLoader} that produces empty cells of {@link ArrayDataAccess} @@ -84,10 +84,9 @@ public Cell< A > get( final Long key ) throws Exception { final long index = key; final long[] cellMin = new long[ grid.numDimensions() ]; - final int[] cellDims = new int[ grid.numDimensions() ]; - grid.getCellDimensions( index, cellMin, cellDims ); - final long numEntities = entitiesPerPixel.mulCeil( Intervals.numElements( cellDims ) ); - return new Cell<>( cellDims, cellMin, creator.createArray( ( int ) numEntities ) ); + final CellDimensionsAndSteps dimsAndSteps = grid.getCellDimensions( index, cellMin ); + final long numEntities = entitiesPerPixel.mulCeil( dimsAndSteps.numPixels() ); + return new Cell<>( dimsAndSteps, cellMin, creator.createArray( ( int ) numEntities ) ); } public static < T extends NativeType< T >, A extends ArrayDataAccess< A > > EmptyCellCacheLoader< A > get( diff --git a/src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java b/src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java index cc55df0..1090c18 100644 --- a/src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java +++ b/src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java @@ -58,6 +58,7 @@ import net.imglib2.img.basictypeaccess.array.ShortArray; import net.imglib2.img.cell.Cell; import net.imglib2.img.cell.CellGrid; +import net.imglib2.img.cell.CellGrid.CellDimensionsAndSteps; import net.imglib2.type.NativeType; import net.imglib2.type.PrimitiveType; import net.imglib2.util.Fraction; @@ -115,14 +116,13 @@ public Cell< A > get( final Long key ) throws Exception { final long index = key; final long[] cellMin = new long[ grid.numDimensions() ]; - final int[] cellDims = new int[ grid.numDimensions() ]; - grid.getCellDimensions( index, cellMin, cellDims ); - final long numEntities = entitiesPerPixel.mulCeil( Intervals.numElements( cellDims ) ); + final CellDimensionsAndSteps dimsAndSteps = grid.getCellDimensions( index, cellMin ); + final long numEntities = entitiesPerPixel.mulCeil( dimsAndSteps.numPixels() ); final A array = creator.createArray( ( int ) numEntities ); @SuppressWarnings( { "rawtypes", "unchecked" } ) - final SingleCellArrayImg< T, ? > img = new SingleCellArrayImg( cellDims, cellMin, wrapper.wrap( array ), wrapper.wrapDirty( array ), type ); + final SingleCellArrayImg< T, ? > img = new SingleCellArrayImg( dimsAndSteps.dimensions(), cellMin, wrapper.wrap( array ), wrapper.wrapDirty( array ), type ); loader.load( img ); - return new Cell<>( cellDims, cellMin, array ); + return new Cell<>( dimsAndSteps, cellMin, array ); } public static < T extends NativeType< T >, A extends ArrayDataAccess< A > > LoadedCellCacheLoader< T, A > get( diff --git a/src/main/java/net/imglib2/cache/img/RandomAccessibleCacheLoader.java b/src/main/java/net/imglib2/cache/img/RandomAccessibleCacheLoader.java index dd09ba0..bf1603c 100644 --- a/src/main/java/net/imglib2/cache/img/RandomAccessibleCacheLoader.java +++ b/src/main/java/net/imglib2/cache/img/RandomAccessibleCacheLoader.java @@ -36,6 +36,7 @@ import static net.imglib2.img.basictypeaccess.AccessFlags.DIRTY; import static net.imglib2.img.basictypeaccess.AccessFlags.VOLATILE; +import java.util.Arrays; import java.util.Set; import java.util.function.Function; @@ -78,11 +79,11 @@ import net.imglib2.img.basictypeaccess.volatiles.array.VolatileShortArray; import net.imglib2.img.cell.Cell; import net.imglib2.img.cell.CellGrid; +import net.imglib2.img.cell.CellGrid.CellDimensionsAndSteps; import net.imglib2.type.NativeType; import net.imglib2.type.PrimitiveType; import net.imglib2.type.NativeTypeFactory; import net.imglib2.util.Fraction; -import net.imglib2.util.Intervals; import net.imglib2.view.Views; /** @@ -151,22 +152,19 @@ public Cell< CA > get( final Long key ) throws Exception final int n = grid.numDimensions(); final long[] cellMin = new long[ n ]; - final int[] cellDims = new int[ n ]; final long[] cellMax = new long[ n ]; - - grid.getCellDimensions( index, cellMin, cellDims ); - final long numEntities = entitiesPerPixel.mulCeil( Intervals.numElements( cellDims ) ); + final CellDimensionsAndSteps dimsAndSteps = grid.getCellDimensions( index, cellMin ); + Arrays.setAll( cellMax, d -> cellMin[ d ] + dimsAndSteps.dimensions()[ d ] - 1 ); + final long numEntities = entitiesPerPixel.mulCeil( dimsAndSteps.numPixels() ); final A data = creator.createArray( ( int ) numEntities ); final T t = createType( data ); t.updateIndex( 0 ); - for ( int d = 0; d < n; ++d ) - cellMax[ d ] = cellMin[ d ] + cellDims[ d ] - 1; for ( final T s : Views.interval( source, cellMin, cellMax ) ) { t.set( s ); t.incIndex(); } - return new Cell<>( cellDims, cellMin, rewrap.apply( data ) ); + return new Cell<>( dimsAndSteps, cellMin, rewrap.apply( data ) ); } public static < T extends NativeType< T >, A extends ArrayDataAccess< A >, CA extends ArrayDataAccess< CA > > RandomAccessibleCacheLoader< T, A, CA > get( diff --git a/src/main/java/net/imglib2/cache/util/IntervalKeyLoaderAsLongKeyLoader.java b/src/main/java/net/imglib2/cache/util/IntervalKeyLoaderAsLongKeyLoader.java index 2da5bde..0125544 100644 --- a/src/main/java/net/imglib2/cache/util/IntervalKeyLoaderAsLongKeyLoader.java +++ b/src/main/java/net/imglib2/cache/util/IntervalKeyLoaderAsLongKeyLoader.java @@ -33,8 +33,8 @@ */ package net.imglib2.cache.util; +import java.util.Arrays; import java.util.function.Function; -import java.util.stream.IntStream; import net.imglib2.FinalInterval; import net.imglib2.Interval; @@ -79,10 +79,10 @@ public Cell< A > get( final Long key ) final int n = grid.numDimensions(); final long[] cellMin = new long[ n ]; - final int[] cellDims = new int[ n ]; - grid.getCellDimensions( index, cellMin, cellDims ); - final long[] cellMax = IntStream.range( 0, n ).mapToLong( d -> cellMin[ d ] + cellDims[ d ] - 1 ).toArray(); - final A result = intervalKeyLoader.apply( new FinalInterval( cellMin, cellMax ) ); - return new Cell<>( cellDims, cellMin, result ); + final long[] cellMax = new long[ n ]; + final CellGrid.CellDimensionsAndSteps dimsAndSteps = grid.getCellDimensions( index, cellMin ); + Arrays.setAll( cellMax, d -> cellMin[ d ] + dimsAndSteps.dimensions()[ d ] - 1 ); + final A result = intervalKeyLoader.apply( FinalInterval.wrap( cellMin, cellMax ) ); + return new Cell<>( dimsAndSteps, cellMin, result ); } }