MeteoIODoc 2.11.0
mio::Gradient Class Reference

Detailed Description

This converts numeric values into rgb values. The object is initialized with the range that the gradient should cover and the gradient type. Then each numeric value that is given will be converted into rgb values from the selected gradient. Data out of range are converted to either the minimum or the maximum of the gradient. Special pixels should return a=true to indicate transparency (however, pure white is the transparency color, so do not use it in your gradients!).

Some special pixels are recognized:

  • IOUtils::nodata returns a transparent pixel
  • legend::bg_color returns an almost white pixel
  • legend::text_color returns a black pixel

The autoscale is handled both by the object and its caller: if "autoscale==true", the gradient might adjust its control points, for example removing sea and snow lines in the terrain gradient. The min and max values are used to scale the gradient: all values less than min will receive the start color while all values greater than max will receive the end color. Therefore true autoscale is acheived by:

  • setting min/max to the data min/max
  • passing i_autoscale=true so the gradient might receive some specific adjustments

On the other hand, fixed scale is acheived by:

  • setting min/max to fixed values (so the gradient will be rescaled between these fixed boundaries)
  • passing i_autoscale=false so the gradient might be able to set so fix points (like sea and snow line)

For some interesting discussion on how to define color gradients, see Bernice E. Rogowitz, Lloyd A. Treinish "Why Should Engineers and Scientists Be Worried About Color?" http://www.research.ibm.com/people/l/lloydt/color/color.HTM

Author
Mathias Bavay
Date
2012-01-06

#include <Graphics.h>

Public Types

enum  Type {
  none , terrain , slope , azi ,
  heat , freeze , blue_pink , pastel ,
  bg_isomorphic , bluewhitered , whitetoblk , blktowhite ,
  blue
}
 This enum provides names for possible color gradients. More...
 

Public Member Functions

 Gradient ()
 Default Constructor. This should be followed by a call to set() before calling getColor. More...
 
 Gradient (const Type &i_type, const double &min_val, const double &max_val, const bool &i_autoscale)
 Constructor. The object will associate to each numeric value RGB values. See class description for more... More...
 
 Gradient (const Gradient &c)
 
 ~Gradient ()
 
void set (const Type &i_type, const double &min_val, const double &max_val, const bool &i_autoscale)
 Setter See class description for more... More...
 
void setNrOfLevels (const unsigned char &i_nr_unique_levels)
 Set a reduced number of levels for the gradient The given argument is an upper bound for the number of unique levels in the generated gradient (leading to a reduced number of colors). This is a specially easy and useful way of reducing a file size with no run time overhead (and even a small benefit) and little visible impact if the number of levels/colors remains large enough (say, at least 20-30). This is only applicable to indexed images, that is when getPalette is called an pixels are set using getColor(const double& val, unsigned char& index). More...
 
void getColor (const double &val, unsigned char &r, unsigned char &g, unsigned char &b, bool &a) const
 Get RGB values for a given numeric value See class description for more explanations on the implementation/behavior. More...
 
void getColor (const double &val, unsigned char &index) const
 Get palette index values for a given numeric value See class description for more explanations on the implementation/behavior. More...
 
void getPalette (std::vector< unsigned char > &palette, size_t &nr_colors) const
 Get palette colors for the selected gradient When building an indexed image, one needs to first retrieve the palette using this method. Afterwards, getColor(val, index) will be called for each pixel in order to retrieve its palette index. The returned colors are interlaced (rgb). More...
 
Gradientoperator= (const Gradient &source)
 

Static Public Attributes

static const unsigned char channel_max_color = 255
 nr of colors per channel of the generated gradients More...
 

Member Enumeration Documentation

◆ Type

This enum provides names for possible color gradients.

Enumerator
none 

no type selected

terrain 

suitable for DEM. if autoscale, then sea and snow line are turned off

slope 

suitable to represent slope

azi 

suitable to represent slope azimuth. In autoscale, it becomes a two color gradient

heat 

the traditional heat gradient (with all its associated shortcomings)

freeze 

two, two-color gradients with a sharp transition at 0

blue_pink 

blue to pink gradient, isomorphic gradient

pastel 

same color scale as "slope" but linear

bg_isomorphic 

drak-blue to light-green isomorphic gradient

bluewhitered 

blue to white, then white to red

whitetoblk 

white to black gradient

blktowhite 

black to white gradient

blue 

white to slightly violet gradient. This is similar to the one used for the SLF avalanche bulletin

Constructor & Destructor Documentation

◆ Gradient() [1/3]

mio::Gradient::Gradient ( )
inline

Default Constructor. This should be followed by a call to set() before calling getColor.

◆ Gradient() [2/3]

mio::Gradient::Gradient ( const Type i_type,
const double &  min_val,
const double &  max_val,
const bool &  i_autoscale 
)

Constructor. The object will associate to each numeric value RGB values. See class description for more...

Parameters
i_typeset the color gradient to use, from the enum Gradient::Type
min_valstart value of the gradient
max_valend value of the gradient
i_autoscaledo autoscale for setting the colors?

◆ Gradient() [3/3]

mio::Gradient::Gradient ( const Gradient c)

◆ ~Gradient()

mio::Gradient::~Gradient ( )
inline

Member Function Documentation

◆ getColor() [1/2]

void mio::Gradient::getColor ( const double &  val,
unsigned char &  index 
) const

Get palette index values for a given numeric value See class description for more explanations on the implementation/behavior.

Parameters
valnumerical value to convert
indexpalette index for the given value

◆ getColor() [2/2]

void mio::Gradient::getColor ( const double &  val,
unsigned char &  r,
unsigned char &  g,
unsigned char &  b,
bool &  a 
) const

Get RGB values for a given numeric value See class description for more explanations on the implementation/behavior.

Parameters
valnumerical value to convert
rred (between 0 and 255)
ggreen (between 0 and 255)
bblue (between 0 and 255)
atransparent pixel?

◆ getPalette()

void mio::Gradient::getPalette ( std::vector< unsigned char > &  palette,
size_t &  nr_colors 
) const

Get palette colors for the selected gradient When building an indexed image, one needs to first retrieve the palette using this method. Afterwards, getColor(val, index) will be called for each pixel in order to retrieve its palette index. The returned colors are interlaced (rgb).

Parameters
paletteinterlaced colors
nr_colorsnumber of colors in the palette

◆ operator=()

Gradient & mio::Gradient::operator= ( const Gradient source)

◆ set()

void mio::Gradient::set ( const Type i_type,
const double &  min_val,
const double &  max_val,
const bool &  i_autoscale 
)

Setter See class description for more...

Parameters
i_typeset the color gradient to use, from the enum Gradient::Type
min_valstart value of the gradient
max_valend value of the gradient
i_autoscaledo autoscale for setting the colors?

◆ setNrOfLevels()

void mio::Gradient::setNrOfLevels ( const unsigned char &  i_nr_unique_levels)

Set a reduced number of levels for the gradient The given argument is an upper bound for the number of unique levels in the generated gradient (leading to a reduced number of colors). This is a specially easy and useful way of reducing a file size with no run time overhead (and even a small benefit) and little visible impact if the number of levels/colors remains large enough (say, at least 20-30). This is only applicable to indexed images, that is when getPalette is called an pixels are set using getColor(const double& val, unsigned char& index).

Parameters
i_nr_unique_levelsmaximum number of unique levels

Member Data Documentation

◆ channel_max_color

const unsigned char mio::Gradient::channel_max_color = 255
static

nr of colors per channel of the generated gradients


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