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
9namespace colormap
10{
11
12 struct Color
13 {
14 double r, g, b, a;
15 };
16
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&
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
209
210namespace colormap
211{
212 class ColormapList
213 {
214 public:
215 static std::vector<std::shared_ptr<Colormap const>>
217 {
218 return {
220 };
221 }
222
223 private:
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
uint8_t index
static std::vector< std::shared_ptr< Colormap const > > getAll()
Definition colormap.h:216
local_real_t abs(local_real_t v) const
Definition colormap.h:193
std::common_type< Value, MinMax >::type clamp(Value v, MinMax min, MinMax max) const
Definition colormap.h:158
local_real_t mod(local_real_t x, local_real_t y) const
Definition colormap.h:199
Value sign(Value v) const
Definition colormap.h:176
virtual ~Colormap()
Definition colormap.h:20
virtual std::string getSource() const =0
virtual std::string getCategory() const =0
virtual std::string getTitle() const =0
virtual Color getColor(double x) const =0
T min(T t1, T t2)
Definition gdiam.h:44
T max(T t1, T t2)
Definition gdiam.h:51
This file offers overloads of toIce() and fromIce() functions for STL container types.
This file was automatically created with "create_c++_header.sh".
Definition colormap.h:10
double & operator[](size_t index)
Definition colormap.h:68
double operator[](size_t index) const
Definition colormap.h:40
vec4 operator*(double v) const
Definition colormap.h:102
vec4(double a0, double a1, double a2, double a3)
Definition colormap.h:35
std::string to_string() const
Definition colormap.h:114
vec4 operator+(vec4 const &v) const
Definition colormap.h:108
bool operator==(vec4 const &o) const
Definition colormap.h:96