Class ConvertTo<T>
Object
ConvertTo<T>
- Type Parameters:
T
- destination buffer-type
- Direct Known Subclasses:
ToFloat
,ToUnsignedByte
,ToUnsignedInt
,ToUnsignedShort
Converts a subset of raw voxel bytes in a buffer to a possibly a buffer with different data-type.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
The total number of elements (whatever the destination type is) in the destination buffer.protected Extent
The size of the source and destination buffers.protected int
The number of elements (bytes) to increment by, when iterating through the source buffer.protected int
The total number of elements (always bytes) in the source buffer. -
Constructor Summary
ConstructorsConstructorDescriptionConvertTo
(Function<VoxelsUntyped, Voxels<T>> functionCast, IntFunction<T> allocateBuffer, Function<T, VoxelBuffer<T>> wrapBuffer) Creates a newConvertTo
instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
The number bytes to describe each source-voxel.protected T
convert
(ByteBuffer source, int channelIndexRelative, OrientationChange orientationCorrection, boolean littleEndian) Converts a slice of single-channel into a newly created buffer of type TT
.protected VoxelBuffer
<T> convertSliceOfSingleChannel
(ByteBuffer source, int channelIndexRelative, OrientationChange orientationCorrection) Converts a slice of single-channel into a newly createdVoxelBuffer
.void
copyAllChannels
(Dimensions dimensions, ByteBuffer source, DestinationChannelForIndex destination, int z, ImageFileEncoding sourceImageEncoding, OrientationChange orientationCorrection) Copies the channels in the source buffer into a particularDestinationChannelForIndex
.protected abstract void
copyChangeOrientation
(ByteBuffer source, boolean littleEndian, int channelIndexRelative, T destination, OrientationChange orientationCorrection) Copy the bytes, changing orientation.protected abstract void
copyKeepOrientation
(ByteBuffer source, boolean littleEndian, int channelIndexRelative, T destination) Copy the bytes, without changing orientation.protected void
setupBefore
(Dimensions dimensions, ImageFileEncoding sourceImageEncoding) Always called before any batch of calls toconvertSliceOfSingleChannel(java.nio.ByteBuffer, int, org.anchoranalysis.image.core.dimensions.OrientationChange)
.protected abstract boolean
Whether the source buffer can encode more than one channel?
-
Field Details
-
extent
The size of the source and destination buffers. -
sourceIncrement
protected int sourceIncrementThe number of elements (bytes) to increment by, when iterating through the source buffer. -
sourceSize
protected int sourceSizeThe total number of elements (always bytes) in the source buffer. -
destinationSize
protected int destinationSizeThe total number of elements (whatever the destination type is) in the destination buffer.
-
-
Constructor Details
-
ConvertTo
public ConvertTo(Function<VoxelsUntyped, Voxels<T>> functionCast, IntFunction<T> allocateBuffer, Function<T, VoxelBuffer<T>> wrapBuffer) Creates a newConvertTo
instance.- Parameters:
functionCast
- How to convert aVoxelsUntyped
to the specific destination-type.allocateBuffer
- A function that creates a new buffer of typeT
of a given size.wrapBuffer
- A function to wrap a buffer of typeT
into aVoxelBuffer
.
-
-
Method Details
-
copyAllChannels
public void copyAllChannels(Dimensions dimensions, ByteBuffer source, DestinationChannelForIndex destination, int z, ImageFileEncoding sourceImageEncoding, OrientationChange orientationCorrection) throws IOException Copies the channels in the source buffer into a particularDestinationChannelForIndex
.- Parameters:
dimensions
- scene-dimension.source
- the buffer we copy all channels from.destination
- finds an appropriate destination channel for a particular relative-channel-index.z
- the current slice we are working on.sourceImageEncoding
- how voxels are stored in the source-image.orientationCorrection
- any correction of orientation to be applied as bytes are converted.- Throws:
IOException
- if any error occurs when copying channels.
-
setupBefore
protected void setupBefore(Dimensions dimensions, ImageFileEncoding sourceImageEncoding) throws IOException Always called before any batch of calls toconvertSliceOfSingleChannel(java.nio.ByteBuffer, int, org.anchoranalysis.image.core.dimensions.OrientationChange)
.- Parameters:
dimensions
- the final dimensions of the image.sourceImageEncoding
- how voxels are stored in the source-image.- Throws:
IOException
- if a particular combination of parameters is unsupported.
-
convertSliceOfSingleChannel
protected VoxelBuffer<T> convertSliceOfSingleChannel(ByteBuffer source, int channelIndexRelative, OrientationChange orientationCorrection) throws IOException Converts a slice of single-channel into a newly createdVoxelBuffer
.- Parameters:
source
- source buffer containing the bytes we copy from.channelIndexRelative
- 0 if the buffer is non interleaved, or otherwise the index of the channel among the interleaved channels.orientationCorrection
- any correction of orientation to be applied as bytes are converted.- Returns:
- the converted buffer.
- Throws:
IOException
- when operation is unsupported, given particular parameterization.
-
convert
protected T convert(ByteBuffer source, int channelIndexRelative, OrientationChange orientationCorrection, boolean littleEndian) throws IOException Converts a slice of single-channel into a newly created buffer of type TT
.- Parameters:
source
- source buffer containing the bytes we copy from.channelIndexRelative
- 0 if the buffer is non interleaved, or otherwise the index of the channel among the interleaved channels.orientationCorrection
- any correction of orientation to be applied as bytes are converted.littleEndian
- true iff the bytes insource
are in little-endian order.- Returns:
- the converted buffer.
- Throws:
IOException
- when operation is unsupported, given particular parameterization.
-
copyKeepOrientation
protected abstract void copyKeepOrientation(ByteBuffer source, boolean littleEndian, int channelIndexRelative, T destination) throws IOException Copy the bytes, without changing orientation.This is kept separate to
copyChangeOrientation(java.nio.ByteBuffer, boolean, int, T, org.anchoranalysis.image.core.dimensions.OrientationChange)
as it can be done slightly more efficiently.- Parameters:
source
- the buffer we copy all channels from.littleEndian
- true iff the bytes insource
are in little-endian order.channelIndexRelative
- 0 if the buffer is non interleaved, or otherwise the index of the channel among the interleaved channels.destination
- finds an appropriate destination channel for a particular relative-channel-index.- Throws:
IOException
- when the operation fails due to read or write IO problems.
-
copyChangeOrientation
protected abstract void copyChangeOrientation(ByteBuffer source, boolean littleEndian, int channelIndexRelative, T destination, OrientationChange orientationCorrection) throws IOException Copy the bytes, changing orientation.- Parameters:
source
- the buffer we copy all channels from.littleEndian
- true iff the bytes insource
are in little-endian order.channelIndexRelative
- 0 if the buffer is non interleaved, or otherwise the index of the channel among the interleaved channels.destination
- finds an appropriate destination channel for a particular relative-channel-index.orientationCorrection
- any correction of orientation to be applied as bytes are converted.- Throws:
IOException
- when the operation fails due to read or write IO problems.
-
supportsMultipleChannelsPerSourceBuffer
protected abstract boolean supportsMultipleChannelsPerSourceBuffer()Whether the source buffer can encode more than one channel?- Returns:
- true if this possible (either with interleaving or with RGB-encoded voxels), false if a buffer will always describe one channel only.
-
bytesPerVoxel
protected abstract int bytesPerVoxel()The number bytes to describe each source-voxel.- Returns:
- the number of bytes.
-