A library for working with phylogenetic and population genetic data.
v0.27.0
ColorMap Class Reference

#include <genesis/utils/tools/color/map.hpp>

Detailed Description

Store a list of colors and offer them as a map for values in range [ 0.0, 1.0 ].

The class is an abstraction of color lists, making them easier to use for ranges, gradients, etc. When invoked, it interpolates between entries of the list according to the provided value. It is best used in combination with a ColorNormalization, so that arbitrary ranges can be mapped into the allowed interval [ 0.0, 1.0 ].

Definition at line 61 of file map.hpp.

Public Member Functions

 ColorMap ()=default
 
 ColorMap (ColorMap &&)=default
 
 ColorMap (ColorMap const &)=default
 
 ColorMap (std::vector< Color > const &colors)
 
 ~ColorMap ()=default
 
ColorMapclip (bool value)
 
bool clip_over () const
 Clip (clamp) values greater than max() to be inside [ min, max ]. More...
 
ColorMapclip_over (bool value)
 Clip (clamp) values greater than max() to be inside [ min, max ]. More...
 
bool clip_under () const
 Clip (clamp) values less than min() to be inside [ min, max ]. More...
 
ColorMapclip_under (bool value)
 Clip (clamp) values less than min() to be inside [ min, max ]. More...
 
Color color (size_t index) const
 Return a particular color from the palette, module the palette size. More...
 
std::vector< Colorcolor_list (size_t n=256) const
 Get a color list based on the palette, containing n colors sampled at equal distance across the palette. More...
 
bool empty () const
 Return whether the Palette is empty, that is, no colors were set. More...
 
Color const & mask_color () const
 Color that indicates values equal to ColorNormalization::mask_value() or non-finite values. More...
 
ColorMapmask_color (Color value)
 Color that indicates values equal to ColorNormalization::mask_value() or non-finite values. More...
 
Color operator() (ColorNormalization const &norm, double value) const
 Return a Color for the given value, normalized by norm. More...
 
template<class ForwardIterator >
std::vector< Coloroperator() (ColorNormalization const &norm, ForwardIterator first, ForwardIterator last) const
 Return the mapped colors for a range of values, normalized by norm. More...
 
std::vector< Coloroperator() (ColorNormalization const &norm, std::vector< double > const &values) const
 Return the mapped colors for a vector of values, normalized by norm. More...
 
Color operator() (double value) const
 Return an interpolated color for a value in the range [ 0.0, 1.0 ], representing a position in the palette. More...
 
template<class ForwardIterator >
std::vector< Coloroperator() (ForwardIterator first, ForwardIterator last) const
 Return the mapped colors for a range of values. More...
 
std::vector< Coloroperator() (std::vector< double > const &values) const
 Return the mapped colors for a vector of values. More...
 
ColorMapoperator= (ColorMap &&)=default
 
ColorMapoperator= (ColorMap const &)=default
 
Color const & over_color () const
 Color that indicates values greater than max(). More...
 
ColorMapover_color (Color value)
 Color that indicates values greater than max(). More...
 
std::vector< Color > const & palette () const
 Get the color list currently in use. More...
 
ColorMappalette (std::vector< Color > const &value)
 
bool reverse () const
 Use the palette colors in reverse, back to front. More...
 
ColorMapreverse (bool value)
 
size_t size () const
 Return the size of the map, that is, the number of colors in the list. More...
 
Color const & under_color () const
 Color that indicates values less than min(). More...
 
ColorMapunder_color (Color value)
 Color that indicates values less than min(). More...
 

Constructor & Destructor Documentation

◆ ColorMap() [1/4]

ColorMap ( )
default

◆ ColorMap() [2/4]

ColorMap ( std::vector< Color > const &  colors)
inlineexplicit

Definition at line 71 of file map.hpp.

◆ ~ColorMap()

~ColorMap ( )
default

◆ ColorMap() [3/4]

ColorMap ( ColorMap const &  )
default

◆ ColorMap() [4/4]

ColorMap ( ColorMap &&  )
default

Member Function Documentation

◆ clip()

ColorMap& clip ( bool  value)
inline

Set both clip_under( bool ) and clip_over( bool ).

Definition at line 188 of file map.hpp.

◆ clip_over() [1/2]

bool clip_over ( ) const
inline

Clip (clamp) values greater than max() to be inside [ min, max ].

If set to true, over_color() is not used to indicate values out of range.

Definition at line 141 of file map.hpp.

◆ clip_over() [2/2]

ColorMap& clip_over ( bool  value)
inline

Clip (clamp) values greater than max() to be inside [ min, max ].

If set to true, over_color() is not used to indicate values out of range.

Definition at line 207 of file map.hpp.

◆ clip_under() [1/2]

bool clip_under ( ) const
inline

Clip (clamp) values less than min() to be inside [ min, max ].

If set to true, under_color() is not used to indicate values out of range.

Definition at line 131 of file map.hpp.

◆ clip_under() [2/2]

ColorMap& clip_under ( bool  value)
inline

Clip (clamp) values less than min() to be inside [ min, max ].

If set to true, under_color() is not used to indicate values out of range.

Definition at line 198 of file map.hpp.

◆ color()

Color color ( size_t  index) const
inline

Return a particular color from the palette, module the palette size.

This is useful for qualitative measures. The function respects the reverse() setting, and uses modulo for indices out of range, that is, it "wraps around".

