org.geotools.coverage.processing
Class ColorMap

Object
  extended by ColorMap
All Implemented Interfaces:
Serializable

public class ColorMap
extends Object
implements Serializable

Colors associated to categories. This is the parameter type for the Recolor operation.

Since:
2.4
Author:
Martin Desruisseaux
See Also:
Recolor, Serialized Form
Module:

Field Summary
static CharSequence ANY_QUANTITATIVE_CATEGORY
          A special category name meaning "any quantitative value".
 
Constructor Summary
ColorMap()
          Creates an initially empty color map.
ColorMap(Color[] colors)
          Creates a color map initialized to the specified color ramp to be applied on any quantitative category.
ColorMap(Map<? extends CharSequence,Color[]> colorMap)
          Creates a color map initialized to the specified map.
 
Method Summary
 boolean equals(Object object)
          Compares this color map with the specified object for equality.
 Color[] getColors(CharSequence category)
          Returns the color ramp for the given category.
 MeasurementRange<?> getGeophysicsRange(CharSequence category)
          Returns the range of geophysics values for the given category.
 NumberRange getRelativeRange(CharSequence category)
          Returns the relative range of values for the given category.
 boolean getResetUnspecifiedColors()
          If true, the ARGB values corresponding to any category not specified in this color map will be reset to the color specified by the category.
 int hashCode()
          Returns a hash code value for this color map.
 GridSampleDimension recolor(GridSampleDimension sampleDimension, int[] ARGB)
          Applies to the specified sample dimension the colors given to this color map.
 void setColor(CharSequence category, Color color)
          Applies a uniform color to the given (usually qualitative) category.
 void setColors(CharSequence category, Color[] colors)
          Applies a color ramp to the given (usually quantitative) category.
 void setGeophysicsRange(CharSequence category, MeasurementRange<?> range)
          Sets a range of geophysics values for the color ramp associated with a quantitative category.
 void setRelativeRange(CharSequence category, NumberRange<?> range)
          Sets a relative range of values for the color ramp associated to a quantitative category.
 void setResetUnspecifiedColors(boolean reset)
          If true, the ARGB values corresponding to any category not specified in this color map will be reset to the color specified by the category.
 String toString()
          Returns a string representation of this color map.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ANY_QUANTITATIVE_CATEGORY

public static final CharSequence ANY_QUANTITATIVE_CATEGORY
A special category name meaning "any quantitative value".

Constructor Detail

ColorMap

public ColorMap()
Creates an initially empty color map.


ColorMap

public ColorMap(Color[] colors)
Creates a color map initialized to the specified color ramp to be applied on any quantitative category.

Parameters:
colors - The colors to be given to this map.

ColorMap

public ColorMap(Map<? extends CharSequence,Color[]> colorMap)
Creates a color map initialized to the specified map.

Parameters:
colorMap - A map of (category name, colors) pairs.
Method Detail

setColor

public void setColor(CharSequence category,
                     Color color)
Applies a uniform color to the given (usually qualitative) category.

Parameters:
category - The name of the category for which to set the color.
color - A uniform color to apply to the specified category, or null for removing the color mapping.
See Also:
recolor(org.geotools.coverage.GridSampleDimension, int[])

setColors

public void setColors(CharSequence category,
                      Color[] colors)
Applies a color ramp to the given (usually quantitative) category. The color array may have any length; colors will be interpolated as needed.

Parameters:
category - The name of the category for which to set the colors, or ANY_QUANTITATIVE_CATEGORY if the colors should apply to any quantitative category.
colors - The colors to apply to the specified category, or null or an empty array for removing the color mapping.
See Also:
recolor(org.geotools.coverage.GridSampleDimension, int[])

getColors

public Color[] getColors(CharSequence category)
Returns the color ramp for the given category.

Parameters:
category - The category name, or ANY_QUANTITATIVE_CATEGORY for fetching the colors to apply to any quantitative category.
Returns:
The color ramp, or null if none.

setGeophysicsRange

public void setGeophysicsRange(CharSequence category,
                               MeasurementRange<?> range)
