ImagePlusImg( final A creator, final long[] dim, final int entitiesPerPixel ) { this( dim, entitiesPerPixel ); mirror.clear(); for ( int i = 0; i < numSlices; ++i ) mirror.add( creator.createArray( width * height * entitiesPerPixel ) ); }
private static < A extends ArrayDataAccess< A > > List< A > createSlices( A creator, long[] dim, Fraction entitiesPerPixel ) { int numSlices = numberOfSlices( dim ); List< A > mirror = new ArrayList<>( numSlices ); final int pixelsPerPlane = (int) (( ( dim.length > 1 ) ? dim[ 1 ] : 1 ) * dim[ 0 ]); final int numEntitiesPerSlice = ( int ) entitiesPerPixel.mulCeil( pixelsPerPlane ); for ( int i = 0; i < numSlices; ++i ) mirror.add( creator.createArray( numEntitiesPerSlice ) ); return mirror; } }
private static < A extends ArrayDataAccess< A > > List< A > createSlices( A creator, long[] dim, Fraction entitiesPerPixel ) { int numSlices = numberOfSlices( dim ); List< A > mirror = new ArrayList<>( numSlices ); final int pixelsPerPlane = (int) (( ( dim.length > 1 ) ? dim[ 1 ] : 1 ) * dim[ 0 ]); final int numEntitiesPerSlice = ( int ) entitiesPerPixel.mulCeil( pixelsPerPlane ); for ( int i = 0; i < numSlices; ++i ) mirror.add( creator.createArray( numEntitiesPerSlice ) ); return mirror; } }
@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 ) ); }
private < A extends ArrayDataAccess< A > > ArrayImg< T, A > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); final int numEntities = numEntitiesRangeCheck( dimensions, entitiesPerPixel ); final A data = ArrayDataAccessFactory.get( typeFactory ).createArray( numEntities ); final ArrayImg< T, A > img = new ArrayImg<>( data, dimensions, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }
private < A extends ArrayDataAccess< A > > ArrayImg< T, A > create( final long[] dimensions, final T type, final NativeTypeFactory< T, A > typeFactory ) { final Fraction entitiesPerPixel = type.getEntitiesPerPixel(); final int numEntities = numEntitiesRangeCheck( dimensions, entitiesPerPixel ); final A data = ArrayDataAccessFactory.get( typeFactory ).createArray( numEntities ); final ArrayImg< T, A > img = new ArrayImg<>( data, dimensions, entitiesPerPixel ); img.setLinkedType( typeFactory.createLinkedType( img ) ); return img; }
@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 ) ); }
@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 ); }
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; }