colormap.h
Go to the documentation of this file.
1 #pragma once
2 #include <algorithm>
3 #include <cassert>
4 #include <cmath>
5 #include <memory>
6 #include <string>
7 #include <vector>
8 
9 namespace colormap
10 {
11 
12  struct Color
13  {
14  double r, g, b, a;
15  };
16 
17  class Colormap
18  {
19  public:
20  virtual ~Colormap()
21  {
22  }
23 
24  virtual Color getColor(double x) const = 0;
25 
26  virtual std::string getTitle() const = 0;
27 
28  virtual std::string getCategory() const = 0;
29 
30  virtual std::string getSource() const = 0;
31 
32  protected:
33  struct vec4
34  {
35  vec4(double a0, double a1, double a2, double a3) : x(a0), y(a1), z(a2), w(a3)
36  {
37  }
38 
39  double
40  operator[](size_t index) const
41  {
42  assert(index < 4);
43  if (index < 2)
44  {
45  if (index < 1)
46  {
47  return x;
48  }
49  else
50  {
51  return y;
52  }
53  }
54  else
55  {
56  if (index < 3)
57  {
58  return z;
59  }
60  else
61  {
62  return w;
63  }
64  }
65  }
66 
67  double&
68  operator[](size_t index)
69  {
70  assert(index < 4);
71  if (index < 2)
72  {
73  if (index < 1)
74  {
75  return x;
76  }
77  else
78  {
79  return y;
80  }
81  }
82  else
83  {
84  if (index < 3)
85  {
86  return z;
87  }
88  else
89  {
90  return w;
91  }
92  }
93  }
94 
95  bool
96  operator==(vec4 const& o) const
97  {
98  return x == o.x && y == o.y && z == o.z && w == o.w;
99  }
100 
101  vec4
102  operator*(double v) const
103  {
104  return vec4(r * v, g * v, b * v, a * v);
105  }
106 
107  vec4
108  operator+(vec4 const& v) const
109  {
110  return vec4(r + v.r, g + v.g, b + v.b, a + v.a);
111  }
112 
113  std::string
114  to_string() const
115  {
116  return std::string("{") + std::to_string(x) + std::string(",") + std::to_string(y) +
117  std::string(",") + std::to_string(z) + std::string(",") + std::to_string(w) +
118  std::string("}");
119  }
120 
121  union
122  {
123  double r;
124  double x;
125  };
126 
127  union
128  {
129  double g;
130  double y;
131  };
132 
133  union
134  {
135  double b;
136  double z;
137  };
138 
139  union
140  {
141  double a;
142  double w;
143  };
144  };
145 
147  {
148  public:
149  virtual ~WrapperBase()
150  {
151  }
152 
153  protected:
154  typedef double local_real_t;
155 
156  template <class Value, class MinMax>
157  typename std::common_type<Value, MinMax>::type
158  clamp(Value v, MinMax min, MinMax max) const
159  {
160  if (v < min)
161  {
162  return min;
163  }
164  else if (max < v)
165  {
166  return max;
167  }
168  else
169  {
170  return v;
171  }
172  }
173 
174  template <class Value>
175  Value
176  sign(Value v) const
177  {
178  if (v < (Value)0)
179  {
180  return (Value)-1;
181  }
182  else if ((Value)0 < v)
183  {
184  return (Value)1;
185  }
186  else
187  {
188  return (Value)0;
189  }
190  }
191 
194  {
195  return std::fabs(v);
196  }
197 
200  {
201  return std::fmod(x, y);
202  }
203  };
204  };
205 
206 } // namespace colormap
207 
208 #include "./private/all_colormaps.h"
209 
210 namespace colormap
211 {
213  {
214  public:
215  static std::vector<std::shared_ptr<Colormap const>>
217  {
218  return {
220  };
221  }
222 
223  private:
224  ColormapList()
225  {
226  }
227 
228  ColormapList(ColormapList const&) = delete;
229  ColormapList(ColormapList&&) = delete;
230  ColormapList& operator=(ColormapList const&) = delete;
231  ColormapList& operator=(ColormapList&&) = delete;
232  };
233 
234 } // namespace colormap
colormap::Colormap::vec4::to_string
std::string to_string() const
Definition: colormap.h:114
colormap::Colormap::vec4::operator==
bool operator==(vec4 const &o) const
Definition: colormap.h:96
colormap::Colormap::vec4::vec4
vec4(double a0, double a1, double a2, double a3)
Definition: colormap.h:35
ColorMap::Value
Value
Color maps that associate a color to every float from [0..1].
Definition: color.h:16
colormap::Colormap::WrapperBase::sign
Value sign(Value v) const
Definition: colormap.h:176
colormap::Colormap
Definition: colormap.h:17
colormap::Colormap::vec4::w
double w
Definition: colormap.h:142
init_colormap_list.inc
colormap::Colormap::vec4::operator+
vec4 operator+(vec4 const &v) const
Definition: colormap.h:108
colormap::Colormap::vec4::y
double y
Definition: colormap.h:130
colormap::Colormap::vec4::r
double r
Definition: colormap.h:123
index
uint8_t index
Definition: EtherCATFrame.h:59
colormap::Colormap::getTitle
virtual std::string getTitle() const =0
colormap::Colormap::WrapperBase::clamp
std::common_type< Value, MinMax >::type clamp(Value v, MinMax min, MinMax max) const
Definition: colormap.h:158
colormap::Color::g
double g
Definition: colormap.h:14
colormap::Colormap::vec4::operator[]
double & operator[](size_t index)
Definition: colormap.h:68
colormap::ColormapList
Definition: colormap.h:212
colormap::Colormap::vec4
Definition: colormap.h:33
colormap::Colormap::vec4::z
double z
Definition: colormap.h:136
colormap::Colormap::vec4::operator*
vec4 operator*(double v) const
Definition: colormap.h:102
colormap::Colormap::vec4::x
double x
Definition: colormap.h:124
colormap::Colormap::WrapperBase::abs
local_real_t abs(local_real_t v) const
Definition: colormap.h:193
colormap::Colormap::getSource
virtual std::string getSource() const =0
colormap::Colormap::getColor
virtual Color getColor(double x) const =0
colormap::Color::a
double a
Definition: colormap.h:14
colormap::Colormap::vec4::operator[]
double operator[](size_t index) const
Definition: colormap.h:40
colormap::Color::b
double b
Definition: colormap.h:14
max
T max(T t1, T t2)
Definition: gdiam.h:51
colormap::Colormap::~Colormap
virtual ~Colormap()
Definition: colormap.h:20
all_colormaps.h
colormap::Colormap::getCategory
virtual std::string getCategory() const =0
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
colormap::Color
Definition: colormap.h:12
colormap::Colormap::WrapperBase::local_real_t
double local_real_t
Definition: colormap.h:154
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
colormap
This file was automatically created with "create_c++_header.sh".
Definition: colormap.h:9
colormap::Color::r
double r
Definition: colormap.h:14
colormap::Colormap::WrapperBase::mod
local_real_t mod(local_real_t x, local_real_t y) const
Definition: colormap.h:199
colormap::Colormap::WrapperBase
Definition: colormap.h:146
colormap::Colormap::vec4::g
double g
Definition: colormap.h:129
min
T min(T t1, T t2)
Definition: gdiam.h:44
colormap::ColormapList::getAll
static std::vector< std::shared_ptr< Colormap const > > getAll()
Definition: colormap.h:216
colormap::Colormap::WrapperBase::~WrapperBase
virtual ~WrapperBase()
Definition: colormap.h:149
colormap::Colormap::vec4::b
double b
Definition: colormap.h:135
colormap::Colormap::vec4::a
double a
Definition: colormap.h:141