trase
Colors.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018, University of Oxford.
3 All rights reserved.
4 
5 University of Oxford means the Chancellor, Masters and Scholars of the
6 University of Oxford, having an administrative office at Wellington
7 Square, Oxford OX1 2JD, UK.
8 
9 This file is part of trase.
10 
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright notice, this
14  list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18 * Neither the name of the copyright holder nor the names of its
19  contributors may be used to endorse or promote products derived from
20  this software without specific prior written permission.
21 
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
35 
36 #ifndef COLORS_H_
37 #define COLORS_H_
38 
39 #include <array>
40 #include <string>
41 #include <vector>
42 
43 #include "util/Vector.hpp"
44 
45 namespace trase {
46 
48 class RGBA {
49 
51  int m_r;
52 
54  int m_g;
55 
57  int m_b;
58 
60  int m_a;
61 
62 public:
63  const static int default_alpha;
64  const static std::array<const RGBA, 10> defaults;
65  const static RGBA black;
66  const static RGBA white;
67 
69  RGBA() = default;
70 
72  RGBA(int r, int g, int b, int a = default_alpha) noexcept;
73 
75  explicit RGBA(const Vector<float, 4> &v) noexcept;
76 
78  explicit RGBA(const Vector<float, 3> &v) noexcept;
79 
81  explicit operator Vector<float, 4>() const noexcept {
82  return {static_cast<float>(m_r), static_cast<float>(m_g),
83  static_cast<float>(m_b), static_cast<float>(m_a)};
84  };
85 
87  std::string to_rgb_string() const noexcept;
88 
90  int r() const noexcept;
91 
93  int g() const noexcept;
94 
96  int b() const noexcept;
97 
99  int a() const noexcept;
100 
102  RGBA &r(int r) noexcept;
103 
105  RGBA &g(int g) noexcept;
106 
108  RGBA &b(int b) noexcept;
109 
111  RGBA &a(int a) noexcept;
112 
114  bool operator==(const RGBA &b) const noexcept;
115  bool operator!=(const RGBA &b) const noexcept;
116 };
117 
119 class Colormap {
120  std::vector<Vector<float, 3>> m_colors;
121 
122 public:
124  explicit Colormap(std::vector<Vector<float, 3>> list) noexcept;
125 
127  RGBA to_color(float i) const;
128 };
129 
130 struct Colormaps {
131  static const Colormap viridis;
132 };
133 
134 } // namespace trase
135 
136 #endif // COLORS_H_
int r() const noexcept
Get the current red value.
Definition: Colors.cpp:54
a linear segmented colormap
Definition: Colors.hpp:119
Definition: Colors.hpp:130
int a() const noexcept
Get the current alpha value.
Definition: Colors.cpp:57
static const Colormap viridis
https://github.com/BIDS/colormap/blob/master/option_d.py
Definition: Colors.hpp:131
An N-dimensional vector class.
Definition: Vector.hpp:59
std::string to_rgb_string() const noexcept
convert to an rgb string of form #rrggbb
Definition: Colors.cpp:79
bool operator==(const RGBA &b) const noexcept
Equality comparison.
Definition: Colors.cpp:88
Colour class with red, green, blue and alpha in range 0 to 255.
Definition: Colors.hpp:48
int b() const noexcept
Get the current blue value.
Definition: Colors.cpp:56
int g() const noexcept
Get the current green value.
Definition: Colors.cpp:55
RGBA()=default
default constructor
Definition: Backend.cpp:39