Web Analytics Made Easy - Statcounter
Skip to content

Class SBDPaletteDiscrete#

ClassList > SBDPaletteDiscrete

The SBDPaletteDiscrete class is a specialized class for creating discrete color palettes.More...

  • #include <SBDPaletteDiscrete.hpp>

Inherits the following classes: SBDPalette

Public Types inherited from SBDPalette#

See SBDPalette

Type Name
enum PaletteType
The three different types of palettes - qualitative, sequential, and diverging - are all constructed by combining three different types of trajectories (constant, linear, triangular) for the three different coordinates in the given color space (e.h.: hue H, chroma C, luminance L)

Public Functions#

Type Name
SBDPaletteDiscrete ()
Default constructor.
SBDPaletteDiscrete (const std::vector< SBColor > & colors, std::string name=std::string(""), bool reverse=false)
Construct a discrete palette based on colors .
SBDPaletteDiscrete (const SBDPaletteDiscrete & otherColorPalette)
Copy constructor.
virtual SBDPaletteDiscrete * clone () override const
Clones the color palette.
virtual void getColor (float * color, float value) override const
Computes sRGB color color based on this palette for the given intensity valuevalue which should be in the range [0.0, 1.0].
const std::vector< SBColor > & getColors () const
Returns the vector of colors used in the color palette.
SBColor getCycledColor (int value) const
Returns SBColor based on the palette and a value value that will be cycled to be within the range [0, number of colors in the palette].
virtual void getCycledColor (float * color, int value) const
Computes RGB color color based on the palette and a valuevalue that will be cycled to be within the range [0, number of colors in the palette].
size_t getNumberOfColors () const
Returns the number of colors in the color palette.
virtual PaletteType getType () override const
Returns the type of the color palette.
virtual bool isEqual (const SBDPalette & other) override const
Returns whether this palette is equal to other .
virtual bool isSerializable () override const
Returns true __
virtual void serialize (SBCSerializer * serializer, const SBVersionNumber & sdkVersionNumber=SB_SDK_VERSION_NUMBER, const SBVersionNumber & classVersionNumber=SBVersionNumber(1, 0, 0)) override const
Serializes the palette.
virtual std::string toPythonCode () override const
Returns the string representation of the object that can be used to reconstruct it in Python.
virtual void unserialize (SBCSerializer * serializer, const SBVersionNumber & sdkVersionNumber=SB_SDK_VERSION_NUMBER, const SBVersionNumber & classVersionNumber=SBVersionNumber(1, 0, 0)) override
Unserializes the palette.
virtual ~SBDPaletteDiscrete ()
Destructor.

Public Functions inherited from SBDPalette#

See SBDPalette

Type Name
SBDPalette ()
Default constructor for HSV color palette.
SBDPalette (bool reverse)
Constructor for HSV color palette with reverse flag.
virtual SBDPalette * clone () const
Clones the palette.
SBColor getColor (float value) const
Returns SBColor based on the palette and an intensity value value .
virtual void getColor (float * color, float value) const
Computes RGB color color based on the palette and an intensity valuevalue which should be in the range [0.0, 1.0].
virtual void getColorInPaletteColorSpace (float * color, float value) const
Computes color coordinates color in this palette's color space for the given intensity valuevalue which should be in the range [0.0, 1.0].
const std::string & getName () const
Returns the palette's name.
bool getReverseFlag () const
Returns the reverse flag - whether the color palette is mirrored or not.
virtual PaletteType getType () const
Returns the type of the color palette.
std::string getTypeString (bool humanReadable=false) const
Returns the string representation of the color palette type.
virtual bool isEqual (const SBDPalette & other) const
Returns whether this palette is equal to other .
virtual bool isSerializable () const
Returns true __
bool operator!= (const SBDPalette & other) const
Inequality operator.
bool operator== (const SBDPalette & other) const
Equality operator.
virtual void serialize (SBCSerializer * serializer, const SBVersionNumber & sdkVersionNumber=SB_SDK_VERSION_NUMBER, const SBVersionNumber & classVersionNumber=SBVersionNumber(1, 0, 0)) const
Serializes the document.
void setName (const std::string & name)
Sets the palette's name to name .
void setReverseFlag (bool b)
Sets the reverse flag - whether to mirror or not the color palette.
virtual std::string toPythonCode () const
Returns the string representation of the object that can be used to reconstruct it in Python.
virtual void unserialize (SBCSerializer * serializer, const SBVersionNumber & sdkVersionNumber=SB_SDK_VERSION_NUMBER, const SBVersionNumber & classVersionNumber=SBVersionNumber(1, 0, 0))
Unserializes the document.
virtual ~SBDPalette ()
Destructor.

Public Static Functions inherited from SBDPalette#

See SBDPalette

Type Name
std::string getTypeString (PaletteType paletteType, bool humanReadable=false)
Returns the string representation of the color palette type paletteType .
float getValueAlongLinearTrajectory (float y1, float y2, float power, float x)
Returns a value along the "linear" trajectory.
float getValueAlongTriangularTrajectory (float y1, float ymax, float y2, float power, float x)
Returns a value along "triangular" trajectory.

Protected Attributes#

Type Name
std::vector< SBColor > * colors
The vector of colors.

Protected Attributes inherited from SBDPalette#

See SBDPalette

Type Name
std::string * name
The palette's name.
bool reverseFlag
Reverse flag: if true, then the palette is reversed/mirrored.

Detailed Description#

This class extends the SBDPalette class, allowing for the creation of discrete color palettes. Discrete palettes are defined by a list of distinct colors, typically used for categorical data.

The discrete palettes allows you to cycle through its colors through SBDPaletteDiscrete::getCycledColor.

Short name: SBPaletteDiscrete

