VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkColor.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 00024 #ifndef __vtkColor_h 00025 #define __vtkColor_h 00026 00027 #include "vtkTuple.h" 00028 #include "vtkObject.h" // for legacy macros 00029 00030 // .NAME vtkColor3 - templated base type for storage of 3 component colors. 00031 // 00032 template<typename T> 00033 class vtkColor3 : public vtkTuple<T, 3> 00034 { 00035 public: 00036 vtkColor3() 00037 { 00038 } 00039 00040 explicit vtkColor3(const T& scalar) : vtkTuple<T, 3>(scalar) 00041 { 00042 } 00043 00044 explicit vtkColor3(const T* init) : vtkTuple<T, 3>(init) 00045 { 00046 } 00047 00048 vtkColor3(const T& red, const T& green, const T& blue) 00049 { 00050 this->Data[0] = red; 00051 this->Data[1] = green; 00052 this->Data[2] = blue; 00053 } 00054 00056 00057 void Set(const T& red, const T& green, const T& blue) 00058 { 00059 this->Data[0] = red; 00060 this->Data[1] = green; 00061 this->Data[2] = blue; 00062 } 00064 00066 void SetRed(const T& red) { this->Data[0] = red; } 00067 00069 const T& GetRed() const { return this->Data[0]; } 00070 00072 void SetGreen(const T& green) { this->Data[1] = green; } 00073 00075 const T& GetGreen() const { return this->Data[1]; } 00076 00078 void SetBlue(const T& blue) { this->Data[2] = blue; } 00079 00081 const T& GetBlue() const { return this->Data[2]; } 00082 00084 VTK_LEGACY(const T& Red() const); 00085 00087 VTK_LEGACY(const T& Green() const); 00088 00090 00091 VTK_LEGACY(const T& Blue() const); 00092 }; 00094 00095 // .NAME vtkColor4 - templated base type for storage of 4 component colors. 00096 // 00097 template<typename T> 00098 class vtkColor4 : public vtkTuple<T, 4> 00099 { 00100 public: 00101 vtkColor4() 00102 { 00103 } 00104 00105 explicit vtkColor4(const T& scalar) : vtkTuple<T, 4>(scalar) 00106 { 00107 } 00108 00109 explicit vtkColor4(const T* init) : vtkTuple<T, 4>(init) 00110 { 00111 } 00112 00113 vtkColor4(const T& red, const T& green, const T& blue, const T& alpha) 00114 { 00115 this->Data[0] = red; 00116 this->Data[1] = green; 00117 this->Data[2] = blue; 00118 this->Data[3] = alpha; 00119 } 00120 00122 00123 void Set(const T& red, const T& green, const T& blue) 00124 { 00125 this->Data[0] = red; 00126 this->Data[1] = green; 00127 this->Data[2] = blue; 00128 } 00130 00132 00133 void Set(const T& red, const T& green, const T& blue, const T& alpha) 00134 { 00135 this->Data[0] = red; 00136 this->Data[1] = green; 00137 this->Data[2] = blue; 00138 this->Data[3] = alpha; 00139 } 00141 00143 void SetRed(const T& red) { this->Data[0] = red; } 00144 00146 const T& GetRed() const { return this->Data[0]; } 00147 00149 void SetGreen(const T& green) { this->Data[1] = green; } 00150 00152 const T& GetGreen() const { return this->Data[1]; } 00153 00155 void SetBlue(const T& blue) { this->Data[2] = blue; } 00156 00158 const T& GetBlue() const { return this->Data[2]; } 00159 00161 void SetAlpha(const T& alpha) { this->Data[3] = alpha; } 00162 00164 const T& GetAlpha() const { return this->Data[3]; } 00165 00167 VTK_LEGACY(const T& Red() const); 00168 00170 VTK_LEGACY(const T& Green() const); 00171 00173 VTK_LEGACY(const T& Blue() const); 00174 00176 00177 VTK_LEGACY(const T& Alpha() const); 00178 }; 00180 00182 00183 class vtkColor3ub : public vtkColor3<unsigned char> 00184 { 00185 public: 00186 vtkColor3ub() {} 00187 explicit vtkColor3ub(unsigned char scalar) 00188 : vtkColor3<unsigned char>(scalar) {} 00189 explicit vtkColor3ub(const unsigned char* init) 00190 : vtkColor3<unsigned char>(init) {} 00192 00194 00196 explicit vtkColor3ub(int hexSigned) 00197 { 00198 unsigned int hex = static_cast<unsigned int>(hexSigned); 00199 this->Data[2] = hex & 0xff; 00200 hex >>= 8; 00201 this->Data[1] = hex & 0xff; 00202 hex >>= 8; 00203 this->Data[0] = hex & 0xff; 00204 } 00206 00207 vtkColor3ub(unsigned char r, unsigned char g, unsigned char b) 00208 : vtkColor3<unsigned char>(r, g, b) {} 00209 }; 00210 00211 class vtkColor3f : public vtkColor3<float> 00212 { 00213 public: 00214 vtkColor3f() {} 00215 explicit vtkColor3f(float scalar) : vtkColor3<float>(scalar) {} 00216 explicit vtkColor3f(const float* init) : vtkColor3<float>(init) {} 00217 vtkColor3f(float r, float g, float b) : vtkColor3<float>(r, g, b) {} 00218 }; 00219 00220 class vtkColor3d : public vtkColor3<double> 00221 { 00222 public: 00223 vtkColor3d() {} 00224 explicit vtkColor3d(double scalar) : vtkColor3<double>(scalar) {} 00225 explicit vtkColor3d(const double* init) : vtkColor3<double>(init) {} 00226 vtkColor3d(double r, double g, double b) : vtkColor3<double>(r, g, b) {} 00227 }; 00228 00229 class vtkColor4ub : public vtkColor4<unsigned char> 00230 { 00231 public: 00232 vtkColor4ub() {} 00233 explicit vtkColor4ub(unsigned char scalar) 00234 : vtkColor4<unsigned char>(scalar) {} 00235 explicit vtkColor4ub(const unsigned char* init) 00236 : vtkColor4<unsigned char>(init) {} 00237 00239 00241 explicit vtkColor4ub(int hexSigned) 00242 { 00243 unsigned int hex = static_cast<unsigned int>(hexSigned); 00244 this->Data[3] = hex & 0xff; 00245 hex >>= 8; 00246 this->Data[2] = hex & 0xff; 00247 hex >>= 8; 00248 this->Data[1] = hex & 0xff; 00249 hex >>= 8; 00250 this->Data[0] = hex & 0xff; 00251 } 00253 00254 vtkColor4ub(unsigned char r, unsigned char g, 00255 unsigned char b, unsigned char a = 255) 00256 : vtkColor4<unsigned char>(r, g, b, a) {} 00257 vtkColor4ub(const vtkColor3ub &c) : 00258 vtkColor4<unsigned char>(c[0], c[1], c[2], 255) {} 00259 }; 00260 00261 class vtkColor4f : public vtkColor4<float> 00262 { 00263 public: 00264 vtkColor4f() {} 00265 explicit vtkColor4f(float scalar) : vtkColor4<float>(scalar) {} 00266 explicit vtkColor4f(const float* init) : vtkColor4<float>(init) {} 00267 vtkColor4f(float r, float g, float b, float a = 1.0) 00268 : vtkColor4<float>(r, g, b, a) {} 00269 }; 00270 00271 class vtkColor4d : public vtkColor4<double> 00272 { 00273 public: 00274 vtkColor4d() {} 00275 explicit vtkColor4d(double scalar) : vtkColor4<double>(scalar) {} 00276 explicit vtkColor4d(const double* init) : vtkColor4<double>(init) {} 00277 vtkColor4d(double r, double g, double b, double a = 1.0) 00278 : vtkColor4<double>(r, g, b, a) {} 00279 }; 00280 00281 #ifndef VTK_LEGACY_REMOVE 00282 template<typename T> 00283 const T& vtkColor3<T>::Red() const 00284 { 00285 VTK_LEGACY_REPLACED_BODY(vtkColor3::Red, "VTK 6.0", vtkColor3::GetRed); 00286 return this->GetRed(); 00287 } 00288 00289 template<typename T> 00290 const T& vtkColor3<T>::Green() const 00291 { 00292 VTK_LEGACY_REPLACED_BODY(vtkColor3::Green, "VTK 6.0", vtkColor3::GetGreen); 00293 return this->GetGreen(); 00294 } 00295 00296 template<typename T> 00297 const T& vtkColor3<T>::Blue() const 00298 { 00299 VTK_LEGACY_REPLACED_BODY(vtkColor3::Blue, "VTK 6.0", vtkColor3::GetBlue); 00300 return this->GetBlue(); 00301 } 00302 00303 template<typename T> 00304 const T& vtkColor4<T>::Red() const 00305 { 00306 VTK_LEGACY_REPLACED_BODY(vtkColor4::Red, "VTK 6.0", vtkColor4::GetRed); 00307 return this->GetRed(); 00308 } 00309 00310 template<typename T> 00311 const T& vtkColor4<T>::Green() const 00312 { 00313 VTK_LEGACY_REPLACED_BODY(vtkColor4::Green, "VTK 6.0", vtkColor4::GetGreen); 00314 return this->GetGreen(); 00315 } 00316 00317 template<typename T> 00318 const T& vtkColor4<T>::Blue() const 00319 { 00320 VTK_LEGACY_REPLACED_BODY(vtkColor4::Blue, "VTK 6.0", vtkColor4::GetBlue); 00321 return this->GetBlue(); 00322 } 00323 00324 template<typename T> 00325 const T& vtkColor4<T>::Alpha() const 00326 { 00327 VTK_LEGACY_REPLACED_BODY(vtkColor4::Alpha, "VTK 6.0", vtkColor4::GetAlpha); 00328 return this->GetAlpha(); 00329 } 00330 #endif // VTK_LEGACY_REMOVE 00331 00332 #endif // __vtkColor_h 00333 // VTK-HeaderTest-Exclude: vtkColor.h