edu.mines.jtk.awt
Class ColorMap

java.lang.Object
  extended by edu.mines.jtk.awt.ColorMap
Direct Known Subclasses:
FloatColorMap

public class ColorMap
extends java.lang.Object

A color map converts a range of double values to colors. For any double value, a color map (1) transforms the value to an integer pixel in the range [0,255], (2) maps this integer pixel to a color using an index color model.

The method getIndex(double) performs step (1). For any double value, that method (1a) clips to a specified min-max range of values, (1b) linearly translates and scales to [0.0,255.0], and (1c) rounds to the nearest integer pixel in [0,255]. Extensions of this class may of course override this method to implement alternative mappings.

A color map maintains a list of color map listeners, and notifies those listeners whenever its mapping from values to colors has changed.

Version:
2006.07.01
Author:
Dave Hale, Colorado School of Mines

Field Summary
static java.awt.image.IndexColorModel GRAY
          Color model for grays from black to white.
static java.awt.image.IndexColorModel HUE
          Color model for hues from red to blue.
static java.awt.image.IndexColorModel HUE_BLUE_TO_RED
          Color model for hues from blue to red.
static java.awt.image.IndexColorModel HUE_RED_TO_BLUE
          Color model for hues from red to blue.
static java.awt.image.IndexColorModel JET
          Color model for red to blue like Matlab's jet color map.
static java.awt.image.IndexColorModel PRISM
          Color model for eight complete cycles of hues.
static java.awt.image.IndexColorModel RED_WHITE_BLUE
          Color model for red to white to blue.
 
Constructor Summary
ColorMap(double vmin, double vmax, byte[] r, byte[] g, byte[] b)
          Constructs a color map for specified values and colors.
ColorMap(double vmin, double vmax, java.awt.Color[] c)
          Constructs a color map for specified values and colors.
ColorMap(double vmin, double vmax, float[] r, float[] g, float[] b)
          Constructs a color map for specified values and colors.
ColorMap(double vmin, double vmax, java.awt.image.IndexColorModel colorModel)
          Constructs a color map for specified values and index color model.
ColorMap(java.awt.image.IndexColorModel colorModel)
          Constructs a color map for values in [0,1] the index color model.
 
Method Summary
 void addListener(ColorMapListener cml)
          Adds the specified color map listener.
 java.awt.Color getColor(double v)
          Gets the color corresponding to the specified value.
 java.awt.image.IndexColorModel getColorModel()
          Gets the index color model used by this color map.
static java.awt.image.IndexColorModel getGray()
          Gets a linear gray black-to-white color model.
static java.awt.image.IndexColorModel getGray(double g0, double g255)
          Gets a linear gray color model for the specified gray levels.
static java.awt.image.IndexColorModel getGray(double g0, double g255, double alpha)
          Gets a linear gray color model for the specified gray levels.
static java.awt.image.IndexColorModel getHue()
          Gets a red-to-blue linear hue color model.
static java.awt.image.IndexColorModel getHue(double h0, double h255)
          Gets a linear hue color model for the specified hues.
static java.awt.image.IndexColorModel getHueBlueToRed()
          Gets a blue-to-red linear hue color model.
static java.awt.image.IndexColorModel getHueRedToBlue()
          Gets a red-to-blue linear hue color model.
 int getIndex(double v)
          Gets the index in the range [0,255] corresponding to the specified value.
static java.awt.image.IndexColorModel getJet()
          Gets a red-to-blue color model like Matlab's jet color map.
static java.awt.image.IndexColorModel getJet(double alpha)
          Gets a red-to-blue color model like Matlab's jet color map.
 double getMaxValue()
          Gets the maximum value in the range of mapped values.
 double getMinValue()
          Gets the minimum value in the range of mapped values.
static java.awt.image.IndexColorModel getPrism()
          Gets a color model with eight complete cycles of hues.
static java.awt.image.IndexColorModel getRedWhiteBlue()
          Gets a red-white-blue color model.
static java.awt.image.IndexColorModel makeIndexColorModel(java.awt.Color[] c)
          Returns an index color model for the specified array of 256 colors.
 void removeListener(ColorMapListener cml)
          Removes the specified color map listener.
 void setColorModel(java.awt.image.IndexColorModel colorModel)
          Sets the index color model for this color map.
 void setValueRange(double vmin, double vmax)
          Sets the min-max range of values mapped to colors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRAY

public static final java.awt.image.IndexColorModel GRAY
Color model for grays from black to white.


JET

public static final java.awt.image.IndexColorModel JET
Color model for red to blue like Matlab's jet color map.


HUE

public static final java.awt.image.IndexColorModel HUE
Color model for hues from red to blue.


HUE_RED_TO_BLUE

public static final java.awt.image.IndexColorModel HUE_RED_TO_BLUE
Color model for hues from red to blue.


HUE_BLUE_TO_RED

public static final java.awt.image.IndexColorModel HUE_BLUE_TO_RED
Color model for hues from blue to red.


PRISM

public static final java.awt.image.IndexColorModel PRISM
Color model for eight complete cycles of hues.


RED_WHITE_BLUE

public static final java.awt.image.IndexColorModel RED_WHITE_BLUE
Color model for red to white to blue.

Constructor Detail

ColorMap

public ColorMap(java.awt.image.IndexColorModel colorModel)
Constructs a color map for values in [0,1] the index color model. The integers 0 and 255 must be valid pixels for the color model.

Parameters:
colorModel - the index color model.

