Package org.evoludo.simulator
Class ColorMap.Gradient2D<T>
Object
ColorMap<T>
ColorMap.Gradient<T>
Gradient2D<T>
- Type Parameters:
T- type of color object: String orMeshLambertMaterialfor GWT andColorfor 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), wheremaxmaximum data value to be mapped.protected double[]Minimum data value.protected final intNumber of colors in the gradient:nGradient+1.protected final intNumber of traits in the gradient:nTraits=2.(package private) intThe index of the color for the first trait.(package private) intThe index of the color for the second trait. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGradient2D(int nTraits, int nGradient) For internal use only.protectedGradient2D(Color[] colors, int dep, T[][] gradient) Construct a 2D color gradient. -
Method Summary
Modifier and TypeMethodDescriptionprotected intbinOf(double[] value, int trait) Utility method to calculate the index of the gradient color that corresponds tovaluefor trait with indextrait.protected intbinOf(double value, int trait) Utility method to calculate the index of the gradient color that corresponds tovaluefor trait with indextrait.voidAssign a newcolorto the gradient forvalue.voidAssign a newcolorto the gradient forvaluewith transparencyalpha.voidsetRange(double[] min, double[] max) Sets the range of values spanned by the gradient to[min,max]in both dimensions.voidsetRange(double[] min, double[] max, int idx) Set the range of data values for three dimensional data with dependent trait.voidsetRange(double min, double max) Sets the range of values spanned by the gradient to[min,max]in both dimensions.voidsetRange(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[]arraydatato a color.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.Methods inherited from class ColorMap.Gradient
interpolateColors, interpolateColors, translateMethods 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), wheremaxmaximum data value to be mapped. -
trait1
int trait1The index of the color for the first trait. -
trait2
int trait2The index of the color for the second trait.
-
-
Constructor Details
-
Gradient2D
Construct a 2D color gradient. With a dependent trait (dep >= 0) the gradient is created on a simplex. While without a dependent trait (dep < 0) the gradient is created with black in the corner where both traits are zero. The number of shades in the gradient are determined by the dimensions ofgradient.Important: The
gradientarray is assumed to be square.- Parameters:
colors- the array of trait colorsdep- the index of the dependent traitgradient- the array to store the gradient colors
-
Gradient2D
protected Gradient2D(int nTraits, int nGradient) For internal use only. Initialize color gradient fornTraitsandnGradientincrements. 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 newcolorto the gradient forvalue.- Parameters:
value- the value of thecolorcolor- the new color forvalue
-
setColor
Assign a newcolorto the gradient forvaluewith transparencyalpha.Note: the transparency of the supplied color is always honoured but overruled if
alpha != 255.- Parameters:
value- the value of thecolorcolor- the new color forvaluealpha- 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 tovaluefor trait with indextrait. Returns-1ifvalueis 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 tovaluefor trait with indextrait. Returns-1ifvalueis 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=2for 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:ColorMapTranslate the multi-traitdouble[]arraydatato a color. The type of object returned depends on the implementation. -
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.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 thecolorarray. - 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 thedataarray ofdouble[]multi-trait values to colors and store the results in thecolorarray. The type of thecolorarray depends on the implementation.Implementation:
- Each entry in
datarepresents a multi-dimensional trait value, which is converted to the corresponding gradient color and returned in thecolorarray. 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
-