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 
24 #ifndef __vtkColor_h
25 #define __vtkColor_h
26 
27 #include "vtkTuple.h"
28 #include "vtkObject.h" // for legacy macros
29 
30 // .NAME vtkColor3 - templated base type for storage of 3 component colors.
31 //
32 template<typename T>
33 class vtkColor3 : public vtkTuple<T, 3>
34 {
35 public:
37  {
38  }
39 
40  explicit vtkColor3(const T& scalar) : vtkTuple<T, 3>(scalar)
41  {
42  }
43 
44  explicit vtkColor3(const T* init) : vtkTuple<T, 3>(init)
45  {
46  }
47 
48  vtkColor3(const T& red, const T& green, const T& blue)
49  {
50  this->Data[0] = red;
51  this->Data[1] = green;
52  this->Data[2] = blue;
53  }
54 
56 
57  void Set(const T& red, const T& green, const T& blue)
58  {
59  this->Data[0] = red;
60  this->Data[1] = green;
61  this->Data[2] = blue;
62  }
64 
66  void SetRed(const T& red) { this->Data[0] = red; }
67 
69  const T& GetRed() const { return this->Data[0]; }
70 
72  void SetGreen(const T& green) { this->Data[1] = green; }
73 
75  const T& GetGreen() const { return this->Data[1]; }
76 
78  void SetBlue(const T& blue) { this->Data[2] = blue; }
79 
81  const T& GetBlue() const { return this->Data[2]; }
82 
84  VTK_LEGACY(const T& Red() const);
85 
87  VTK_LEGACY(const T& Green() const);
88 
90 
91  VTK_LEGACY(const T& Blue() const);
92 };
94 
95 // .NAME vtkColor4 - templated base type for storage of 4 component colors.
96 //
97 template<typename T>
98 class vtkColor4 : public vtkTuple<T, 4>
99 {
100 public:
102  {
103  }
104 
105  explicit vtkColor4(const T& scalar) : vtkTuple<T, 4>(scalar)
106  {
107  }
108 
109  explicit vtkColor4(const T* init) : vtkTuple<T, 4>(init)
110  {
111  }
112 
113  vtkColor4(const T& red, const T& green, const T& blue, const T& alpha)
114  {
115  this->Data[0] = red;
116  this->Data[1] = green;
117  this->Data[2] = blue;
118  this->Data[3] = alpha;
119  }
120 
122 
123  void Set(const T& red, const T& green, const T& blue)
124  {
125  this->Data[0] = red;
126  this->Data[1] = green;
127  this->Data[2] = blue;
128  }
130 
132 
133  void Set(const T& red, const T& green, const T& blue, const T& alpha)
134  {
135  this->Data[0] = red;
136  this->Data[1] = green;
137  this->Data[2] = blue;
138  this->Data[3] = alpha;
139  }
141 
143  void SetRed(const T& red) { this->Data[0] = red; }
144 
146  const T& GetRed() const { return this->Data[0]; }
147 
149  void SetGreen(const T& green) { this->Data[1] = green; }
150 
152  const T& GetGreen() const { return this->Data[1]; }
153 
155  void SetBlue(const T& blue) { this->Data[2] = blue; }
156 
158  const T& GetBlue() const { return this->Data[2]; }
159 
161  void SetAlpha(const T& alpha) { this->Data[3] = alpha; }
162 
164  const T& GetAlpha() const { return this->Data[3]; }
165 
167  VTK_LEGACY(const T& Red() const);
168 
170  VTK_LEGACY(const T& Green() const);
171 
173  VTK_LEGACY(const T& Blue() const);
174 
176 
177  VTK_LEGACY(const T& Alpha() const);
178 };
180 
182 
183 class vtkColor3ub : public vtkColor3<unsigned char>
184 {
185 public:
187  explicit vtkColor3ub(unsigned char scalar)
188  : vtkColor3<unsigned char>(scalar) {}
189  explicit vtkColor3ub(const unsigned char* init)
190  : vtkColor3<unsigned char>(init) {}
192 
194 
196  explicit vtkColor3ub(int hexSigned)
197  {
198  unsigned int hex = static_cast<unsigned int>(hexSigned);
199  this->Data[2] = hex & 0xff;
200  hex >>= 8;
201  this->Data[1] = hex & 0xff;
202  hex >>= 8;
203  this->Data[0] = hex & 0xff;
204  }
206 
207  vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
208  : vtkColor3<unsigned char>(r, g, b) {}
209 };
210 
211 class vtkColor3f : public vtkColor3<float>
212 {
213 public:
215  explicit vtkColor3f(float scalar) : vtkColor3<float>(scalar) {}
216  explicit vtkColor3f(const float* init) : vtkColor3<float>(init) {}
217  vtkColor3f(float r, float g, float b) : vtkColor3<float>(r, g, b) {}
218 };
219 
220 class vtkColor3d : public vtkColor3<double>
221 {
222 public:
224  explicit vtkColor3d(double scalar) : vtkColor3<double>(scalar) {}
225  explicit vtkColor3d(const double* init) : vtkColor3<double>(init) {}
226  vtkColor3d(double r, double g, double b) : vtkColor3<double>(r, g, b) {}
227 };
228 
229 class vtkColor4ub : public vtkColor4<unsigned char>
230 {
231 public:
233  explicit vtkColor4ub(unsigned char scalar)
234  : vtkColor4<unsigned char>(scalar) {}
235  explicit vtkColor4ub(const unsigned char* init)
236  : vtkColor4<unsigned char>(init) {}
237 
239 
241  explicit vtkColor4ub(int hexSigned)
242  {
243  unsigned int hex = static_cast<unsigned int>(hexSigned);
244  this->Data[3] = hex & 0xff;
245  hex >>= 8;
246  this->Data[2] = hex & 0xff;
247  hex >>= 8;
248  this->Data[1] = hex & 0xff;
249  hex >>= 8;
250  this->Data[0] = hex & 0xff;
251  }
253 
254  vtkColor4ub(unsigned char r, unsigned char g,
255  unsigned char b, unsigned char a = 255)
256  : vtkColor4<unsigned char>(r, g, b, a) {}
258  vtkColor4<unsigned char>(c[0], c[1], c[2], 255) {}
259 };
260 
261 class vtkColor4f : public vtkColor4<float>
262 {
263 public:
265  explicit vtkColor4f(float scalar) : vtkColor4<float>(scalar) {}
266  explicit vtkColor4f(const float* init) : vtkColor4<float>(init) {}
267  vtkColor4f(float r, float g, float b, float a = 1.0)
268  : vtkColor4<float>(r, g, b, a) {}
269 };
270 
271 class vtkColor4d : public vtkColor4<double>
272 {
273 public:
275  explicit vtkColor4d(double scalar) : vtkColor4<double>(scalar) {}
276  explicit vtkColor4d(const double* init) : vtkColor4<double>(init) {}
277  vtkColor4d(double r, double g, double b, double a = 1.0)
278  : vtkColor4<double>(r, g, b, a) {}
279 };
280 
281 #ifndef VTK_LEGACY_REMOVE
282 template<typename T>
283 const T& vtkColor3<T>::Red() const
284 {
286  return this->GetRed();
287 }
288 
289 template<typename T>
290 const T& vtkColor3<T>::Green() const
291 {
293  return this->GetGreen();
294 }
295 
296 template<typename T>
297 const T& vtkColor3<T>::Blue() const
298 {
300  return this->GetBlue();
301 }
302 
303 template<typename T>
304 const T& vtkColor4<T>::Red() const
305 {
307  return this->GetRed();
308 }
309 
310 template<typename T>
311 const T& vtkColor4<T>::Green() const
312 {
314  return this->GetGreen();
315 }
316 
317 template<typename T>
318 const T& vtkColor4<T>::Blue() const
319 {
321  return this->GetBlue();
322 }
323 
324 template<typename T>
325 const T& vtkColor4<T>::Alpha() const
326 {
328  return this->GetAlpha();
329 }
330 #endif // VTK_LEGACY_REMOVE
331 
332 #endif // __vtkColor_h
333 // VTK-HeaderTest-Exclude: vtkColor.h
const T & GetGreen() const
Definition: vtkColor.h:152
vtkColor3f(const float *init)
Definition: vtkColor.h:216
T Data[Size]
Definition: vtkTuple.h:136
void SetAlpha(const T &alpha)
Definition: vtkColor.h:161
const T & Green() const
Definition: vtkColor.h:290
vtkColor3(const T &scalar)
Definition: vtkColor.h:40
const T & GetAlpha() const
Definition: vtkColor.h:164
vtkColor4ub(const vtkColor3ub &c)
Definition: vtkColor.h:257
vtkColor4()
Definition: vtkColor.h:101
GLboolean GLboolean GLboolean b
Definition: vtkgl.h:12312
const T & Blue() const
Definition: vtkColor.h:318
vtkColor3(const T &red, const T &green, const T &blue)
Definition: vtkColor.h:48
void Set(const T &red, const T &green, const T &blue, const T &alpha)
Definition: vtkColor.h:133
GLclampf green
Definition: vtkgl.h:11313
void SetGreen(const T &green)
Definition: vtkColor.h:72
vtkColor3d(const double *init)
Definition: vtkColor.h:225
const T & GetBlue() const
Definition: vtkColor.h:81
GLclampf GLclampf blue
Definition: vtkgl.h:11313
const T & Red() const
Definition: vtkColor.h:304
const T & Alpha() const
Definition: vtkColor.h:325
void SetBlue(const T &blue)
Definition: vtkColor.h:155
#define VTK_LEGACY_REPLACED_BODY(method, version, replace)
Definition: vtkSetGet.h:814
vtkColor3ub(int hexSigned)
Definition: vtkColor.h:196
vtkColor4ub(const unsigned char *init)
Definition: vtkColor.h:235
vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
Definition: vtkColor.h:207
GLdouble GLdouble GLdouble r
Definition: vtkgl.h:11610
vtkColor4ub(unsigned char scalar)
Definition: vtkColor.h:233
const T & GetRed() const
Definition: vtkColor.h:69
vtkColor3d(double scalar)
Definition: vtkColor.h:224
void SetGreen(const T &green)
Definition: vtkColor.h:149
void SetRed(const T &red)
Definition: vtkColor.h:143
vtkColor3f(float scalar)
Definition: vtkColor.h:215
void SetRed(const T &red)
Definition: vtkColor.h:66
vtkColor3()
Definition: vtkColor.h:36
void Set(const T &red, const T &green, const T &blue)
Definition: vtkColor.h:57
templated base type for containers of constant size.
Definition: vtkTuple.h:34
vtkColor4(const T *init)
Definition: vtkColor.h:109
vtkColor3d(double r, double g, double b)
Definition: vtkColor.h:226
vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: vtkColor.h:254
const GLubyte * c
Definition: vtkgl.h:15720
vtkColor3ub(const unsigned char *init)
Definition: vtkColor.h:189
vtkColor4d(double r, double g, double b, double a=1.0)
Definition: vtkColor.h:277
void Set(const T &red, const T &green, const T &blue)
Definition: vtkColor.h:123
vtkColor3ub(unsigned char scalar)
Definition: vtkColor.h:187
vtkColor4f(const float *init)
Definition: vtkColor.h:266
#define VTK_LEGACY(method)
Definition: vtkSetGet.h:787
vtkColor4(const T &scalar)
Definition: vtkColor.h:105
const T & Blue() const
Definition: vtkColor.h:297
const T & Green() const
Definition: vtkColor.h:311
GLboolean GLboolean GLboolean GLboolean a
Definition: vtkgl.h:12312
vtkColor3d()
Definition: vtkColor.h:223
vtkColor4ub(int hexSigned)
Definition: vtkColor.h:241
vtkColor4f()
Definition: vtkColor.h:264
vtkColor4f(float scalar)
Definition: vtkColor.h:265
vtkColor4d()
Definition: vtkColor.h:274
void SetBlue(const T &blue)
Definition: vtkColor.h:78
GLboolean GLboolean g
Definition: vtkgl.h:12312
const T & GetBlue() const
Definition: vtkColor.h:158
vtkColor3(const T *init)
Definition: vtkColor.h:44
vtkColor3f()
Definition: vtkColor.h:214
GLclampf GLclampf GLclampf alpha
Definition: vtkgl.h:11313
vtkColor4(const T &red, const T &green, const T &blue, const T &alpha)
Definition: vtkColor.h:113
vtkColor4f(float r, float g, float b, float a=1.0)
Definition: vtkColor.h:267
vtkColor4d(const double *init)
Definition: vtkColor.h:276
const T & GetGreen() const
Definition: vtkColor.h:75
const T & Red() const
Definition: vtkColor.h:283
vtkColor3f(float r, float g, float b)
Definition: vtkColor.h:217
vtkColor4d(double scalar)
Definition: vtkColor.h:275
const T & GetRed() const
Definition: vtkColor.h:146