Package org.evoludo.simulator
Class ColorMap<T>
Object
ColorMap<T>
- Type Parameters:
T
- type of color object: String orMeshLambertMaterial
for GWT andColor
for 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 class
Abstract super class for color maps following a gradient.static class
One dimensional color gradient spanning two or more colorsstatic class
Two dimensional color gradient with one color for each dimension.static class
Color gradient forN
dimensional data with one color for each dimension.static class
Color gradient following the hue.static class
Associates integer indices with colors. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final double
Useful constant for convertingint
representations 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 Color
Utility method to add (or override) the transparency of colorcolor
.static Color
Utility method for adding the red, green, blue and alpha components of two colors.static Color
blendColors
(Color[] colors, double[] weights) Utility method for the smooth, component-wise blending of multiplecolors
with respectiveweights
(includes alpha-channel).static Color
blendColors
(Color one, Color two, double w1) Utility method for the smooth, component-wise blending of two colors, where colorone
has weightw1
(and colortwo
has weight(1-w1)
) and includes the alpha-channel.abstract T
color2Color
(Color color) Utility method to convert thecolor
into a color object of typeT
.translate
(double[] data) Translate the multi-traitdouble[]
arraydata
to a color.boolean
Translate thedata1
anddata2
arrays ofdouble[]
multi-trait values to colors and store the results in thecolor
array.boolean
Translate thedata
array ofdouble[]
multi-trait values to colors and store the results in thecolor
array.boolean
Translate thedata
array ofdouble[]
multi-trait values with dependent traitdep
to colors and store the results in thecolor
array.boolean
Translate thedata
array ofdouble
values to colors and store the results in thecolor
array.boolean
Translate thedata
array ofint
values to colors and store the results in thecolor
array.
-
Field Details
-
INV255
protected static final double INV255Useful constant for convertingint
representations 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 thedata
array ofint
values to colors and store the results in thecolor
array. The type of thecolor
array depends on the implementation.Note: for performance reasons no validity checks are performed on the data. If any data entry is negative or
>nColors
an ArrayIndexOutOfBoundsException is thrown.- Parameters:
data
- theint[]
array to convert to colorscolor
- the array for the resulting colors- Returns:
true
if translation successful
-
translate
Translate the multi-traitdouble[]
arraydata
to 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 thedata
array ofdouble
values to colors and store the results in thecolor
array. The type of thecolor
array depends on the implementation.Note: whether
data
refers to a single or multiple traits is up to the implementation to decide. For example,CXPopulation
stores multiple traits in a linear array.- Parameters:
data
- thedouble[]
array to convert to colorscolor
- the array for the resulting colors- Returns:
true
if translation successful
-
translate
Translate thedata
array ofdouble[]
multi-trait values to colors and store the results in thecolor
array. The type of thecolor
array depends on the implementation.- Parameters:
data
- thedouble[][]
array to convert to colorscolor
- the array for the resulting colors- Returns:
true
if translation successful
-
translate
Translate thedata
array ofdouble[]
multi-trait values with dependent traitdep
to colors and store the results in thecolor
array. The type of thecolor
array depends on the implementation.- Parameters:
data
- thedouble[]
array to convert to colorscolor
- the array for the resulting colorsdep
- index of dependent trait- Returns:
true
if translation successful
-
translate
Translate thedata1
anddata2
arrays ofdouble[]
multi-trait values to colors and store the results in thecolor
array. The type of thecolor
array depends on the implementation.For example, frequencies and fitnesses, say
data1
anddata2
, 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:
true
if 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 colorone
has weightw1
(and colortwo
has 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 multiplecolors
with 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 thecolor
into a color object of typeT
.- Parameters:
color
- the color to convert- Returns:
- the color represented as an object of type
T
-