Public Functions Documentation#

function SBDPaletteDiscrete [1/3]#

Default constructor.

SBDPaletteDiscrete::SBDPaletteDiscrete () 

Constructs an empty discrete palette with no colors.


function SBDPaletteDiscrete [2/3]#

Construct a discrete palette based on colors .

SBDPaletteDiscrete::SBDPaletteDiscrete (
    const std::vector< SBColor > & colors,
    std::string name=std::string(""),
    bool reverse=false
) 

Constructs a discrete palette from a list of colors.

Parameters:

  • colors The vector of colors to include in the palette.
  • name Optional name for the palette. Defaults to an empty string.
  • reverse If true, the palette will be reversed when accessed.

function SBDPaletteDiscrete [3/3]#

Copy constructor.

SBDPaletteDiscrete::SBDPaletteDiscrete (
    const SBDPaletteDiscrete & otherColorPalette
) 

Parameters:

  • otherColorPalette The palette to copy.

function clone#

Clones the color palette.

virtual SBDPaletteDiscrete * SBDPaletteDiscrete::clone () override const

Creates a copy of this palette.

Returns:

A pointer to a new SBDPaletteDiscrete that is a copy of this instance.

Implements SBDPalette::clone


function getColor#

Computes sRGB color color based on this palette for the given intensity valuevalue which should be in the range [0.0, 1.0].

virtual void SBDPaletteDiscrete::getColor (
    float * color,
    float value
) override const

SBDPaletteDiscrete::getColor - Computes RGB color color based on the palette and an intensity value value.

Parameters:

  • color - an array for color coordinates with the size equal to 4.
  • value - an intensity value based on which the resulting color is computed, the intensity value should be in range [0.0, 1.0] where 1 corresponds to the full intensity.

Implements SBDPalette::getColor


function getColors#

Returns the vector of colors used in the color palette.

const std::vector< SBColor > & SBDPaletteDiscrete::getColors () const

Retrieves the vector of colors used in the palette.

Returns:

A constant reference to the vector of SBColor objects.


function getCycledColor [1/2]#

Returns SBColor based on the palette and a value value that will be cycled to be within the range [0, number of colors in the palette].

SBColor SBDPaletteDiscrete::getCycledColor (
    int value
) const

Returns a color from the palette based on a given integer value, cycling the value if necessary.

Parameters:

  • value An integer value used to select the color; it will be cycled to the valid range.

Returns:

The SBColor selected from the palette.


function getCycledColor [2/2]#

Computes RGB color color based on the palette and a valuevalue that will be cycled to be within the range [0, number of colors in the palette].

virtual void SBDPaletteDiscrete::getCycledColor (
    float * color,
    int value
) const

SBDPaletteDiscrete::getCycledColor - Computes RGB color color based on the palette and a value value.

Parameters:

  • color - an array for color coordinates with the size equal to 4 to store the RGB color.
  • value - an integer value based on which the resulting color is computed, the value will be cycled to be within the range [0, number of colors in the palette].

function getNumberOfColors#

Returns the number of colors in the color palette.

size_t SBDPaletteDiscrete::getNumberOfColors () const

Retrieves the number of colors in the palette.

Returns:

The number of colors.


function getType#

Returns the type of the color palette.

virtual PaletteType SBDPaletteDiscrete::getType () override const

Retrieves the type of this palette.

Returns:

The PaletteType indicating this is a discrete palette.

Implements SBDPalette::getType


function isEqual#

Returns whether this palette is equal to other .

virtual bool SBDPaletteDiscrete::isEqual (
    const SBDPalette & other
) override const

Checks whether this palette is equal to another palette.

Parameters:

  • other The other palette to compare against.

Returns:

true if the palettes have the same colors and properties; false otherwise.

Implements SBDPalette::isEqual


function isSerializable#

Returns true __

virtual bool SBDPaletteDiscrete::isSerializable () override const

Indicates whether this palette can be serialized.

Returns:

true, as discrete palettes support serialization.

Implements SBDPalette::isSerializable


function serialize#

Serializes the palette.

virtual void SBDPaletteDiscrete::serialize (
    SBCSerializer * serializer,
    const SBVersionNumber & sdkVersionNumber=SB_SDK_VERSION_NUMBER,
    const SBVersionNumber & classVersionNumber=SBVersionNumber (1, 0, 0)
) override const

Serializes the palette to a serializer.

Parameters:

  • serializer The serializer used to write the palette data.
  • sdkVersionNumber The SDK version for compatibility checks.
  • classVersionNumber The class version for compatibility checks.

Implements SBDPalette::serialize


function toPythonCode#

Returns the string representation of the object that can be used to reconstruct it in Python.

virtual std::string SBDPaletteDiscrete::toPythonCode () override const

Generates a Python code representation of this palette.

Returns:

A string containing Python code that can recreate this palette.

Implements SBDPalette::toPythonCode


function unserialize#

Unserializes the palette.

virtual void SBDPaletteDiscrete::unserialize (
    SBCSerializer * serializer,
    const SBVersionNumber & sdkVersionNumber=SB_SDK_VERSION_NUMBER,
    const SBVersionNumber & classVersionNumber=SBVersionNumber (1, 0, 0)
) override

Unserializes the palette from a serializer.

Parameters:

  • serializer The serializer used to read the palette data.
  • sdkVersionNumber The SDK version for compatibility checks.
  • classVersionNumber The class version for compatibility checks.

Implements SBDPalette::unserialize


function ~SBDPaletteDiscrete#

Destructor.

virtual SBDPaletteDiscrete::~SBDPaletteDiscrete () 

Releases allocated resources.


Protected Attributes Documentation#

variable colors#

The vector of colors.

std::vector<SBColor>* SBDPaletteDiscrete::colors;