Color.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <RobotAPI/interface/ArViz/Elements.h>
4 
5 #include <SimoxUtility/color/Color.h>
6 
7 #include <Eigen/Core>
8 
9 
10 namespace armarx::viz
11 {
12 
13  struct Color : data::Color
14  {
15  using data::Color::Color;
16 
17  Color(const data::Color& c) : data::Color(c) {}
18 
20  {
21  this->r = c.r;
22  this->g = c.g;
23  this->b = c.b;
24  this->a = c.a;
25  }
26  Color(int r, int g, int b, int a = 255)
27  {
28  this->r = simox::color::to_byte(r);
29  this->g = simox::color::to_byte(g);
30  this->b = simox::color::to_byte(b);
31  this->a = simox::color::to_byte(a);
32  }
33  Color(float r, float g, float b, float a = 1.0)
34  {
35  this->r = simox::color::to_byte(r);
36  this->g = simox::color::to_byte(g);
37  this->b = simox::color::to_byte(b);
38  this->a = simox::color::to_byte(a);
39  }
40 
41  /// Construct a byte color from R, G, B and optional alpha.
42  static inline Color fromRGBA(int r, int g, int b, int a = 255)
43  {
44  return {r, g, b, a};
45  }
46 
47  /// Construct a float color from R, G, B and optional alpha.
48  static inline Color fromRGBA(float r, float g, float b, float a = 1.0)
49  {
50  return {r, g, b, a};
51  }
52 
53  /// Construct from a simox Color.
54  static inline Color fromRGBA(simox::Color c)
55  {
56  return {c};
57  }
58 
59 
60  // Colorless
61 
62  static inline Color black(int a = 255)
63  {
64  return simox::Color::black(a);
65  }
66 
67  static inline Color white(int a = 255)
68  {
69  return simox::Color::white(a);
70  }
71 
72  static inline Color gray(int g = 128, int a = 255)
73  {
74  return simox::Color::gray(g, a);
75  }
76 
77  // Primary colors
78 
79  static inline Color red(int r = 255, int a = 255)
80  {
81  return simox::Color::red(r, a);
82  }
83 
84  static inline Color green(int g = 255, int a = 255)
85  {
86  return simox::Color::green(g, a);
87  }
88 
89  static inline Color blue(int b = 255, int a = 255)
90  {
91  return simox::Color::blue(b, a);
92  }
93 
94 
95  // Secondary colors
96 
97  /// Green + Blue
98  static inline Color cyan(int c = 255, int a = 255)
99  {
100  return simox::Color::cyan(c, a);
101  }
102 
103  /// Red + Green
104  static inline Color yellow(int y = 255, int a = 255)
105  {
106  return simox::Color::yellow(y, a);
107  }
108 
109  /// Red + Blue
110  static inline Color magenta(int m = 255, int a = 255)
111  {
112  return simox::Color::magenta(m, a);
113  }
114 
115 
116  // 2:1 Mixed colors
117 
118  /// 2 Red + 1 Green
119  static inline Color orange(int o = 255, int a = 255)
120  {
121  return simox::Color::orange(o, a);
122  }
123 
124  /// 2 Red + 1 Blue
125  static inline Color pink(int p = 255, int a = 255)
126  {
127  return simox::Color::pink(p, a);
128  }
129 
130  /// 2 Green + 1 Red
131  static inline Color lime(int l = 255, int a = 255)
132  {
133  return simox::Color::lime(l, a);
134  }
135 
136  /// 2 Green + 1 Blue
137  static inline Color turquoise(int t = 255, int a = 255)
138  {
139  return simox::Color::turquoise(t, a);
140  }
141 
142  /// 2 Blue + 1 Green
143  static inline Color azure(int az = 255, int a = 255)
144  {
145  return simox::Color::azure(az, a);
146  }
147 
148  /// 2 Blue + 1 Red
149  static inline Color purple(int p = 255, int a = 255)
150  {
151  return simox::Color::purple(p, a);
152  }
153 
154  };
155 
156 
157  inline std::ostream& operator<<(std::ostream& os, const Color& c)
158  {
159  return os << "(" << int(c.r) << " " << int(c.g) << " " << int(c.b)
160  << " | " << int(c.a) << ")";
161  }
162 
163  inline bool operator==(const Color& lhs, const Color& rhs)
164  {
165  return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && lhs.a == rhs.a;
166  }
167 
168  inline bool operator!=(const Color& lhs, const Color& rhs)
169  {
170  return !(lhs == rhs);
171  }
172 
173  namespace data
174  {
175  // viz::Color == simox::Color
176  inline bool operator==(const viz::data::Color& lhs, const simox::color::Color& rhs)
177  {
178  return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && lhs.a == rhs.a;
179  }
180 
181  // simox::Color == viz::Color
182  inline bool operator==(const simox::color::Color& lhs, const armarx::viz::data::Color& rhs)
183  {
184  return rhs == lhs;
185  }
186 
187  inline std::ostream& operator<<(std::ostream& os, const viz::data::Color& c)
188  {
189  return os << "(" << int(c.r) << " " << int(c.g) << " " << int(c.b)
190  << " | " << int(c.a) << ")";
191  }
192  }
193 }
armarx::viz::Color::black
static Color black(int a=255)
Definition: Color.h:62
armarx::viz::Color::purple
static Color purple(int p=255, int a=255)
2 Blue + 1 Red
Definition: Color.h:149
armarx::viz::Color::fromRGBA
static Color fromRGBA(int r, int g, int b, int a=255)
Construct a byte color from R, G, B and optional alpha.
Definition: Color.h:42
armarx::viz::Color::blue
static Color blue(int b=255, int a=255)
Definition: Color.h:89
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::viz::Color::Color
Color(float r, float g, float b, float a=1.0)
Definition: Color.h:33
armarx::viz::operator<<
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition: Color.h:157
armarx::viz::Color::lime
static Color lime(int l=255, int a=255)
2 Green + 1 Red
Definition: Color.h:131
armarx::viz::Color::Color
Color(int r, int g, int b, int a=255)
Definition: Color.h:26
armarx::viz::Color::white
static Color white(int a=255)
Definition: Color.h:67
armarx::viz::data::operator==
bool operator==(const viz::data::Color &lhs, const simox::color::Color &rhs)
Definition: Color.h:176
armarx::viz::Color::turquoise
static Color turquoise(int t=255, int a=255)
2 Green + 1 Blue
Definition: Color.h:137
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
Color
uint32_t Color
RGBA color.
Definition: color.h:8
armarx::viz::operator!=
bool operator!=(const Color &lhs, const Color &rhs)
Definition: Color.h:168
armarx::viz::Color::yellow
static Color yellow(int y=255, int a=255)
Red + Green.
Definition: Color.h:104
armarx::viz::Color::Color
Color(simox::Color c)
Definition: Color.h:19
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::viz::operator==
bool operator==(const Color &lhs, const Color &rhs)
Definition: Color.h:163
armarx::viz::Color
Definition: Color.h:13
armarx::viz::Color::gray
static Color gray(int g=128, int a=255)
Definition: Color.h:72
armarx::viz::Color::red
static Color red(int r=255, int a=255)
Definition: Color.h:79
armarx::viz::Color::cyan
static Color cyan(int c=255, int a=255)
Green + Blue.
Definition: Color.h:98
armarx::red
QColor red()
Definition: StyleSheets.h:76
armarx::viz::Color::fromRGBA
static Color fromRGBA(simox::Color c)
Construct from a simox Color.
Definition: Color.h:54
armarx::viz::Color::pink
static Color pink(int p=255, int a=255)
2 Red + 1 Blue
Definition: Color.h:125
armarx::viz::Color::magenta
static Color magenta(int m=255, int a=255)
Red + Blue.
Definition: Color.h:110
armarx::viz::Color::orange
static Color orange(int o=255, int a=255)
2 Red + 1 Green
Definition: Color.h:119
armarx::viz::Color::green
static Color green(int g=255, int a=255)
Definition: Color.h:84
armarx::viz::Color::Color
Color(const data::Color &c)
Definition: Color.h:17
armarx::viz::Color::azure
static Color azure(int az=255, int a=255)
2 Blue + 1 Green
Definition: Color.h:143
armarx::viz::data::operator<<
std::ostream & operator<<(std::ostream &os, const viz::data::Color &c)
Definition: Color.h:187
armarx::orange
QColor orange()
Definition: StyleSheets.h:80
armarx::viz
This file is part of ArmarX.
Definition: ArVizStorage.cpp:370
armarx::green
QColor green()
Definition: StyleSheets.h:72
armarx::viz::Color::fromRGBA
static Color fromRGBA(float r, float g, float b, float a=1.0)
Construct a float color from R, G, B and optional alpha.
Definition: Color.h:48