Class TileOrganizer
java.lang.Object
org.apache.sis.internal.referencing.j2d.TileOrganizer
Creates a collection of
Tile
s from their grid to CRS affine transforms.
When the Rectangle
that describe the destination region is known for each tiles,
the Tile(Rectangle, Dimension)
constructor should be invoked directly.
But in some cases the destination rectangle is not known directly. Instead we have a set of tiles,
all of them with an upper-left corner located at (0,0), but different grid to CRS
affine transforms read from World Files.
This TileOrganizer
class infers the destination regions automatically
from the set of affine transforms.- Since:
- 1.1
- Version:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
An affine transform which is translated relative to an original transform. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
Small number for floating point comparisons.private final Map<AffineTransform,
Tile> Tiles for which we should compute the bounding box after we have them all.private static final Comparator<AffineTransform>
Sorts affine transform by increasing X scales in absolute value.private final int
The location of the final bounding box (the one including every tiles).private static final Comparator<AffineTransform>
Sorts affine transform by increasing Y scales in absolute value.private final int
The location of the final bounding box (the one including every tiles). -
Constructor Summary
ConstructorsConstructorDescriptionTileOrganizer
(Point location) Creates an initially empty tile collection with the given location. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a tile to the collection of tiles to process.private static int
computePyramidLevels
(AffineTransform[] gridToCRS, int length, Map<AffineTransform, Dimension> result, boolean isY) Computes the pyramid level for the given affine transforms along the X or Y axis, and stores the result in the given map.private static List<Map<AffineTransform,
Dimension>> computePyramidLevels
(Collection<AffineTransform> gridToCRS) From a set of arbitrary affine transforms, computes pyramid levels that can be given toTile
constructors.Returns the location of the tile collections to be created.private static int
level
(double ratio) Computes the pyramid level from the ratio between two affine transform coefficients.tiles()
Returns the tiles.toString()
Returns a string representation of the tiles contained in this object.protected boolean
unavailableSize
(Tile tile, IOException exception) Invoked when an I/O error occurred inTile.getSize()
orTile.getRegion()
.
-
Field Details
-
EPS
private static final double EPSSmall number for floating point comparisons.- See Also:
-
xLocation
private final int xLocationThe location of the final bounding box (the one including every tiles). Tiles will be translated as needed in order to fit this location. This is usually zero, but not necessarily. -
yLocation
private final int yLocationThe location of the final bounding box (the one including every tiles). Tiles will be translated as needed in order to fit this location. This is usually zero, but not necessarily. -
tiles
Tiles for which we should compute the bounding box after we have them all. Their bounding box (region) will need to be adjusted for the affine transform. -
X_COMPARATOR
Sorts affine transform by increasing X scales in absolute value. ForcomputePyramidLevels(Collection)
internal working only. -
Y_COMPARATOR
Sorts affine transform by increasing Y scales in absolute value. ForcomputePyramidLevels(Collection)
internal working only.
-
-
Constructor Details
-
TileOrganizer
Creates an initially empty tile collection with the given location.- Parameters:
location
- the location, ornull
for (0,0).
-
-
Method Details
-
getLocation
Returns the location of the tile collections to be created. The location is often (0,0) as expected inBufferedImage
, but does not have to.- Returns:
- origin of the tile collections to be created.
-
add
Adds a tile to the collection of tiles to process. Each tile can be added only once.- Parameters:
tile
- the tile to add.- Returns:
true
if the tile has been successfully added, orfalse
if the tile does not need to be processed by this class.
-
tiles
Returns the tiles. Keys are pyramid geometry (containing mosaic bounds and grid to CRS transforms) and values are the tiles in that pyramid. This method usually returns a singleton map, but more entries may be present if this method was not able to build a single pyramid using all provided tiles.Invoking this method clear the collection. On return, this instance is empty. This is because current implementation modify its workspace directly for efficiency.
- Returns:
- all tiles added to this
TileOrganizer
, grouped by pyramids. - Throws:
IOException
- if a call toTile.getSize()
orTile.getRegion()
failed, andunavailableSize(Tile, IOException)
did not consumed the exception.
-
computePyramidLevels
private static List<Map<AffineTransform,Dimension>> computePyramidLevels(Collection<AffineTransform> gridToCRS) From a set of arbitrary affine transforms, computes pyramid levels that can be given toTile
constructors. This method tries to locate the affine transform with finest resolution. This is typically (but not always, depending on rotation or axis flip) the transform with smallest scale X and scale Y coefficients in absolute value. That transform is given a "resolution" of (1,1) and stored in anIdentityHashMap
. Other transforms are stored in the same map with their resolution relative to the first one, or discarded if the relative resolution is not an integer. In the latter case, the transforms that were discarded from the first pass will be put in a new map to be added as the second element in the returned list. A new pass is run, discarded transforms from the second pass are put in the third element of the list, etc.- Parameters:
gridToCRS
- the grid to CRS affine transforms computed from the image to use in a pyramid. The collection and the transform elements are not modified by this method (they may be modified by the caller however).- Returns:
- a subset of the given transforms with their relative resolution. This method typically returns one map, but more could be returned if the scale ratio is not an integer for every transforms.
-
computePyramidLevels
private static int computePyramidLevels(AffineTransform[] gridToCRS, int length, Map<AffineTransform, Dimension> result, boolean isY) Computes the pyramid level for the given affine transforms along the X or Y axis, and stores the result in the given map.- Parameters:
gridToCRS
- the AffineTransform to analyze. This array must be sorted along the dimension specified byisY
.length
- the number of valid entries in thegridToCRS
array.result
- an initially empty map in which to store the results.isY
-false
for analyzing the X axis, ortrue
for the Y axis.- Returns:
- the number of entries remaining in
gridToCRS
.
-
level
private static int level(double ratio) Computes the pyramid level from the ratio between two affine transform coefficients. If the ratio has been computed fromentry2.scaleX / entry1.scaleX
, then a return value of:- 1 means that both entries are at the same level.
- 2 means that the second entry has pixels twice as large as first entry.
- 3 means that the second entry has pixels three time larger than first entry.
- etc...
- A negative number means that the second entry has pixels smaller than first entry.
- 0 means that the ratio between entries is not an integer number.
- Parameters:
ratio
- the ratio between affine transform coefficients.- Returns:
- the pixel size (actually subsampling) relative to the smallest pixel, or 0 if it cannot be computed. If the ratio is between 0 and 1, then this method returns a negative number.
-
toString
Returns a string representation of the tiles contained in this object. Since this method is for debugging purpose, only the first tiles may be formatted in order to avoid consuming to much space in the debugger.
-