A utility class for palettes. More...
#include <util/palette.h>
Public Types | |
typedef util::Color< GLfloat > | Color |
Public Member Functions | |
void | blend (unsigned int ind1, unsigned int ind2, double w, double alpha=1) const |
Blend two colors together and make the result the current OpenGL color. | |
Color | getColor (unsigned int ind1, unsigned int ind2, double w, double alpha=1) const |
Blend two colors in the palette together. | |
Color | getColor (unsigned int index, double alpha=1) const |
Get a color from the palette. | |
Palette () | |
Construct an empty palette with only black colors. | |
Palette (std::string filename) | |
Construct the palette from a file. | |
void | reread () |
Reread the file describing the palette. | |
void | select (unsigned int start, unsigned int end, double w, double alpha=1) const |
Select a color from a range in a palette and make it the current OpenGL color. | |
Color | selectColor (unsigned int start, unsigned int end, double w, double alpha=1) const |
Select a color from a range in a palette and returns it. | |
void | useColor (unsigned int index, double alpha=1) const |
Get a color and make it the current OpenGL color. | |
Static Public Member Functions | |
static Color | blend (const Color &c1, const Color &c2, double w) |
Blend two colors together. |
A utility class for palettes.
This class provides an interface for VLAB palette files and their use for OpenGL.
Definition at line 23 of file palette.h.
util::Palette::Palette | ( | std::string | filename | ) |
Construct the palette from a file.
filename | File to read the palette from |
Definition at line 10 of file palette.cpp.
References reread().
00011 : FileObject(filename) 00012 { 00013 reread(); 00014 }
util::Palette::Palette | ( | ) |
Construct an empty palette with only black colors.
Definition at line 16 of file palette.cpp.
00017 : FileObject() 00018 { 00019 for(int i = 0 ; i < 255 ; ++i) 00020 { 00021 colors[i] = 0.0f; 00022 } 00023 }
Palette::Color util::Palette::blend | ( | const Color & | c1, | |
const Color & | c2, | |||
double | w | |||
) | [static] |
Blend two colors together.
Definition at line 87 of file palette.cpp.
References util::Color< T >::a(), util::Color< T >::b(), util::Color< T >::g(), and util::Color< T >::r().
00088 { 00089 Color result( GLfloat(a.r() * (1.0 - w) + b.r() * w), 00090 GLfloat(a.g() * (1.0 - w) + b.g() * w), 00091 GLfloat(a.b() * (1.0 - w) + b.b() * w), 00092 GLfloat(a.a() * (1.0 - w) + b.a() * w)); 00093 return result; 00094 }
void util::Palette::blend | ( | unsigned int | ind1, | |
unsigned int | ind2, | |||
double | w, | |||
double | alpha = 1 | |||
) | const |
Blend two colors together and make the result the current OpenGL color.
ind1 | Index of the first color | |
ind2 | Index of the second color | |
w | Blending coefficient, from 0 to 1. The color is linearly interpolated from ind1 to ind2 . | |
alpha | Alpha value to use for this color. |
Definition at line 82 of file palette.cpp.
References getColor().
00083 { 00084 glColor4fv( getColor(ind1, ind2, w, alpha).c_data() ); 00085 }
Palette::Color util::Palette::getColor | ( | unsigned int | ind1, | |
unsigned int | ind2, | |||
double | w, | |||
double | alpha = 1 | |||
) | const |
Blend two colors in the palette together.
ind1 | Index of the first color (between 0 and 255) | |
ind2 | Index of the second color (between 0 and 255) | |
w | Blending coefficient, from 0 to 1. The color is linearly interpolated from ind1 to ind2 . alpha Alpha value to use for this color (between 0 and 1) |
Definition at line 54 of file palette.cpp.
References util::Color< T >::b(), util::Color< T >::g(), getColor(), and util::Color< T >::r().
00055 { 00056 if (ind1 > 255) 00057 ind1 = 255; 00058 if (ind2 > 255) 00059 ind2 = 255; 00060 if (w > 1.0) 00061 w = 1.0; 00062 else if (w < 0.0) 00063 w = 0.0; 00064 00065 if(ind1 == ind2) 00066 return getColor(ind1, alpha); 00067 else if(w < COLOR_EPSILON) 00068 return getColor(ind1, alpha); 00069 else if(w > 1-COLOR_EPSILON) 00070 return getColor(ind2, alpha); 00071 else 00072 { 00073 Color a = colors[ind1], b = colors[ind2]; 00074 Color result( GLfloat(a.r() * (1.0 - w) + b.r() * w), 00075 GLfloat(a.g() * (1.0 - w) + b.g() * w), 00076 GLfloat(a.b() * (1.0 - w) + b.b() * w), 00077 GLfloat(alpha)); 00078 return result; 00079 } 00080 }
Palette::Color util::Palette::getColor | ( | unsigned int | index, | |
double | alpha = 1 | |||
) | const |
Get a color from the palette.
index | Index of the color in the palette (between 0 and 255) | |
alpha | Alpha value to use for this color (between 0 and 1) |
Definition at line 40 of file palette.cpp.
References util::Color< T >::a().
Referenced by blend(), tissue::Tissue< Model, CellContent, JunctionContent, WallContent, CellEdgeContent, CellJunctionContent, JunctionCellContent, compact, LeafClass >::drawCell(), tissue::Tissue< Model, CellContent, JunctionContent, WallContent, CellEdgeContent, CellJunctionContent, JunctionCellContent, compact, LeafClass >::drawWalledCell(), getColor(), tissue_model::TissueModel< RealModel, TissueClass >::preDraw(), bspline_tissue_model::TissueModel< RealModel, TissueClass >::preDraw(), selectColor(), and useColor().
void util::Palette::reread | ( | ) | [virtual] |
Reread the file describing the palette.
Implements util::FileObject.
Definition at line 25 of file palette.cpp.
References util::Color< T >::b(), util::Color< T >::g(), and util::Color< T >::r().
Referenced by Palette().
00026 { 00027 std::ifstream in(filename.c_str(), std::ios::binary); 00028 00029 unsigned int index = 0; 00030 while (!in.eof() || !in.good() || !in) 00031 { 00032 if (index > 255) break; 00033 colors[index].r(GLfloat(in.get())/255.f); 00034 colors[index].g(GLfloat(in.get())/255.f); 00035 colors[index].b(GLfloat(in.get())/255.f); 00036 index++; 00037 } 00038 }
void util::Palette::select | ( | unsigned int | start, | |
unsigned int | end, | |||
double | w, | |||
double | alpha = 1 | |||
) | const |
Select a color from a range in a palette and make it the current OpenGL color.
start | Index of the first color of the range | |
end | Index of the last color of the range | |
w | Position within the range, if the value correspond to a color in between two defined colors, they will be linearly interpolated. | |
alpha | Alpha value to use for this color. |
Definition at line 119 of file palette.cpp.
References selectColor().
00120 { 00121 glColor4fv(selectColor(start, end, w, alpha).c_data()); 00122 }
Palette::Color util::Palette::selectColor | ( | unsigned int | start, | |
unsigned int | end, | |||
double | w, | |||
double | alpha = 1 | |||
) | const |
Select a color from a range in a palette and returns it.
start | Index of the first color of the range | |
end | Index of the last color of the range | |
w | Position within the range, if the value correspond to a color in between two defined colors, they will be linearly interpolated. | |
alpha | Alpha value to use for this color. |
Definition at line 96 of file palette.cpp.
References getColor().
Referenced by select(), tissue::Tissue< Model, CellContent, JunctionContent, WallContent, CellEdgeContent, CellJunctionContent, JunctionCellContent, compact, LeafClass >::valueCenterColor(), and tissue::Tissue< Model, CellContent, JunctionContent, WallContent, CellEdgeContent, CellJunctionContent, JunctionCellContent, compact, LeafClass >::valueColor().
00097 { 00098 if (start > 255) 00099 start = 255; 00100 if (end > 255) 00101 end = 255; 00102 if (w > 1.0) 00103 w = 1.0; 00104 else if (w < 0.0) 00105 w = 0.0; 00106 00107 int delta_color = (int)end-(int)start; 00108 double pos_w = delta_color*w + start; 00109 int before = (int)std::floor(pos_w); 00110 int after = before+1; 00111 double ratio = pos_w - (double)before; 00112 if(ratio < COLOR_EPSILON) 00113 return getColor(before, alpha); 00114 if(ratio > 1-COLOR_EPSILON) 00115 return getColor(after, alpha); 00116 return getColor(before, after, ratio, alpha); 00117 }
void util::Palette::useColor | ( | unsigned int | index, | |
double | alpha = 1 | |||
) | const |
Get a color and make it the current OpenGL color.
index | Index of the color in the palette | |
alpha | Alpha value fo use for this color |
Definition at line 49 of file palette.cpp.
References getColor().
Referenced by tissue::Tissue< Model, CellContent, JunctionContent, WallContent, CellEdgeContent, CellJunctionContent, JunctionCellContent, compact, LeafClass >::drawCell(), and tissue::Tissue< Model, CellContent, JunctionContent, WallContent, CellEdgeContent, CellJunctionContent, JunctionCellContent, compact, LeafClass >::drawCellContour().
00050 { 00051 glColor4fv(getColor(index, alpha).c_data()); 00052 }