Example #1
0
static inline void hsl2rgb(double h, double s, double l,
             unsigned & r, unsigned & g, unsigned & b) {
    if (!s) {
        r = g = b = static_cast<unsigned>(l * 255);
    }
    double m2 = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
    double m1 = l * 2 - m2;
    r = static_cast<unsigned>(hueToRGB(m1, m2, h + 0.33333) * 255);
    g = static_cast<unsigned>(hueToRGB(m1, m2, h) * 255);
    b = static_cast<unsigned>(hueToRGB(m1, m2, h - 0.33333) * 255);
}
Example #2
0
static inline void hsl_to_rgb(double h, double s, double l,
             unsigned & r, unsigned & g, unsigned & b) {
    if (!s) {
        r = g = b = static_cast<unsigned>(std::floor((l * 255.0)+.5));
    }
    else
    {
        double m2 = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
        double m1 = l * 2.0 - m2;
        r = static_cast<unsigned>(std::floor(hueToRGB(m1, m2, h + 0.33333) * 255.0)+.5);
        g = static_cast<unsigned>(std::floor(hueToRGB(m1, m2, h) * 255.0)+.5);
        b = static_cast<unsigned>(std::floor(hueToRGB(m1, m2, h - 0.33333) * 255.0)+.5);
    }
}
Example #3
0
void draw_grid_data2d(Array2f& data, Vec2f origin, float dx, bool color) {
   float max_val = FLT_MIN;
   float min_val = FLT_MAX;
   for(int j = 0; j < data.nj; ++j) for(int i = 0; i < data.ni; ++i) {
      max_val = max(data(i,j),max_val);
      min_val = min(data(i,j),min_val);
   }
   
   for(int j = 0; j < data.nj; ++j) {
      for(int i = 0; i < data.ni; ++i) {
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
         Vec2f bl = origin + Vec2f(i*dx,j*dx);
         float r,g,b;
         if(color) {
            hueToRGB(240*(data(i,j) - min_val)/(max_val-min_val), 1, 1, r,g,b);
         }
         else {
            float gray = (data(i,j) - min_val)/(max_val-min_val);
            r = g = b = gray;
         }
         //TODO Black body colormap, if I can find it.
         glColor3f(r,g,b);
         draw_box2d(bl, dx, dx);
      }
   }

}