Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## sim.util.gui
Class SimpleColorMap

    java.lang.Object
      sim.util.gui.SimpleColorMap

All Implemented Interfaces:
  ColorMap

    public class SimpleColorMap

extends java.lang.Object
implements ColorMap

Maps numerical levels to colors using either a lookup table, color interpolation, or both. A simple implementation of the ColorMap interface.

1. Method 1: a color table. The user can provide an array of Colors; if the numerical value, cast into an integer, is between 0 and (the length of this array - 1), then the appropriate Color is returned.
2. Method 2: color interpolation. The user can provide a min-level, min-Color, max-level, and max-Color. If the numerical value is below min-level, then minColor is provided. If it's above max-level, then max-Color is provided. If it's between min-level and max-level, then a linear interpolation between min-Color and max-Color is provided.

   You can customize the interpolation by overriding the filterLevel(double) method. This method receives a level value converted to between 0.0 and 1.0 inclusive, and is supposed to return a revised value between 0.0 and 1.0. For example, if you'd like to nudge colors up towards the maximum portion of the table, you could return the square root of the value you receive. The default simply returns the value itself.

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().

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.

defaultValue() is set to return 0 if the color table exists, else min-level is provided.

Field Summary
`java.awt.Color` | `clearColor`
`static int` | `COLOR_DISCRETIZATION`
`java.awt.Color[]` | `colors` User-provided color table
`int` | `maxAlpha`
`int` | `maxBlue`
`java.awt.Color` | `maxColor`
`int` | `maxGreen`
`double` | `maxLevel`
`int` | `maxRed`
`int` | `minAlpha`
`int` | `minBlue`
`java.awt.Color` | `minColor`
`int` | `minGreen`
`double` | `minLevel`
`int` | `minRed`

Constructor Summary
`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.

Method Summary
`double` | `defaultValue()` Returns some level which is valid (that is, validLevel(defaultValue()) should always return true).
`double` | `filterLevel(double level)`
`int` | `getAlpha(double level)` Returns the alpha value for a color for the given level.
`java.awt.Color` | `getColor(double level)` Override this if you'd like to customize the color for values in the portrayal.
`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.
`boolean` | `validLevel(double value)` Returns true if a level is "valid" (it provides a meaningful color)

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### minRed

    public int minRed

### minBlue

    public int minBlue

### minGreen

    public int minGreen

### minAlpha

    public int minAlpha

### maxRed

    public int maxRed

### maxBlue

    public int maxBlue

### maxGreen

    public int maxGreen

### maxAlpha

    public int maxAlpha

### maxLevel

    public double maxLevel

### minLevel

    public double minLevel

### clearColor

    public final java.awt.Color clearColor

### minColor

    public java.awt.Color minColor

### maxColor

    public java.awt.Color maxColor

### COLOR_DISCRETIZATION

    public static final int COLOR_DISCRETIZATION

See Also:
  Constant Field Values

### colors

    public java.awt.Color[] colors

  User-provided color table

Constructor Detail

### SimpleColorMap

    public SimpleColorMap()

  Constructs a ColorMap that gradiates from 0.0 -> black to 1.0 -> white. Values higher than 1.0 are mapped to white. Values less than 0.0 are mapped to black. Values from 0.0 through 1.0 are considered valid levels by validLevel(...). The default value is 0.0 (for defaultValue() ).

### SimpleColorMap

    public SimpleColorMap(double minLevel,
                          double maxLevel,
                          java.awt.Color minColor,
                          java.awt.Color maxColor)

  Constructs a ColorMap that gradiates from minLevel -> minColor to maxLevel -> maxColor. Values higher than maxLevel are mapped to maxColor. Values less than minLevel are mapped to minColor. Values from minLevel through maxLevel are considered valid levels by validLevel(...). The default value is minLevel (for defaultValue() ).

### SimpleColorMap

    public 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. Any real-valued number x, for 0 <= x < n, is converted into an integer (with floor()) and then mapped to an array color. For all other values, black is returned. Values from x through n, not including n, are considered valid levels by validLevel(...). The default value is 0 (for defaultValue() ).

### SimpleColorMap

    public 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. Any real-valued number x, for 0 <= x < n, is converted into an integer (with floor()) and then mapped to an array color. Outside this range, gradiation occurs for minLevel <= x <= maxLevel. For any other value of x, values higher than maxLevel are mapped to maxColor, and values less than minLevel are mapped to minColor. Values from x through n, not including n, and additionally values from minLevel through maxLevel, are considered valid levels by validLevel(...) The default value is 0 (for defaultValue() ).

Method Detail

### setLevels

    public 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. These are overridden by any array provided in setColorTable(). If the value in the IntGrid2D or DoubleGrid2D is less than or equal to minLevel, then minColor is used. If the value is greater than or equal to maxColor, then maxColor is used. Otherwise a linear interpolation from minColor to maxColor is used.

### setColorTable

    public 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 ... colors.length, then that index in the colors table should be used to represent that value. Otherwise, values in setLevels(...) are used. You can remove the color table by passing in null here. Returns the old color table.

### filterLevel

    public double filterLevel(double level)

### getColor

    public java.awt.Color getColor(double level)

  Override this if you'd like to customize the color for values in the portrayal. The default version looks up the value in the colors[] table, else computes the interpolated color and grabs it out of a predefined color cache (there can't be more than about 1024 or so interpolated colors, max).

  Specified by:
    `getColor` in interface `ColorMap`

### getAlpha

    public int getAlpha(double level)

  Description copied from interface: `ColorMap`
  Returns the alpha value for a color for the given level. This could be simply written as

  `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.

  Specified by:
    `getAlpha` in interface `ColorMap`

### getRGB

    public int getRGB(double level)

  Description copied from interface: `ColorMap`
  Returns the RGB values, plus alpha, for a color for the given level. The byte ordering should be in the same fashion that Color.getRGB() is provided. This could be simply written as

  `... however it's likely that this method could be written more efficiently than this.`

  Specified by:
    `getRGB` in interface `ColorMap`

### validLevel

    public boolean validLevel(double value)

  Description copied from interface: `ColorMap`
  Returns true if a level is "valid" (it provides a meaningful color)

  Specified by:
    `validLevel` in interface `ColorMap`

### defaultValue

    public double defaultValue()

  Description copied from interface: `ColorMap`
  Returns some level which is valid (that is, validLevel(defaultValue()) should always return true). This is commonly provided to give the user a level to replace an "invalid" level he's typed in.

  Specified by:
    `defaultValue` in interface `ColorMap`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD