Package org.evoludo.simulator
Class ColorMap<T>
Object
ColorMap<T>
- Type Parameters:
T- type of color object: String orMeshLambertMaterialfor GWT andColorfor JRE
- Direct Known Subclasses:
ColorMap.Gradient,ColorMap.Index,ColorMap3D,ColorMapCSS
Interface for mapping data to colors.
Colors are handled very differently in JRE and GWT as well as for HTML
canvas'es and WebGL. This class provides a unified interface,
which hides the implementation details.
Note:
- the interface provides a number of useful methods to blend colors.
- the implementation of all methods is optional because not all may be adequate for every data-to-color mapping.
- the
translate(...)methods fill in arrays of typeObject[]or returnObject's, respectively. This ambiguity is required to render the interface agnostic to the different implementations. - Color is emulated in GWT and can be used to set and manipulate colors but
needs to be converted to to CSS (for
canvas) or to Material (for WebGL), respectively, before applying to graphics or the GUI.
- Author:
- Christoph Hauert
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract super class for color maps following a gradient.static classOne dimensional color gradient spanning two or more colorsstatic classTwo dimensional color gradient with one color for each dimension.static classColor gradient forNdimensional data with one color for each dimension.static classColor gradient following the hue.static classAssociates integer indices with colors. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final doubleUseful constant for convertingintrepresentations of color channels (0-255) to floating point representations (0-1). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Color[]Utility method to add (or override) the transparency in the arraycolor.static ColorUtility method to add (or override) the transparency of colorcolor.static ColorUtility method for adding the red, green, blue and alpha components of two colors.static ColorblendColors(Color[] colors, double[] weights) Utility method for the smooth, component-wise blending of multiplecolorswith respectiveweights(includes alpha-channel).static ColorblendColors(Color one, Color two, double w1) Utility method for the smooth, component-wise blending of two colors, where coloronehas weightw1(and colortwohas weight(1-w1)) and includes the alpha-channel.abstract Tcolor2Color(Color color) Utility method to convert thecolorinto a color object of typeT.translate(double[] data) Translate the multi-traitdouble[]arraydatato a color.booleanTranslate thedata1anddata2arrays ofdouble[]multi-trait values to colors and store the results in thecolorarray.booleanTranslate thedataarray ofdouble[]multi-trait values to colors and store the results in thecolorarray.booleanTranslate thedataarray ofdoublevalues to colors and store the results in thecolorarray.booleanTranslate thedataarray ofintvalues to colors and store the results in thecolorarray.
-
Field Details
-
INV255
protected static final double INV255Useful constant for convertingintrepresentations of color channels (0-255) to floating point representations (0-1).- See Also:
-
-
Constructor Details
-
ColorMap
public ColorMap()Constructs a new color map.
-
-
Method Details
-
translate
Translate thedataarray ofintvalues to colors and store the results in thecolorarray. The type of thecolorarray depends on the implementation.Note: for performance reasons no validity checks are performed on the data. If any data entry is negative or
>nColorsan ArrayIndexOutOfBoundsException is thrown.- Parameters:
data- theint[]array to convert to colorscolor- the array for the resulting colors- Returns:
trueif translation successful
-
translate
Translate the multi-traitdouble[]arraydatato a color. The type of object returned depends on the implementation.- Parameters:
data- thedouble[]array to convert to a color- Returns:
- the color object
-
translate
Translate thedataarray ofdoublevalues to colors and store the results in thecolorarray. The type of thecolorarray depends on the implementation.Note: whether
datarefers to a single or multiple traits is up to the implementation to decide. For example,CXPopulationstores multiple traits in a linear array.- Parameters:
data- thedouble[]array to convert to colorscolor- the array for the resulting colors- Returns:
trueif translation successful
-
translate
Translate thedataarray ofdouble[]multi-trait values to colors and store the results in thecolorarray. The type of thecolorarray depends on the implementation.- Parameters:
data- thedouble[][]array to convert to colorscolor- the array for the resulting colors- Returns:
trueif translation successful
-
translate
Translate thedata1anddata2arrays ofdouble[]multi-trait values to colors and store the results in thecolorarray. The type of thecolorarray depends on the implementation.For example, frequencies and fitnesses, say
data1anddata2, respectively, yield the average fitness asdata1·data2(dot product), which then gets converted to a color.- Parameters:
data1- the firstdouble[]array to convert to colorsdata2- the seconddouble[]array to convert to colorscolor- the array for the resulting colors- Returns:
trueif translation successful
-
addColors
Utility method for adding the red, green, blue and alpha components of two colors.- Parameters:
one- the first colortwo- the second color- Returns:
- component-wise addition of the two colors
-
addAlpha
Utility method to add (or override) the transparency of colorcolor.- Parameters:
color- the color to add transparencyalpha- the new transparency (0: opaque, 255: transparent)- Returns:
- the new translucent color
-
addAlpha
Utility method to add (or override) the transparency in the arraycolor.- Parameters:
colors- the color array to add transparencyalpha- the new transparency (0: opaque, 255: transparent)- Returns:
- the new translucent color
-
blendColors
Utility method for the smooth, component-wise blending of two colors, where coloronehas weightw1(and colortwohas weight(1-w1)) and includes the alpha-channel.- Parameters:
one- the first colortwo- the second colorw1- the weight of colorone- Returns:
- component-wise addition of the two colors
-
blendColors
Utility method for the smooth, component-wise blending of multiplecolorswith respectiveweights(includes alpha-channel).- Parameters:
colors- the colors for blendingweights- the weights of each color- Returns:
- component-wise blending of
colors
-
color2Color
Utility method to convert thecolorinto a color object of typeT.- Parameters:
color- the color to convert- Returns:
- the color represented as an object of type
T
-