Definition at line 259 of file map.hpp.

◆ color_list()

std::vector< Color > color_list ( size_t  n = 256) const

Get a color list based on the palette, containing n colors sampled at equal distance across the palette.

This is for example useful for creating a palette to write a bitmap file, see BmpWriter::to_file().

If n == 0, the original palette is returned, making it equal to palette(). If n == 1, the mid point color is returned.

Definition at line 47 of file map.cpp.

◆ empty()

bool empty ( ) const
inline

Return whether the Palette is empty, that is, no colors were set.

Definition at line 240 of file map.hpp.

◆ mask_color() [1/2]

Color const& mask_color ( ) const
inline

Color that indicates values equal to ColorNormalization::mask_value() or non-finite values.

This color is used whenever an invalid (i.e., non-finite) value is requested. This happens for example for the ColorNormalization::mask_value(), which is a simple "invalid value" filter that can be used if a dataset contains a specific value to indicate N/A or NAN values. For example, some sensor data might use 99999 as this value. If this appears, and the ColorNormalization::mask_value() is set to that value, it will be mapped to a quited NAN by the ColorNormalization, and so end up getting the mask color here. Another instance where this happens is if negative values are used with the ColorNormalizationLogarithmic.

Definition at line 101 of file map.hpp.

◆ mask_color() [2/2]

ColorMap& mask_color ( Color  value)
inline

Color that indicates values equal to ColorNormalization::mask_value() or non-finite values.

This color is used whenever an invalid (i.e., non-finite) value is requested. This happens for example for the ColorNormalization::mask_value(), which is a simple "invalid value" filter that can be used if a dataset contains a specific value to indicate N/A or NAN values. For example, some sensor data might use 99999 as this value. If this appears, and the ColorNormalization::mask_value() is set to that value, it will be mapped to a quited NAN by the ColorNormalization, and so end up getting the mask color here. Another instance where this happens is if negative values are used with the ColorNormalizationLogarithmic.

Definition at line 161 of file map.hpp.

◆ operator()() [1/6]

Color operator() ( ColorNormalization const &  norm,
double  value 
) const

Return a Color for the given value, normalized by norm.

Definition at line 131 of file map.cpp.

◆ operator()() [2/6]

std::vector<Color> operator() ( ColorNormalization const &  norm,
ForwardIterator  first,
ForwardIterator  last 
) const
inline

Return the mapped colors for a range of values, normalized by norm.

Definition at line 331 of file map.hpp.

◆ operator()() [3/6]

std::vector< Color > operator() ( ColorNormalization const &  norm,
std::vector< double > const &  values 
) const

Return the mapped colors for a vector of values, normalized by norm.

Definition at line 136 of file map.cpp.

◆ operator()() [4/6]

Color operator() ( double  value) const

Return an interpolated color for a value in the range [ 0.0, 1.0 ], representing a position in the palette.

Values less than 0.0 are mapped to under_color() or to the first color of the map, depending on whether clip_under() is set. The same applies for values greater than 1.0: Either they map to over_color() or the last color in the map, depending on whether clip_over() is set. Lastly, any non-finite values (e.g., NaN) are mapped to mask_color().

Definition at line 68 of file map.cpp.

◆ operator()() [5/6]

std::vector<Color> operator() ( ForwardIterator  first,
ForwardIterator  last 
) const
inline

Return the mapped colors for a range of values.

Simply applies operator() ( double value ) to all values.

Definition at line 307 of file map.hpp.

◆ operator()() [6/6]

std::vector< Color > operator() ( std::vector< double > const &  values) const

Return the mapped colors for a vector of values.

Simply applies operator() ( double value ) to all values.

Definition at line 125 of file map.cpp.

◆ operator=() [1/2]

ColorMap& operator= ( ColorMap &&  )
default

◆ operator=() [2/2]

ColorMap& operator= ( ColorMap const &  )
default

◆ over_color() [1/2]

Color const& over_color ( ) const
inline

Color that indicates values greater than max().

Only used if clip_over() == false.

Definition at line 111 of file map.hpp.

◆ over_color() [2/2]

ColorMap& over_color ( Color  value)
inline

Color that indicates values greater than max().

Only used if clip_over() == false.

Definition at line 170 of file map.hpp.

◆ palette() [1/2]

std::vector<Color> const& palette ( ) const
inline

Get the color list currently in use.

Definition at line 232 of file map.hpp.

◆ palette() [2/2]

ColorMap& palette ( std::vector< Color > const &  value)
inline

Definition at line 219 of file map.hpp.

◆ reverse() [1/2]

bool reverse ( ) const
inline

Use the palette colors in reverse, back to front.

Definition at line 149 of file map.hpp.

◆ reverse() [2/2]

ColorMap& reverse ( bool  value)
inline

Definition at line 213 of file map.hpp.

◆ size()

size_t size ( ) const
inline

Return the size of the map, that is, the number of colors in the list.

Definition at line 248 of file map.hpp.

◆ under_color() [1/2]

Color const& under_color ( ) const
inline

Color that indicates values less than min().

Only used if clip_under() == false.

Definition at line 121 of file map.hpp.

◆ under_color() [2/2]

ColorMap& under_color ( Color  value)
inline

Color that indicates values less than min().

Only used if clip_under() == false.

Definition at line 179 of file map.hpp.


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