KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | List of all members
kjb::Palette Class Reference

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::PixelRGBAoperator[] (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...
 

Detailed Description

Construct some colors, for visualizing grids of numbers.

The main property of the colors here is that they are supposed to be pairwise-distinct, 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.

Member Typedef Documentation

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.

Constructor & Destructor Documentation

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.

kjb::Palette::Palette ( const std::vector< kjb::PixelRGBA > &  some_pal)
inline

Build a palette from a vector of colored Pixels.

Member Function Documentation

const kjb::PixelRGBA& kjb::Palette::operator[] ( size_t  index) const
inline

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

kjb::PixelRGBA kjb::Palette::pick_max ( const kjb::Vector weights) const
inline

An unforgiving function that chooses the most popular color.

Returns
most popular color
Parameters
weightsvector of numeric votes for the palette colors
Exceptions
Illegal_argumentif '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.

size_t kjb::Palette::size ( ) const
inline

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

void kjb::Palette::swap ( size_t  iii,
size_t  jjj 
)
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.

Returns
a color mixed from the palette components
Parameters
weights_dvector of weights, sum of 1, big means more of that color.
Exceptions
Illegal_argumentif 'weights' is the wrong length.
Illegal_argumentif '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.


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