Template Class DiscreteColor

Inheritance Relationships

Base Types

  • public flamegpu::visualiser::ColorFunction (Class ColorFunction)

  • public std::map< int32_t, Color >

Class Documentation

template<typename T = int32_t>
class DiscreteColor : public flamegpu::visualiser::ColorFunction, public std::map<int32_t, Color>

Used to define a discrete color selection function Integer keys are mapped to static colors Add key:color pairs to this class as you would a std::map * This class only supports being instantiated with types int32_t, and uint32_t These have been typedef as iDiscreteColor and uDiscreteColor respectively The agent variable which provides the key should be of the corresponding type

Note

Currently ignores alpha channel of colors as Alpha support isn’t properly tested

Public Functions

DiscreteColor(const std::string &variable_name, const Color &fallback)

Constructs a discrete color function generator

Parameters:
  • variable_name – Name of the agent variable which provides the integer key, this key must have type T within the model

  • fallbackColor that is returned when the provided integer is not found within the map

DiscreteColor(const std::string &variable_name, const Palette &palette, const Color &fallback, T offset = 0, T stride = 1)

Constructs a discrete color function generator from a palette, with a separate fallback color

Parameters:
  • variable_name – Name of the agent variable which provides the integer key

  • palette – The colors to use

  • fallback – The color to return when they lookup doesn’t have a matching int

  • offset – The key to map to the first palette color

  • stride – The value to added to every subsequent key

DiscreteColor(const std::string &variable_name, const Palette &palette, T offset = 0, T stride = 1)

Constructs a discrete color function generator from a palette, with the palette’s final color used as the fallback color This version maps the final color of the palette to the fallback, rather than an integer key

Parameters:
  • variable_name – Name of the agent variable which provides the integer key

  • palette – The colors to use

  • offset – The key to map to the first palette color

  • stride – The value to added to every subsequent key

virtual std::string getSrc(unsigned int array_len) const override

Returns a function containing a switch statement through the entries of the map, e.g. uniform samplerBuffer color_arg; vec4 calculateColor() { const int category = floatBitsToInt(texelFetch(color_arg, gl_InstanceID).x); switch (category) { case 12: return vec4(1, 0, 0, 1); default: return vec4(0, 1, 0, 1); } }

Parameters:

array_len – Length of the variable array

virtual std::string getSamplerName() const override

Always returns “color_arg”

virtual std::string getAgentVariableName() const override

Returns variable_name

virtual std::type_index getAgentVariableRequiredType() const override

Returns std::type_index(typeid(T))

bool validate() const

Checks whether the current components can be used as a valid RGBA colour Returns false if any contained color components are outside of the range [0.0, 1.0]