VTK
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 "vtkTuple.h"
29 #include "vtkObject.h" // for legacy macros
30 
31 // .NAME vtkColor3 - templated base type for storage of 3 component colors.
32 //
33 template<typename T>
34 class vtkColor3 : public vtkTuple<T, 3>
35 {
36 public:
38  {
39  }
40 
41  explicit vtkColor3(const T& scalar) : vtkTuple<T, 3>(scalar)
42  {
43  }
44 
45  explicit vtkColor3(const T* init) : 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 //
101 template<typename T>
102 class vtkColor4 : public vtkTuple<T, 4>
103 {
104 public:
106  {
107  }
108 
109  explicit vtkColor4(const T& scalar) : vtkTuple<T, 4>(scalar)
110  {
111  }
112 
113  explicit vtkColor4(const T* init) : 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 
194 class vtkColor3ub : public vtkColor3<unsigned char>
195 {
196 public:
198  explicit vtkColor3ub(unsigned char scalar)
199  : vtkColor3<unsigned char>(scalar) {}
200  explicit vtkColor3ub(const unsigned char* init)
201  : vtkColor3<unsigned char>(init) {}
202 
204 
207  explicit vtkColor3ub(int hexSigned)
208  {
209  unsigned int hex = static_cast<unsigned int>(hexSigned);
210  this->Data[2] = hex & 0xff;
211  hex >>= 8;
212  this->Data[1] = hex & 0xff;
213  hex >>= 8;
214  this->Data[0] = hex & 0xff;
215  }
217 
218  vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
219  : vtkColor3<unsigned char>(r, g, b) {}
220 };
221 
222 class vtkColor3f : public vtkColor3<float>
223 {
224 public:
226  explicit vtkColor3f(float scalar) : vtkColor3<float>(scalar) {}
227  explicit vtkColor3f(const float* init) : vtkColor3<float>(init) {}
228  vtkColor3f(float r, float g, float b) : vtkColor3<float>(r, g, b) {}
229 };
230 
231 class vtkColor3d : public vtkColor3<double>
232 {
233 public:
235  explicit vtkColor3d(double scalar) : vtkColor3<double>(scalar) {}
236  explicit vtkColor3d(const double* init) : vtkColor3<double>(init) {}
237  vtkColor3d(double r, double g, double b) : vtkColor3<double>(r, g, b) {}
238 };
239 
240 class vtkColor4ub : public vtkColor4<unsigned char>
241 {
242 public:
244  explicit vtkColor4ub(unsigned char scalar)
245  : vtkColor4<unsigned char>(scalar) {}
246  explicit vtkColor4ub(const unsigned char* init)
247  : vtkColor4<unsigned char>(init) {}
248 
250 
254  explicit vtkColor4ub(int hexSigned)
255  {
256  unsigned int hex = static_cast<unsigned int>(hexSigned);
257  this->Data[3] = hex & 0xff;
258  hex >>= 8;
259  this->Data[2] = hex & 0xff;
260  hex >>= 8;
261  this->Data[1] = hex & 0xff;
262  hex >>= 8;
263  this->Data[0] = hex & 0xff;
264  }
266 
267  vtkColor4ub(unsigned char r, unsigned char g,
268  unsigned char b, unsigned char a = 255)
269  : vtkColor4<unsigned char>(r, g, b, a) {}
271  vtkColor4<unsigned char>(c[0], c[1], c[2], 255) {}
272 };
273 
274 class vtkColor4f : public vtkColor4<float>
275 {
276 public:
278  explicit vtkColor4f(float scalar) : vtkColor4<float>(scalar) {}
279  explicit vtkColor4f(const float* init) : vtkColor4<float>(init) {}
280  vtkColor4f(float r, float g, float b, float a = 1.0)
281  : vtkColor4<float>(r, g, b, a) {}
282 };
283 
284 class vtkColor4d : public vtkColor4<double>
285 {
286 public:
288  explicit vtkColor4d(double scalar) : vtkColor4<double>(scalar) {}
289  explicit vtkColor4d(const double* init) : vtkColor4<double>(init) {}
290  vtkColor4d(double r, double g, double b, double a = 1.0)
291  : vtkColor4<double>(r, g, b, a) {}
292 };
293 
294 #endif // vtkColor_h
295 // VTK-HeaderTest-Exclude: vtkColor.h
const T & GetGreen() const
Get the green component of the color, i.e.
Definition: vtkColor.h:168
vtkColor3f(const float *init)
Definition: vtkColor.h:227
T Data[Size]
The only thing stored in memory!
Definition: vtkTuple.h:145
void SetAlpha(const T &alpha)
Set the alpha component of the color, i.e.
Definition: vtkColor.h:183
vtkColor3(const T &scalar)
Definition: vtkColor.h:41
const T & GetAlpha() const
Get the alpha component of the color, i.e.
Definition: vtkColor.h:188
vtkColor4ub(const vtkColor3ub &c)
Definition: vtkColor.h:270
vtkColor4()
Definition: vtkColor.h:105
vtkColor3(const T &red, const T &green, const T &blue)
Definition: vtkColor.h:49
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
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition: vtkColor.h:81
vtkColor3d(const double *init)
Definition: vtkColor.h:236
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition: vtkColor.h:96
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition: vtkColor.h:173
vtkColor3ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FF (blue).
Definition: vtkColor.h:207
vtkColor4ub(const unsigned char *init)
Definition: vtkColor.h:246
vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
Definition: vtkColor.h:218
vtkColor4ub(unsigned char scalar)
Definition: vtkColor.h:244
const T & GetRed() const
Get the red component of the color, i.e.
Definition: vtkColor.h:76
vtkColor3d(double scalar)
Definition: vtkColor.h:235
void SetGreen(const T &green)
Set the green component of the color, i.e.
Definition: vtkColor.h:163
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition: vtkColor.h:153
vtkColor3f(float scalar)
Definition: vtkColor.h:226
void SetRed(const T &red)
Set the red component of the color, i.e.
Definition: vtkColor.h:71
vtkColor3()
Definition: vtkColor.h:37
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
templated base type for containers of constant size.
Definition: vtkTuple.h:35
vtkColor4(const T *init)
Definition: vtkColor.h:113
vtkColor3d(double r, double g, double b)
Definition: vtkColor.h:237
Some derived classes for the different colors commonly used.
Definition: vtkColor.h:194
vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: vtkColor.h:267
vtkColor3ub(const unsigned char *init)
Definition: vtkColor.h:200
vtkColor4d(double r, double g, double b, double a=1.0)
Definition: vtkColor.h:290
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
vtkColor3ub(unsigned char scalar)
Definition: vtkColor.h:198
vtkColor4f(const float *init)
Definition: vtkColor.h:279
vtkColor4(const T &scalar)
Definition: vtkColor.h:109
vtkColor3d()
Definition: vtkColor.h:234
vtkColor4ub(int hexSigned)
Construct a color from a hexadecimal representation such as 0x0000FFAA (opaque blue).
Definition: vtkColor.h:254
vtkColor4f()
Definition: vtkColor.h:277
vtkColor4f(float scalar)
Definition: vtkColor.h:278
vtkColor4d()
Definition: vtkColor.h:287
void SetBlue(const T &blue)
Set the blue component of the color, i.e.
Definition: vtkColor.h:91
const T & GetBlue() const
Get the blue component of the color, i.e.
Definition: vtkColor.h:178
vtkColor3(const T *init)
Definition: vtkColor.h:45
vtkColor3f()
Definition: vtkColor.h:225
vtkColor4(const T &red, const T &green, const T &blue, const T &alpha)
Definition: vtkColor.h:117
vtkColor4f(float r, float g, float b, float a=1.0)
Definition: vtkColor.h:280
vtkColor4d(const double *init)
Definition: vtkColor.h:289
const T & GetGreen() const
Get the green component of the color, i.e.
Definition: vtkColor.h:86
vtkColor3f(float r, float g, float b)
Definition: vtkColor.h:228
vtkColor4d(double scalar)
Definition: vtkColor.h:288
const T & GetRed() const
Get the red component of the color, i.e.
Definition: vtkColor.h:158