ColorMap

public ColorMap(double vmin,
                double vmax,
                java.awt.image.IndexColorModel colorModel)
Constructs a color map for specified values and index color model. The integers 0 and 255 must be valid pixels for the color model.

Parameters:
vmin - the minimum value.
vmax - the maximum value.
colorModel - the index color model.

ColorMap

public ColorMap(double vmin,
                double vmax,
                java.awt.Color[] c)
Constructs a color map for specified values and colors. The default value range is [0.0,1.0].

Parameters:
vmin - the minimum value.
vmax - the maximum value.
c - array[256] of colors.

ColorMap

public ColorMap(double vmin,
                double vmax,
                byte[] r,
                byte[] g,
                byte[] b)
Constructs a color map for specified values and colors. Red, green, and blue components are bytes in the range [0,255], inclusive.

Parameters:
vmin - the minimum value.
vmax - the maximum value.
r - array[256] of reds.
g - array[256] of greens.
b - array[256] of blues.

ColorMap

public ColorMap(double vmin,
                double vmax,
                float[] r,
                float[] g,
                float[] b)
Constructs a color map for specified values and colors. Red, green, and blue components are floats in the range [0,1], inclusive.

Parameters:
vmin - the minimum value.
vmax - the maximum value.
r - array[256] of reds.
g - array[256] of greens.
b - array[256] of blues.
Method Detail

getMinValue

public double getMinValue()
Gets the minimum value in the range of mapped values.

Returns:
the minimum value.

getMaxValue

public double getMaxValue()
Gets the maximum value in the range of mapped values.

Returns:
the maximum value.

getColorModel

public java.awt.image.IndexColorModel getColorModel()
Gets the index color model used by this color map.

Returns:
the index color model.

getColor

public java.awt.Color getColor(double v)
Gets the color corresponding to the specified value.

Parameters:
v - the value to be mapped to a color.
Returns:
the color.

getIndex

public int getIndex(double v)
Gets the index in the range [0,255] corresponding to the specified value.

Parameters:
v - the value to be mapped to an index.
Returns:
the index in the range [0,255].

setValueRange

public void setValueRange(double vmin,
                          double vmax)
Sets the min-max range of values mapped to colors. Values outside this range are clipped. The default range is [0.0,1.0].

Parameters:
vmin - the minimum value.
vmax - the maximum value.

setColorModel

public void setColorModel(java.awt.image.IndexColorModel colorModel)
Sets the index color model for this color map.

Parameters:
colorModel - the index color model.

addListener

public void addListener(ColorMapListener cml)
Adds the specified color map listener. Then notifies the listener that this colormap has changed.

Parameters:
cml - the listener.

removeListener

public void removeListener(ColorMapListener cml)
Removes the specified color map listener.

Parameters:
cml - the listener.

getGray

public static java.awt.image.IndexColorModel getGray()
Gets a linear gray black-to-white color model.

Returns:
the color model.

getGray

public static java.awt.image.IndexColorModel getGray(double g0,
                                                     double g255)
Gets a linear gray color model for the specified gray levels. Gray levels equal to 0.0 and 1.0 correspond to colors black and white, respectively.

Parameters:
g0 - the gray level corresponding to index value 0.
g255 - the gray level corresponding to index value 255.
Returns:
the color model.

getGray

public static java.awt.image.IndexColorModel getGray(double g0,
                                                     double g255,
                                                     double alpha)
Gets a linear gray color model for the specified gray levels. Gray levels equal to 0.0 and 1.0 correspond to colors black and white, respectively.

Parameters:
g0 - the gray level corresponding to index value 0.
g255 - the gray level corresponding to index value 255.
alpha - the opacity for all colors in this color model.
Returns:
the color model.

getJet

public static java.awt.image.IndexColorModel getJet()
Gets a red-to-blue color model like Matlab's jet color map.

Returns:
the color model.

getJet

public static java.awt.image.IndexColorModel getJet(double alpha)
Gets a red-to-blue color model like Matlab's jet color map.

Parameters:
alpha - the opacity for all colors in this color model.
Returns:
the color model.

getPrism

public static java.awt.image.IndexColorModel getPrism()
Gets a color model with eight complete cycles of hues.

Returns:
the color model.

getHue

public static java.awt.image.IndexColorModel getHue()
Gets a red-to-blue linear hue color model.

Returns:
the color model.

getHueRedToBlue

public static java.awt.image.IndexColorModel getHueRedToBlue()
Gets a red-to-blue linear hue color model.

Returns:
the color model.

getHueBlueToRed

public static java.awt.image.IndexColorModel getHueBlueToRed()
Gets a blue-to-red linear hue color model.

Returns:
the color model.

getHue

public static java.awt.image.IndexColorModel getHue(double h0,
                                                    double h255)
Gets a linear hue color model for the specified hues. Hues equal to 0.00, 0.33, and 0.67, and 1.00 correspond approximately to the colors red, green, blue, and red, respectively.

Parameters:
h0 - the hue corresponding to index value 0.
h255 - the hue corresponding to index value 255.
Returns:
the color model.

getRedWhiteBlue

public static java.awt.image.IndexColorModel getRedWhiteBlue()
Gets a red-white-blue color model.

Returns:
the color model.

makeIndexColorModel

public static java.awt.image.IndexColorModel makeIndexColorModel(java.awt.Color[] c)
Returns an index color model for the specified array of 256 colors.

Parameters:
c - array[256] of colors.
Returns:
the index color model.