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 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 ) ); }
@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 ); }
@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 ) ); } };
@Override public Cell< A > get( final Long key ) { final long index = 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 ); } }
@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 ) ); 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 ); loader.load( img ); return new Cell<>( cellDims, cellMin, array ); }
@Override public Cell< CA > get( final Long key ) throws Exception { final long index = key; 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 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 ) ); }
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; }
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; }