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