1.9
Public Types | Public Member Functions | Protected Attributes | List of all members
ColorMap Class Reference

A ColorMap contains a series of sequential color steps that can be used for generating colors by interpolation. More...

Public Types

enum class  Interpolation { rgba , hsv , hsl }
 Interpolation color space method. More...
 
using StepsArray = std::vector< Color >
 Type used for color steps array. More...
 

Public Member Functions

 ColorMap (Interpolation interp) noexcept
 
template<class T >
 ColorMap (std::initializer_list< T > steps, Interpolation interp=Interpolation::rgba)
 
 ColorMap (StepsArray steps, Interpolation interp=Interpolation::rgba)
 
size_t count () const
 Count the number of color steps. More...
 
bool empty () const
 Are there any color steps? More...
 
Color interp (float t) const
 Get a color at the specified offset. More...
 
Color interp_cached (float t, size_t accuracy=1000) const
 Get a color at the specified offset. More...
 
void step (const Color &color)
 Append a color step. More...
 
const StepsArraysteps () const
 Get a reference to the color steps array. More...
 
void steps (const StepsArray &steps)
 Set the color steps. More...
 

Protected Attributes

std::array< std::map< size_t, Color >, 3 > m_cache {}
 Interpolation cache. More...
 
Interpolation m_interp {Interpolation::rgba}
 Interpolation color space method. More...
 
StepsArray m_steps
 Steps in the color map. More...
 

Detailed Description

A ColorMap contains a series of sequential color steps that can be used for generating colors by interpolation.

Member Typedef Documentation

◆ StepsArray

using StepsArray = std::vector<Color>

Type used for color steps array.

Member Enumeration Documentation

◆ Interpolation

enum Interpolation
strong

Interpolation color space method.

Enumerator
rgba 
hsv 
hsl 

Constructor & Destructor Documentation

◆ ColorMap() [1/3]

ColorMap ( Interpolation  interp)
inlineexplicitnoexcept
Parameters
[in]interpInterpolation color space.

◆ ColorMap() [2/3]

ColorMap ( StepsArray  steps,
Interpolation  interp = Interpolation::rgba 
)
inlineexplicit
Parameters
[in]stepsPre-defined color steps.
[in]interpInterpolation color space.

◆ ColorMap() [3/3]

ColorMap ( std::initializer_list< T >  steps,
Interpolation  interp = Interpolation::rgba 
)
inlineexplicit
Parameters
[in]stepsPre-defined color steps.
[in]interpInterpolation color space.

Member Function Documentation

◆ count()

size_t count ( ) const
inline

Count the number of color steps.

◆ empty()

bool empty ( ) const
inline

Are there any color steps?

◆ interp()

Color interp ( float  t) const

Get a color at the specified offset.

Parameters
[in]tOffset from 0 to 1.

◆ interp_cached()

Color interp_cached ( float  t,
size_t  accuracy = 1000 
) const

Get a color at the specified offset.

This will use a cache to speed up repetitive calls to interpolate.

Parameters
[in]tOffset from 0 to 1.
[in]accuracyAccuracy of the cached result.

◆ step()

void step ( const Color color)
inline

Append a color step.

◆ steps() [1/2]

const StepsArray& steps ( ) const
inline

Get a reference to the color steps array.

◆ steps() [2/2]

void steps ( const StepsArray steps)
inline

Set the color steps.

Member Data Documentation

◆ m_cache

std::array<std::map<size_t, Color>, 3> m_cache {}
mutableprotected

Interpolation cache.

◆ m_interp

Interpolation m_interp {Interpolation::rgba}
protected

Interpolation color space method.

◆ m_steps

StepsArray m_steps
protected

Steps in the color map.