org.geotools.coverage.processing
Class ColorMap

java.lang.Object
  extended by org.geotools.coverage.processing.ColorMap
All Implemented Interfaces:
java.io.Serializable

public class ColorMap
extends java.lang.Object
implements java.io.Serializable

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

Since:
2.4
Version:
$Id: ColorMap.java 30760 2008-06-18 14:28:24Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Recolor, Serialized Form

Field Summary
static java.lang.CharSequence ANY_QUANTITATIVE_CATEGORY
          A special category name meaning "any quantitative value".
 
Constructor Summary
ColorMap()
          Creates an initially empty color map.
ColorMap(java.awt.Color[] colors)
          Creates a color map initialized to the specified color ramp to be applied on any quantitative category.
ColorMap(java.util.Map<? extends java.lang.CharSequence,java.awt.Color[]> colorMap)
          Creates a color map initialized to the specified map.
 
Method Summary
 boolean equals(java.lang.Object object)
          Compares this color map with the specified object for equality.
 java.awt.Color[] getColors(java.lang.CharSequence category)
          Returns the color ramp for the given category.
 MeasurementRange<?> getGeophysicsRange(java.lang.CharSequence category)
          Returns the range of geophysics values for the given category.
 NumberRange getRelativeRange(java.lang.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(java.lang.CharSequence category, java.awt.Color color)
          Applies a uniform color to the given (usually qualitative) category.
 void setColors(java.lang.CharSequence category, java.awt.Color[] colors)
          Applies a color ramp to the given (usually quantitative) category.
 void setGeophysicsRange(java.lang.CharSequence category, MeasurementRange<?> range)
          Sets a range of geophysics values for the color ramp associated with a quantitative category.
 void setRelativeRange(java.lang.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.
 java.lang.String toString()
          Returns a string representation of this color map.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ANY_QUANTITATIVE_CATEGORY

public static final java.lang.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(java.awt.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(java.util.Map<? extends java.lang.CharSequence,java.awt.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(java.lang.CharSequence category,
                     java.awt.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(java.lang.CharSequence category,
                      java.awt.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 java.awt.Color[] getColors(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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 java.lang.Object

equals

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

Overrides:
equals in class java.lang.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 java.lang.String toString()
Returns a string representation of this color map.

Overrides:
toString in class java.lang.Object


Copyright © 1996-2010 Geotools. All Rights Reserved.