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
134#ifndef vtkColor_h
135#define vtkColor_h
136
137#include "vtkObject.h" // for legacy macros
138#include "vtkTuple.h"
139
140// .NAME vtkColor3 - templated base type for storage of 3 component colors.
141//
142template <typename T>
143class vtkColor3 : public vtkTuple<T, 3>
144{
145public:
146 vtkColor3() = default;
147
148 explicit vtkColor3(const T& scalar)
149 : vtkTuple<T, 3>(scalar)
150 {
151 }
152
153 explicit vtkColor3(const T* init)
154 : vtkTuple<T, 3>(init)
155 {
156 }
157
158 vtkColor3(const T& red, const T& green, const T& blue)
159 {
160 this->Data[0] = red;
161 this->Data[1] = green;
162 this->Data[2] = blue;
163 }
164
166
169 void Set(const T& red, const T& green, const T& blue)
170 {
171 this->Data[0] = red;
172 this->Data[1] = green;
173 this->Data[2] = blue;
174 }
176
180 void SetRed(const T& red) { this->Data[0] = red; }
181
185 const T& GetRed() const { return this->Data[0]; }
186
190 void SetGreen(const T& green) { this->Data[1] = green; }
191
195 const T& GetGreen() const { return this->Data[1]; }
196
200 void SetBlue(const T& blue) { this->Data[2] = blue; }
201
205 const T& GetBlue() const { return this->Data[2]; }
206};
207
208// .NAME vtkColor4 - templated base type for storage of 4 component colors.
209//
210template <typename T>
211class vtkColor4 : public vtkTuple<T, 4>
212{
213public:
214 vtkColor4() = default;
215
216 explicit vtkColor4(const T& scalar)
217 : vtkTuple<T, 4>(scalar)
218 {
219 }
220
221 explicit vtkColor4(const T* init)
222 : vtkTuple<T, 4>(init)
223 {
224 }
225
226 vtkColor4(const T& red, const T& green, const T& blue, const T& alpha)
227 {
228 this->Data[0] = red;
229 this->Data[1] = green;
230 this->Data[2] = blue;
231 this->Data[3] = alpha;
232 }
233
235
238 void Set(const T& red, const T& green, const T& blue)
239 {
240 this->Data[0] = red;
241 this->Data[1] = green;
242 this->Data[2] = blue;
243 }
245
247
250 void Set(const T& red, const T& green, const T& blue, const T& alpha)
251 {
252 this->Data[0] = red;
253 this->Data[1] = green;
254 this->Data[2] = blue;
255 this->Data[3] = alpha;
256 }
258
262 void SetRed(const T& red) { this->Data[0] = red; }
263
267 const T& GetRed() const { return this->Data[0]; }
268
272 void SetGreen(const T& green) { this->Data[1] = green; }
273
277 const T& GetGreen() const { return this->Data[1]; }
278
282 void SetBlue(const T& blue) { this->Data[2] = blue; }
283
287 const T& GetBlue() const { return this->Data[2]; }
288
292 void SetAlpha(const T& alpha) { this->Data[3] = alpha; }
293
297 const T& GetAlpha() const { return this->Data[3]; }
298};
299
303class vtkColor3ub : public vtkColor3<unsigned char>
304{
305public:
306 vtkColor3ub() = default;
307 explicit vtkColor3ub(unsigned char scalar)
308 : vtkColor3<unsigned char>(scalar)
309 {
310 }
311 explicit vtkColor3ub(const unsigned char* init)
312 : vtkColor3<unsigned char>(init)
313 {
314 }
315
317
320 explicit vtkColor3ub(int hexSigned)
321 {
322 unsigned int hex = static_cast<unsigned int>(hexSigned);
323 this->Data[2] = hex & 0xff;
324 hex >>= 8;
325 this->Data[1] = hex & 0xff;
326 hex >>= 8;
327 this->Data[0] = hex & 0xff;
328 }
330
331 vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
332 : vtkColor3<unsigned char>(r, g, b)
333 {
334 }
335};
336
337class vtkColor3f : public vtkColor3<float>
338{
339public:
340 vtkColor3f() = default;
341 explicit vtkColor3f(float scalar)
342 : vtkColor3<float>(scalar)
343 {
344 }
345 explicit vtkColor3f(const float* init)
346 : vtkColor3<float>(init)
347 {
348 }
349 vtkColor3f(float r, float g, float b)
350 : vtkColor3<float>(r, g, b)
351 {
352 }
353};
354
355class vtkColor3d : public vtkColor3<double>
356{
357public:
358 vtkColor3d() = default;
359 explicit vtkColor3d(double scalar)
360 : vtkColor3<double>(scalar)
361 {
362 }
363 explicit vtkColor3d(const double* init)
364 : vtkColor3<double>(init)
365 {
366 }
367 vtkColor3d(double r, double g, double b)
368 : vtkColor3<double>(r, g, b)
369 {
370 }
371};
372
373class vtkColor4ub : public vtkColor4<unsigned char>
374{
375public:
376 vtkColor4ub() = default;
377 explicit vtkColor4ub(unsigned char scalar)
378 : vtkColor4<unsigned char>(scalar)
379 {
380 }
381 explicit vtkColor4ub(const unsigned char* init)
382 : vtkColor4<unsigned char>(init)
383 {
384 }
385
387
391 explicit vtkColor4ub(int hexSigned)
392 {
393 unsigned int hex = static_cast<unsigned int>(hexSigned);
394 this->Data[3] = hex & 0xff;
395 hex >>= 8;
396 this->Data[2] = hex & 0xff;
397 hex >>= 8;
398 this->Data[1] = hex & 0xff;
399 hex >>= 8;
400 this->Data[0] = hex & 0xff;
401 }
403
404 vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
405 : vtkColor4<unsigned char>(r, g, b, a)
406 {
407 }
409 : vtkColor4<unsigned char>(c[0], c[1], c[2], 255)
410 {
411 }
412};
413
414class vtkColor4f : public vtkColor4<float>
415{
416public:
417 vtkColor4f() = default;
418 explicit vtkColor4f(float scalar)
419 : vtkColor4<float>(scalar)
420 {
421 }
422 explicit vtkColor4f(const float* init)
423 : vtkColor4<float>(init)
424 {
425 }
426 vtkColor4f(float r, float g, float b, float a = 1.0)
427 : vtkColor4<float>(r, g, b, a)
428 {
429 }
430};
431
432class vtkColor4d : public vtkColor4<double>
433{
434public:
435 vtkColor4d() = default;
436 explicit vtkColor4d(double scalar)
437 : vtkColor4<double>(scalar)
438 {
439 }
440 explicit vtkColor4d(const double* init)
441 : vtkColor4<double>(init)
442 {
443 }
444 vtkColor4d(double r, double g, double b, double a = 1.0)
445 : vtkColor4<double>(r, g, b, a)
446 {
447 }
448};
449
450#endif // vtkColor_h
451// VTK-HeaderTest-Exclude: vtkColor.h
vtkColor3(const T &scalar)
Definition: vtkColor.h:148
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition: vtkColor.h:190
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:169
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition: vtkColor.h:205
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition: vtkColor.h:180
const T & GetRed() const
Get the red component of the color, i.e.
Definition: vtkColor.h:185
vtkColor3(const T &red, const T &green, const T &blue)
Definition: vtkColor.h:158
vtkColor3(const T *init)
Definition: vtkColor.h:153
const T & GetGreen() const
Get the green component of the color, i.e.
Definition: vtkColor.h:195
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition: vtkColor.h:200
vtkColor3d(const double *init)
Definition: vtkColor.h:363
vtkColor3d(double scalar)
Definition: vtkColor.h:359
vtkColor3d()=default
vtkColor3d(double r, double g, double b)
Definition: vtkColor.h:367
vtkColor3f()=default
vtkColor3f(float r, float g, float b)
Definition: vtkColor.h:349
vtkColor3f(float scalar)
Definition: vtkColor.h:341
vtkColor3f(const float *init)
Definition: vtkColor.h:345
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:304
vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
Definition: vtkColor.h:331
vtkColor3ub(unsigned char scalar)
Definition: vtkColor.h:307
vtkColor3ub()=default
vtkColor3ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FF (blue).
Definition: vtkColor.h:320
vtkColor3ub(const unsigned char *init)
Definition: vtkColor.h:311
vtkColor4()=default
const T & GetAlpha() const
Get the alpha component of the color, i.e.
Definition: vtkColor.h:297
void SetAlpha(const T &alpha)
Set the alpha component of the color, i.e.
Definition: vtkColor.h:292
vtkColor4(const T &scalar)
Definition: vtkColor.h:216
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:250
vtkColor4(const T &red, const T &green, const T &blue, const T &alpha)
Definition: vtkColor.h:226
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition: vtkColor.h:262
vtkColor4(const T *init)
Definition: vtkColor.h:221
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition: vtkColor.h:287
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition: vtkColor.h:282
const T & GetGreen() const
Get the green component of the color, i.e.
Definition: vtkColor.h:277
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition: vtkColor.h:272
void Set(const T &red, const T &green, const T &blue)
Set the red, green and blue components of the color.
Definition: vtkColor.h:238
const T & GetRed() const
Get the red component of the color, i.e.
Definition: vtkColor.h:267
vtkColor4d(double r, double g, double b, double a=1.0)
Definition: vtkColor.h:444
vtkColor4d(const double *init)
Definition: vtkColor.h:440
vtkColor4d()=default
vtkColor4d(double scalar)
Definition: vtkColor.h:436
vtkColor4f(float r, float g, float b, float a=1.0)
Definition: vtkColor.h:426
vtkColor4f(float scalar)
Definition: vtkColor.h:418
vtkColor4f(const float *init)
Definition: vtkColor.h:422
vtkColor4f()=default
vtkColor4ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FFAA (opaque blue).
Definition: vtkColor.h:391
vtkColor4ub(const vtkColor3ub &c)
Definition: vtkColor.h:408
vtkColor4ub(unsigned char scalar)
Definition: vtkColor.h:377
vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: vtkColor.h:404
vtkColor4ub()=default
vtkColor4ub(const unsigned char *init)
Definition: vtkColor.h:381
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