/** * Get the single primitive array containing the data of this cell. * * @return primitive array with the cell data. Actual type will be * {@code char[]}, {@code byte[]}, {@code short[]}, {@code int[]}, * {@code long[]}, {@code double[]}, or {@code float[]}, depending * on the pixel type. */ public Object getStorageArray() { return data.getCurrentStorageArray(); }
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 ) ); }
@Override public DoubleArray wrap( final A access ) { return new DoubleArray( ( double[] ) access.getCurrentStorageArray() ); }
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 ShortArray wrap( final A access ) { return new ShortArray( ( short[] ) access.getCurrentStorageArray() ); }
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 IntArray wrap( final A access ) { return new IntArray( ( int[] ) access.getCurrentStorageArray() ); }
@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 LongArray wrap( final A access ) { return new LongArray( ( long[] ) access.getCurrentStorageArray() ); }
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 void compute(final ArrayImg<T, A> input, final ArrayImg<T, A> output) { final Object inArray = input.update(null).getCurrentStorageArray(); System.arraycopy(inArray, 0, output.update(null) .getCurrentStorageArray(), 0, Array.getLength(inArray)); }
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 ByteArray wrap( final A access ) { return new ByteArray( ( byte[] ) access.getCurrentStorageArray() ); }
@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 CharArray wrap( final A access ) { return new CharArray( ( char[] ) access.getCurrentStorageArray() ); }
@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 FloatArray wrap( final A access ) { return new FloatArray( ( float[] ) access.getCurrentStorageArray() ); }
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; }
/** * gets a plane of data from the Dataset. The representation of the plane is * determined by the native ImgLib container. The behavior of this method when * a reference to the actual data cannot be obtained depends upon the value of * the input copyOK boolean. If copyOK is true a copy of the data is created * and returned. If copyOK is false null is returned. */ @Override public Object getPlane(final int planeNumber, final boolean copyOK) { final Img<? extends RealType<?>> img = imgPlus.getImg(); if (img instanceof PlanarAccess) { final PlanarAccess<?> planarAccess = (PlanarAccess<?>) img; final Object plane = planarAccess.getPlane(planeNumber); if (plane instanceof ArrayDataAccess) return ((ArrayDataAccess<?>) plane) .getCurrentStorageArray(); } if (copyOK) return copyOfPlane(planeNumber); return null; }
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; }