summaryrefslogtreecommitdiff
path: root/src/io/colormaps.h
blob: 673425df3e8a7dffd634c1ca9c654751ffc2c0a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2007 Jonas Latt
 *  E-mail contact: info@openlb.net
 *  The most recent release of OpenLB can be downloaded at
 *  <http://www.openlb.net/>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA  02110-1301, USA.
*/

#ifndef COLORMAPS_H
#define COLORMAPS_H

#include <string>
#include <vector>

namespace olb {

namespace graphics {

template <typename T>
struct ScalarFunction {
  virtual ~ScalarFunction() { }
  virtual T operator() (T x) const =0;
  virtual ScalarFunction<T>* clone() const=0;
};

template <typename T>
class LinearFunction : public ScalarFunction<T> {
public:
  LinearFunction(T x1_, T x2_, T y1_, T y2_);
  T operator() (T x) const override;
  LinearFunction<T>* clone() const override;
private:
  T x1, x2, y1, y2;
};

template <typename T>
class PowerLawFunction : public ScalarFunction<T> {
public:
  PowerLawFunction(T x1_, T x2_, T y1_, T y2_, T b_);
  T operator() (T x) const override;
  PowerLawFunction<T>* clone() const override;
private:
  T x1, x2, y1, y2;
  T b;
};

template <typename T>
struct Piece {
  Piece(T closedBegin_, T openEnd_) : closedBegin(closedBegin_), openEnd(openEnd_)
  {
  }
  T closedBegin, openEnd;
};

template <typename T>
class PiecewiseFunction : public ScalarFunction<T> {
public:
  PiecewiseFunction() { }
  ~PiecewiseFunction() override;
  PiecewiseFunction(PiecewiseFunction<T> const& rhs);
  PiecewiseFunction<T>& operator=(PiecewiseFunction<T> const& rhs);
  void swap(PiecewiseFunction<T>& rhs);
  void addPiece(Piece<T> piece, ScalarFunction<T>* f);
  T operator() (T x) const override;
  PiecewiseFunction<T>* clone() const override;
private:
  std::vector<Piece<T> > pieces;
  std::vector<ScalarFunction<T>*> functions;
};

template <typename T>
struct rgb {
  rgb(T r_, T g_, T b_) : r(r_), g(g_), b(b_)
  {
  }
  T r,g,b;
};

template <typename T>
class ColorMap {
public:
  ColorMap(PiecewiseFunction<T> const& red_,
           PiecewiseFunction<T> const& green_,
           PiecewiseFunction<T> const& blue_);
  rgb<T> get(T x) const;
private:
  PiecewiseFunction<T> red, green, blue;
};

namespace mapGenerators {

template <typename T> PiecewiseFunction<T> generateEarthRed();
template <typename T> PiecewiseFunction<T> generateEarthGreen();
template <typename T> PiecewiseFunction<T> generateEarthBlue();

template <typename T> PiecewiseFunction<T> generateWaterRed();
template <typename T> PiecewiseFunction<T> generateWaterGreen();
template <typename T> PiecewiseFunction<T> generateWaterBlue();

template <typename T> PiecewiseFunction<T> generateAirRed();
template <typename T> PiecewiseFunction<T> generateAirGreen();
template <typename T> PiecewiseFunction<T> generateAirBlue();

template <typename T> PiecewiseFunction<T> generateFireRed();
template <typename T> PiecewiseFunction<T> generateFireGreen();
template <typename T> PiecewiseFunction<T> generateFireBlue();

template <typename T> PiecewiseFunction<T> generateLeeLooRed();
template <typename T> PiecewiseFunction<T> generateLeeLooGreen();
template <typename T> PiecewiseFunction<T> generateLeeLooBlue();

template <typename T> ColorMap<T> generateMap(std::string mapName);

} // namespace mapGenerators

}  // namespace graphics

}  // namespace olb

#endif