public interface Tile extends Iterable<Tile.Pos>
Target tiles to be computed are passed into an Operator
's
computeTile
and computeTileStack
computeTileStack} methods.
Source tiles are obtained by using the
getSourceTile
method.
Three ways are provided to access and manipulate the sample data of a target tile:
(1) This is the simplest (but also slowest) way to modify sample data of a tile:
for (int y = tile.getMinY(); y <= tile.getMaxY(); y++) { for (int x = tile.getMinX(); x <= tile.getMaxX(); x++) { // compute sample value... tile.setSample(x, y, sample); } }which can also be written even simpler using a tile iterator:
for (Tile.Pos pos : tile) { // compute sample value... tile.setSample(pos.x, pos.y, sample); }
The methods getSampleFloat(int, int)
and setSample(int, int, float)
and their derivatives
used in option (1) return and expect (geo-)physically scaled sample values.
(2) More performance is gained if the sample data buffer is checked out and committed (required after modification only):
ProductData samples = tile.getRawSamples(); // check out for (int y = 0; y < tile.getHeight(); y++) { for (int x = 0; x < tile.getWidth(); x++) { // compute sample value... samples.setElemFloatAt(y * getWidth() + x, sample); // ... } } tile.setRawSamples(samples); // commit
The method getRawSamples()
used in option (2) returns a writable buffer for the raw, non-calibrated
sample values.
Use the toGeoPhysical(float)
and toRaw(float)
to convert between physical and raw
sample values.
(3) The the fastest way to read from or write to sample data is to directly access the sample data via their primitive data buffers:
float[] samples = tile.getDataBufferFloat(); float sample; int offset = tile.getScanlineOffset(); for (int y = 0; y < tile.getHeight(); y++) { int index = offset; for (int x = 0; x < tile.getWidth(); x++) { // compute sample value... samples[index] = sample; index++; } offset += tile.getScanlineStride(); }
Note that option (3) can only be used if the exact sample data type
is known or has been identified in a former step. The code snippet above
implies that the underlying data type is float
(because getRasterDataNode().getDataType()
returns ProductData.TYPE_FLOAT32
).
The getDataBufferFloat()
and its derivatives all return arrays of raw, non-calibrated sample values.
Use the toGeoPhysical(float)
and toRaw(float)
to convert between physical and raw
sample values.
Modifier and Type | Interface and Description |
---|---|
static class |
Tile.Pos
A pixel position within the tile's raster.
|
Modifier and Type | Method and Description |
---|---|
ProductData |
getDataBuffer()
Obtains access to the underlying raw sample buffer.
|
byte[] |
getDataBufferByte()
Gets the underlying raw sample array of type
byte (signed or unsigned). |
double[] |
getDataBufferDouble()
Gets the underlying raw sample array of type
double . |
float[] |
getDataBufferFloat()
Gets the underlying raw sample array of type
float . |
int |
getDataBufferIndex(int x,
int y)
Gets the index into the underlying raw sample buffer for the given pixel coordinates.
|
int[] |
getDataBufferInt()
Gets the underlying raw sample array of type
int . |
short[] |
getDataBufferShort()
Gets the underlying raw sample array of type
short (signed or unsigned). |
int |
getHeight()
Gets the height in pixels within the scene covered by the tile's
RasterDataNode . |
int |
getMaxX()
Gets the maximum pixel x-coordinate within the scene covered by the tile's
RasterDataNode . |
int |
getMaxY()
Gets the maximum pixel y-coordinate within the scene covered by the tile's
RasterDataNode . |
int |
getMinX()
Gets the minimum pixel x-coordinate within the scene covered by the tile's
RasterDataNode . |
int |
getMinY()
Gets the minimum pixel y-coordinate within the scene covered by the tile's
RasterDataNode . |
RasterDataNode |
getRasterDataNode()
Gets the
RasterDataNode associated with this tile,
e.g. |
ProductData |
getRawSamples()
Gets the raw (unscaled, uncalibrated) samples, e.g.
|
Rectangle |
getRectangle()
Gets the tile rectangle in pixel coordinates within the scene covered by the tile's
RasterDataNode . |
boolean |
getSampleBit(int x,
int y,
int bitIndex)
Gets the bit-coded sample value for the given pixel coordinate and the specified bit index as a
boolean . |
boolean |
getSampleBoolean(int x,
int y)
Gets the (geo-)physically scaled sample at the given pixel coordinate as
boolean value. |
double |
getSampleDouble(int x,
int y)
Gets the (geo-)physically scaled sample value for the given pixel coordinate as
double . |
float |
getSampleFloat(int x,
int y)
Gets the (geo-)physically scaled sample at the given pixel coordinate as
float value. |
int |
getSampleInt(int x,
int y)
Gets the (geo-)physically scaled sample at the given pixel coordinate as
int value. |
byte[] |
getSamplesByte()
Gets the scaled, (geo-)physical array of
int samples, copied from or directly returning the underlying
data buffer. |
double[] |
getSamplesDouble()
Gets the scaled, (geo-)physical array of
double samples, copied from or directly returning the underlying
data buffer. |
float[] |
getSamplesFloat()
Gets the scaled, (geo-)physical array of
double samples, copied from or directly returning the underlying
data buffer. |
int[] |
getSamplesInt()
Gets the scaled, (geo-)physical array of
int samples, copied from or directly returning the underlying
data buffer. |
short[] |
getSamplesShort()
Gets the scaled, (geo-)physical array of
int samples, copied from or directly returning the underlying
data buffer. |
int |
getScanlineOffset()
Gets the scanline offset.
|
int |
getScanlineStride()
Gets the raster scanline stride for addressing the internal data buffer.
|
int |
getWidth()
Gets the width in pixels within the scene covered by the tile's
RasterDataNode . |
boolean |
isSampleValid(int x,
int y)
Checks whether or not the sample value exists and is valid at a given image pixel position.
|
boolean |
isTarget()
Checks if this is a target tile.
|
Iterator<Tile.Pos> |
iterator()
Gets an iterator which can be used to visit all pixels in the tile.
|
void |
setRawSamples(ProductData rawSamples)
Sets this tile's raw (unscaled, uncalibrated) samples.
|
void |
setSample(int x,
int y,
boolean sample)
Sets the (geo-)physically scaled sample at the given pixel coordinate from a
boolean value. |
void |
setSample(int x,
int y,
double sample)
Sets the (geo-)physically scaled sample at the given pixel coordinate from a
double value. |
void |
setSample(int x,
int y,
float sample)
Sets the (geo-)physically scaled sample at the given pixel coordinate from a
float value. |
void |
setSample(int x,
int y,
int sample)
Sets the (geo-)physically scaled sample at the given pixel coordinate from a
int value. |
void |
setSample(int x,
int y,
int bitIndex,
boolean sample)
Sets the bit-coded sample at the given pixel coordinate and the specified bit index from a
boolean value. |
void |
setSamples(byte[] samples)
Sets this tile's scaled, (geo-)physical samples as array of
floats s. |
void |
setSamples(double[] samples)
Sets this tile's scaled, (geo-)physical samples as array of
double s. |
void |
setSamples(float[] samples)
Sets this tile's scaled, (geo-)physical samples as array of
floats s. |
void |
setSamples(int[] samples)
Sets this tile's scaled, (geo-)physical samples as array of
floats s. |
void |
setSamples(short[] samples)
Sets this tile's scaled, (geo-)physical samples as array of
floats s. |
double |
toGeoPhysical(double rawSample)
Converts a raw sample value (e.g.
|
float |
toGeoPhysical(float rawSample)
Converts a raw sample value (e.g.
|
double |
toRaw(double sample)
Converts a (geo-)physically scaled sample value of type
double to a
its corresponding raw sample value (e.g. |
float |
toRaw(float sample)
Converts a (geo-)physically scaled sample value of type
float to a
its corresponding raw sample value (e.g. |
forEach, spliterator
RasterDataNode getRasterDataNode()
RasterDataNode
associated with this tile,
e.g. a Band
for source and target tiles or
TiePointGrid
for a source tile.RasterDataNode
associated with this tile.boolean isTarget()
true
if this is a target tile.float toGeoPhysical(float rawSample)
float
.rawSample
- The raw sample value.double toGeoPhysical(double rawSample)
double
.rawSample
- The raw sample value.float toRaw(float sample)
float
to a
its corresponding raw sample value (e.g. digital counts).sample
- The calibrated sample value.double toRaw(double sample)
double
to a
its corresponding raw sample value (e.g. digital counts).sample
- The calibrated sample value.Rectangle getRectangle()
RasterDataNode
.
Simply returns new Rectangle(
minX
,
minY
,
width
,
height
)
.int getMinX()
RasterDataNode
.int getMaxX()
RasterDataNode
.int getMinY()
RasterDataNode
.int getMaxY()
RasterDataNode
.int getWidth()
RasterDataNode
.int getHeight()
RasterDataNode
.int getDataBufferIndex(int x, int y)
The pixel coordinates are absolute; meaning they are defined in the scene raster coordinate system
of this tile's RasterDataNode
.
The returned index is computed as follows:
int dx = x -getMinX()
; int dy = y -getMinY()
; int index =getScanlineOffset()
+ dy *getScanlineStride()
+ dx;
ProductData getDataBuffer()
Obtains access to the underlying raw sample buffer. The data buffer holds the
raw (unscaled, uncalibrated) sample data (e.g. detector counts).
Elements in this array must be addressed
by an index computed via the scanlineStride
and
scanlineOffset
properties.
The index can also be directly computed using the getDataBufferIndex(int, int)
method.
The most efficient way to access and/or modify the samples in the raw data buffer is using the following nested loops:
int lineStride = tile.getScanlineStride()
; int lineOffset = tile.getScanlineOffset()
; for (int y = tile.getMinY()
; y <= tile.getMaxY()
; y++) { int index = lineOffset; for (int x = tile.getMinX()
; x <= tile.getMaxX()
; x++) { // use index here to access raw data buffer... index++; } lineOffset += lineStride; }
If the absolute x,y pixel coordinates are not required, the following construct maybe more readable:
int lineStride = tile.getScanlineStride()
; int lineOffset = tile.getScanlineOffset()
; for (int y = 0; y < tile.getHeight()
; y++) { int index = lineOffset; for (int x = 0; x < tile.getWidth()
; x++) { // use index here to access raw data buffer... index++; } lineOffset += lineStride; }
byte[] getDataBufferByte()
byte
(signed or unsigned).
If the underlying data buffer is not of type byte
, null
is returned.
Refer to getDataBuffer()
for using the primitive array.
null
(see above).getDataBufferIndex(int, int)
,
getDataBuffer()
short[] getDataBufferShort()
short
(signed or unsigned).
If the underlying data buffer is not of type short
, null
is returned.
Refer to getDataBuffer()
for using the primitive array.
null
(see above).getDataBufferIndex(int, int)
,
getDataBuffer()
int[] getDataBufferInt()
int
.
If the underlying data buffer is not of type int
, null
is returned.
Refer to getDataBuffer()
for using the primitive array.
null
(see above).getDataBufferIndex(int, int)
,
getDataBuffer()
float[] getDataBufferFloat()
float
.
If the underlying data buffer is not of type float
, null
is returned.
Refer to getDataBuffer()
for using the primitive array.
null
(see above).getDataBufferIndex(int, int)
,
getDataBuffer()
double[] getDataBufferDouble()
double
.
If the underlying data buffer is not of type double
, null
is returned.
Refer to getDataBuffer()
for using the primitive array.
null
(see above).getDataBufferIndex(int, int)
,
getDataBuffer()
int getScanlineOffset()
getScanlineStride()
int getScanlineStride()
getScanlineOffset()
ProductData getRawSamples()
getDataBuffer()
method, the returned samples
will cover exactly the region getRectangle()
rectangle} of this tile. Thus, the number
of returned samples will always equal width
*
height
.
In order to apply changes of the samples values to this tile, it is mandatory to call
setRawSamples(ProductData)
with the modified
ProductData
instance.
void setRawSamples(ProductData rawSamples)
width
*
height
of this tile.
This method must be used
in order to apply changes made to the samples returned by the getRawSamples()
method.
rawSamples
- The raw samples to be set.byte[] getSamplesByte()
int
samples, copied from or directly returning the underlying
data buffer. In contradiction to the getDataBuffer()
method, the returned samples
will cover exactly the region getRectangle()
rectangle} of this tile. Thus, the number
of returned samples will always equal width
*
height
.
Sample values that are masked out (see isSampleValid(int, int)
) are set to zero.
setSamples(byte[])
short[] getSamplesShort()
int
samples, copied from or directly returning the underlying
data buffer. In contradiction to the getDataBuffer()
method, the returned samples
will cover exactly the region getRectangle()
rectangle} of this tile. Thus, the number
of returned samples will always equal width
*
height
.
Sample values that are masked out (see isSampleValid(int, int)
) are set to zero.
setSamples(short[])
int[] getSamplesInt()
int
samples, copied from or directly returning the underlying
data buffer. In contradiction to the getDataBuffer()
method, the returned samples
will cover exactly the region getRectangle()
rectangle} of this tile. Thus, the number
of returned samples will always equal width
*
height
.
Sample values that are masked out (see isSampleValid(int, int)
) are set to zero.
setSamples(int[])
float[] getSamplesFloat()
double
samples, copied from or directly returning the underlying
data buffer. In contradiction to the getDataBuffer()
method, the returned samples
will cover exactly the region getRectangle()
rectangle} of this tile. Thus, the number
of returned samples will always equal width
*
height
.
Sample values that are masked out (see isSampleValid(int, int)
) are set to Float.NaN
.
setSamples(float[])
double[] getSamplesDouble()
double
samples, copied from or directly returning the underlying
data buffer. In contradiction to the getDataBuffer()
method, the returned samples
will cover exactly the region getRectangle()
rectangle} of this tile. Thus, the number
of returned samples will always equal width
*
height
.
Sample values that are masked out (see isSampleValid(int, int)
) are set to Double.NaN
.
setSamples(double[])
void setSamples(byte[] samples)
floats
s.
The number of given samples must be equal width
*
height
of this tile.samples
- The (geo-)physical samples to be set.getSamplesByte()
void setSamples(short[] samples)
floats
s.
The number of given samples must be equal width
*
height
of this tile.samples
- The (geo-)physical samples to be set.getSamplesShort()
void setSamples(int[] samples)
floats
s.
The number of given samples must be equal width
*
height
of this tile.samples
- The (geo-)physical samples to be set.getSamplesInt()
void setSamples(float[] samples)
floats
s.
The number of given samples must be equal width
*
height
of this tile.samples
- The (geo-)physical samples to be set.getSamplesFloat()
void setSamples(double[] samples)
double
s.
The number of given samples must be equal width
*
height
of this tile.
This method must be used
in order to apply changes made to the samples returned by the getRawSamples()
method.
samples
- The (geo-)physical samples to be set.getSamplesDouble()
boolean isSampleValid(int x, int y)
x
- the image pixel x-coordinatey
- the image pixel y-coordinateboolean getSampleBoolean(int x, int y)
boolean
value.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed.
Note that in most cases, accessing the tile's dataBuffer
directly in conjunction
with the scanlineOffset
and scanlineStride
properties
gives a better performance.
void setSample(int x, int y, boolean sample)
boolean
value.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed.
Note that in most cases, accessing the tile's dataBuffer
directly in conjunction
with the scanlineOffset
and scanlineStride
properties
gives a better performance.
int getSampleInt(int x, int y)
int
value.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed.
Note that in most cases, accessing the tile's dataBuffer
directly in conjunction
with the scanlineOffset
and scanlineStride
properties
gives a better performance.
void setSample(int x, int y, int sample)
int
value.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed. The conversion ensures that no overflow happens. If necessary the value is cropped to the value range.
Note that in most cases, accessing the tile's dataBuffer
directly in conjunction
with the scanlineOffset
and scanlineStride
properties
gives a better performance.
float getSampleFloat(int x, int y)
float
value.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed.
Note that in most cases it is more performant to directly access the tile's dataBuffer
in conjunction
with the scanlineOffset
and scanlineStride
properties.
void setSample(int x, int y, float sample)
float
value.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed. The conversion ensures that no overflow happens. If necessary the value is cropped to the value range.
Note that in most cases, accessing the tile's dataBuffer
directly in conjunction
with the scanlineOffset
and scanlineStride
properties
gives a better performance.
double getSampleDouble(int x, int y)
double
.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed.
Note that in most cases, accessing the tile's dataBuffer
directly in conjunction
with the scanlineOffset
and scanlineStride
properties
gives a better performance.
void setSample(int x, int y, double sample)
double
value.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed. The conversion ensures that no overflow happens. If necessary the value is cropped to the value range.
Note that in most cases, accessing the tile's dataBuffer
directly in conjunction
with the scanlineOffset
and scanlineStride
properties
gives a better performance.
boolean getSampleBit(int x, int y, int bitIndex)
boolean
.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed.
Note that in most cases it is more performant to directly access the tile's dataBuffer
in conjunction
with the scanlineOffset
and scanlineStride
properties.
void setSample(int x, int y, int bitIndex, boolean sample)
boolean
value.
If the underlying data buffer is of a different sample data type, an appropriate type conversion is performed.
Note that in most cases it is more performant to directly access the tile's dataBuffer
in conjunction
with the scanlineOffset
and scanlineStride
properties.
Iterator<Tile.Pos> iterator()
for (Tile.Pos pos: tile) { int x = pos.x; int y = pos.y; // ... }is equivalent to iterating over all pixels using two nested loops
for (int y = tile.getMinY(); y <= tile.getMaxY(); y++) { for (int x = tile.getMinX(); x <= tile.getMaxX(); x++) { // ... } }
Copyright © 2014–2016 European Space Agency (ESA). All rights reserved.