Sets a range of geophysics values for the color ramp associated with a quantitative category. For example if the category "Height" applies to geophysics values in the range [0..500] metres and if a range of [100..400] metres is defined as below:
setRelativeRange("Height", new MeasurementRange(0, 100, SI.METRE)); setColors("Height", myColorPalette);
Then myColorPalette will applies to pixel values in the range [100..400] instead of [0..500]. This is typically used in order to augment the contrast in a range of values of special interest.

This method is exclusive with setRelativeRange(java.lang.CharSequence, org.geotools.util.NumberRange).

Parameters:
category - The name of the category for which to set the geophysics range.
range - The minimal and maximal values for the color ramp. A null value removes the range mapping.
See Also:
recolor(org.geotools.coverage.GridSampleDimension, int[])

setRelativeRange

public void setRelativeRange(CharSequence category,
                             NumberRange<?> range)
Sets a relative range of values for the color ramp associated to a quantitative category. For example if the category "Height" applies to pixel values in the range [0..200] and if a relative range of [20%..80%] is defined as below:
setRelativeRange("Height", new NumberRange(20, 80)); setColors("Height", myColorPalette);
Then myColorPalette will applies to pixel values in the range [40..160] instead of [0..200]. This is typically used in order to augment the contrast in a range of values of special interest.

This method is exclusive with setGeophysicsRange(java.lang.CharSequence, org.geotools.util.MeasurementRange).

Parameters:
category - The name of the category for which to set the relative range.
range - The minimal and maximal relative values for the color ramp, as percentages between 0 and 100. A null value removes the range mapping.
See Also:
recolor(org.geotools.coverage.GridSampleDimension, int[])

getGeophysicsRange

public MeasurementRange<?> getGeophysicsRange(CharSequence category)
Returns the range of geophysics values for the given category.

Parameters:
category - The category name, or ANY_QUANTITATIVE_CATEGORY for fetching the range to apply to any quantitative category.
Returns:
The geophysics range, or null if none.

getRelativeRange

public NumberRange getRelativeRange(CharSequence category)
Returns the relative range of values for the given category.

Parameters:
category - The category name, or ANY_QUANTITATIVE_CATEGORY for fetching the relative range to apply to any quantitative category.
Returns:
The relative range, or null if none.

setResetUnspecifiedColors

public void setResetUnspecifiedColors(boolean reset)
If true, the ARGB values corresponding to any category not specified in this color map will be reset to the color specified by the category. The default value is false.

Parameters:
reset - true if unspecified colors should be reset to the colors given in the category object.

getResetUnspecifiedColors

public boolean getResetUnspecifiedColors()
If true, the ARGB values corresponding to any category not specified in this color map will be reset to the color specified by the category. The default value is false.

Returns:
true if unspecified colors should be reset to the colors given in the category object.

recolor

public GridSampleDimension recolor(GridSampleDimension sampleDimension,
                                   int[] ARGB)
Applies to the specified sample dimension the colors given to this color map. This method iterates throug every categories in the given sample dimension. For each category with a name matching one of the (name, colors) or (name, range) entries given to this color map, the recolor method is invoked on that category and the result inserted into a new sample dimension to be returned.

If the optional ARGB array is non-null, then the ARGB colors for recolorized categories will be written in this array. Only the elements with index in the category range will be overwritten; other elements will not be modified.

NOTE: The geophysics and relative ranges are taken in account for the ARGB array only; they do not have impact on the categories to be included in the returned sample dimension.

Parameters:
sampleDimension - The sample dimension to recolorize.
ARGB - An optional array where to store the ARGB values of recolorized categories, or null if none.
Returns:
A new sample dimension, or sampleDimension if no color change were applied.
See Also:
Category.recolor(java.awt.Color[])

hashCode

public int hashCode()
Returns a hash code value for this color map.

Overrides:
hashCode in class Object

equals

public boolean equals(Object object)
Compares this color map with the specified object for equality.

Overrides:
equals in class Object
Parameters:
object - The object to compare with this color map.
Returns:
true if the given object is equals to this color map.

toString

public String toString()
Returns a string representation of this color map.

Overrides:
toString in class Object


Copyright © 1996-2009 Geotools. All Rights Reserved.