OpenLB 1.7
Loading...
Searching...
No Matches
colormaps.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2006, 2007 Jonas Latt
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef COLORMAPS_HH
25#define COLORMAPS_HH
26
27#include "colormaps.h"
28#include "utilities/omath.h"
29
30namespace olb {
31
32namespace graphics {
33
34template <typename T>
35LinearFunction<T>::LinearFunction(T x1_, T x2_, T y1_, T y2_)
36 : x1(x1_), x2(x2_), y1(y1_), y2(y2_)
37{ }
38
39template <typename T>
41{
42 return ( (y2-y1) * x + x2*y1-x1*y2 )/(x2-x1);
43}
44
45template <typename T>
47{
48 return new LinearFunction(*this);
49}
50
51template <typename T>
52PowerLawFunction<T>::PowerLawFunction(T x1_, T x2_, T y1_, T y2_, T b_)
53 : x1(util::pow(x1_,b_)), x2(util::pow(x2_,b_)), y1(y1_), y2(y2_), b(b_)
54{ }
55
56template <typename T>
58{
59 return ( (y2-y1) * util::pow(x,b) + x2*y1-x1*y2 )/(x2-x1);
60}
61
62template <typename T>
67
68
69template <typename T>
71 : pieces(rhs.pieces),
72 functions(rhs.functions.size())
73{
74 for (unsigned iF=0; iF<functions.size(); ++iF) {
75 functions[iF] = rhs.functions[iF]->clone();
76 }
77}
78
79template <typename T>
85
86template <typename T>
88{
89 for (unsigned iF=0; iF<functions.size(); ++iF) {
90 delete functions[iF];
91 }
92}
93
94template <typename T>
96{
97 pieces.swap(rhs.pieces);
98 functions.swap(rhs.functions);
99}
100
101template <typename T>
103{
104 typename std::vector<Piece<T> >::iterator pieceIt = pieces.begin();
105 typename std::vector<ScalarFunction<T>*>::iterator fIt = functions.begin();
106 while (pieceIt != pieces.end() && piece.closedBegin >= pieceIt->closedBegin) {
107 ++pieceIt;
108 ++fIt;
109 }
110 pieces.insert(pieceIt, piece);
111 functions.insert(fIt, f);
112}
113
114template <typename T>
116{
117 if (pieces.empty() || x<pieces[0].closedBegin) {
118 return T();
119 }
120 unsigned iPiece=0;
121 while (iPiece != pieces.size() && x >= pieces[iPiece].openEnd) {
122 ++iPiece;
123 }
124 if (iPiece == pieces.size() || x < pieces[iPiece].closedBegin) {
125 return T();
126 }
127 return (*functions[iPiece])(x);
128}
129
130template <typename T>
135
136template <typename T>
138 PiecewiseFunction<T> const& green_,
139 PiecewiseFunction<T> const& blue_)
140 : red(red_), green(green_), blue(blue_)
141{ }
142
143template <typename T>
145{
146 return rgb<T>( red(x), green(x), blue(x) );
147}
148
149namespace mapGenerators {
150
151template <typename T>
153{
154 T p0 = (T) 0.;
155 T p1 = (T) 3./8.;
156 T p2 = (T) 6./8.;
157 T p3 = (T) 1.;
158
159 PiecewiseFunction<T> earthRed;
160 earthRed.addPiece (Piece<T>(p0, p1), new PowerLawFunction<T>(p0, p1, (T)0., (T)0.8, (T)0.6) );
161 earthRed.addPiece (Piece<T>(p1, p2), new PowerLawFunction<T>(p1, p2, (T)0.8, (T)0.9, (T)0.9) );
162 earthRed.addPiece (Piece<T>(p2, p3), new PowerLawFunction<T>(p2, p3, (T)0.9, (T)1.0, (T)0.2) );
163
164 return earthRed;
165}
166
167template <typename T>
169{
170 T p0 = (T) 0.;
171 T p1 = (T) 3./8.;
172 T p2 = (T) 6./8.;
173 T p3 = (T) 1.;
174
175 PiecewiseFunction<T> earthGreen;
176 earthGreen.addPiece (Piece<T>(p0, p1), new PowerLawFunction<T>(p0, p1, (T)0., (T)0.5, (T)0.6) );
177 earthGreen.addPiece (Piece<T>(p1, p2), new PowerLawFunction<T>(p1, p2, (T)0.5, (T)0.9, (T)0.2) );
178 earthGreen.addPiece (Piece<T>(p2, p3), new PowerLawFunction<T>(p2, p3, (T)0.9, (T)1.0, (T)0.2) );
179
180 return earthGreen;
181}
182
183template <typename T>
185{
186 T p0 = (T) 0.;
187 T p1 = (T) 3./8.;
188 T p2 = (T) 6./8.;
189 T p3 = (T) 1.;
190
191 PiecewiseFunction<T> earthBlue;
192 earthBlue.addPiece (Piece<T>(p0, p1), new PowerLawFunction<T>(p0, p1, (T)0., (T)0.5, (T)0.6) );
193 earthBlue.addPiece (Piece<T>(p1, p2), new PowerLawFunction<T>(p1, p2, (T)0.5, (T)0.7, (T)0.2) );
194 earthBlue.addPiece (Piece<T>(p2, p3), new PowerLawFunction<T>(p2, p3, (T)0.7, (T)1.0, (T)0.2) );
195
196 return earthBlue;
197}
198
199template <typename T>
201{
202 T p0 = (T) 0.;
203 T p1 = (T) 3./8.;
204 T p2 = (T) 6./8.;
205 T p3 = (T) 1.;
206
207 PiecewiseFunction<T> waterRed;
208 waterRed.addPiece (Piece<T>(p0, p1), new PowerLawFunction<T>(p0, p1, (T)0., (T)0.5, (T)0.6) );
209 waterRed.addPiece (Piece<T>(p1, p2), new PowerLawFunction<T>(p1, p2, (T)0.5, (T)0.7, (T)0.2) );
210 waterRed.addPiece (Piece<T>(p2, p3), new PowerLawFunction<T>(p2, p3, (T)0.7, (T)1.0, (T)0.2) );
211
212 return waterRed;
213}
214
215template <typename T>
217{
218 T p0 = (T) 0.;
219 T p1 = (T) 3./8.;
220 T p2 = (T) 6./8.;
221 T p3 = (T) 1.;
222
223 PiecewiseFunction<T> waterGreen;
224 waterGreen.addPiece (Piece<T>(p0, p1), new PowerLawFunction<T>(p0, p1, (T)0., (T)0.5, (T)0.6) );
225 waterGreen.addPiece (Piece<T>(p1, p2), new PowerLawFunction<T>(p1, p2, (T)0.5, (T)0.9, (T)0.2) );
226 waterGreen.addPiece (Piece<T>(p2, p3), new PowerLawFunction<T>(p2, p3, (T)0.9, (T)1.0, (T)0.2) );
227
228 return waterGreen;
229}
230
231template <typename T>
233{
234 T p0 = (T) 0.;
235 T p1 = (T) 3./8.;
236 T p2 = (T) 6./8.;
237 T p3 = (T) 1.;
238
239 PiecewiseFunction<T> waterBlue;
240 waterBlue.addPiece (Piece<T>(p0, p1), new PowerLawFunction<T>(p0, p1, (T)0., (T)0.8, (T)0.6) );
241 waterBlue.addPiece (Piece<T>(p1, p2), new PowerLawFunction<T>(p1, p2, (T)0.8, (T)0.9, (T)0.9) );
242 waterBlue.addPiece (Piece<T>(p2, p3), new PowerLawFunction<T>(p2, p3, (T)0.9, (T)1.0, (T)0.2) );
243
244 return waterBlue;
245}
246
247template <typename T>
249{
250 T p0 = (T) 0.;
251 T p1 = (T) 1.;
252
254 airRed.addPiece (Piece<T>(p0, p1), new LinearFunction<T>(p0, p1, (T)0., (T)1.) );
255
256 return airRed;
257}
258
259template <typename T>
261{
262 T p0 = (T) 0.;
263 T p1 = (T) 1.;
264
265 PiecewiseFunction<T> airGreen;
266 airGreen.addPiece (Piece<T>(p0, p1), new LinearFunction<T>(p0, p1, (T)1., (T)0.) );
267
268 return airGreen;
269}
270
271template <typename T>
273{
274 T p0 = (T) 0.;
275 T p1 = (T) 1.;
276
277 PiecewiseFunction<T> airBlue;
278 airBlue.addPiece (Piece<T>(p0, p1), new LinearFunction<T>(p0, p1, (T)1., (T)1.) );
279
280 return airBlue;
281}
282
283
284template <typename T>
286{
287 T p0 = (T) 0.;
288 T p1 = (T) 0.36;
289 T p3 = (T) 1.;
290
291 PiecewiseFunction<T> fireRed;
292 fireRed.addPiece (Piece<T>(p0, p1), new LinearFunction<T>(p0, p1, (T)0., (T)1.) );
293 fireRed.addPiece (Piece<T>(p1, p3), new LinearFunction<T>(p1, p3, (T)1., (T)1.) );
294
295 return fireRed;
296}
297
298template <typename T>
300{
301 T p0 = (T) 0.;
302 T p1 = (T) 0.36;
303 T p2 = (T) 0.75;
304 T p3 = (T) 1.;
305
306 PiecewiseFunction<T> fireGreen;
307 fireGreen.addPiece (Piece<T>(p0, p1), new LinearFunction<T>(p0, p1, (T)0., (T)0.) );
308 fireGreen.addPiece (Piece<T>(p1, p2), new LinearFunction<T>(p1, p2, (T)0., (T)1.) );
309 fireGreen.addPiece (Piece<T>(p2, p3), new LinearFunction<T>(p2, p3, (T)1., (T)1.) );
310
311 return fireGreen;
312}
313
314template <typename T>
316{
317 T p0 = (T) 0.;
318 T p2 = (T) 0.75;
319 T p3 = (T) 1.;
320
321 PiecewiseFunction<T> fireBlue;
322 fireBlue.addPiece (Piece<T>(p0, p2), new LinearFunction<T>(p0, p2, (T)0., (T)0.) );
323 fireBlue.addPiece (Piece<T>(p2, p3), new LinearFunction<T>(p2, p3, (T)0., (T)1.) );
324
325 return fireBlue;
326}
327
328
329template <typename T>
331{
332 T p0 = (T) 0.;
333 T p2 = (T) 3./8.;
334 T p3 = (T) 5./8.;
335 T p4 = (T) 7./8.;
336 T p5 = (T) 1.;
337 T p6 = (T) 9./8.;
338
339
340 PiecewiseFunction<T> leeLooRed;
341 leeLooRed.addPiece (Piece<T>(p0, p2), new LinearFunction<T>(p0, p2, (T)0., (T)0.) );
342 leeLooRed.addPiece (Piece<T>(p2, p3), new LinearFunction<T>(p2, p3, (T)0., (T)1.) );
343 leeLooRed.addPiece (Piece<T>(p3, p4), new LinearFunction<T>(p3, p4, (T)1., (T)1.) );
344 leeLooRed.addPiece (Piece<T>(p4, p5), new LinearFunction<T>(p4, p6, (T)1., (T)0.) );
345
346 return leeLooRed;
347}
348
349template <typename T>
351{
352 T p0 = (T) 0.;
353 T p1 = (T) 1./8.;
354 T p2 = (T) 3./8.;
355 T p3 = (T) 5./8.;
356 T p4 = (T) 7./8.;
357 T p5 = (T) 1.;
358 T p6 = (T) 9/8;
359
360
361 PiecewiseFunction<T> leeLooGreen;
362 leeLooGreen.addPiece (Piece<T>(p0, p1), new LinearFunction<T>(p0, p1, (T)0., (T)0.) );
363 leeLooGreen.addPiece (Piece<T>(p1, p2), new LinearFunction<T>(p1, p2, (T)0., (T)1.) );
364 leeLooGreen.addPiece (Piece<T>(p2, p3), new LinearFunction<T>(p2, p3, (T)1., (T)1.) );
365 leeLooGreen.addPiece (Piece<T>(p3, p4), new LinearFunction<T>(p3, p4, (T)1., (T)0.) );
366 leeLooGreen.addPiece (Piece<T>(p4, p5), new LinearFunction<T>(p4, p6, (T)0., (T)0.) );
367
368 return leeLooGreen;
369}
370
371template <typename T>
373{
374 T pm1 = (T) -1./8.;
375 T p0 = (T) 0.;
376 T p1 = (T) 1./8.;
377 T p2 = (T) 3./8.;
378 T p3 = (T) 5./8.;
379 T p5 = (T) 1.;
380
381
382 PiecewiseFunction<T> leeLooBlue;
383 leeLooBlue.addPiece (Piece<T>(p0, p1), new LinearFunction<T>(pm1, p1, (T)0., (T)1.) );
384 leeLooBlue.addPiece (Piece<T>(p1, p2), new LinearFunction<T>(p1, p2, (T)1., (T)1.) );
385 leeLooBlue.addPiece (Piece<T>(p2, p3), new LinearFunction<T>(p2, p3, (T)1., (T)0.) );
386 leeLooBlue.addPiece (Piece<T>(p3, p5), new LinearFunction<T>(p3, p5, (T)0., (T)0.) );
387
388 return leeLooBlue;
389}
390
391template <typename T>
392ColorMap<T> generateMap(std::string mapName)
393{
394 if (mapName == "earth") {
395 return ColorMap<T> (
396 generateEarthRed<T>(),
397 generateEarthGreen<T>(),
398 generateEarthBlue<T>() );
399 }
400 else if (mapName == "water") {
401 return ColorMap<T> (
402 generateWaterRed<T>(),
403 generateWaterGreen<T>(),
404 generateWaterBlue<T>() );
405 }
406 else if (mapName == "air") {
407 return ColorMap<T> (
408 generateAirRed<T>(),
409 generateAirGreen<T>(),
410 generateAirBlue<T>() );
411 }
412 else if (mapName == "fire") {
413 return ColorMap<T> (
414 generateFireRed<T>(),
415 generateFireGreen<T>(),
416 generateFireBlue<T>() );
417 }
418 else if (mapName == "leeloo") {
419 return ColorMap<T> (
420 generateLeeLooRed<T>(),
421 generateLeeLooGreen<T>(),
422 generateLeeLooBlue<T>() );
423 }
424 return ColorMap<T> (
425 generateLeeLooRed<T>(),
426 generateLeeLooGreen<T>(),
427 generateLeeLooBlue<T>() );
428}
429
430} // namespace mapGenerators
431
432} // namespace graphics
433
434} // namespace olb
435
436#endif
ColorMap(PiecewiseFunction< T > const &red_, PiecewiseFunction< T > const &green_, PiecewiseFunction< T > const &blue_)
Definition colormaps.hh:137
rgb< T > get(T x) const
Definition colormaps.hh:144
T operator()(T x) const override
Definition colormaps.hh:40
LinearFunction(T x1_, T x2_, T y1_, T y2_)
Definition colormaps.hh:35
LinearFunction< T > * clone() const override
Definition colormaps.hh:46
T operator()(T x) const override
Definition colormaps.hh:115
PiecewiseFunction< T > * clone() const override
Definition colormaps.hh:131
void swap(PiecewiseFunction< T > &rhs)
Definition colormaps.hh:95
PiecewiseFunction< T > & operator=(PiecewiseFunction< T > const &rhs)
Definition colormaps.hh:80
void addPiece(Piece< T > piece, ScalarFunction< T > *f)
Definition colormaps.hh:102
T operator()(T x) const override
Definition colormaps.hh:57
PowerLawFunction< T > * clone() const override
Definition colormaps.hh:63
PowerLawFunction(T x1_, T x2_, T y1_, T y2_, T b_)
Definition colormaps.hh:52
PiecewiseFunction< T > generateWaterBlue()
Definition colormaps.hh:232
PiecewiseFunction< T > generateAirGreen()
Definition colormaps.hh:260
PiecewiseFunction< T > generateFireGreen()
Definition colormaps.hh:299
PiecewiseFunction< T > generateWaterRed()
Definition colormaps.hh:200
PiecewiseFunction< T > generateFireRed()
Definition colormaps.hh:285
PiecewiseFunction< T > generateEarthRed()
Definition colormaps.hh:152
PiecewiseFunction< T > generateEarthBlue()
Definition colormaps.hh:184
PiecewiseFunction< T > generateWaterGreen()
Definition colormaps.hh:216
PiecewiseFunction< T > generateLeeLooBlue()
Definition colormaps.hh:372
ColorMap< T > generateMap(std::string mapName)
Definition colormaps.hh:392
PiecewiseFunction< T > generateLeeLooRed()
Definition colormaps.hh:330
PiecewiseFunction< T > generateAirBlue()
Definition colormaps.hh:272
PiecewiseFunction< T > generateAirRed()
Definition colormaps.hh:248
PiecewiseFunction< T > generateEarthGreen()
Definition colormaps.hh:168
PiecewiseFunction< T > generateLeeLooGreen()
Definition colormaps.hh:350
PiecewiseFunction< T > generateFireBlue()
Definition colormaps.hh:315
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
Top level namespace for all of OpenLB.