VTK  9.2.6
vtkColor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkColor.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
34 #ifndef vtkColor_h
35 #define vtkColor_h
36 
37 #include "vtkObject.h" // for legacy macros
38 #include "vtkTuple.h"
39 
40 // .NAME vtkColor3 - templated base type for storage of 3 component colors.
41 //
42 template <typename T>
43 class vtkColor3 : public vtkTuple<T, 3>
44 {
45 public:
46  vtkColor3() = default;
47 
48  explicit vtkColor3(const T& scalar)
49  : vtkTuple<T, 3>(scalar)
50  {
51  }
52 
53  explicit vtkColor3(const T* init)
54  : vtkTuple<T, 3>(init)
55  {
56  }
57 
58  vtkColor3(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  }
64 
66 
69  void Set(const T& red, const T& green, const T& blue)
70  {
71  this->Data[0] = red;
72  this->Data[1] = green;
73  this->Data[2] = blue;
74  }
76 
80  void SetRed(const T& red) { this->Data[0] = red; }
81 
85  const T& GetRed() const { return this->Data[0]; }
86 
90  void SetGreen(const T& green) { this->Data[1] = green; }
91 
95  const T& GetGreen() const { return this->Data[1]; }
96 
100  void SetBlue(const T& blue) { this->Data[2] = blue; }
101 
105  const T& GetBlue() const { return this->Data[2]; }
106 };
107 
108 // .NAME vtkColor4 - templated base type for storage of 4 component colors.
109 //
110 template <typename T>
111 class vtkColor4 : public vtkTuple<T, 4>
112 {
113 public:
114  vtkColor4() = default;
115 
116  explicit vtkColor4(const T& scalar)
117  : vtkTuple<T, 4>(scalar)
118  {
119  }
120 
121  explicit vtkColor4(const T* init)
122  : vtkTuple<T, 4>(init)
123  {
124  }
125 
126  vtkColor4(const T& red, const T& green, const T& blue, const T& alpha)
127  {
128  this->Data[0] = red;
129  this->Data[1] = green;
130  this->Data[2] = blue;
131  this->Data[3] = alpha;
132  }
133 
135 
138  void Set(const T& red, const T& green, const T& blue)
139  {
140  this->Data[0] = red;
141  this->Data[1] = green;
142  this->Data[2] = blue;
143  }
145 
147 
150  void Set(const T& red, const T& green, const T& blue, const T& alpha)
151  {
152  this->Data[0] = red;
153  this->Data[1] = green;
154  this->Data[2] = blue;
155  this->Data[3] = alpha;
156  }
158 
162  void SetRed(const T& red) { this->Data[0] = red; }
163 
167  const T& GetRed() const { return this->Data[0]; }
168 
172  void SetGreen(const T& green) { this->Data[1] = green; }
173 
177  const T& GetGreen() const { return this->Data[1]; }
178 
182  void SetBlue(const T& blue) { this->Data[2] = blue; }
183 
187  const T& GetBlue() const { return this->Data[2]; }
188 
192  void SetAlpha(const T& alpha) { this->Data[3] = alpha; }
193 
197  const T& GetAlpha() const { return this->Data[3]; }
198 };
199 
203 class vtkColor3ub : public vtkColor3<unsigned char>
204 {
205 public:
206  vtkColor3ub() = default;
207  explicit vtkColor3ub(unsigned char scalar)
208  : vtkColor3<unsigned char>(scalar)
209  {
210  }
211  explicit vtkColor3ub(const unsigned char* init)
212  : vtkColor3<unsigned char>(init)
213  {
214  }
215 
217 
220  explicit vtkColor3ub(int hexSigned)
221  {
222  unsigned int hex = static_cast<unsigned int>(hexSigned);
223  this->Data[2] = hex & 0xff;
224  hex >>= 8;
225  this->Data[1] = hex & 0xff;
226  hex >>= 8;
227  this->Data[0] = hex & 0xff;
228  }
230 
231  vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
232  : vtkColor3<unsigned char>(r, g, b)
233  {
234  }
235 };
236 
237 class vtkColor3f : public vtkColor3<float>
238 {
239 public:
240  vtkColor3f() = default;
241  explicit vtkColor3f(float scalar)
242  : vtkColor3<float>(scalar)
243  {
244  }
245  explicit vtkColor3f(const float* init)
246  : vtkColor3<float>(init)
247  {
248  }
249  vtkColor3f(float r, float g, float b)
250  : vtkColor3<float>(r, g, b)
251  {
252  }
253 };
254 
255 class vtkColor3d : public vtkColor3<double>
256 {
257 public:
258  vtkColor3d() = default;
259  explicit vtkColor3d(double scalar)
260  : vtkColor3<double>(scalar)
261  {
262  }
263  explicit vtkColor3d(const double* init)
264  : vtkColor3<double>(init)
265  {
266  }
267  vtkColor3d(double r, double g, double b)
268  : vtkColor3<double>(r, g, b)
269  {
270  }
271 };
272 
273 class vtkColor4ub : public vtkColor4<unsigned char>
274 {
275 public:
276  vtkColor4ub() = default;
277  explicit vtkColor4ub(unsigned char scalar)
278  : vtkColor4<unsigned char>(scalar)
279  {
280  }
281  explicit vtkColor4ub(const unsigned char* init)
282  : vtkColor4<unsigned char>(init)
283  {
284  }
285 
287 
291  explicit vtkColor4ub(int hexSigned)
292  {
293  unsigned int hex = static_cast<unsigned int>(hexSigned);
294  this->Data[3] = hex & 0xff;
295  hex >>= 8;
296  this->Data[2] = hex & 0xff;
297  hex >>= 8;
298  this->Data[1] = hex & 0xff;
299  hex >>= 8;
300  this->Data[0] = hex & 0xff;
301  }
303 
304  vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
305  : vtkColor4<unsigned char>(r, g, b, a)
306  {
307  }
309  : vtkColor4<unsigned char>(c[0], c[1], c[2], 255)
310  {
311  }
312 };
313 
314 class vtkColor4f : public vtkColor4<float>
315 {
316 public:
317  vtkColor4f() = default;
318  explicit vtkColor4f(float scalar)
319  : vtkColor4<float>(scalar)
320  {
321  }
322  explicit vtkColor4f(const float* init)
323  : vtkColor4<float>(init)
324  {
325  }
326  vtkColor4f(float r, float g, float b, float a = 1.0)
327  : vtkColor4<float>(r, g, b, a)
328  {
329  }
330 };
331 
332 class vtkColor4d : public vtkColor4<double>
333 {
334 public:
335  vtkColor4d() = default;
336  explicit vtkColor4d(double scalar)
337  : vtkColor4<double>(scalar)
338  {
339  }
340  explicit vtkColor4d(const double* init)
341  : vtkColor4<double>(init)
342  {
343  }
344  vtkColor4d(double r, double g, double b, double a = 1.0)
345  : vtkColor4<double>(r, g, b, a)
346  {
347  }
348 };
349 
350 #endif // vtkColor_h
351 // VTK-HeaderTest-Exclude: vtkColor.h
vtkColor3(const T &scalar)
Definition: vtkColor.h:48
const T & GetRed() const
Get the red component of the color, i.e.
Definition: vtkColor.h:85
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition: vtkColor.h:90
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:69
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition: vtkColor.h:80
vtkColor3(const T &red, const T &green, const T &blue)
Definition: vtkColor.h:58
vtkColor3(const T *init)
Definition: vtkColor.h:53
const T & GetGreen() const
Get the green component of the color, i.e.
Definition: vtkColor.h:95
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition: vtkColor.h:105
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition: vtkColor.h:100
vtkColor3d(const double *init)
Definition: vtkColor.h:263
vtkColor3d(double scalar)
Definition: vtkColor.h:259
vtkColor3d()=default
vtkColor3d(double r, double g, double b)
Definition: vtkColor.h:267
vtkColor3f()=default
vtkColor3f(float r, float g, float b)
Definition: vtkColor.h:249
vtkColor3f(float scalar)
Definition: vtkColor.h:241
vtkColor3f(const float *init)
Definition: vtkColor.h:245
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:204
vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
Definition: vtkColor.h:231
vtkColor3ub(unsigned char scalar)
Definition: vtkColor.h:207
vtkColor3ub()=default
vtkColor3ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FF (blue).
Definition: vtkColor.h:220
vtkColor3ub(const unsigned char *init)
Definition: vtkColor.h:211
const T & GetGreen() const
Get the green component of the color, i.e.
Definition: vtkColor.h:177
vtkColor4()=default
const T & GetRed() const
Get the red component of the color, i.e.
Definition: vtkColor.h:167
void SetAlpha(const T &alpha)
Set the alpha component of the color, i.e.
Definition: vtkColor.h:192
vtkColor4(const T &scalar)
Definition: vtkColor.h:116
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:150
vtkColor4(const T &red, const T &green, const T &blue, const T &alpha)
Definition: vtkColor.h:126
const T & GetAlpha() const
Get the alpha component of the color, i.e.
Definition: vtkColor.h:197
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition: vtkColor.h:162
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition: vtkColor.h:187
vtkColor4(const T *init)
Definition: vtkColor.h:121
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition: vtkColor.h:182
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition: vtkColor.h:172
void Set(const T &red, const T &green, const T &blue)
Set the red, green and blue components of the color.
Definition: vtkColor.h:138
vtkColor4d(double r, double g, double b, double a=1.0)
Definition: vtkColor.h:344
vtkColor4d(const double *init)
Definition: vtkColor.h:340
vtkColor4d()=default
vtkColor4d(double scalar)
Definition: vtkColor.h:336
vtkColor4f(float r, float g, float b, float a=1.0)
Definition: vtkColor.h:326
vtkColor4f(float scalar)
Definition: vtkColor.h:318
vtkColor4f(const float *init)
Definition: vtkColor.h:322
vtkColor4f()=default
vtkColor4ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FFAA (opaque blue).
Definition: vtkColor.h:291
vtkColor4ub(const vtkColor3ub &c)
Definition: vtkColor.h:308
vtkColor4ub(unsigned char scalar)
Definition: vtkColor.h:277
vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: vtkColor.h:304
vtkColor4ub()=default
vtkColor4ub(const unsigned char *init)
Definition: vtkColor.h:281
templated base type for containers of constant size.
Definition: vtkTuple.h:38
T Data[Size]
The only thing stored in memory!
Definition: vtkTuple.h:154
@ alpha
Definition: vtkX3D.h:256