Provides a palette of distinct RGB colors. More...
#include <colorpal.h>
Public Member Functions | |
ColorPalette (int _n, bool grays=false) | |
The constructor of a palette of a prescribed size. | |
~ColorPalette () | |
The destructor. | |
int | operator[] (int i) const |
Returns the color with the given number. | |
Private Member Functions | |
ColorPalette (const ColorPalette &src) | |
The copy constructor is not allowed. | |
ColorPalette & | operator= (const ColorPalette &src) |
The assignment operator is not allowed. | |
Static Private Member Functions | |
static int | generateComponent (int bitMask) |
Generates a color component based on the bit mask. | |
Private Attributes | |
int | n |
The number of colors in the palette. | |
int * | colors |
The RBG colors in the palette. |
Provides a palette of distinct RGB colors.
The first color is black. White is considered a background color and thus is not provided.
Definition at line 51 of file colorpal.h.
chomp::homology::ColorPalette::ColorPalette | ( | int | _n, | |
bool | grays = false | |||
) | [inline] |
The constructor of a palette of a prescribed size.
Definition at line 99 of file colorpal.h.
References colors, generateComponent(), and n.
: n (_n), colors (0) { if (n <= 0) return; colors = new int [n]; if (grays) { for (int i = 0; i < n; ++ i) { int shade = i * 255 / n; colors [i] = shade | (shade << 8) | (shade << 16); } return; } const int niceCount = 14; int niceColors [niceCount] = { 0x000000, 0x0000FF, 0xFF0000, 0x00FF00, 0x00FFFF, 0xFF00FF, 0x7F007F, 0xFF7F00, 0x007F00, 0x7F7F7F, 0xAFAFAF, 0x00007F, 0x7F00FF, 0xFFFF00, }; int counter = 1; int pos = 0; while (pos < n) { // take a nice color if possible if (pos < niceCount) { colors [pos] = niceColors [pos]; ++ pos; continue; } // create a color based on the current counter int red = generateComponent (counter >> 1); int green = generateComponent (counter >> 2); int blue = generateComponent (counter); int color = (red << 16) | (green << 8) | blue; // check whether this color has already appeared before bool repeated = false; for (int i = 0; i < pos; ++ i) { if (colors [i] == color) { repeated = true; break; } } // if the color is not repeated and it is not white then ok if (!repeated && (color != 0xFFFFFF) && (color != 0xFFFF7F)) colors [pos ++] = color; ++ counter; } return; } /* ColorPalette::ColorPalette */
chomp::homology::ColorPalette::~ColorPalette | ( | ) | [inline] |
chomp::homology::ColorPalette::ColorPalette | ( | const ColorPalette & | src | ) | [inline, private] |
The copy constructor is not allowed.
Definition at line 169 of file colorpal.h.
{ return; } /* ColorPalette::ColorPalette */
int chomp::homology::ColorPalette::generateComponent | ( | int | bitMask | ) | [inline, static, private] |
Generates a color component based on the bit mask.
The nonzero bits are every 3 locations in the mask.
Definition at line 85 of file colorpal.h.
Referenced by ColorPalette().
{ int mask = 0x100; int result = 1; while (mask && bitMask) { if (bitMask & 1) result = mask; mask >>= 1; bitMask >>= 3; } return (result - 1) & 0xFF; } /* ColorPalette::generateComponent */
ColorPalette & chomp::homology::ColorPalette::operator= | ( | const ColorPalette & | src | ) | [inline, private] |
The assignment operator is not allowed.
Definition at line 174 of file colorpal.h.
{ return *this; } /* ColorPalette::operator = */
int chomp::homology::ColorPalette::operator[] | ( | int | i | ) | const [inline] |
int* chomp::homology::ColorPalette::colors [private] |
The RBG colors in the palette.
Definition at line 79 of file colorpal.h.
Referenced by ColorPalette(), operator[](), and ~ColorPalette().
int chomp::homology::ColorPalette::n [private] |
The number of colors in the palette.
Definition at line 76 of file colorpal.h.
Referenced by ColorPalette(), and operator[]().