#ifndef CVD_INC_COLOURMAPS_H #define CVD_INC_COLOURMAPS_H #include #include #include #include #include namespace CVD { namespace Internal { Rgb grey(float d) { using std::max; using std::min; d = max(0.f, min(d, 1.0f)); return Rgb(d, d, d); } Rgb hot(float d) { using std::max; using std::min; d = max(0.f, min(d, 1.0f)); if(d < 1. / 3.) return Rgb(d * 3, 0, 0); else if(d < 2. / 3.) return Rgb(1, (d - 1. / 3.) * 3, 0); else return Rgb(1, 1, (d - 2. / 3.) * 3); } Rgb jet(float d) { using std::max; using std::min; d = max(0.f, min(d, 1.0f)); double r = 0, g = 0, b = 0; if(d < 1. / 4.) // Red to yello { r = 1; g = d / (1. / 4.); b = 0; } else if(d < 2. / 4.) //Yello to green { g = 1; r = 1 - (d - 1. / 4.) / (1. / 4.); b = 0; } else if(d < 3. / 4.) // Green to cyan { r = 0; g = 1; b = (d - 2. / 4.) / (1. / 4.); } else //cyan to blue { b = 1; g = 1 - (d - 3. / 4.) / (1. / 4.); r = 0; } return Rgb(r, g, b); } Rgb gkr(float d) { using std::max; using std::min; if(d < 1. / 2.) return Rgb(1 - d * 2, 0, 0); else return Rgb(0, (d - 1. / 2.) * 2, 0); } template Rgb conv(const D& func, float d) { Rgb col = func(d); Rgb r; Pixel::ConvertPixels, Rgb>::convert(&col, &r, 1); return r; } }; template struct Colourmap; ///Handy class for generating a colourscale. ///Expected range is \f$[0, 1)\f$, and clamping is performed. ///Currently only RGB scales are provided. TODO: RGBA scales. ///@ingroup gGraphics ///Examples in examples/colourmaps.cc ///@include colourmaps.cc template struct Colourmap> { ///Glow/Hot colourscale (red-yellow-white) ///@param d Value in \f$[0, 1)\f$ to map static Rgb hot(double d) { return Internal::conv(Internal::hot, d); } ///Jet colourscale (red-yellow-green-cyan-blue) ///@param d Value in \f$[0, 1)\f$ to map static Rgb jet(double d) { return Internal::conv(Internal::jet, d); } ///Green-black-red colourscale ///@param d Value in \f$[0, 1)\f$ to map static Rgb gkr(double d) { return Internal::conv(Internal::gkr, d); } ///Gray colourscale ///@param d Value in \f$[0, 1)\f$ to map static Rgb grey(double d) { return Internal::conv(Internal::grey, d); } }; ///@example colourmaps.cc ///Example of how to use the CVD::Colourmap class for visualisation. }; #endif