Interface PrimitiveBlocks<T extends NativeType<T>>
-
- Type Parameters:
T- pixel type
- All Known Implementing Classes:
FallbackPrimitiveBlocks,ViewPrimitiveBlocks
public interface PrimitiveBlocks<T extends NativeType<T>>Copy blocks of data out of aNativeType<T>source into primitive arrays (of the appropriate type).Use the static method
PrimitiveBlocks.ofto create aPrimitiveBlocksaccessor for an arbitraryRandomAccessiblesource. Then use thecopy(long[], java.lang.Object, int[])method, to copy blocks out of the source into flat primitive arrays.PrimitiveBlocks.ofunderstands a lot of View constructions (that ultimately end inCellImg,ArrayImg, etc) and will try to build an optimized copier. For example, the following will work:CellImg< UnsignedByteType, ? > cellImg3D; RandomAccessible< FloatType > view = Converters.convert( Views.extendBorder( Views.hyperSlice( Views.zeroMin( Views.rotate( cellImg3D, 1, 0 ) ), 2, 80 ) ), new RealFloatConverter<>(), new FloatType() ); PrimitiveBlocks< FloatType > blocks = PrimitiveBlocks.of( view ); final float[] data = new float[ 40 * 50 ]; blocks.copy( new int[] { 10, 20 }, data, new int[] { 40, 50 } );If a source
RandomAccessiblecannot be understood,PrimitiveBlocks.ofwill return a fall-back implementation (based onLoopBuilder).With the optional
OnFallbackargument toPrimitiveBlocks.ofit can be configured, whether fall-back should be silently accepted (ACCEPT), a warning should be printed (WARN), or anIllegalArgumentExceptionthrown (FAIL). The warning/exception message explains why the inputRandomAccessiblerequires fall-back.The only really un-supported case is if the pixel type
Tdoes not map one-to-one to a primitive type. (For example,ComplexDoubleTypeorUnsigned4BitTypeare not supported.)Implementations are not thread-safe in general. Use
threadSafe()to obtain a thread-safe instance (implemented usingThreadLocalcopies). E.g.,PrimitiveBlocks< FloatType > blocks = PrimitiveBlocks.of( view ).threadSafe();
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classPrimitiveBlocks.OnFallback
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidcopy(int[] srcPos, java.lang.Object dest, int[] size)Copy a block from the (T-typed) source into primitive arrays (of the appropriate type).voidcopy(long[] srcPos, java.lang.Object dest, int[] size)Copy a block from the (T-typed) source into primitive arrays (of the appropriate type).TgetType()PrimitiveBlocks<T>independentCopy()static <T extends NativeType<T>>
PrimitiveBlocks<T>of(RandomAccessible<T> ra)Create aPrimitiveBlocksaccessor for an arbitraryRandomAccessiblesource.static <T extends NativeType<T>>
PrimitiveBlocks<T>of(RandomAccessible<T> ra, PrimitiveBlocks.OnFallback onFallback)Create aPrimitiveBlocksaccessor for an arbitraryRandomAccessiblesource.PrimitiveBlocks<T>threadSafe()Get a thread-safe version of thisPrimitiveBlocks.
-
-
-
Method Detail
-
getType
T getType()
-
copy
void copy(long[] srcPos, java.lang.Object dest, int[] size)Copy a block from the (T-typed) source into primitive arrays (of the appropriate type).- Parameters:
srcPos- min coordinate of the block to copydest- primitive array to copy into. Must correspond toT, for example, ifTisUnsignedByteTypethendestmust bebyte[].size- the size of the block to copy
-
copy
default void copy(int[] srcPos, java.lang.Object dest, int[] size)Copy a block from the (T-typed) source into primitive arrays (of the appropriate type).- Parameters:
srcPos- min coordinate of the block to copydest- primitive array to copy into. Must correspond toT, for example, ifTisUnsignedByteTypethendestmust bebyte[].size- the size of the block to copy
-
threadSafe
PrimitiveBlocks<T> threadSafe()
Get a thread-safe version of thisPrimitiveBlocks. (Implemented as a wrapper that makesThreadLocalcopies).
-
independentCopy
PrimitiveBlocks<T> independentCopy()
-
of
static <T extends NativeType<T>> PrimitiveBlocks<T> of(RandomAccessible<T> ra)
Create aPrimitiveBlocksaccessor for an arbitraryRandomAccessiblesource. Many View constructions (that ultimately end inCellImg,ArrayImg, etc.) are understood and will be handled by an optimized copier.If the source
RandomAccessiblecannot be understood, a warning is printed, and a fall-back implementation (based onLoopBuilder) is returned.The returned
PrimitiveBlocksis not thread-safe in general. UsethreadSafe()to obtain a thread-safe instance, e.g.,PrimitiveBlocks.of(view).threadSafe().- Type Parameters:
T- pixel type- Parameters:
ra- the source- Returns:
- a
PrimitiveBlocksaccessor forra.
-
of
static <T extends NativeType<T>> PrimitiveBlocks<T> of(RandomAccessible<T> ra, PrimitiveBlocks.OnFallback onFallback)
Create aPrimitiveBlocksaccessor for an arbitraryRandomAccessiblesource. Many View constructions (that ultimately end inCellImg,ArrayImg, etc.) are understood and will be handled by an optimized copier.If the source
RandomAccessiblecannot be understood, a fall-back implementation (based onLoopBuilder) has to be used. TheonFallbackargument specifies how to handle this case:ACCEPT: silently accept fall-backWARN: accept fall-back, but print a warning explaining why the inputrarequires fall-backFAIL: throwIllegalArgumentExceptionexplaining why the inputrarequires fall-back
PrimitiveBlocksis not thread-safe in general. UsethreadSafe()to obtain a thread-safe instance, e.g.,PrimitiveBlocks.of(view).threadSafe().- Type Parameters:
T- pixel type- Parameters:
ra- the source- Returns:
- a
PrimitiveBlocksaccessor forra.
-
-