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 
82  const T& GetBlue() const { return this->Data[2]; }
83 };
85 
86 // .NAME vtkColor4 - templated base type for storage of 4 component colors.
87 //
88 template<typename T>
89 class vtkColor4 : public vtkTuple<T, 4>
90 {
91 public:
93  {
94  }
95 
96  explicit vtkColor4(const T& scalar) : vtkTuple<T, 4>(scalar)
97  {
98  }
99 
100  explicit vtkColor4(const T* init) : vtkTuple<T, 4>(init)
101  {
102  }
103 
104  vtkColor4(const T& red, const T& green, const T& blue, const T& alpha)
105  {
106  this->Data[0] = red;
107  this->Data[1] = green;
108  this->Data[2] = blue;
109  this->Data[3] = alpha;
110  }
111 
113 
114  void Set(const T& red, const T& green, const T& blue)
115  {
116  this->Data[0] = red;
117  this->Data[1] = green;
118  this->Data[2] = blue;
119  }
121 
123 
124  void Set(const T& red, const T& green, const T& blue, const T& alpha)
125  {
126  this->Data[0] = red;
127  this->Data[1] = green;
128  this->Data[2] = blue;
129  this->Data[3] = alpha;
130  }
132 
134  void SetRed(const T& red) { this->Data[0] = red; }
135 
137  const T& GetRed() const { return this->Data[0]; }
138 
140  void SetGreen(const T& green) { this->Data[1] = green; }
141 
143  const T& GetGreen() const { return this->Data[1]; }
144 
146  void SetBlue(const T& blue) { this->Data[2] = blue; }
147 
149  const T& GetBlue() const { return this->Data[2]; }
150 
152  void SetAlpha(const T& alpha) { this->Data[3] = alpha; }
153 
155 
156  const T& GetAlpha() const { return this->Data[3]; }
157 };
159 
161 
162 class vtkColor3ub : public vtkColor3<unsigned char>
163 {
164 public:
166  explicit vtkColor3ub(unsigned char scalar)
167  : vtkColor3<unsigned char>(scalar) {}
168  explicit vtkColor3ub(const unsigned char* init)
169  : vtkColor3<unsigned char>(init) {}
171 
173 
175  explicit vtkColor3ub(int hexSigned)
176  {
177  unsigned int hex = static_cast<unsigned int>(hexSigned);
178  this->Data[2] = hex & 0xff;
179  hex >>= 8;
180  this->Data[1] = hex & 0xff;
181  hex >>= 8;
182  this->Data[0] = hex & 0xff;
183  }
185 
186  vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
187  : vtkColor3<unsigned char>(r, g, b) {}
188 };
189 
190 class vtkColor3f : public vtkColor3<float>
191 {
192 public:
194  explicit vtkColor3f(float scalar) : vtkColor3<float>(scalar) {}
195  explicit vtkColor3f(const float* init) : vtkColor3<float>(init) {}
196  vtkColor3f(float r, float g, float b) : vtkColor3<float>(r, g, b) {}
197 };
198 
199 class vtkColor3d : public vtkColor3<double>
200 {
201 public:
203  explicit vtkColor3d(double scalar) : vtkColor3<double>(scalar) {}
204  explicit vtkColor3d(const double* init) : vtkColor3<double>(init) {}
205  vtkColor3d(double r, double g, double b) : vtkColor3<double>(r, g, b) {}
206 };
207 
208 class vtkColor4ub : public vtkColor4<unsigned char>
209 {
210 public:
212  explicit vtkColor4ub(unsigned char scalar)
213  : vtkColor4<unsigned char>(scalar) {}
214  explicit vtkColor4ub(const unsigned char* init)
215  : vtkColor4<unsigned char>(init) {}
216 
218 
220  explicit vtkColor4ub(int hexSigned)
221  {
222  unsigned int hex = static_cast<unsigned int>(hexSigned);
223  this->Data[3] = hex & 0xff;
224  hex >>= 8;
225  this->Data[2] = hex & 0xff;
226  hex >>= 8;
227  this->Data[1] = hex & 0xff;
228  hex >>= 8;
229  this->Data[0] = hex & 0xff;
230  }
232 
233  vtkColor4ub(unsigned char r, unsigned char g,
234  unsigned char b, unsigned char a = 255)
235  : vtkColor4<unsigned char>(r, g, b, a) {}
237  vtkColor4<unsigned char>(c[0], c[1], c[2], 255) {}
238 };
239 
240 class vtkColor4f : public vtkColor4<float>
241 {
242 public:
244  explicit vtkColor4f(float scalar) : vtkColor4<float>(scalar) {}
245  explicit vtkColor4f(const float* init) : vtkColor4<float>(init) {}
246  vtkColor4f(float r, float g, float b, float a = 1.0)
247  : vtkColor4<float>(r, g, b, a) {}
248 };
249 
250 class vtkColor4d : public vtkColor4<double>
251 {
252 public:
254  explicit vtkColor4d(double scalar) : vtkColor4<double>(scalar) {}
255  explicit vtkColor4d(const double* init) : vtkColor4<double>(init) {}
256  vtkColor4d(double r, double g, double b, double a = 1.0)
257  : vtkColor4<double>(r, g, b, a) {}
258 };
259 
260 #endif // vtkColor_h
261 // VTK-HeaderTest-Exclude: vtkColor.h
const T & GetGreen() const
Definition: vtkColor.h:143
vtkColor3f(const float *init)
Definition: vtkColor.h:195
T Data[Size]
Definition: vtkTuple.h:136
void SetAlpha(const T &alpha)
Definition: vtkColor.h:152
vtkColor3(const T &scalar)
Definition: vtkColor.h:40
const T & GetAlpha() const
Definition: vtkColor.h:156
vtkColor4ub(const vtkColor3ub &c)
Definition: vtkColor.h:236
vtkColor4()
Definition: vtkColor.h:92
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:124
void SetGreen(const T &green)
Definition: vtkColor.h:72
vtkColor3d(const double *init)
Definition: vtkColor.h:204
const T & GetBlue() const
Definition: vtkColor.h:82
void SetBlue(const T &blue)
Definition: vtkColor.h:146
vtkColor3ub(int hexSigned)
Definition: vtkColor.h:175
vtkColor4ub(const unsigned char *init)
Definition: vtkColor.h:214
vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
Definition: vtkColor.h:186
vtkColor4ub(unsigned char scalar)
Definition: vtkColor.h:212
const T & GetRed() const
Definition: vtkColor.h:69
vtkColor3d(double scalar)
Definition: vtkColor.h:203
void SetGreen(const T &green)
Definition: vtkColor.h:140
void SetRed(const T &red)
Definition: vtkColor.h:134
vtkColor3f(float scalar)
Definition: vtkColor.h:194
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:100
vtkColor3d(double r, double g, double b)
Definition: vtkColor.h:205
vtkColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: vtkColor.h:233
vtkColor3ub(const unsigned char *init)
Definition: vtkColor.h:168
vtkColor4d(double r, double g, double b, double a=1.0)
Definition: vtkColor.h:256
void Set(const T &red, const T &green, const T &blue)
Definition: vtkColor.h:114
vtkColor3ub(unsigned char scalar)
Definition: vtkColor.h:166
vtkColor4f(const float *init)
Definition: vtkColor.h:245
vtkColor4(const T &scalar)
Definition: vtkColor.h:96
vtkColor3d()
Definition: vtkColor.h:202
vtkColor4ub(int hexSigned)
Definition: vtkColor.h:220
vtkColor4f()
Definition: vtkColor.h:243
vtkColor4f(float scalar)
Definition: vtkColor.h:244
vtkColor4d()
Definition: vtkColor.h:253
void SetBlue(const T &blue)
Definition: vtkColor.h:78
const T & GetBlue() const
Definition: vtkColor.h:149
vtkColor3(const T *init)
Definition: vtkColor.h:44
vtkColor3f()
Definition: vtkColor.h:193
vtkColor4(const T &red, const T &green, const T &blue, const T &alpha)
Definition: vtkColor.h:104
vtkColor4f(float r, float g, float b, float a=1.0)
Definition: vtkColor.h:246
vtkColor4d(const double *init)
Definition: vtkColor.h:255
const T & GetGreen() const
Definition: vtkColor.h:75
vtkColor3f(float r, float g, float b)
Definition: vtkColor.h:196
vtkColor4d(double scalar)
Definition: vtkColor.h:254
const T & GetRed() const
Definition: vtkColor.h:137