T - pixel typepublic interface PrimitiveBlocks<T extends NativeType<T>> extends Typed<T>, EuclideanSpace
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(net.imglib2.Interval, java.lang.Object) 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();
| Modifier and Type | Interface and Description |
|---|---|
static class |
PrimitiveBlocks.OnFallback |
| Modifier and Type | Method and Description |
|---|---|
default void |
copy(int[] srcPos,
Object dest,
int[] size)
Copy a block from the (
T-typed) source into primitive arrays (of
the appropriate type). |
void |
copy(Interval interval,
Object dest)
Copy a block from the (
T-typed) source into primitive arrays (of
the appropriate type). |
default void |
copy(long[] srcPos,
Object dest,
int[] size)
Copy a block from the (
T-typed) source into primitive arrays (of
the appropriate type). |
PrimitiveBlocks<T> |
independentCopy() |
static <T extends NativeType<T>> |
of(RandomAccessible<T> ra)
Create a
PrimitiveBlocks accessor for an arbitrary RandomAccessible source. |
static <T extends NativeType<T>> |
of(RandomAccessible<T> ra,
PrimitiveBlocks.OnFallback onFallback)
Create a
PrimitiveBlocks accessor for an arbitrary RandomAccessible source. |
PrimitiveBlocks<T> |
threadSafe()
Get a thread-safe version of this
PrimitiveBlocks. |
numDimensionsvoid copy(Interval interval, Object dest)
T-typed) source into primitive arrays (of
the appropriate type).interval - position and size of the block to copydest - primitive array to copy into. Must correspond to T, for
example, if T is UnsignedByteType then dest must
be byte[].default void copy(long[] srcPos,
Object dest,
int[] size)
T-typed) source into primitive arrays (of
the appropriate type).srcPos - min coordinate of the block to copydest - primitive array to copy into. Must correspond to T, for
example, if T is UnsignedByteType then dest must
be byte[].size - the size of the block to copydefault void copy(int[] srcPos,
Object dest,
int[] size)
T-typed) source into primitive arrays (of
the appropriate type).srcPos - min coordinate of the block to copydest - primitive array to copy into. Must correspond to T, for
example, if T is UnsignedByteType then dest must
be byte[].size - the size of the block to copyPrimitiveBlocks<T> threadSafe()
PrimitiveBlocks.
(Implemented as a wrapper that makes ThreadLocal copies).PrimitiveBlocks<T> independentCopy()
static <T extends NativeType<T>> PrimitiveBlocks<T> of(RandomAccessible<T> ra)
PrimitiveBlocks accessor for an arbitrary RandomAccessible source. Many View constructions (that ultimately end in
CellImg, ArrayImg, etc.) are understood and will be
handled by an optimized copier.
If the source RandomAccessible cannot be understood, a warning is
printed, and a fall-back implementation (based on LoopBuilder) is
returned.
The returned PrimitiveBlocks is not thread-safe in general. Use
threadSafe() to obtain a thread-safe instance, e.g., PrimitiveBlocks.of(view).threadSafe().
T - pixel typera - the sourcePrimitiveBlocks accessor for ra.static <T extends NativeType<T>> PrimitiveBlocks<T> of(RandomAccessible<T> ra, PrimitiveBlocks.OnFallback onFallback)
PrimitiveBlocks accessor for an arbitrary RandomAccessible source. Many View constructions (that ultimately end in
CellImg, ArrayImg, etc.) are understood and will be
handled by an optimized copier.
If the source RandomAccessible cannot be understood, a fall-back
implementation (based on LoopBuilder) has to be used. The onFallback argument specifies how to handle this case:
ACCEPT: silently accept fall-backWARN: accept fall-back, but print a warning explaining why the input ra requires fall-backFAIL: throw IllegalArgumentException explaining why the input ra requires fall-backPrimitiveBlocks is not thread-safe in general. Use
threadSafe() to obtain a thread-safe instance, e.g., PrimitiveBlocks.of(view).threadSafe().T - pixel typera - the sourcePrimitiveBlocks accessor for ra.Copyright © 2009–2024 ImgLib2. All rights reserved.