Package nom.tam.image
Class StandardImageTiler
java.lang.Object
nom.tam.image.StandardImageTiler
- All Implemented Interfaces:
ImageTiler
- Direct Known Subclasses:
ImageData.ImageDataTiler
Standard image tiling implementation. FITS tiles are always 2-dimentional, but really images of any dimensions may be covered with such tiles.
Modified May 2, 2000 by T. McGlynn to permit tiles that go off the edge of the image.
-
Constructor Summary
ConstructorsConstructorDescriptionStandardImageTiler
(RandomAccess f, long fileOffset, int[] dims, Class<?> base) Create a tiler. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
fillFileData
(Object output, long delta, int outputOffset, int segment) File a tile segment from a file using a default value for striding.protected void
fillFileData
(Object output, long delta, int outputOffset, int segment, int step) File a tile segment from a file, jumping each step number of values to the next read.protected void
fillFileData
(ArrayDataOutput output, long delta, int segment) File a tile segment from a file into the given stream.protected void
fillFileData
(ArrayDataOutput output, long delta, int segment, int step) File a tile segment from a file into the given stream.protected void
fillMemData
(Object data, int[] posits, int length, Object output, int outputOffset, int dim) Fill a single segment from memory.protected void
fillMemData
(Object data, int[] posits, int length, Object output, int outputOffset, int dim, int step) Fill a single segment from memory.protected void
Fill the subset using a default value for striding.protected void
Fill the subset, jumping each step value to the next read.Returns the entire image reconstructed from the available tiles.protected abstract Object
See if we can get the image data from memory.static long
getOffset
(int[] dims, int[] pos) getTile
(int[] corners, int[] lengths) Returns a tile from the image of the specified size at the specified location.getTile
(int[] corners, int[] lengths, int[] steps) Returns a sparsely sampled tile from the image of the specified size at the specified location.void
Fills the supplied array or output stream with the data from an image tile of the specified size at the specified location.void
Fills the supplied array our output stream with the sparsely sampled data from an image tile of the specified size at the specified location.protected static boolean
incrementPosition
(int[] start, int[] current, int[] lengths) Increment the offset within the position array.protected static boolean
incrementPosition
(int[] start, int[] current, int[] lengths, int[] steps) Increment the offset within the position array.
-
Constructor Details
-
StandardImageTiler
Create a tiler.- Parameters:
f
- The random access device from which image data may be read. This may be null if the tile information is available from memory.fileOffset
- The file offset within the RandomAccess device at which the data begins.dims
- The actual dimensions of the image.base
- The base class (should be a primitive type) of the image.
-
-
Method Details
-
getOffset
public static long getOffset(int[] dims, int[] pos) - Parameters:
dims
- The dimensions of the array.pos
- The index requested.- Returns:
- the offset of a given position.
-
incrementPosition
protected static boolean incrementPosition(int[] start, int[] current, int[] lengths) Increment the offset within the position array. Note that we never look at the last index since we copy data a block at a time and not byte by byte.- Parameters:
start
- The starting corner values.current
- The current offsets.lengths
- The desired dimensions of the subset.- Returns:
true
if the current array was changed
-
incrementPosition
protected static boolean incrementPosition(int[] start, int[] current, int[] lengths, int[] steps) Increment the offset within the position array. Note that we never look at the last index since we copy data a block at a time and not byte by byte.- Parameters:
start
- The starting corner values.current
- The current offsets.lengths
- The desired dimensions of the subset.steps
- The desired number of steps to take until the next position.- Returns:
true
if the current array was changed
-
fillFileData
protected void fillFileData(Object output, long delta, int outputOffset, int segment) throws IOException File a tile segment from a file using a default value for striding.- Parameters:
output
- The output to send data. This can be an ArrayDataOutput to stream data to and prevent memory consumption of a tile being in memory.delta
- The offset from the beginning of the image in bytes.outputOffset
- The index into the output array.segment
- The number of elements to be read for this segment.- Throws:
IOException
- if the underlying stream failed
-
fillFileData
protected void fillFileData(Object output, long delta, int outputOffset, int segment, int step) throws IOException File a tile segment from a file, jumping each step number of values to the next read.- Parameters:
output
- The output to send data. This can be an ArrayDataOutput to stream data to and prevent memory consumption of a tile being in memory.delta
- The offset from the beginning of the image in bytes.outputOffset
- The index into the output array.segment
- The number of elements to be read for this segment.step
- The number of jumps until the next read. Only works for streaming out data.- Throws:
EOFException
- if already at the end of file / streamIOException
- if the underlying stream failed
-
fillFileData
File a tile segment from a file into the given stream. This will deal only with bytes to avoid having to check the base type and calling a specific method. Converting the base type to a byte is a simple multiplication operation anyway. Uses a default value for striding (1).- Parameters:
output
- The output stream.delta
- The offset from the beginning of the image in bytes.segment
- The number of elements to be read for this segment.- Throws:
IOException
- if the underlying stream failed
-
fillFileData
protected void fillFileData(ArrayDataOutput output, long delta, int segment, int step) throws IOException File a tile segment from a file into the given stream. This will deal only with bytes to avoid having to check the base type and calling a specific method. Converting the base type to a byte is a simple multiplication operation anyway.- Parameters:
output
- The output stream.delta
- The offset from the beginning of the image in bytes.segment
- The number of elements to be read for this segment.step
- The number of elements until the next read.- Throws:
IOException
- if the underlying stream failed- Since:
- 1.18
-
fillMemData
protected void fillMemData(Object data, int[] posits, int length, Object output, int outputOffset, int dim) throws IOException Fill a single segment from memory. This routine is called recursively to handle multidimensional arrays. E.g., if data is three-dimensional, this will recurse two levels until we get a call with a single dimensional datum. At that point the appropriate data will be copied into the output. Uses a default value for striding (1).- Parameters:
data
- The in-memory image data.posits
- The current position for which data is requested.length
- The size of the segments.output
- The output tile.outputOffset
- The current offset into the output tile.dim
- The current dimension being- Throws:
IOException
- If the output is a stream and there is an I/O error.
-
fillMemData
protected void fillMemData(Object data, int[] posits, int length, Object output, int outputOffset, int dim, int step) throws IOException Fill a single segment from memory. This routine is called recursively to handle multidimensional arrays. E.g., if data is three-dimensional, this will recurse two levels until we get a call with a single dimensional datum. At that point the appropriate data will be copied into the output, jumping the number of step values.- Parameters:
data
- The in-memory image data.posits
- The current position for which data is requested.length
- The size of the segments.output
- The output tile.outputOffset
- The current offset into the output tile.dim
- The current dimension beingstep
- The number of jumps to the next value.- Throws:
IOException
- If the output is a stream and there is an I/O error.- Since:
- 1.18
-
fillTile
protected void fillTile(Object data, Object o, int[] newDims, int[] corners, int[] lengths) throws IOException Fill the subset using a default value for striding.- Parameters:
data
- The memory-resident data image. This may be null if the image is to be read from a file. This should be a multidimensional primitive array.o
- The tile to be filled. This is a simple primitive array, or an ArrayDataOutput instance.newDims
- The dimensions of the full image.corners
- The indices of the corner of the image.lengths
- The dimensions of the subset.- Throws:
IOException
- if the underlying stream failed
-
fillTile
protected void fillTile(Object data, Object o, int[] newDims, int[] corners, int[] lengths, int[] steps) throws IOException Fill the subset, jumping each step value to the next read.- Parameters:
data
- The memory-resident data image. This may be null if the image is to be read from a file. This should be a multidimensional primitive array.o
- The tile to be filled. This is a simple primitive array, or an ArrayDataOutput instance.newDims
- The dimensions of the full image.corners
- The indices of the corner of the image.lengths
- The dimensions of the subset.steps
- The number of steps to take until the next read in each axis.- Throws:
IOException
- if the underlying stream failed
-
getCompleteImage
Description copied from interface:ImageTiler
Returns the entire image reconstructed from the available tiles.- Specified by:
getCompleteImage
in interfaceImageTiler
- Returns:
- the complete reconstructed image from the available tiles, as a Java array. This may be an
array of promitives (such as
float[][]
) for images, or anObject[]
for binary tables. - Throws:
IOException
- if there was an error accessing the tile data from the input.- See Also:
-
getMemoryImage
See if we can get the image data from memory. This may be overridden by other classes, notably in nom.tam.fits.ImageData.- Returns:
- the image data
-
getTile
Description copied from interface:ImageTiler
Returns a tile from the image of the specified size at the specified location. An image tile is returned as a one-dimensional array although the image will normally be multidimensional.- Specified by:
getTile
in interfaceImageTiler
- Parameters:
corners
- the pixels indices where the tile starts in the full image. The array =hould contain a value for each image dimension.lengths
- the tile size in pixels. The array should contain a value for each image dimension. For the supported 2D tiles, the values beyond the first two entries should be set to 1.- Returns:
- a Java array containing data for the requested tile. This will always be a flattened 1D array, even if the image is multidimensional
- Throws:
IOException
- if there was an error accessing the tile data from the input.- See Also:
-
getTile
Description copied from interface:ImageTiler
Returns a sparsely sampled tile from the image of the specified size at the specified location.- Specified by:
getTile
in interfaceImageTiler
- Parameters:
corners
- the pixels indices where the tile starts in the full image. The array =hould contain a value for each image dimension.lengths
- the tile size in pixels. The array should contain a value for each image dimension. For the supported 2D tiles, the values beyond the first two entries should be set to 1.steps
- the sampling frequency of the original image, in pixels. The array =hould contain a value for each image dimension.- Returns:
- a Java array containing data for the requested tile. This will always be a flattened 1D array, even if the image is multidimensional
- Throws:
IOException
- if there was an error accessing the tile data from the input.- See Also:
-
getTile
Description copied from interface:ImageTiler
Fills the supplied array or output stream with the data from an image tile of the specified size at the specified location.- Specified by:
getTile
in interfaceImageTiler
- Parameters:
output
- A one-dimensional output array or stream. Data not within the valid limits of the image will be left unchanged. For an array, the length should be the product of lengths. Optionally provide anArrayDataOutput
to stream out data and not fill memory; useful for web applications.corners
- the pixels indices where the tile starts in the full image. The array =hould contain a value for each image dimension.lengths
- the tile size in pixels. The array =hould contain a value for each image dimension. For the supported 2D tiles, the values beyond the first two entries should be set to 1.- Throws:
IOException
- if there was an error writing the tile to the output.- See Also:
-
getTile
Description copied from interface:ImageTiler
Fills the supplied array our output stream with the sparsely sampled data from an image tile of the specified size at the specified location.- Specified by:
getTile
in interfaceImageTiler
- Parameters:
output
- A one-dimensional output array or stream. Data not within the valid limits of the image will be left unchanged. For an array, the length should be the product of lengths. Optionally provide anArrayDataOutput
to stream out data and not fill memory; useful for web applications.corners
- the pixels indices where the tile starts in the full image. The array =hould contain a value for each image dimension.lengths
- the tile size in pixels. The array =hould contain a value for each image dimension. For the supported 2D tiles, the values beyond the first two entries should be set to 1.steps
- the sampling frequency of the original image, in pixels. The array =hould contain a value for each image dimension.- Throws:
IOException
- if there was an error writing the tile to the output.- See Also:
-