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