Interface PrimitiveBlocks<T extends NativeType<T>>
- Type Parameters:
T- pixel type
- All Known Implementing Classes:
FallbackPrimitiveBlocks, ViewPrimitiveBlocks
NativeType<T> source into primitive
arrays (of the appropriate type).
Use the static method PrimitiveBlocks.of to create a PrimitiveBlocks accessor for an
arbitrary RandomAccessible source.
Then use the copy(long[], Object, int[]) method, to copy blocks out of the
source into flat primitive arrays.
PrimitiveBlocks.of understands a
lot of View constructions (that ultimately end in CellImg,
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 RandomAccessible cannot be understood, PrimitiveBlocks.of will return a
fall-back implementation (based on LoopBuilder).
With the optional OnFallback argument to PrimitiveBlocks.of it can
be configured, whether
fall-back should be silently accepted (ACCEPT),
a warning should be printed (WARN), or
an IllegalArgumentException thrown (FAIL).
The warning/exception message explains why the input RandomAccessible
requires fall-back.
The only really un-supported case is if the pixel type T does not map
one-to-one to a primitive type. (For example, ComplexDoubleType or
Unsigned4BitType are not supported.)
Implementations are not thread-safe in general. Use threadSafe() to
obtain a thread-safe instance (implemented using ThreadLocal copies).
E.g.,
PrimitiveBlocks< FloatType > blocks = PrimitiveBlocks.of( view ).threadSafe();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault voidCopy a block from the (T-typed) source into primitive arrays (of the appropriate type).voidCopy a block from the (T-typed) source into primitive arrays (of the appropriate type).getType()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.Get a thread-safe version of thisPrimitiveBlocks.
-
Method Details
-
getType
T getType() -
copy
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
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
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.
-