public class SimpleColorMap extends java.lang.Object implements ColorMap
You can customize the interpolation by overriding the transformLevel(...) method. This method receives a level value and the minimum and maximum values before it's clamped to a minimum or maximum color; you can modify this level value and return a new value (ideally between the minimum and maximum). For example, you could move the values to a log of their previous values.
The default of transformLevel(...) calls another optional function you can override: the filterLevel(...) method. This method is passed a level value which has been pre-transformed such that 0.0 is the "minimum" and 1.0 is the "maximum". You can override this method to return a new value between 0.0 and 1.0 which will be "de-transformed" and used instead. The default simply returns the value itself.
You should only override transformLevel(...), of filterLevel(...), or none, but not both.
The user can provide both a color table and an interpolation; in this case, the color table takes precedence over the interpolation in that region where the color table is relevant. You specify a color table with setColorTable(), and you specify an interpolation range with setLevels(). It's important to note that transformLevel(...) and filterLevel(...) are not applied to the color table, only to the interpolation. So if you provide 2.7 as a level, and have some fancy-shmancy transformation for that in transformLevel(...), but you've made a color table 5 elements long, color number 2 will be used directly without every checking your transformLevel(...) method.
validLevel() is set to return true if the level range is between min-level and max-level, or if it's inside the color table range. Neither transformLevel(...) nor filterLevel(...) are called.
defaultValue() is set to return 0 if the color table exists, else min-level is provided.
NaN is assumed to be the same color as negative infinity.
Modifier and Type | Field and Description |
---|---|
java.awt.Color[] |
colors
User-provided color table
|
Constructor and Description |
---|
SimpleColorMap()
Constructs a ColorMap that gradiates from 0.0 -> black to 1.0 -> white.
|
SimpleColorMap(java.awt.Color[] colorTable)
Given an array of size n, constructs a ColorMap that maps integers from 0 to n-1 to the colors in the array.
|
SimpleColorMap(java.awt.Color[] colorTable,
double minLevel,
double maxLevel,
java.awt.Color minColor,
java.awt.Color maxColor)
Given an array of size n, constructs a ColorMap that maps integers from 0 to n-1 to the colors in the array,
and gradiates from minLevel -> minColor to maxLevel -> maxColor for certain other values.
|
SimpleColorMap(double minLevel,
double maxLevel,
java.awt.Color minColor,
java.awt.Color maxColor)
Constructs a ColorMap that gradiates from minLevel -> minColor to maxLevel -> maxColor.
|
Modifier and Type | Method and Description |
---|---|
double |
defaultValue()
Returns some level which is valid (that is, validLevel(defaultValue()) should
always return true).
|
double |
filterLevel(double level)
Override this to convert level values to new values using some appropriate mathematical transformation.
|
int |
getAlpha(double level)
Returns the alpha value for a color for the given level.
|
java.awt.Color |
getColor(double level)
Returns a color for the given level
|
int |
getRGB(double level)
Returns the RGB values, plus alpha, for a color for the given level.
|
java.awt.Color[] |
setColorTable(java.awt.Color[] colorTable)
Specifies that if a value (cast into an int) in the IntGrid2D or DoubleGrid2D falls in the range 0 ...
|
void |
setLevels(double minLevel,
double maxLevel,
java.awt.Color minColor,
java.awt.Color maxColor)
Sets the color levels for the ValueGridPortrayal2D values for use by the default getColor(...)
method.
|
double |
transformLevel(double level,
double minLevel,
double maxLevel)
Override this to convert level values to new values using some appropriate mathematical transformation.
|
boolean |
validLevel(double value)
Returns true if a level is "valid" (it provides a meaningful color)
|
public SimpleColorMap()
public SimpleColorMap(double minLevel, double maxLevel, java.awt.Color minColor, java.awt.Color maxColor)
public SimpleColorMap(java.awt.Color[] colorTable)
public SimpleColorMap(java.awt.Color[] colorTable, double minLevel, double maxLevel, java.awt.Color minColor, java.awt.Color maxColor)
public java.awt.Color[] setColorTable(java.awt.Color[] colorTable)
public double filterLevel(double level)
Do not override both this function and transformLevel(...). transformLevel simply calls this function.
public double transformLevel(double level, double minLevel, double maxLevel)
Do not override both this function and filterLevel(...). filterLevel is just used by this function.
public void setLevels(double minLevel, double maxLevel, java.awt.Color minColor, java.awt.Color maxColor)
public java.awt.Color getColor(double level)
ColorMap
public int getAlpha(double level)
ColorMap
return getRGB(level) >>> 24 ;
...or it could be written as:
return getColor(level).getAlpha()
...however it's likely that it this method could be written more efficiently than either of these.
public int getRGB(double level)
ColorMap
Why isn't this called getRGBA(...)? Because for some reason the underlying Color
method is likewise getRGB(), even though it ought to be called getRGBA().
... however it's likely that this method could be written more efficiently than this.
public boolean validLevel(double value)
ColorMap
validLevel
in interface ColorMap
public double defaultValue()
ColorMap
defaultValue
in interface ColorMap