Virtual Testbed
Ship dynamics simulator for extreme conditions
Palette.hh
1 #ifndef VTESTBED_GRAPHICS_PALETTE_HH
2 #define VTESTBED_GRAPHICS_PALETTE_HH
3 
4 #include <blitz/array.h>
5 
6 namespace vtb {
7 
8  namespace graphics {
9 
10  template <class T>
11  class Palette3 {
12 
13  public:
14  using color_type = blitz::TinyVector<T,3>;
15 
16  private:
17  color_type _colors[3];
18 
19  public:
20  template <class ... Color>
21  inline explicit
22  Palette3(const Color& ... colors): _colors{colors...} {
23  static_assert(sizeof...(colors) == 3, "bad no. of colors");
24  }
25 
26  inline color_type operator()(T value) const {
27  value = blitz::clamp(value, T{-1}, T{1});
28  const auto* colors = this->_colors;
29  color_type color;
30  if (value < 0) { color = colors[0] + (colors[1]-colors[0])*(value+1); }
31  else { color = colors[1] + (colors[2]-colors[1])*value; }
32  return color;
33  }
34 
35  };
36 
37  template <class T> Palette3<T>
38  temperaturePalette() {
39  using color_type = typename Palette3<T>::color_type;
40  return Palette3<T>{
41  color_type{0,0,T{0.878}},
42  color_type{1,1,T{0.878}},
43  color_type{T{0.878},0,0}
44  };
45  }
46 
47  }
48 
49 }
50 
51 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9