Package org.evoludo.simulator
Class ColorMap.Gradient1D<T>
Object
ColorMap<T>
ColorMap.Gradient<T>
Gradient1D<T>
- Type Parameters:
T
- type of color object: String orMeshLambertMaterial
for GWT andColor
for JRE
- Direct Known Subclasses:
ColorMap.Hue
,ColorMap3D.Gradient1D
,ColorMapCSS.Gradient1D
One dimensional color gradient spanning two or more colors
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class ColorMap
ColorMap.Gradient<T>, ColorMap.Gradient1D<T>, ColorMap.Gradient2D<T>, ColorMap.GradientND<T>, ColorMap.Hue<T>, ColorMap.Index<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected T[]
Reference to pre-allocated gradient colors.protected double
Helper variable to make the mapping from a range of data values to indices of the gradient array more efficient:map=nBins/(max-min)
, wheremax
maximum data value to be mapped.protected double
Minimum data value.protected final int
Number of colors in the gradient:nGradient+1
.protected final int
The index of the trait that this gradient refers to (or-1
if not applicable). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Gradient1D
(Color[] colors, int trait, T[] gradient) For internal use only.protected
Gradient1D
(T[] gradient) For internal use only.protected
Gradient1D
(T[] gradient, int trait) For internal use only. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
binOf
(double value) Utility method to calculate the index of the gradient color that corresponds tovalue
.void
Assign a newcolor
to the gradient forvalue
.void
Assign a newcolor
to the gradient forvalue
with transparencyalpha
.void
setGradient
(Color[] colors) Sets the gradient to span the colors in the arraycolors
.void
setGradient
(Color[] colors, int trait) Sets the gradient for the trait with indextrait
to span the colors in the arraycolors
.void
setRange
(double min, double max) Sets the range of values spanned by the gradient to[min,max]
.translate
(double data) Translate thedouble
valuedata
to a color gradient.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
values to colors and store the results in thecolor
array.Methods inherited from class ColorMap.Gradient
interpolateColors, interpolateColors
Methods inherited from class ColorMap
addAlpha, addAlpha, addColors, blendColors, blendColors, color2Color, translate, translate, translate
-
Field Details
-
gradient
Reference to pre-allocated gradient colors. -
nGradient
protected final int nGradientNumber of colors in the gradient:nGradient+1
. -
min
protected double minMinimum data value. This value is mapped onto colorgradient[0]
. -
map
protected double mapHelper variable to make the mapping from a range of data values to indices of the gradient array more efficient:map=nBins/(max-min)
, wheremax
maximum data value to be mapped. -
trait
protected final int traitThe index of the trait that this gradient refers to (or-1
if not applicable).
-
-
Constructor Details
-
Gradient1D
For internal use only. Construct color gradient running through all the colors in the arraycolors
for the trait with indextrait
(or-1
if not applicable). The gradient colors of typeT
are stored ingradient
. The number of interpolated intermediate colors between two subsequent entries incolors
is(gradient.length-1)/(N-1)
, whereN
is the number of colors incolors
. The default range for mapping data values onto the color gradient is[0.0, 1.0]
.- Parameters:
colors
- the equally spaced reference colors of the gradienttrait
- the trait index for the color gradientgradient
- the array to store the gradient colors- See Also:
-
Gradient1D
For internal use only. Initializes gradient based on the supplied arraygradient
of typeT
.- Parameters:
gradient
- the array to store the gradient colors
-
Gradient1D
For internal use only. Initializes gradient based on the supplied arraygradient
of typeT
for trait with indextrait
. The default range for mapping data values onto the color gradient is[0.0, 1.0]
.- Parameters:
gradient
- the array to store the gradient colorstrait
- the trait index for the color gradient- See Also:
-
-
Method Details
-
setColor
Assign a newcolor
to the gradient forvalue
.- Parameters:
value
- the value of thecolor
color
- the new color forvalue
-
setColor
Assign a newcolor
to the gradient forvalue
with transparencyalpha
.Note: the transparency of the supplied color is always honoured but overruled if
alpha != 255
.- Parameters:
value
- the value of thecolor
color
- the new color forvalue
alpha
- the transparency of the new color
-
binOf
protected int binOf(double value) Utility method to calculate the index of the gradient color that corresponds tovalue
. Returns-1
ifvalue
is invalid or lies outside the range of the gradient.- Parameters:
value
- the value to convert to a bin index of the gradient- Returns:
- the index of the bin or
-1
-
setGradient
Sets the gradient to span the colors in the arraycolors
.- Parameters:
colors
- the array of colors for the gradient
-
setGradient
Sets the gradient for the trait with indextrait
to span the colors in the arraycolors
.- Parameters:
colors
- the array of colors for the gradienttrait
- the trait index for the color gradient
-
setRange
public void setRange(double min, double max) Sets the range of values spanned by the gradient to[min,max]
.- Parameters:
min
- the minimum value of the gradientmax
- the maximum value of the gradient
-
translate
Description copied from class:ColorMap.Gradient
Translate thedouble
valuedata
to a color gradient. The type of object returned depends on the implementation.- Overrides:
translate
in classColorMap.Gradient<T>
- Parameters:
data
- thedouble
value 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.Implementation: For performance reasons no validity checks on
data
. In particular, all data entries must lie inside the range for mapping data values. -
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.Implementation:
- Each entry in
data
is assumed to be one dimensional (only first entry used) and converted to the corresponding gradient color and returned in thecolor
array. - For performance reasons no validity checks on
data
. In particular, all data entries must lie inside the range for mapping data values.
- Each entry in
-
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.
-