Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of getType() API #24

Merged
merged 7 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>34.0.0</version>
<version>37.0.0</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -113,7 +113,7 @@ Jean-Yves Tinevez and Michael Zinsmaier.</license.copyrightOwners>
<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<imglib2.version>6.1.0</imglib2.version>
<imglib2.version>7.0.0</imglib2.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/cache/IoSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
* @param <V>
* value type
* @param <D>
* value data type
* value data type, see {@link CacheRemover}
*
* @author Tobias Pietzsch
*/
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/net/imglib2/cache/img/DiskCellCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/net/imglib2/cache/img/EmptyCellCacheLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/imglib2/cache/img/LoadedCellCacheLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

/**
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/net/imglib2/cache/img/SingleCellArrayImg.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,6 +214,12 @@ public T get()
return type;
}

@Override
public T getType()
{
return type;
}

@Override
public void fwd( final int d )
{
Expand Down Expand Up @@ -363,6 +375,12 @@ public T get()
return type;
}

@Override
public T getType()
{
return type;
}

@Override
public boolean hasNext()
{
Expand Down Expand Up @@ -450,6 +468,12 @@ public T get()
return type;
}

@Override
public T getType()
{
return type;
}

@Override
public void fwd()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
* key type
* @param <V>
* value type
* @param <D>
* value data type, see {@link CacheRemover}
*
* @author Tobias Pietzsch
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
}
Loading