org.geotoolkit.image.io.mosaic
Class TileManager

Object
  extended by TileManager
All Implemented Interfaces:
Serializable

@ThreadSafe
public abstract class TileManager
extends Object
implements Serializable

A collection of Tile objects to be given to MosaicImageReader. This base class does not assume that the tiles are arranged in any particular order (especially grids). But subclasses can make such assumption for better performances.

Since:
2.5
Version:
3.15
Author:
Martin Desruisseaux (Geomatys)
See Also:
Serialized Form
Module:
coverage/geotk-coverageio (download)    View source code for this class

Field Summary
static String SERIALIZED_FILENAME
          The default name of the filename containing a serialized form of a TileManager instance.
 
Constructor Summary
protected TileManager()
          Creates a tile manager.
 
Method Summary
 Tile createGlobalTile(ImageReaderSpi provider, Object input, int imageIndex)
          Creates a tile with a region big enough for containing every tiles.
 ImageGeometry getGridGeometry()
          Returns the grid geometry, including the "grid to real world" transform.
 Set<ImageReaderSpi> getImageReaderSpis()
          Returns all image reader providers used by the tiles.
abstract  Collection<Tile> getTiles()
          Returns all tiles.
abstract  Collection<Tile> getTiles(Rectangle region, Dimension subsampling, boolean subsamplingChangeAllowed)
          Returns every tiles that intersect the given region.
 boolean intersects(Rectangle region, Dimension subsampling)
          Returns true if at least one tile having the given subsampling or a finer one intersects the given region.
 void printErrors(PrintWriter out)
          Checks for file existence and image size of every tiles and reports any error found.
 void setGridToCRS(AffineTransform gridToCRS)
          Sets the grid to CRS transform for every tiles.
 String toString()
          Returns a string representation of this tile manager.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SERIALIZED_FILENAME

public static final String SERIALIZED_FILENAME
The default name of the filename containing a serialized form of a TileManager instance. Files of this name can be created and loaded by various Geotk module, for example geotk-coverage-sql and geotk-wizards-swing.

Since:
3.18
See Also:
Constant Field Values
Constructor Detail

TileManager

protected TileManager()
Creates a tile manager.

Method Detail

setGridToCRS

public void setGridToCRS(AffineTransform gridToCRS)
                  throws IllegalStateException,
                         IOException
Sets the grid to CRS transform for every tiles. A copy of the supplied affine transform is scaled according the subsampling of each tile. Tiles having the same subsampling will share the same immutable instance of affine transform.

The grid to CRS transform is not necessary for proper working of mosaic image reader, but is provided as a convenience for users.

This method can be invoked at most once. It can not be invoked at all if the transform has been automatically invoked by TileManagerFactory.

Parameters:
gridToCRS - The "grid to real world" transform mapping pixel upper left corner.
Throws:
IllegalStateException - if a transform was already assigned to at least one tile.
IOException - If an I/O operation was required and failed.

getGridGeometry

public ImageGeometry getGridGeometry()
                              throws IOException
Returns the grid geometry, including the "grid to real world" transform. This information is typically available only when affine transform were explicitly given to tile constructor.

Note that the grid to CRS transform of the returned geometry maps pixel upper left corner. This is different than OGC practice which maps pixel center, but is consistent with Java2D practice for which this class is designed.

Returns:
The grid geometry, or null if this information is not available.
Throws:
IOException - If an I/O operation was required and failed.
See Also:
Tile.getGridToCRS()

getImageReaderSpis

public Set<ImageReaderSpi> getImageReaderSpis()
                                       throws IOException
Returns all image reader providers used by the tiles. The set will typically contains only one element, but more are allowed. In the later case, the entries in the set are sorted from the most frequently used provider to the less frequently used.

Returns:
The image reader providers (never null).
Throws:
IOException - If an I/O operation was required and failed.
See Also:
MosaicImageReader.getTileReaderSpis()

createGlobalTile

public Tile createGlobalTile(ImageReaderSpi provider,
                             Object input,
                             int imageIndex)
                      throws NoSuchElementException,
                             IOException
Creates a tile with a region big enough for containing every tiles. The created tile has a subsampling of (1,1). This is sometime useful for creating a "virtual" image representing the assembled mosaic as a whole.

Parameters:
provider - The image reader provider to be given to the created tile, or null for inferring it automatically. In the later case the provider is inferred from the input suffix if any (e.g. the ".png" extension in a filename), or failing that the most frequently used provider is selected.
input - The input to be given to the created tile. It doesn't need to be an existing file or URI since this method will not attempt to read it.
imageIndex - The image index to be given to the created tile (usually 0).
Returns:
A global tile big enough for containing every tiles in this manager.
Throws:
NoSuchElementException - If this manager do not contains at least one tile.
IOException - If an I/O operation was required and failed.

getTiles

public abstract Collection<Tile> getTiles()
                                   throws IOException
Returns all tiles.

Returns:
The tiles.
Throws:
IOException - If an I/O operation was required and failed.

getTiles

public abstract Collection<Tile> getTiles(Rectangle region,
                                          Dimension subsampling,
                                          boolean subsamplingChangeAllowed)
                                   throws IOException
Returns every tiles that intersect the given region.

Parameters:
region - The region of interest (shall not be null).
subsampling - On input, the number of source columns and rows to advance for each pixel. On output, the effective values to use. Those values may be different only if subsamplingChangeAllowed is true.
subsamplingChangeAllowed - If true, this method is allowed to replace subsampling by the highest subsampling that overviews can handle, not greater than the given subsampling.
Returns:
The tiles that intercept the given region. May be empty but never null.
Throws:
IOException - If it was necessary to fetch an image dimension from its reader and this operation failed.

intersects

public boolean intersects(Rectangle region,
                          Dimension subsampling)
                   throws IOException
Returns true if at least one tile having the given subsampling or a finer one intersects the given region. The default implementation returns true if getTiles(region, subsampling, false) returns a non-empty set. Subclasses are encouraged to provide a more efficient implementation.

Parameters:
region - The region of interest (shall not be null).
subsampling - The maximal subsampling to look for.
Returns:
true if at least one tile having the given subsampling or a finer one intersects the given region.
Throws:
IOException - If it was necessary to fetch an image dimension from its reader and this operation failed.

printErrors

public void printErrors(PrintWriter out)
Checks for file existence and image size of every tiles and reports any error found.

Parameters:
out - Where to report errors (null for default, which is the standard output stream).

toString

public String toString()
Returns a string representation of this tile manager. The default implementation formats the first tiles in a table. Subclasses may format the tiles in a tree instead. Note that in both cases the result may be a quite long string.

Overrides:
toString in class Object
Returns:
A string representation.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.