Class ColorMap.Gradient2D<T>

Object
ColorMap<T>
ColorMap.Gradient<T>
Gradient2D<T>
Type Parameters:
T - type of color object: String or MeshLambertMaterial for GWT and Color for JRE
Direct Known Subclasses:
ColorMap.GradientND, ColorMap3D.Gradient2D, ColorMapCSS.Gradient2D
Enclosing class:
ColorMap<T>

public abstract static class ColorMap.Gradient2D<T> extends ColorMap.Gradient<T>
Two dimensional color gradient with one color for each dimension.
See Also:
  • Nested Class Summary

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected 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), where max 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.

    Fields inherited from class ColorMap

    INV255
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    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 Type
    Method
    Description
    protected int
    binOf(double[] value, int trait)
    Utility method to calculate the index of the gradient color that corresponds to value for trait with index trait.
    protected int
    binOf(double value, int trait)
    Utility method to calculate the index of the gradient color that corresponds to value for trait with index trait.
    void
    setColor(double[] value, Color color)
    Assign a new color to the gradient for value.
    void
    setColor(double[] value, Color color, int alpha)
    Assign a new color to the gradient for value with transparency alpha.
    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 index index.
    translate(double[] data)
    Translate the multi-trait double[] array data to a color.
    boolean
    translate(double[][] data, T[] color)
    Translate the data array of double[] multi-trait values to colors and store the results in the color array.
    boolean
    translate(double[][] data, T[] color, int dep)
    Translate the data array of double[] multi-trait values with dependent trait dep to colors and store the results in the color array.
    boolean
    translate(double[] data, T[] color)
    Translate the data array of double values to colors and store the results in the color array.
    private T
    translate(double trait1, double trait2)
    Helper method to translate the trait values trait1 and trait2 into color gradient.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • gradient

      protected T[][] gradient
      Reference to pre-allocated gradient colors.
    • nGradient

      protected final int nGradient
      Number of colors in the gradient: nGradient+1.
    • nTraits

      protected final int nTraits
      Number of traits in the gradient: nTraits=2. This is only for convenience and readability of the code.
    • min

      protected double[] min
      Minimum data value. This value is mapped onto color gradient[0].
    • map

      protected double[] map
      Helper variable to make the mapping from a range of data values to indices of the gradient array more efficient: map=nBins/(max-min), where max maximum data value to be mapped.
  • Constructor Details

    • Gradient2D

      protected Gradient2D(Color trait1, Color trait2, Color bg, T[][] gradient)
      For internal use only. Construct 2D color gradient running from the background color bg to trait1 in one dimension and from bg to trait2 in the second dimension and store the resulting colors of type T in the provided 2D array gradient. The default range for mapping data values onto the color gradient is [0.0, 1.0]2.
      Parameters:
      trait1 - the color of the first trait
      trait2 - the color of the second trait
      bg - the background color
      gradient - the array to store the gradient colors
      See Also:
    • Gradient2D

      protected Gradient2D(int nTraits, int nGradient)
      For internal use only. Initialize color gradient for nTraits and nGradient increments. The default range for mapping data values onto the color gradient is [0.0, 1.0]nTraits.
      Parameters:
      nTraits - the number of traits
      nGradient - the number of color interpolations
      See Also:
  • Method Details

    • setColor

      public void setColor(double[] value, Color color)
      Assign a new color to the gradient for value.
      Parameters:
      value - the value of the color
      color - the new color for value
    • setColor

      public void setColor(double[] value, Color color, int alpha)
      Assign a new color to the gradient for value with transparency alpha.

      Note: the transparency of the supplied color is always honoured but overruled if alpha != 255.

      Parameters:
      value - the value of the color
      color - the new color for value
      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 to value for trait with index trait. Returns -1 if value is invalid or lies outside the range of the gradient.
      Parameters:
      value - the array of values to convert to a bin index of the gradient
      trait - 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 to value for trait with index trait. Returns -1 if value is invalid or lies outside the range of the gradient.
      Parameters:
      value - the value to convert to a bin index of the gradient
      trait - 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 gradient
      max - 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 gradient
      max - 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 is idx. The data range for the first trait is [min[0], max[0]] and for the second trait [min[1], max[1], assuming that idx=2 for the above illustration.
      Parameters:
      min - the array with the minimum values
      max - the array with the maximum values
      idx - 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 index index.
      Parameters:
      min - the minimum value of the gradient
      max - the maximum value of the gradient
      idx - the index of the trait
    • translate

      public T translate(double[] data)
      Description copied from class: ColorMap
      Translate the multi-trait double[] array data to a color. The type of object returned depends on the implementation.
      Overrides:
      translate in class ColorMap<T>
      Parameters:
      data - the double[] array to convert to a color
      Returns:
      the color object
    • translate

      private T translate(double trait1, double trait2)
      Helper method to translate the trait values trait1 and trait2 into color gradient.
      Parameters:
      trait1 - the value of the first trait
      trait2 - the value of the second trait
      Returns:
      the gradient Color based on trait1 and trait2
    • translate

      public boolean translate(double[] data, T[] color)
      Translate the data array of double values to colors and store the results in the color array. The type of the color 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:

      1. Two subsequent entries, data[n] and data[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 the color array.
      2. For performance reasons no validity checks on data. In particular, all data entries must lie inside the range for mapping data values.
      Overrides:
      translate in class ColorMap<T>
      Parameters:
      data - the double[] array to convert to colors
      color - the array for the resulting colors
      Returns:
      true if translation successful
      See Also:
    • translate

      public boolean translate(double[][] data, T[] color)
      Translate the data array of double[] multi-trait values to colors and store the results in the color array. The type of the color array depends on the implementation.

      Implementation:

      1. Each entry in data represents a multi-dimensional trait value, which is converted to the corresponding gradient color and returned in the color array. An example are trait densities in PDE models.
      2. For performance reasons no validity checks on data. In particular, all data entries must lie inside the range for mapping data values.
      Overrides:
      translate in class ColorMap<T>
      Parameters:
      data - the double[][] array to convert to colors
      color - the array for the resulting colors
      Returns:
      true if translation successful
      See Also:
    • translate

      public boolean translate(double[][] data, T[] color, int dep)
      Translate the data array of double[] multi-trait values with dependent trait dep to colors and store the results in the color array. The type of the color array depends on the implementation.

      Implementation:

      1. Each entry in data represents a multi-dimensional trait value, which is converted to the corresponding gradient color and returned in the color array. An example are trait densities in PDE models.
      2. For performance reasons no validity checks on data. In particular, all data entries must lie inside the range for mapping data values.
      Overrides:
      translate in class ColorMap<T>
      Parameters:
      data - the double[] array to convert to colors
      color - the array for the resulting colors
      dep - index of dependent trait
      Returns:
      true if translation successful
      See Also: