cgv
Loading...
Searching...
No Matches
cgv::media::discrete_color_scale Class Reference

Implementation of a color_scale with a discrete input domain and output range using a discrete_color_scheme. More...

#include <color_scale.h>

Inheritance diagram for cgv::media::discrete_color_scale:
cgv::media::color_scale

Public Member Functions

 discrete_color_scale (const discrete_color_scheme &scheme, size_t size)
 Construct using the given color scheme and size.
 
bool is_discrete () const override
 See color_scale::is_discrete().
 
bool is_opaque () const override
 See color_scale::is_opaque().
 
float normalize_value (float value) const override
 See color_scale::normalize_value().
 
cgv::rgb get_mapped_color (float value) const override
 Map a value through the scale and return a RGB color.
 
cgv::rgba get_indexed_color (size_t index) const override
 Return the RGBA color with the given index.
 
size_t get_indexed_color_count () const override
 See color_scale::get_indexed_color_count().
 
std::vector< cgv::rgbaquantize (size_t count) const override
 Return a sequence of all indexed colors, ignoring count.
 
std::vector< float > get_ticks (size_t request_count) const override
 Not implemented for discrete color scales.
 
void set_scheme (const discrete_color_scheme &scheme, size_t size)
 Set the color scheme and size used as this scale's indexed color source.
 
discrete_color_scheme get_scheme () const
 Get the color scheme used as this scale's indexed color source.
 
- Public Member Functions inherited from cgv::media::color_scale
virtual ~color_scale ()
 Destruct this color scale.
 
virtual void set_domain (cgv::vec2 domain)
 Set the input domain of scalars that will be mapped.
 
cgv::vec2 get_domain () const
 Get the input domain of scalars that will be mapped.
 
virtual void set_clamped (bool clamped)
 Set whether the input values are clamped to the domain before mapping.
 
bool is_clamped () const
 Get whether the input values are clamped to the domain before mapping.
 
virtual void set_reversed (bool reverse)
 Set whether the output color ramp is reversed.
 
bool is_reversed () const
 Get whether the output color ramp is reversed.
 
virtual void set_unknown_color (cgv::rgba color)
 Set the color returned for scalars outside the domain if clamping is disabled.
 
cgv::rgba get_unknown_color () const
 Get the color returned for scalars outside the domain if clamping is disabled.
 
virtual cgv::rgba map_value (float value) const
 Map a value through the scale and return a RGBA color.
 
virtual float get_mapped_opacity (float value) const
 Map a value through the scale and return an opacity.
 
cgv::data::time_point get_modified_time () const
 Get the time point of the last modification of this object.
 

Additional Inherited Members

- Protected Member Functions inherited from cgv::media::color_scale
void modified ()
 Update the object's modified time.
 
bool is_unknown (float value) const
 Test whether the value is outside the domain according to the mapping options.
 
float map_range_safe (float value, float in_left, float in_right, float out_left, float out_right) const
 Remap a scalar value from an input range to and output range while safely handling empty ranges.
 

Detailed Description

Implementation of a color_scale with a discrete input domain and output range using a discrete_color_scheme.

The scale is mainly used for mapping discrete indices to discrete colors for, e.g., categorical data. Additionally, discrete_color_scale supports mapping continuous input values to discrete colors.

Definition at line 373 of file color_scale.h.

Constructor & Destructor Documentation

◆ discrete_color_scale() [1/2]

cgv::media::discrete_color_scale::discrete_color_scale ( )
inline

Definition at line 376 of file color_scale.h.

◆ discrete_color_scale() [2/2]

cgv::media::discrete_color_scale::discrete_color_scale ( const discrete_color_scheme scheme,
size_t  size 
)
inline

Construct using the given color scheme and size.

Parameters
schemeThe color scheme used as the source for indexed colors.
sizeThe number of colors to extract from the scheme.

Definition at line 382 of file color_scale.h.

Member Function Documentation

◆ get_indexed_color()

cgv::rgba cgv::media::discrete_color_scale::get_indexed_color ( size_t  index) const
overridevirtual

Return the RGBA color with the given index.

Parameters
indexThe index into the lookup table.
Returns
The mapped color.

Reimplemented from cgv::media::color_scale.

Definition at line 204 of file color_scale.cxx.

◆ get_indexed_color_count()

size_t cgv::media::discrete_color_scale::get_indexed_color_count ( ) const
inlineoverridevirtual

See color_scale::get_indexed_color_count().

Reimplemented from cgv::media::color_scale.

Definition at line 415 of file color_scale.h.

Referenced by quantize().

◆ get_mapped_color()

cgv::rgb cgv::media::discrete_color_scale::get_mapped_color ( float  value) const
overridevirtual

Map a value through the scale and return a RGB color.

Normalizes the value to the domain and discretizes it to an integer index in [0,n) where n is the number of indexed colors.

Parameters
valueThe value to map.
Returns
The mapped color.

Reimplemented from cgv::media::color_scale.

Definition at line 190 of file color_scale.cxx.

References cgv::media::color_scale::get_unknown_color(), cgv::media::color_scale::is_unknown(), and normalize_value().

◆ get_scheme()

discrete_color_scheme cgv::media::discrete_color_scale::get_scheme ( ) const
inline

Get the color scheme used as this scale's indexed color source.

Returns
The color scheme.

Definition at line 440 of file color_scale.h.

◆ get_ticks()

std::vector< float > cgv::media::discrete_color_scale::get_ticks ( size_t  request_count) const
overridevirtual

Not implemented for discrete color scales.

Parameters
request_countIgnored.
Returns
An empty sequence.

Implements cgv::media::color_scale.

Definition at line 219 of file color_scale.cxx.

◆ is_discrete()

bool cgv::media::discrete_color_scale::is_discrete ( ) const
inlineoverridevirtual

See color_scale::is_discrete().

Returns
True.

Implements cgv::media::color_scale.

Definition at line 388 of file color_scale.h.

◆ is_opaque()

bool cgv::media::discrete_color_scale::is_opaque ( ) const
inlineoverridevirtual

See color_scale::is_opaque().

Returns
True.

Reimplemented from cgv::media::color_scale.

Definition at line 394 of file color_scale.h.

◆ normalize_value()

float cgv::media::discrete_color_scale::normalize_value ( float  value) const
overridevirtual

◆ quantize()

std::vector< cgv::rgba > cgv::media::discrete_color_scale::quantize ( size_t  count) const
overridevirtual

Return a sequence of all indexed colors, ignoring count.

Will return the reversed sequence if get_reversed() returns true.

Parameters
countIgnored.
Returns
The sequence of indexed colors.

Implements cgv::media::color_scale.

Definition at line 209 of file color_scale.cxx.

References get_indexed_color_count(), and cgv::media::color_scale::is_reversed().

◆ set_scheme()

void cgv::media::discrete_color_scale::set_scheme ( const discrete_color_scheme scheme,
size_t  size 
)

Set the color scheme and size used as this scale's indexed color source.

Parameters
schemeThe color scheme.

Definition at line 223 of file color_scale.cxx.

References cgv::media::discrete_color_scheme::get_colors(), and cgv::media::color_scale::modified().


The documentation for this class was generated from the following files: