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 
29 // .NAME vtkColor3 - templated base type for storage of 3 component colors.
30 //
31 template<typename T>
32 class vtkColor3 : public vtkTuple<T, 3>
33 {
34 public:
36  {
37  }
38 
39  explicit vtkColor3(const T& scalar) : vtkTuple<T, 3>(scalar)
40  {
41  }
42 
43  explicit vtkColor3(const T* init) : vtkTuple<T, 3>(init)
44  {
45  }
46 
47  vtkColor3(const T& red, const T& green, const T& blue)
48  {
49  this->Data[0] = red;
50  this->Data[1] = green;
51  this->Data[2] = blue;
52  }
53 
55 
56  void Set(const T& red, const T& green, const T& blue)
57  {
58  this->Data[0] = red;
59  this->Data[1] = green;
60  this->Data[2] = blue;
61  }
63 
65  void SetRed(const T& red) { this->Data[0] = red; }
66 
68 
69  const T& GetRed() const { return this->Data[0]; }
70  const T& Red() const { return this->Data[0]; }
72 
74  void SetGreen(const T& green) { this->Data[1] = green; }
75 
77 
78  const T& GetGreen() const { return this->Data[1]; }
79  const T& Green() const { return this->Data[1]; }
81 
83  void SetBlue(const T& blue) { this->Data[2] = blue; }
84 
86 
87  const T& GetBlue() const { return this->Data[2]; }
88  const T& Blue() const { return this->Data[2]; }
89 };
91 
92 // .NAME vtkColor4 - templated base type for storage of 4 component colors.
93 //
94 template<typename T>
95 class vtkColor4 : public vtkTuple<T, 4>
96 {
97 public:
99  {
100  }
101 
102  explicit vtkColor4(const T& scalar) : vtkTuple<T, 4>(scalar)
103  {
104  }
105 
106  explicit vtkColor4(const T* init) : vtkTuple<T, 4>(init)
107  {
108  }
109 
110  vtkColor4(const T& red, const T& green, const T& blue, const T& alpha)
111  {
112  this->Data[0] = red;
113  this->Data[1] = green;
114  this->Data[2] = blue;
115  this->Data[3] = alpha;
116  }
117 
119 
120  void Set(const T& red, const T& green, const T& blue)
121  {
122  this->Data[0] = red;
123  this->Data[1] = green;
124  this->Data[2] = blue;
125  }
127 
129 
130  void Set(const T& red, const T& green, const T& blue, const T& alpha)
131  {
132  this->Data[0] = red;
133  this->Data[1] = green;
134  this->Data[2] = blue;
135  this->Data[3] = alpha;
136  }
138 
140  void SetRed(const T& red) { this->Data[0] = red; }
141 
143 
144  const T& GetRed() const { return this->Data[0]; }
145  const T& Red() const { return this->Data[0]; }
147 
149  void SetGreen(const T& green) { this->Data[1] = green; }
150 
152 
153  const T& GetGreen() const { return this->Data[1]; }
154  const T& Green() const { return this->Data[1]; }
156 
158  void SetBlue(const T& blue) { this->Data[2] = blue; }
159 
161 
162  const T& GetBlue() const { return this->Data[2]; }
163  const T& Blue() const { return this->Data[2]; }
165 
167  void SetAlpha(const T& alpha) { this->Data[3] = alpha; }
168 
170 
171  const T& GetAlpha() const { return this->Data[3]; }
172  const T& Alpha() const { return this->Data[3]; }
173 };
175 
177 
179 class vtkColor3ub : public vtkColor3<unsigned char>
180 {
181 public:
183  explicit vtkColor3ub(unsigned char scalar)
184  : vtkColor3<unsigned char>(scalar) {}
185  explicit vtkColor3ub(const unsigned char* init)
186  : vtkColor3<unsigned char>(init) {}
187  vtkColor3ub(unsigned char r, unsigned char g, unsigned char b)
188  : vtkColor3<unsigned char>(r, g, b) {}
189 };
191 
192 class vtkColor3f : public vtkColor3<float>
193 {
194 public:
196  explicit vtkColor3f(float scalar) : vtkColor3<float>(scalar) {}
197  explicit vtkColor3f(const float* init) : vtkColor3<float>(init) {}
198  vtkColor3f(float r, float g, float b) : vtkColor3<float>(r, g, b) {}
199 };
200 
201 class vtkColor3d : public vtkColor3<double>
202 {
203 public:
205  explicit vtkColor3d(double scalar) : vtkColor3<double>(scalar) {}
206  explicit vtkColor3d(const double* init) : vtkColor3<double>(init) {}
207  vtkColor3d(double r, double g, double b) : vtkColor3<double>(r, g, b) {}
208 };
209 
210 class vtkColor4ub : public vtkColor4<unsigned char>
211 {
212 public:
214  explicit vtkColor4ub(unsigned char scalar)
215  : vtkColor4<unsigned char>(scalar) {}
216  explicit vtkColor4ub(const unsigned char* init)
217  : vtkColor4<unsigned char>(init) {}
218  vtkColor4ub(unsigned char r, unsigned char g,
219  unsigned char b, unsigned char a = 255)
220  : vtkColor4<unsigned char>(r, g, b, a) {}
222  vtkColor4<unsigned char>(c[0], c[1], c[2], 255) {}
223 };
224 
225 class vtkColor4f : public vtkColor4<float>
226 {
227 public:
229  explicit vtkColor4f(float scalar) : vtkColor4<float>(scalar) {}
230  explicit vtkColor4f(const float* init) : vtkColor4<float>(init) {}
231  vtkColor4f(float r, float g, float b, float a = 1.0)
232  : vtkColor4<float>(r, g, b, a) {}
233 };
234 
235 class vtkColor4d : public vtkColor4<double>
236 {
237 public:
239  explicit vtkColor4d(double scalar) : vtkColor4<double>(scalar) {}
240  explicit vtkColor4d(const double* init) : vtkColor4<double>(init) {}
241  vtkColor4d(double r, double g, double b, double a = 1.0)
242  : vtkColor4<double>(r, g, b, a) {}
243 };
244 
245 #endif // __vtkColor_h