org.geotools.image.io.mosaic
Class TileManager

java.lang.Object
  extended by org.geotools.image.io.mosaic.TileManager
All Implemented Interfaces:
java.io.Serializable

public abstract class TileManager
extends java.lang.Object
implements java.io.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:
$Id: TileManager.java 31037 2008-07-21 11:31:27Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Constructor Summary
protected TileManager()
          Creates a tile manager.
 
Method Summary
 Tile createGlobalTile(javax.imageio.spi.ImageReaderSpi provider, java.lang.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.
 java.util.Set<javax.imageio.spi.ImageReaderSpi> getImageReaderSpis()
          Returns all image reader providers used by the tiles.
abstract  java.util.Collection<Tile> getTiles()
          Returns all tiles.
abstract  java.util.Collection<Tile> getTiles(java.awt.Rectangle region, java.awt.Dimension subsampling, boolean subsamplingChangeAllowed)
          Returns every tiles that intersect the given region.
 boolean intersects(java.awt.Rectangle region, java.awt.Dimension subsampling)
          Returns true if at least one tile having the given subsampling or a finer one intersects the given region.
 void printErrors(java.io.PrintWriter out)
          Checks for file existence and image size of every tiles and reports any error found.
 void setGridToCRS(java.awt.geom.AffineTransform gridToCRS)
          Sets the grid to CRS transform for every tiles.
 java.lang.String toString()
          Returns a string representation of this tile manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TileManager

protected TileManager()
Creates a tile manager.

Method Detail

setGridToCRS

public void setGridToCRS(java.awt.geom.AffineTransform gridToCRS)
                  throws java.lang.IllegalStateException,
                         java.io.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 only once.

Parameters:
gridToCRS - The "grid to CRS" transform.
Throws:
java.lang.IllegalStateException - if a transform was already assigned to at least one tile.
java.io.IOException - If an I/O operation was required and failed.

getGridGeometry

public ImageGeometry getGridGeometry()
                              throws java.io.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.

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

getImageReaderSpis

public java.util.Set<javax.imageio.spi.ImageReaderSpi> getImageReaderSpis()
                                                                   throws java.io.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.
Throws:
java.io.IOException - If an I/O operation was required and failed.
See Also:
MosaicImageReader.getTileReaderSpis()

createGlobalTile

public Tile createGlobalTile(javax.imageio.spi.ImageReaderSpi provider,
                             java.lang.Object input,
                             int imageIndex)
                      throws java.util.NoSuchElementException,
                             java.io.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:
java.util.NoSuchElementException - If this manager do not contains at least one tile.
java.io.IOException - If an I/O operation was required and failed.

getTiles

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

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

getTiles

public abstract java.util.Collection<Tile> getTiles(java.awt.Rectangle region,
                                                    java.awt.Dimension subsampling,
                                                    boolean subsamplingChangeAllowed)
                                             throws java.io.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:
java.io.IOException - If it was necessary to fetch an image dimension from its reader and this operation failed.

intersects

public boolean intersects(java.awt.Rectangle region,
                          java.awt.Dimension subsampling)
                   throws java.io.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:
java.io.IOException - If it was necessary to fetch an image dimension from its reader and this operation failed.

printErrors

public void printErrors(java.io.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 java.lang.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 java.lang.Object
Returns:
A string representation.


Copyright © 1996-2010 Geotools. All Rights Reserved.