/** * 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(); }
@Override public DoubleArray wrap( final A access ) { return new DoubleArray( ( double[] ) access.getCurrentStorageArray() ); }
@Override public ShortArray wrap( final A access ) { return new ShortArray( ( short[] ) access.getCurrentStorageArray() ); }
@Override public IntArray wrap( final A access ) { return new IntArray( ( int[] ) access.getCurrentStorageArray() ); }
@Override public LongArray wrap( final A access ) { return new LongArray( ( long[] ) access.getCurrentStorageArray() ); }
@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)); }
@Override public ByteArray wrap( final A access ) { return new ByteArray( ( byte[] ) access.getCurrentStorageArray() ); }
@Override public CharArray wrap( final A access ) { return new CharArray( ( char[] ) access.getCurrentStorageArray() ); }
@Override public FloatArray wrap( final A access ) { return new FloatArray( ( float[] ) access.getCurrentStorageArray() ); }
/** * 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; }
/** * 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; }
@SuppressWarnings("unchecked") @Override public boolean setPlaneSilently(final int planeNum, final Object newPlane) { final Img<? extends RealType<?>> img = imgPlus.getImg(); if (!(img instanceof PlanarAccess)) { // cannot set by reference log.error("Cannot set plane for non-planar image"); return false; } // TODO - copy the plane if it cannot be set by reference @SuppressWarnings("rawtypes") final PlanarAccess planarAccess = (PlanarAccess) img; final ArrayDataAccess<?> arrayAccess = (ArrayDataAccess<?>) planarAccess.getPlane(planeNum); final Object currPlane = arrayAccess.getCurrentStorageArray(); if (newPlane == currPlane) return false; final ArrayDataAccess<?> array = createArrayDataAccess(newPlane); planarAccess.setPlane(planeNum, array); return true; }
@SuppressWarnings("unchecked") @Override public boolean setPlaneSilently(final int planeNum, final Object newPlane) { final Img<? extends RealType<?>> img = imgPlus.getImg(); if (!(img instanceof PlanarAccess)) { // cannot set by reference log.error("Cannot set plane for non-planar image"); return false; } // TODO - copy the plane if it cannot be set by reference @SuppressWarnings("rawtypes") final PlanarAccess planarAccess = (PlanarAccess) img; final ArrayDataAccess<?> arrayAccess = (ArrayDataAccess<?>) planarAccess.getPlane(planeNum); final Object currPlane = arrayAccess.getCurrentStorageArray(); if (newPlane == currPlane) return false; final ArrayDataAccess<?> array = createArrayDataAccess(newPlane); planarAccess.setPlane(planeNum, array); return true; }
final PlanarImg<?, ?> planarImg = (PlanarImg<?, ?>) img; return planarImg.getPlane(cIndex + (planeIndex * rgbChannelCount)) .getCurrentStorageArray();
@Test public void testOverSizedBitImageArrayImgs() { final int numLongs = ( int ) Math.ceil( 100 * 100 / 64d ); final ArrayImg< BitType, LongArray > img = ArrayImgs.bits( 100, 100 ); final Random r = new Random( 42l ); img.forEach( p -> { p.set( r.nextBoolean() ); } ); final long[] storage = ( long[] ) ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray(); final long[] sizes = new long[ img.numDimensions() ]; img.dimensions( sizes ); assertEquals( numLongs, storage.length ); } }
imageProcessor = new ByteProcessor( sizeX, sizeY, ( byte[] ) ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray(), null ); break; case ImagePlus.GRAY16: this.bitDepth = 16; imageProcessor = new ShortProcessor( sizeX, sizeY, ( short[] ) ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray(), null ); break; case ImagePlus.COLOR_RGB: this.bitDepth = 24; imageProcessor = new ColorProcessor( sizeX, sizeY, ( int[] ) ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray() ); break; case ImagePlus.GRAY32: this.bitDepth = 32; imageProcessor = new FloatProcessor( sizeX, sizeY, ( float[] ) ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray(), null );
@Test public void testOverSizedBitImageExplicitStorageArray() { final int numLongs = ( int ) Math.ceil( 100 * 100 / 64d ); final ArrayImg< BitType, LongArray > img = ArrayImgs.bits( new LongArray( new long[ numLongs ] ), 100, 100 ); final Random r = new Random( 42l ); img.forEach( p -> { p.set( r.nextBoolean() ); } ); final long[] storage = ( long[] ) ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray(); final long[] sizes = new long[ img.numDimensions() ]; img.dimensions( sizes ); assertEquals( storage.length, numLongs ); }
@Test public void testOverSizedBitImageImgFactory() { final ArrayImgFactory< BitType > factory = new ArrayImgFactory<>( new BitType() ); // evenly dividable by 64 final int numLongs = 1000 * 1000 / 64; final ArrayImg< BitType, ? > img = factory.create( 1000, 1000 ); final Random r = new Random( 42l ); img.forEach( p -> { p.set( r.nextBoolean() ); } ); final long[] storage = ( long[] ) ( ( ArrayDataAccess< ? > ) img.update( null ) ).getCurrentStorageArray(); final long[] sizes = new long[ img.numDimensions() ]; img.dimensions( sizes ); assertEquals( numLongs, storage.length ); }
return store.getCurrentStorageArray();
return store.getCurrentStorageArray();