KJB

Construct some colors, for visualizing grids of numbers. More...
#include <c_palette.h>
Public Types  
typedef kjb::PixelRGBA(Palette::*  PIXOP )(const kjb::Vector &) const 
convenience typedef for generating/mixing a color. More...  
Public Member Functions  
Palette (size_t)  
Build a palette of the indicated size. More...  
Palette (const std::vector< kjb::PixelRGBA > &some_pal)  
Build a palette from a vector of colored Pixels. More...  
const kjb::PixelRGBA &  operator[] (size_t index) const 
Return a palette entry, a color, in the form of a Pixel. More...  
size_t  size () const 
Return the size of the palette (the number of entries) More...  
void  swap (size_t iii, size_t jjj) 
Swap two palette entries, indicated by index. More...  
kjb::PixelRGBA  weighted_sum (const kjb::Vector &) const 
compute a new color mixed from old. More...  
kjb::PixelRGBA  pick_max (const kjb::Vector &weights) const 
An unforgiving function that chooses the most popular color. More...  
Construct some colors, for visualizing grids of numbers.
The main property of the colors here is that they are supposed to be pairwisedistinct, at least on computer monitors. You pick however many colors you want (and tell it to the ctor). Also, this class supports two methods to mix colors from your palette, given a vector of mixing weights.
typedef kjb::PixelRGBA( Palette::* kjb::Palette::PIXOP)(const kjb::Vector &) const 
convenience typedef for generating/mixing a color.
This is a type for "mix my colors" operations: input is a vector of color weights, and the output is a color (in the form of a Pixel).
In other words, you can use this to indicate weighted_sum or pick_max.
kjb::Palette::Palette  (  size_t  size  ) 
Build a palette of the indicated size.
If the size is two then it will just be black and white. If the size is larger then this will pick random colors for you, somewhat intelligenly. If the size is less than two then the result is undefined.

inline 
Build a palette from a vector of colored Pixels.

inline 
Return a palette entry, a color, in the form of a Pixel.

inline 
An unforgiving function that chooses the most popular color.
weights  vector of numeric votes for the palette colors 
Illegal_argument  if 'weights' is the wrong length. 
Less cryptically: the input vector of doubles must be the same size as the palette size. We scan the input vector to find its maximum entry, and whichever one it is, the color in the palette corresponding to that index is returned. In the event of a tie, the smallest of the tying indices is returned. This "mixes" the colors only in the sense that it forms a mix comprising 100% of the most weighted color, and 0% of the others.

inline 
Return the size of the palette (the number of entries)

inline 
Swap two palette entries, indicated by index.
kjb::PixelRGBA kjb::Palette::weighted_sum  (  const kjb::Vector &  weights_d  )  const 
compute a new color mixed from old.
weights_d  vector of weights, sum of 1, big means more of that color. 
Illegal_argument  if 'weights' is the wrong length. 
Illegal_argument  if 'weights' does not sum to unity. 
Less cryptically: the input vector of doubles must be the same size as the palette size(), and the values in the vector are treated as weights; they must be normalized to sum to unity (or pretty close). The output pixel is a weighted sum of the palette colors, using these weights.