VTK  9.1.0
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
25#ifndef vtkColor_h
26#define vtkColor_h
27
28#include "vtkObject.h" // for legacy macros
29#include "vtkTuple.h"
30
31// .NAME vtkColor3 - templated base type for storage of 3 component colors.
32//
33template <typename T>
34class vtkColor3 : public vtkTuple<T, 3>
35{
36public:
37 vtkColor3() = default;
38
39 explicit vtkColor3(const T& scalar)
40 : vtkTuple<T, 3>(scalar)
41 {
42 }
43
44 explicit vtkColor3(const T* init)
45 : vtkTuple<T, 3>(init)
46 {
47 }
48
49 vtkColor3(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 }
55
57
60 void Set(const T& red, const T& green, const T& blue)
61 {
62 this->Data[0] = red;
63 this->Data[1] = green;
64 this->Data[2] = blue;
65 }
67
71 void SetRed(const T& red) { this->Data[0] = red; }
72
76 const T& GetRed() const { return this->Data[0]; }
77
81 void SetGreen(const T& green) { this->Data[1] = green; }
82
86 const T& GetGreen() const { return this->Data[1]; }
87
91 void SetBlue(const T& blue) { this->Data[2] = blue; }
92
96 const T& GetBlue() const { return this->Data[2]; }
97};
98
99// .NAME vtkColor4 - templated base type for storage of 4 component colors.
100//
101template <typename T>
102class vtkColor4 : public vtkTuple<T, 4>
103{
104public:
105 vtkColor4() = default;
106
107 explicit vtkColor4(const T& scalar)
108 : vtkTuple<T, 4>(scalar)
109 {
110 }
111
112 explicit vtkColor4(const T* init)
113 : vtkTuple<T, 4>(init)
114 {
115 }
116
117 vtkColor4(const T& red, const T& green, const T& blue, const T& alpha)
118 {
119 this->Data[0] = red;
120 this->Data[1] = green;
121 this->Data[2] = blue;
122 this->Data[3] = alpha;
123 }
124
126
129 void Set(const T& red, const T& green, const T& blue)
130 {
131 this->Data[0] = red;
132 this->Data[1] = green;
133 this->Data[2] = blue;
134 }
136
138
141 void Set(const T& red, const T& green, const T& blue, const T& alpha)
142 {
143 this->Data[0] = red;
144 this->Data[1] = green;
145 this->Data[2] = blue;
146 this->Data[3] = alpha;
147 }
149
153 void SetRed(const T& red) { this->Data[0] = red; }
154
158 const T& GetRed() const { return this->Data[0]; }
159
163 void SetGreen(const T& green) { this->Data[1] = green; }
164
168 const T& GetGreen() const { return this->Data[1]; }
169
173 void SetBlue(const T& blue) { this->Data[2] = blue; }
174
178 const T& GetBlue() const { return this->Data[2]; }
179
183 void SetAlpha(const T& alpha) { this->Data[3] = alpha; }
184
188 const T& GetAlpha() const { return this->Data[3]; }
189};
190
194class vtkColor3ub : public vtkColor3<unsigned char>
195{
196public:
197 vtkColor3ub() = default;
198 explicit vtkColor3ub(unsigned char scalar)
199 : vtkColor3<unsigned char>(scalar)
200 {
201 }
202 explicit vtkColor3ub(const unsigned char* init)
203 : vtkColor3<unsigned char>(init)
204 {
205 }
206
208
211 explicit vtkColor3ub(int hexSigned)
212 {
213 unsigned int hex = static_cast<unsigned int>(hexSigned);
214 this->Data[2] = hex & 0xff;
215 hex >>= 8;
216 this->Data[1] = hex & 0xff;
217 hex >>= 8;
218 this->Data[0] = hex & 0xff;
219 }
221
222 vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
223 : vtkColor3<unsigned char>(r, g, b)
224 {
225 }
226};
227
228class vtkColor3f : public vtkColor3<float>
229{
230public:
231 vtkColor3f() = default;
232 explicit vtkColor3f(float scalar)
233 : vtkColor3<float>(scalar)
234 {
235 }
236 explicit vtkColor3f(const float* init)
237 : vtkColor3<float>(init)
238 {
239 }
240 vtkColor3f(float r, float g, float b)
241 : vtkColor3<float>(r, g, b)
242 {
243 }
244};
245
246class vtkColor3d : public vtkColor3<double>
247{
248public:
249 vtkColor3d() = default;
250 explicit vtkColor3d(double scalar)
251 : vtkColor3<double>(scalar)
252 {
253 }
254 explicit vtkColor3d(const double* init)
255 : vtkColor3<double>(init)
256 {
257 }
258 vtkColor3d(double r, double g, double b)
259 : vtkColor3<double>(r, g, b)
260 {
261 }
262};
263
264class vtkColor4ub : public vtkColor4<unsigned char>
265{
266public:
267 vtkColor4ub() = default;
268 explicit vtkColor4ub(unsigned char scalar)
269 : vtkColor4<unsigned char>(scalar)
270 {
271 }
272 explicit vtkColor4ub(const unsigned char* init)
273 : vtkColor4<unsigned char>(init)
274 {
275 }
276
278
282 explicit vtkColor4ub(int hexSigned)
283 {
284 unsigned int hex = static_cast<unsigned int>(hexSigned);
285 this->Data[3] = hex & 0xff;
286 hex >>= 8;
287 this->Data[2] = hex & 0xff;
288 hex >>= 8;
289 this->Data[1] = hex & 0xff;
290 hex >>= 8;
291 this->Data[0] = hex & 0xff;
292 }
294
295 vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
296 : vtkColor4<unsigned char>(r, g, b, a)
297 {
298 }
300 : vtkColor4<unsigned char>(c[0], c[1], c[2], 255)
301 {
302 }
303};
304
305class vtkColor4f : public vtkColor4<float>
306{
307public:
308 vtkColor4f() = default;
309 explicit vtkColor4f(float scalar)
310 : vtkColor4<float>(scalar)
311 {
312 }
313 explicit vtkColor4f(const float* init)
314 : vtkColor4<float>(init)
315 {
316 }
317 vtkColor4f(float r, float g, float b, float a = 1.0)
318 : vtkColor4<float>(r, g, b, a)
319 {
320 }
321};
322
323class vtkColor4d : public vtkColor4<double>
324{
325public:
326 vtkColor4d() = default;
327 explicit vtkColor4d(double scalar)
328 : vtkColor4<double>(scalar)
329 {
330 }
331 explicit vtkColor4d(const double* init)
332 : vtkColor4<double>(init)
333 {
334 }
335 vtkColor4d(double r, double g, double b, double a = 1.0)
336 : vtkColor4<double>(r, g, b, a)
337 {
338 }
339};
340
341#endif // vtkColor_h
342// VTK-HeaderTest-Exclude: vtkColor.h
vtkColor3(const T &scalar)
Definition: vtkColor.h:39
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition: vtkColor.h:81
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:60
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition: vtkColor.h:96
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition: vtkColor.h:71
const T & GetRed() const
Get the red component of the color, i.e.
Definition: vtkColor.h:76
vtkColor3(const T &red, const T &green, const T &blue)
Definition: vtkColor.h:49
vtkColor3(const T *init)
Definition: vtkColor.h:44
const T & GetGreen() const
Get the green component of the color, i.e.
Definition: vtkColor.h:86
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition: vtkColor.h:91
vtkColor3d(const double *init)
Definition: vtkColor.h:254
vtkColor3d(double scalar)
Definition: vtkColor.h:250
vtkColor3d()=default
vtkColor3d(double r, double g, double b)
Definition: vtkColor.h:258
vtkColor3f()=default
vtkColor3f(float r, float g, float b)
Definition: vtkColor.h:240
vtkColor3f(float scalar)
Definition: vtkColor.h:232
vtkColor3f(const float *init)
Definition: vtkColor.h:236
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:195
vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
Definition: vtkColor.h:222
vtkColor3ub(unsigned char scalar)
Definition: vtkColor.h:198
vtkColor3ub()=default
vtkColor3ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FF (blue).
Definition: vtkColor.h:211
vtkColor3ub(const unsigned char *init)
Definition: vtkColor.h:202
vtkColor4()=default
const T & GetAlpha() const
Get the alpha component of the color, i.e.
Definition: vtkColor.h:188
void SetAlpha(const T &alpha)
Set the alpha component of the color, i.e.
Definition: vtkColor.h:183
vtkColor4(const T &scalar)
Definition: vtkColor.h:107
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:141
vtkColor4(const T &red, const T &green, const T &blue, const T &alpha)
Definition: vtkColor.h:117
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition: vtkColor.h:153
vtkColor4(const T *init)
Definition: vtkColor.h:112
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition: vtkColor.h:178
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition: vtkColor.h:173
const T & GetGreen() const
Get the green component of the color, i.e.
Definition: vtkColor.h:168
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition: vtkColor.h:163
void Set(const T &red, const T &green, const T &blue)
Set the red, green and blue components of the color.
Definition: vtkColor.h:129
const T & GetRed() const
Get the red component of the color, i.e.
Definition: vtkColor.h:158
vtkColor4d(double r, double g, double b, double a=1.0)
Definition: vtkColor.h:335
vtkColor4d(const double *init)
Definition: vtkColor.h:331
vtkColor4d()=default
vtkColor4d(double scalar)
Definition: vtkColor.h:327
vtkColor4f(float r, float g, float b, float a=1.0)
Definition: vtkColor.h:317
vtkColor4f(float scalar)
Definition: vtkColor.h:309
vtkColor4f(const float *init)
Definition: vtkColor.h:313
vtkColor4f()=default
vtkColor4ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FFAA (opaque blue).
Definition: vtkColor.h:282
vtkColor4ub(const vtkColor3ub &c)
Definition: vtkColor.h:299
vtkColor4ub(unsigned char scalar)
Definition: vtkColor.h:268
vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: vtkColor.h:295
vtkColor4ub()=default
vtkColor4ub(const unsigned char *init)
Definition: vtkColor.h:272
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