VTK  9.3.0
vtkColor.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
13#ifndef vtkColor_h
14#define vtkColor_h
15
16#include "vtkObject.h" // for legacy macros
17#include "vtkTuple.h"
18
19// .NAME vtkColor3 - templated base type for storage of 3 component colors.
20//
21VTK_ABI_NAMESPACE_BEGIN
22template <typename T>
23class vtkColor3 : public vtkTuple<T, 3>
24{
25public:
26 vtkColor3() = default;
27
28 explicit vtkColor3(const T& scalar)
29 : vtkTuple<T, 3>(scalar)
30 {
31 }
32
33 explicit vtkColor3(const T* init)
34 : vtkTuple<T, 3>(init)
35 {
36 }
37
38 vtkColor3(const T& red, const T& green, const T& blue)
39 {
40 this->Data[0] = red;
41 this->Data[1] = green;
42 this->Data[2] = blue;
43 }
44
46
49 void Set(const T& red, const T& green, const T& blue)
50 {
51 this->Data[0] = red;
52 this->Data[1] = green;
53 this->Data[2] = blue;
54 }
56
60 void SetRed(const T& red) { this->Data[0] = red; }
61
65 const T& GetRed() const { return this->Data[0]; }
66
70 void SetGreen(const T& green) { this->Data[1] = green; }
71
75 const T& GetGreen() const { return this->Data[1]; }
76
80 void SetBlue(const T& blue) { this->Data[2] = blue; }
81
85 const T& GetBlue() const { return this->Data[2]; }
86};
87
88// .NAME vtkColor4 - templated base type for storage of 4 component colors.
89//
90template <typename T>
91class vtkColor4 : public vtkTuple<T, 4>
92{
93public:
94 vtkColor4() = default;
95
96 explicit vtkColor4(const T& scalar)
97 : vtkTuple<T, 4>(scalar)
98 {
99 }
100
101 explicit vtkColor4(const T* init)
102 : vtkTuple<T, 4>(init)
103 {
104 }
105
106 vtkColor4(const T& red, const T& green, const T& blue, const T& alpha)
107 {
108 this->Data[0] = red;
109 this->Data[1] = green;
110 this->Data[2] = blue;
111 this->Data[3] = alpha;
112 }
113
115
118 void Set(const T& red, const T& green, const T& blue)
119 {
120 this->Data[0] = red;
121 this->Data[1] = green;
122 this->Data[2] = blue;
123 }
125
127
130 void Set(const T& red, const T& green, const T& blue, const T& alpha)
131 {
132 this->Data[0] = red;
133 this->Data[1] = green;
134 this->Data[2] = blue;
135 this->Data[3] = alpha;
136 }
138
142 void SetRed(const T& red) { this->Data[0] = red; }
143
147 const T& GetRed() const { return this->Data[0]; }
148
152 void SetGreen(const T& green) { this->Data[1] = green; }
153
157 const T& GetGreen() const { return this->Data[1]; }
158
162 void SetBlue(const T& blue) { this->Data[2] = blue; }
163
167 const T& GetBlue() const { return this->Data[2]; }
168
172 void SetAlpha(const T& alpha) { this->Data[3] = alpha; }
173
177 const T& GetAlpha() const { return this->Data[3]; }
178};
179
183class vtkColor3ub : public vtkColor3<unsigned char>
184{
185public:
186 vtkColor3ub() = default;
187 explicit vtkColor3ub(unsigned char scalar)
188 : vtkColor3<unsigned char>(scalar)
189 {
190 }
191 explicit vtkColor3ub(const unsigned char* init)
192 : vtkColor3<unsigned char>(init)
193 {
194 }
195
197
200 explicit vtkColor3ub(int hexSigned)
201 {
202 unsigned int hex = static_cast<unsigned int>(hexSigned);
203 this->Data[2] = hex & 0xff;
204 hex >>= 8;
205 this->Data[1] = hex & 0xff;
206 hex >>= 8;
207 this->Data[0] = hex & 0xff;
208 }
210
211 vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
212 : vtkColor3<unsigned char>(r, g, b)
213 {
214 }
215};
216
217class vtkColor3f : public vtkColor3<float>
218{
219public:
220 vtkColor3f() = default;
221 explicit vtkColor3f(float scalar)
222 : vtkColor3<float>(scalar)
223 {
224 }
225 explicit vtkColor3f(const float* init)
226 : vtkColor3<float>(init)
227 {
228 }
229 vtkColor3f(float r, float g, float b)
230 : vtkColor3<float>(r, g, b)
231 {
232 }
233};
234
235class vtkColor3d : public vtkColor3<double>
236{
237public:
238 vtkColor3d() = default;
239 explicit vtkColor3d(double scalar)
240 : vtkColor3<double>(scalar)
241 {
242 }
243 explicit vtkColor3d(const double* init)
244 : vtkColor3<double>(init)
245 {
246 }
247 vtkColor3d(double r, double g, double b)
248 : vtkColor3<double>(r, g, b)
249 {
250 }
251};
252
253class vtkColor4ub : public vtkColor4<unsigned char>
254{
255public:
256 vtkColor4ub() = default;
257 explicit vtkColor4ub(unsigned char scalar)
258 : vtkColor4<unsigned char>(scalar)
259 {
260 }
261 explicit vtkColor4ub(const unsigned char* init)
262 : vtkColor4<unsigned char>(init)
263 {
264 }
265
267
271 explicit vtkColor4ub(int hexSigned)
272 {
273 unsigned int hex = static_cast<unsigned int>(hexSigned);
274 this->Data[3] = hex & 0xff;
275 hex >>= 8;
276 this->Data[2] = hex & 0xff;
277 hex >>= 8;
278 this->Data[1] = hex & 0xff;
279 hex >>= 8;
280 this->Data[0] = hex & 0xff;
281 }
283
284 vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
285 : vtkColor4<unsigned char>(r, g, b, a)
286 {
287 }
289 : vtkColor4<unsigned char>(c[0], c[1], c[2], 255)
290 {
291 }
292};
293
294class vtkColor4f : public vtkColor4<float>
295{
296public:
297 vtkColor4f() = default;
298 explicit vtkColor4f(float scalar)
299 : vtkColor4<float>(scalar)
300 {
301 }
302 explicit vtkColor4f(const float* init)
303 : vtkColor4<float>(init)
304 {
305 }
306 vtkColor4f(float r, float g, float b, float a = 1.0)
307 : vtkColor4<float>(r, g, b, a)
308 {
309 }
310};
311
312class vtkColor4d : public vtkColor4<double>
313{
314public:
315 vtkColor4d() = default;
316 explicit vtkColor4d(double scalar)
317 : vtkColor4<double>(scalar)
318 {
319 }
320 explicit vtkColor4d(const double* init)
321 : vtkColor4<double>(init)
322 {
323 }
324 vtkColor4d(double r, double g, double b, double a = 1.0)
325 : vtkColor4<double>(r, g, b, a)
326 {
327 }
328};
329
330VTK_ABI_NAMESPACE_END
331#endif // vtkColor_h
332// VTK-HeaderTest-Exclude: vtkColor.h
vtkColor3(const T &scalar)
Definition vtkColor.h:28
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition vtkColor.h:70
vtkColor3()=default
void Set(const T &red, const T &green, const T &blue)
Set the red, green and blue components of the color.
Definition vtkColor.h:49
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition vtkColor.h:85
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition vtkColor.h:60
const T & GetRed() const
Get the red component of the color, i.e.
Definition vtkColor.h:65
vtkColor3(const T &red, const T &green, const T &blue)
Definition vtkColor.h:38
vtkColor3(const T *init)
Definition vtkColor.h:33
const T & GetGreen() const
Get the green component of the color, i.e.
Definition vtkColor.h:75
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition vtkColor.h:80
vtkColor3d(const double *init)
Definition vtkColor.h:243
vtkColor3d(double scalar)
Definition vtkColor.h:239
vtkColor3d()=default
vtkColor3d(double r, double g, double b)
Definition vtkColor.h:247
vtkColor3f()=default
vtkColor3f(float r, float g, float b)
Definition vtkColor.h:229
vtkColor3f(float scalar)
Definition vtkColor.h:221
vtkColor3f(const float *init)
Definition vtkColor.h:225
Some derived classes for the different colors commonly used.
Definition vtkColor.h:184
vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
Definition vtkColor.h:211
vtkColor3ub(unsigned char scalar)
Definition vtkColor.h:187
vtkColor3ub()=default
vtkColor3ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FF (blue).
Definition vtkColor.h:200
vtkColor3ub(const unsigned char *init)
Definition vtkColor.h:191
vtkColor4()=default
const T & GetAlpha() const
Get the alpha component of the color, i.e.
Definition vtkColor.h:177
void SetAlpha(const T &alpha)
Set the alpha component of the color, i.e.
Definition vtkColor.h:172
vtkColor4(const T &scalar)
Definition vtkColor.h:96
void Set(const T &red, const T &green, const T &blue, const T &alpha)
Set the red, green, blue and alpha components of the color.
Definition vtkColor.h:130
vtkColor4(const T &red, const T &green, const T &blue, const T &alpha)
Definition vtkColor.h:106
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition vtkColor.h:142
vtkColor4(const T *init)
Definition vtkColor.h:101
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition vtkColor.h:167
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition vtkColor.h:162
const T & GetGreen() const
Get the green component of the color, i.e.
Definition vtkColor.h:157
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition vtkColor.h:152
void Set(const T &red, const T &green, const T &blue)
Set the red, green and blue components of the color.
Definition vtkColor.h:118
const T & GetRed() const
Get the red component of the color, i.e.
Definition vtkColor.h:147
vtkColor4d(double r, double g, double b, double a=1.0)
Definition vtkColor.h:324
vtkColor4d(const double *init)
Definition vtkColor.h:320
vtkColor4d()=default
vtkColor4d(double scalar)
Definition vtkColor.h:316
vtkColor4f(float r, float g, float b, float a=1.0)
Definition vtkColor.h:306
vtkColor4f(float scalar)
Definition vtkColor.h:298
vtkColor4f(const float *init)
Definition vtkColor.h:302
vtkColor4f()=default
vtkColor4ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FFAA (opaque blue).
Definition vtkColor.h:271
vtkColor4ub(const vtkColor3ub &c)
Definition vtkColor.h:288
vtkColor4ub(unsigned char scalar)
Definition vtkColor.h:257
vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition vtkColor.h:284
vtkColor4ub()=default
vtkColor4ub(const unsigned char *init)
Definition vtkColor.h:261
templated base type for containers of constant size.
Definition vtkTuple.h:27
T Data[Size]
The only thing stored in memory!
Definition vtkTuple.h:143