VTK  9.3.20240424
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
32#ifndef vtkColor_h
33#define vtkColor_h
34
35#include "vtkObject.h" // for legacy macros
36#include "vtkTuple.h"
37
38// .NAME vtkColor3 - templated base type for storage of 3 component colors.
39//
40VTK_ABI_NAMESPACE_BEGIN
41template <typename T>
42class vtkColor3 : public vtkTuple<T, 3>
43{
44public:
45 vtkColor3() = default;
46
47 explicit vtkColor3(const T& scalar)
48 : vtkTuple<T, 3>(scalar)
49 {
50 }
51
52 explicit vtkColor3(const T* init)
53 : vtkTuple<T, 3>(init)
54 {
55 }
56
57 vtkColor3(const T& red, const T& green, const T& blue)
58 {
59 this->Data[0] = red;
60 this->Data[1] = green;
61 this->Data[2] = blue;
62 }
63
65
68 void Set(const T& red, const T& green, const T& blue)
69 {
70 this->Data[0] = red;
71 this->Data[1] = green;
72 this->Data[2] = blue;
73 }
75
79 void SetRed(const T& red) { this->Data[0] = red; }
80
84 const T& GetRed() const { return this->Data[0]; }
85
89 void SetGreen(const T& green) { this->Data[1] = green; }
90
94 const T& GetGreen() const { return this->Data[1]; }
95
99 void SetBlue(const T& blue) { this->Data[2] = blue; }
100
104 const T& GetBlue() const { return this->Data[2]; }
105};
106
107// .NAME vtkColor4 - templated base type for storage of 4 component colors.
108//
109template <typename T>
110class vtkColor4 : public vtkTuple<T, 4>
111{
112public:
113 vtkColor4() = default;
114
115 explicit vtkColor4(const T& scalar)
116 : vtkTuple<T, 4>(scalar)
117 {
118 }
119
120 explicit vtkColor4(const T* init)
121 : vtkTuple<T, 4>(init)
122 {
123 }
124
125 vtkColor4(const T& red, const T& green, const T& blue, const T& alpha)
126 {
127 this->Data[0] = red;
128 this->Data[1] = green;
129 this->Data[2] = blue;
130 this->Data[3] = alpha;
131 }
132
134
137 void Set(const T& red, const T& green, const T& blue)
138 {
139 this->Data[0] = red;
140 this->Data[1] = green;
141 this->Data[2] = blue;
142 }
144
146
149 void Set(const T& red, const T& green, const T& blue, const T& alpha)
150 {
151 this->Data[0] = red;
152 this->Data[1] = green;
153 this->Data[2] = blue;
154 this->Data[3] = alpha;
155 }
157
161 void SetRed(const T& red) { this->Data[0] = red; }
162
166 const T& GetRed() const { return this->Data[0]; }
167
171 void SetGreen(const T& green) { this->Data[1] = green; }
172
176 const T& GetGreen() const { return this->Data[1]; }
177
181 void SetBlue(const T& blue) { this->Data[2] = blue; }
182
186 const T& GetBlue() const { return this->Data[2]; }
187
191 void SetAlpha(const T& alpha) { this->Data[3] = alpha; }
192
196 const T& GetAlpha() const { return this->Data[3]; }
197};
198
202class vtkColor3ub : public vtkColor3<unsigned char>
203{
204public:
205 vtkColor3ub() = default;
206 explicit vtkColor3ub(unsigned char scalar)
207 : vtkColor3<unsigned char>(scalar)
208 {
209 }
210 explicit vtkColor3ub(const unsigned char* init)
211 : vtkColor3<unsigned char>(init)
212 {
213 }
214
216
219 explicit vtkColor3ub(int hexSigned)
220 {
221 unsigned int hex = static_cast<unsigned int>(hexSigned);
222 this->Data[2] = hex & 0xff;
223 hex >>= 8;
224 this->Data[1] = hex & 0xff;
225 hex >>= 8;
226 this->Data[0] = hex & 0xff;
227 }
229
230 vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
231 : vtkColor3<unsigned char>(r, g, b)
232 {
233 }
234};
235
236class vtkColor3f : public vtkColor3<float>
237{
238public:
239 vtkColor3f() = default;
240 explicit vtkColor3f(float scalar)
241 : vtkColor3<float>(scalar)
242 {
243 }
244 explicit vtkColor3f(const float* init)
245 : vtkColor3<float>(init)
246 {
247 }
248 vtkColor3f(float r, float g, float b)
249 : vtkColor3<float>(r, g, b)
250 {
251 }
252};
253
254class vtkColor3d : public vtkColor3<double>
255{
256public:
257 vtkColor3d() = default;
258 explicit vtkColor3d(double scalar)
259 : vtkColor3<double>(scalar)
260 {
261 }
262 explicit vtkColor3d(const double* init)
263 : vtkColor3<double>(init)
264 {
265 }
266 vtkColor3d(double r, double g, double b)
267 : vtkColor3<double>(r, g, b)
268 {
269 }
270};
271
272class vtkColor4ub : public vtkColor4<unsigned char>
273{
274public:
275 vtkColor4ub() = default;
276 explicit vtkColor4ub(unsigned char scalar)
277 : vtkColor4<unsigned char>(scalar)
278 {
279 }
280 explicit vtkColor4ub(const unsigned char* init)
281 : vtkColor4<unsigned char>(init)
282 {
283 }
284
286
290 explicit vtkColor4ub(int hexSigned)
291 {
292 unsigned int hex = static_cast<unsigned int>(hexSigned);
293 this->Data[3] = hex & 0xff;
294 hex >>= 8;
295 this->Data[2] = hex & 0xff;
296 hex >>= 8;
297 this->Data[1] = hex & 0xff;
298 hex >>= 8;
299 this->Data[0] = hex & 0xff;
300 }
302
303 vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
304 : vtkColor4<unsigned char>(r, g, b, a)
305 {
306 }
308 : vtkColor4<unsigned char>(c[0], c[1], c[2], 255)
309 {
310 }
311};
312
313class vtkColor4f : public vtkColor4<float>
314{
315public:
316 vtkColor4f() = default;
317 explicit vtkColor4f(float scalar)
318 : vtkColor4<float>(scalar)
319 {
320 }
321 explicit vtkColor4f(const float* init)
322 : vtkColor4<float>(init)
323 {
324 }
325 vtkColor4f(float r, float g, float b, float a = 1.0)
326 : vtkColor4<float>(r, g, b, a)
327 {
328 }
329};
330
331class vtkColor4d : public vtkColor4<double>
332{
333public:
334 vtkColor4d() = default;
335 explicit vtkColor4d(double scalar)
336 : vtkColor4<double>(scalar)
337 {
338 }
339 explicit vtkColor4d(const double* init)
340 : vtkColor4<double>(init)
341 {
342 }
343 vtkColor4d(double r, double g, double b, double a = 1.0)
344 : vtkColor4<double>(r, g, b, a)
345 {
346 }
347};
348
349VTK_ABI_NAMESPACE_END
350#endif // vtkColor_h
351// VTK-HeaderTest-Exclude: vtkColor.h
vtkColor3(const T &scalar)
Definition vtkColor.h:47
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition vtkColor.h:89
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:68
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition vtkColor.h:104
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition vtkColor.h:79
const T & GetRed() const
Get the red component of the color, i.e.
Definition vtkColor.h:84
vtkColor3(const T &red, const T &green, const T &blue)
Definition vtkColor.h:57
vtkColor3(const T *init)
Definition vtkColor.h:52
const T & GetGreen() const
Get the green component of the color, i.e.
Definition vtkColor.h:94
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition vtkColor.h:99
vtkColor3d(const double *init)
Definition vtkColor.h:262
vtkColor3d(double scalar)
Definition vtkColor.h:258
vtkColor3d()=default
vtkColor3d(double r, double g, double b)
Definition vtkColor.h:266
vtkColor3f()=default
vtkColor3f(float r, float g, float b)
Definition vtkColor.h:248
vtkColor3f(float scalar)
Definition vtkColor.h:240
vtkColor3f(const float *init)
Definition vtkColor.h:244
Some derived classes for the different colors commonly used.
Definition vtkColor.h:203
vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
Definition vtkColor.h:230
vtkColor3ub(unsigned char scalar)
Definition vtkColor.h:206
vtkColor3ub()=default
vtkColor3ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FF (blue).
Definition vtkColor.h:219
vtkColor3ub(const unsigned char *init)
Definition vtkColor.h:210
vtkColor4()=default
const T & GetAlpha() const
Get the alpha component of the color, i.e.
Definition vtkColor.h:196
void SetAlpha(const T &alpha)
Set the alpha component of the color, i.e.
Definition vtkColor.h:191
vtkColor4(const T &scalar)
Definition vtkColor.h:115
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:149
vtkColor4(const T &red, const T &green, const T &blue, const T &alpha)
Definition vtkColor.h:125
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition vtkColor.h:161
vtkColor4(const T *init)
Definition vtkColor.h:120
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition vtkColor.h:186
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition vtkColor.h:181
const T & GetGreen() const
Get the green component of the color, i.e.
Definition vtkColor.h:176
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition vtkColor.h:171
void Set(const T &red, const T &green, const T &blue)
Set the red, green and blue components of the color.
Definition vtkColor.h:137
const T & GetRed() const
Get the red component of the color, i.e.
Definition vtkColor.h:166
vtkColor4d(double r, double g, double b, double a=1.0)
Definition vtkColor.h:343
vtkColor4d(const double *init)
Definition vtkColor.h:339
vtkColor4d()=default
vtkColor4d(double scalar)
Definition vtkColor.h:335
vtkColor4f(float r, float g, float b, float a=1.0)
Definition vtkColor.h:325
vtkColor4f(float scalar)
Definition vtkColor.h:317
vtkColor4f(const float *init)
Definition vtkColor.h:321
vtkColor4f()=default
vtkColor4ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FFAA (opaque blue).
Definition vtkColor.h:290
vtkColor4ub(const vtkColor3ub &c)
Definition vtkColor.h:307
vtkColor4ub(unsigned char scalar)
Definition vtkColor.h:276
vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition vtkColor.h:303
vtkColor4ub()=default
vtkColor4ub(const unsigned char *init)
Definition vtkColor.h:280
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