Package org.evoludo.simulator
Class ColorMap.Gradient2D<T>
Object
ColorMap<T>
ColorMap.Gradient<T>
Gradient2D<T>
- Type Parameters:
T
- type of color object: String orMeshLambertMaterial
for GWT andColor
for JRE
- Direct Known Subclasses:
ColorMap.GradientND
,ColorMap3D.Gradient2D
,ColorMapCSS.Gradient2D
Two dimensional color gradient with one color for each dimension.
- 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
Number of traits in the gradient:nTraits=2
. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Gradient2D
(int nTraits, int nGradient) For internal use only.protected
Gradient2D
(Color trait1, Color trait2, Color bg, T[][] gradient) For internal use only. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
binOf
(double[] value, int trait) Utility method to calculate the index of the gradient color that corresponds tovalue
for trait with indextrait
.protected int
binOf
(double value, int trait) Utility method to calculate the index of the gradient color that corresponds tovalue
for trait with indextrait
.void
Assign a newcolor
to the gradient forvalue
.void
Assign a newcolor
to the gradient forvalue
with transparencyalpha
.void
setRange
(double[] min, double[] max) Sets the range of values spanned by the gradient to[min,max]
in both dimensions.void
setRange
(double[] min, double[] max, int idx) Set the range of data values for three dimensional data with dependent trait.void
setRange
(double min, double max) Sets the range of values spanned by the gradient to[min,max]
in both dimensions.void
setRange
(double min, double max, int idx) Sets the range of values spanned by the gradient to[min,max]
for the trait with indexindex
.translate
(double[] data) Translate the multi-traitdouble[]
arraydata
to a color.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.private T
translate
(double trait1, double trait2) Helper method to translate the trait valuestrait1
andtrait2
into color gradient.Methods inherited from class ColorMap.Gradient
interpolateColors, interpolateColors, translate
Methods inherited from class ColorMap
addAlpha, addAlpha, addColors, blendColors, blendColors, color2Color, translate, translate
-
Field Details
-
gradient
Reference to pre-allocated gradient colors. -
nGradient
protected final int nGradientNumber of colors in the gradient:nGradient+1
. -
nTraits
protected final int nTraitsNumber of traits in the gradient:nTraits=2
. This is only for convenience and readability of the code. -
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.
-
-
Constructor Details
-
Gradient2D
For internal use only. Construct 2D color gradient running from the background colorbg
totrait1
in one dimension and frombg
totrait2
in the second dimension and store the resulting colors of typeT
in the provided 2D arraygradient
. The default range for mapping data values onto the color gradient is[0.0, 1.0]2
.- Parameters:
trait1
- the color of the first traittrait2
- the color of the second traitbg
- the background colorgradient
- the array to store the gradient colors- See Also:
-
Gradient2D
protected Gradient2D(int nTraits, int nGradient) For internal use only. Initialize color gradient fornTraits
andnGradient
increments. The default range for mapping data values onto the color gradient is[0.0, 1.0]nTraits
.- Parameters:
nTraits
- the number of traitsnGradient
- the number of color interpolations- 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, int trait) Utility method to calculate the index of the gradient color that corresponds tovalue
for trait with indextrait
. Returns-1
ifvalue
is invalid or lies outside the range of the gradient.- Parameters:
value
- the array of values to convert to a bin index of the gradienttrait
- the index of the trait- Returns:
- the index of the bin or
-1
-
binOf
protected int binOf(double value, int trait) Utility method to calculate the index of the gradient color that corresponds tovalue
for trait with indextrait
. 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 gradienttrait
- the index of the corresponding trait- Returns:
- the index of the bin or
-1
-
setRange
public void setRange(double min, double max) Sets the range of values spanned by the gradient to[min,max]
in both dimensions.- Parameters:
min
- the minimum value of the gradientmax
- the maximum value of the gradient
-
setRange
public void setRange(double[] min, double[] max) Sets the range of values spanned by the gradient to[min,max]
in both dimensions.- Parameters:
min
- the minimum value of the gradientmax
- the maximum value of the gradient
-
setRange
public void setRange(double[] min, double[] max, int idx) Set the range of data values for three dimensional data with dependent trait. The index of the dependent trait isidx
. The data range for the first trait is[min[0], max[0]]
and for the second trait[min[1], max[1]
, assuming thatidx=2
for the above illustration.- Parameters:
min
- the array with the minimum valuesmax
- the array with the maximum valuesidx
- the index of the dependent trait
-
setRange
public void setRange(double min, double max, int idx) Sets the range of values spanned by the gradient to[min,max]
for the trait with indexindex
.- Parameters:
min
- the minimum value of the gradientmax
- the maximum value of the gradientidx
- the index of the trait
-
translate
Description copied from class:ColorMap
Translate the multi-traitdouble[]
arraydata
to a color. The type of object returned depends on the implementation. -
translate
Helper method to translate the trait valuestrait1
andtrait2
into color gradient.- Parameters:
trait1
- the value of the first traittrait2
- the value of the second trait- Returns:
- the gradient Color based on
trait1
andtrait2
-
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:
- Two subsequent entries,
data[n]
anddata[n+1]
are converted to the corresponding gradient colors. This applies, for example, to data from continuous games with multiple traits. The gradient colors are 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.
- Two subsequent entries,
-
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
represents a multi-dimensional trait value, which is converted to the corresponding gradient color and returned in thecolor
array. An example are trait densities in PDE models. - 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 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.Implementation:
- Each entry in
data
represents a multi-dimensional trait value, which is converted to the corresponding gradient color and returned in thecolor
array. An example are trait densities in PDE models. - 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
-