protected < S extends NativeType< S > > VolatileCachedCellImg< S, A > prepareCachedImage( final int timepointId, final int level, final LoadingStrategy loadingStrategy, final S t ) { final int priority = resolutions.length - 1 - level; final CacheHints cacheHints = new CacheHints( loadingStrategy, priority, false ); final CellGrid grid = new CellGrid( dimensions[ level ], cellDimensions[level ] ); return cache.createImg( grid, timepointId, setupId, level, cacheHints, loader, t ); }
@Override public Cell< A > get( final Long key ) throws Exception { final int n = grid.numDimensions(); final long[] cellMin = new long[ n ]; final int[] cellDims = new int[ n ]; grid.getCellDimensions( key, cellMin, cellDims ); return new Cell<>( cellDims, cellMin, cacheArrayLoader.loadArray( timepoint, setup, level, cellDims, cellMin ) ); } };
public LazyCellImg( final CellGrid grid, final Fraction entitiesPerPixel, final Get< Cell< A > > get ) { super( grid, new LazyCells<>( grid.getGridDimensions(), get ), entitiesPerPixel ); }
private < A extends ArrayDataAccess< A > > CellImg< T, A > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { verifyDimensions( dimensions ); final int n = dimensions.length; final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); final int[] cellDimensions = getCellDimensions( defaultCellDimensions, n, entitiesPerPixel ); final CellGrid grid = new CellGrid( dimensions, cellDimensions ); final long[] gridDimensions = new long[ grid.numDimensions() ]; grid.gridDimensions( gridDimensions ); final Cell< A > cellType = new Cell<>( new int[] { 1 }, new long[] { 1 }, null ); final ListImg< Cell< A > > cells = new ListImg<>( gridDimensions, cellType ); final long[] cellGridPosition = new long[ n ]; final long[] cellMin = new long[ n ]; final int[] cellDims = new int[ n ]; final ListLocalizingCursor< Cell< A > > cellCursor = cells.localizingCursor(); while ( cellCursor.hasNext() ) { cellCursor.fwd(); cellCursor.localize( cellGridPosition ); grid.getCellDimensions( cellGridPosition, cellMin, cellDims ); final A data = ArrayDataAccessFactory.get( typeFactory ).createArray( ( int ) entitiesPerPixel.mulCeil( Intervals.numElements( cellDims ) ) ); cellCursor.set( new Cell<>( cellDims, cellMin, data ) ); } final CellImg< T, A > img = new CellImg<>( this, grid, cells, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }
public CellRandomAccess( final AbstractCellImg< T, ?, C, ? > img ) { super( img.numDimensions() ); type = img.createLinkedType(); grid = img.getCellGrid(); randomAccessOnCells = img.getCells().randomAccess(); cellDims = new int[ n ]; dimensions = new long[ n ]; img.getCellGrid().cellDimensions( cellDims ); img.getCellGrid().imgDimensions( dimensions ); isOutOfBounds = false; oobCellMin = new long[ n ]; oobCellMax = new long[ n ]; for ( int d = 0; d < n; ++d ) { oobCellMin[ d ] = Long.MAX_VALUE; oobCellMax[ d ] = Long.MIN_VALUE; } img.getCellGrid().getCellPosition( position, randomAccessOnCells ); updatePosition( false ); }
private < T extends NativeType< T > > void testDefaultCellSize( final T type ) { final int defaultCellSize = 43; final int[] expectedCellDims = { 43, 43, 43, 43 }; final CellImgFactory< T > factory = new CellImgFactory<>( type, defaultCellSize ); final long[] dimension = { 100, 80, 4, 3 }; final CellImg< T, ? > img = factory.create( dimension ); final int[] cellDims = new int[ dimension.length ]; img.getCellGrid().cellDimensions( cellDims ); assertArrayEquals( expectedCellDims, cellDims ); }
public DiskCellCache( final Path blockcache, final CellGrid grid, final CacheLoader< Long, Cell< A > > backingLoader, final AccessIo< A > accessIo, final Fraction entitiesPerPixel ) { this.blockcache = blockcache; this.grid = grid; this.n = grid.numDimensions(); this.entitiesPerPixel = entitiesPerPixel; this.accessIo = accessIo; this.backingLoader = backingLoader; }
@Override public Cell< A > get( final Long key ) throws Exception { final long index = key; final String filename = blockname( index ); 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 long bytesize = numEntities * accessIo.getBytesPerElement(); 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 ); } } else { return backingLoader.get( key ); } }
/** * To be equal an object has to be a {@link CellIterationOrder} on a * {@link CellImg} of the same dimensions and cell-dimensions. * * @return true, if obj is a compatible {@link CellIterationOrder}. */ @Override public boolean equals( final Object obj ) { if ( !( obj instanceof CellIterationOrder ) ) return false; final AbstractCellImg< ?, ?, ?, ? > other = ( ( CellIterationOrder ) obj ).img; return other.getCellGrid().equals( img.getCellGrid() ) && other.getCells().iterationOrder().equals( img.getCells().iterationOrder() ); } }
grid.getCellPosition( position, randomAccessOnCells );
private < A extends ArrayDataAccess< A > > CellImg< T, A > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { verifyDimensions( dimensions ); final int n = dimensions.length; final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); final int[] cellDimensions = getCellDimensions( defaultCellDimensions, n, entitiesPerPixel ); final CellGrid grid = new CellGrid( dimensions, cellDimensions ); final long[] gridDimensions = new long[ grid.numDimensions() ]; grid.gridDimensions( gridDimensions ); final Cell< A > cellType = new Cell<>( new int[] { 1 }, new long[] { 1 }, null ); final ListImg< Cell< A > > cells = new ListImg<>( gridDimensions, cellType ); final long[] cellGridPosition = new long[ n ]; final long[] cellMin = new long[ n ]; final int[] cellDims = new int[ n ]; final ListLocalizingCursor< Cell< A > > cellCursor = cells.localizingCursor(); while ( cellCursor.hasNext() ) { cellCursor.fwd(); cellCursor.localize( cellGridPosition ); grid.getCellDimensions( cellGridPosition, cellMin, cellDims ); final A data = ArrayDataAccessFactory.get( typeFactory ).createArray( ( int ) entitiesPerPixel.mulCeil( Intervals.numElements( cellDims ) ) ); cellCursor.set( new Cell<>( cellDims, cellMin, data ) ); } final CellImg< T, A > img = new CellImg<>( this, grid, cells, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }
public CellRandomAccess( final AbstractCellImg< T, ?, C, ? > img ) { super( img.numDimensions() ); type = img.createLinkedType(); grid = img.getCellGrid(); randomAccessOnCells = img.getCells().randomAccess(); cellDims = new int[ n ]; dimensions = new long[ n ]; img.getCellGrid().cellDimensions( cellDims ); img.getCellGrid().imgDimensions( dimensions ); isOutOfBounds = false; oobCellMin = new long[ n ]; oobCellMax = new long[ n ]; for ( int d = 0; d < n; ++d ) { oobCellMin[ d ] = Long.MAX_VALUE; oobCellMax[ d ] = Long.MIN_VALUE; } img.getCellGrid().getCellPosition( position, randomAccessOnCells ); updatePosition( false ); }
private < T extends NativeType< T > > void testDefaultCellDimensions( final T type ) { final int[] defaultCellDims = { 6, 8, 5, 3 }; final int[] expectedCellDims = defaultCellDims.clone(); final CellImgFactory< T > factory = new CellImgFactory<>( type, defaultCellDims ); final long[] dimension = { 100, 80, 4, 3 }; final CellImg< T, ? > img = factory.create( dimension ); final int[] cellDims = new int[ dimension.length ]; img.getCellGrid().cellDimensions( cellDims ); assertArrayEquals( expectedCellDims, cellDims ); }
/** * To be equal an object has to be a {@link CellIterationOrder} on a * {@link CellImg} of the same dimensions and cell-dimensions. * * @return true, if obj is a compatible {@link CellIterationOrder}. */ @Override public boolean equals( final Object obj ) { if ( !( obj instanceof CellIterationOrder ) ) return false; final AbstractCellImg< ?, ?, ?, ? > other = ( ( CellIterationOrder ) obj ).img; return other.getCellGrid().equals( img.getCellGrid() ) && other.getCells().iterationOrder().equals( img.getCells().iterationOrder() ); } }
grid.getCellPosition( position, randomAccessOnCells );
@Override 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 ) ); }
/** * Create a {@link VolatileCachedCellImg} backed by the cache. The type * should be either {@link ARGBType} and {@link VolatileARGBType}. */ protected < T extends NativeType< T > > VolatileCachedCellImg< T, VolatileByteArray > prepareCachedImage( final int timepointId, final int setupId, final int level, final LoadingStrategy loadingStrategy, final T type ) { final long[] dimensions = imageDimensions[ level ]; final int[] cellDimensions = blockDimensions[ level ]; final CellGrid grid = new CellGrid( dimensions, cellDimensions ); final int priority = numScales - 1 - level; final CacheHints cacheHints = new CacheHints( loadingStrategy, priority, false ); return cache.createImg( grid, timepointId, setupId, level, cacheHints, loader, type ); }
cellImg.getCellGrid().cellDimensions( cellDimensions ); final long[] dimensions = new long[ 3 ]; cellImg.dimensions( dimensions );
public LazyCellImg( final CellGrid grid, final Fraction entitiesPerPixel, final Get< Cell< A > > get ) { super( grid, new LazyCells<>( grid.getGridDimensions(), get ), entitiesPerPixel ); }
@Override public Cell< A > createInvalid( 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 A data = creator.getEmptyArray( numEntities ); return new Cell<>( cellDims, cellMin, data ); }