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
|
| 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...
|
|
Gradient & | operator= (const Gradient &source) |
|