Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

vtkPaletteElement.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 * 00003 * $Id: vtkPaletteElement.h,v 1.1 2004/06/02 11:35:08 xpxqx Exp $ 00004 * 00005 * Copyright (c) 2004 Sean McInerney 00006 * All rights reserved. 00007 * 00008 * See Copyright.txt or http://vtkextensions.sourceforge.net/Copyright.html 00009 * for details. 00010 * 00011 * This software is distributed WITHOUT ANY WARRANTY; without even 00012 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 * PURPOSE. See the above copyright notice for more information. 00014 * 00015 */ 00016 #ifndef VTK_PALETTE_ELEMENT_H_ 00017 # define VTK_PALETTE_ELEMENT_H_ 00018 # include "vtkExtensionsPaletteConfigure.h" // vtkExtensions configuration 00019 # include "vtkExtensionsTypes.h" // vtkExtensions types 00020 # include "vtkExtensionsObject.h" 00021 # include "vtkStringOps.h" // for inlined string ops 00022 00023 00024 # define VTK_PALETTE_NONE 0x00000000 00025 # define VTK_PALETTE_COMPOSITE 0x00000001 00026 # define VTK_PALETTE_AMBIENT 0x00000002 00027 # define VTK_PALETTE_DIFFUSE 0x00000004 00028 # define VTK_PALETTE_SPECULAR 0x00000008 00029 # define VTK_PALETTE_MATERIAL ( VTK_PALETTE_AMBIENT | VTK_PALETTE_DIFFUSE | VTK_PALETTE_SPECULAR ) 00030 # define VTK_PALETTE_PALETTE ( VTK_PALETTE_COMPOSITE | VTK_PALETTE_MATERIAL ) 00031 # define VTK_PALETTE_USER 0x00000010 00032 00033 00034 VTK_EXTENSIONS_PALETTE_NAMESPACE_BEGIN 00035 00046 class VTK_EXTENSIONS_PALETTE_EXPORT vtkPaletteElement 00047 : public vtkExtensionsObject 00048 { 00049 public: 00050 vtkTypeRevisionMacro (vtkPaletteElement, vtkExtensionsObject); 00051 void PrintSelf (ostream&, vtkIndent); 00052 00054 virtual vtkPaletteElement* GetParent (void) const; 00055 00056 //BTX 00058 vtkGetXMLStringMacro(ID, vtkXMLChType); 00059 00061 vtkGetXMLStringMacro(Name, vtkXMLChType); 00062 00065 vtkGetXMLStringMacro(Description, vtkXMLChType); 00066 vtkSetXMLStringMacro(Description, vtkXMLChType); 00070 virtual const vtkXMLChType* GetTagName (void) const = 0; 00071 //ETX 00072 00074 virtual int GetType (void) const; 00075 00077 virtual int IsRoot (void) const; 00078 00080 virtual int IsLeaf (void) const; 00081 00083 virtual int IsEmpty (void) const; 00084 00086 virtual vtkIdType GetSize (void) const; 00087 00089 virtual vtkIdType GetCapacity (void) const; 00090 00098 virtual vtkPaletteElement* Find (const char* name) const; 00099 00111 virtual int Insert (vtkPaletteElement* element); 00112 00119 virtual int Erase (const char* name); 00120 00121 //BTX 00123 void Marshal (ostream& target, vtkIndent indent); 00124 00126 void UnmarshalAttributes (const vtkXMLChType** attrs); 00127 00129 virtual void UnmarshalContent (const vtkXMLChType* const& content) {} 00130 00134 static inline void ConvertColor (unsigned char const& c0, 00135 unsigned char const& c1, 00136 unsigned char const& c2, 00137 unsigned char const& alpha, 00138 vtkColorWord & color); 00139 00141 static inline void ConvertColor (double const& c0, 00142 double const& c1, 00143 double const& c2, 00144 double const& alpha, 00145 vtkColorWord & color); 00146 00148 static inline void ConvertColor (vtkColorWord const& color, 00149 unsigned char & c0, 00150 unsigned char & c1, 00151 unsigned char & c2, 00152 unsigned char & alpha); 00153 00155 static inline void ConvertColor (vtkColorWord const& color, 00156 double & c0, 00157 double & c1, 00158 double & c2, 00159 double & alpha); 00160 00162 static inline void ConvertColor (double const& c0, 00163 double const& c1, 00164 double const& c2, 00165 double const& alpha, 00166 vtkMaterial & material); 00167 00169 static inline void ConvertColor (unsigned char const& c0, 00170 unsigned char const& c1, 00171 unsigned char const& c2, 00172 unsigned char const& alpha, 00173 vtkMaterial & material); 00174 00176 static inline void ConvertColor (vtkColorWord const& color, 00177 vtkMaterial & material); 00178 00180 static inline void ConvertMaterial (vtkMaterial const& material, 00181 double & c0, 00182 double & c1, 00183 double & c2, 00184 double & alpha); 00185 00187 static inline void ConvertMaterial (vtkMaterial const& material, 00188 unsigned char & c0, 00189 unsigned char & c1, 00190 unsigned char & c2, 00191 unsigned char & alpha); 00192 00194 static inline void ConvertMaterial (vtkMaterial const& material, 00195 vtkColorWord & color); 00198 static const vtkXMLChType* const idString; 00199 static const vtkXMLChType* const nameString; 00200 static const vtkXMLChType* const descriptionString; 00201 //ETX 00202 00203 protected: 00204 vtkPaletteElement (void); 00205 ~vtkPaletteElement(); 00206 00207 //BTX 00208 friend class vtkPalette; 00209 friend class vtkPaletteMaterial; 00210 00211 vtkSetObjectMacro(Parent, vtkPaletteElement); 00212 00214 void SetID (const vtkXMLChType* const&); 00215 00217 vtkSetXMLStringMacro(Name, vtkXMLChType); 00218 00219 virtual void MarshalAttributes (ostream& target); 00220 00221 virtual void MarshalContent (ostream& target, vtkIndent indent) {} 00222 00223 virtual void UnmarshalAttribute (const vtkXMLChType* const& attr, 00224 const vtkXMLChType* const& value); 00225 00226 vtkPaletteElement* Parent; 00227 vtkXMLChType* ID; 00228 vtkXMLChType* Name; 00229 vtkXMLChType* Description; 00230 //ETX 00231 00232 private: 00239 vtkPaletteElement (const vtkPaletteElement&); 00240 void operator= (const vtkPaletteElement&); 00242 }; 00243 00244 // ---------------------------------------------------------------------------- 00245 inline void 00246 vtkPaletteElement::SetID (const vtkXMLChType* const& aID) 00247 { 00248 vtkStringOps::ToLatin1 tmp(aID); 00249 00250 if (this->SetUUID(tmp.data())) 00251 { 00252 vtkSetXMLStringBodyMacro(ID, aID); 00253 } 00254 else 00255 { 00256 vtkErrorMacro(<< "SetID(): Failed to set UUID from string \"" 00257 << tmp.data() << "\"."); 00258 } 00259 } 00260 00261 // ---------------------------------------------------------------------------- 00262 inline vtkPaletteElement* 00263 vtkPaletteElement::GetParent (void) const 00264 { 00265 return this->Parent; 00266 } 00267 00268 inline int 00269 vtkPaletteElement::GetType (void) const 00270 { 00271 return VTK_PALETTE_NONE; 00272 } 00273 00274 inline int 00275 vtkPaletteElement::IsRoot (void) const 00276 { 00277 return VTK_FALSE; 00278 } 00279 00280 inline int 00281 vtkPaletteElement::IsLeaf (void) const 00282 { 00283 return VTK_TRUE; 00284 } 00285 00286 inline int 00287 vtkPaletteElement::IsEmpty (void) const 00288 { 00289 return VTK_TRUE; 00290 } 00291 00292 inline vtkIdType 00293 vtkPaletteElement::GetSize (void) const 00294 { 00295 return 0; 00296 } 00297 00298 inline vtkIdType 00299 vtkPaletteElement::GetCapacity (void) const 00300 { 00301 return 0; 00302 } 00303 00304 inline vtkPaletteElement* 00305 vtkPaletteElement::Find (const char* name) const 00306 { 00307 return (vtkPaletteElement *) 0; 00308 } 00309 00310 inline int 00311 vtkPaletteElement::Insert (vtkPaletteElement* element) 00312 { 00313 return VTK_FALSE; 00314 } 00315 00316 inline int 00317 vtkPaletteElement::Erase (const char* name) 00318 { 00319 return VTK_FALSE; 00320 } 00321 00322 // ---------------------------------------------------------------------------- 00323 inline void 00324 vtkPaletteElement::ConvertColor (unsigned char const& a0, 00325 unsigned char const& a1, 00326 unsigned char const& a2, 00327 unsigned char const& aA, 00328 vtkColorWord & aColor) 00329 { 00330 aColor = VTK_EXTENSIONS_MAKE_RGBA(a0, a1, a2, aA); 00331 } 00332 00333 inline void 00334 vtkPaletteElement::ConvertColor (double const& a0, 00335 double const& a1, 00336 double const& a2, 00337 double const& aA, 00338 vtkColorWord & aColor) 00339 { 00340 vtkPaletteElement::ConvertColor( 00341 (unsigned char)( ( (a0>1.0 ? 1.0 : (a0<0.0 ? 0.0 : a0)) * 00342 double(VTK_EXTENSIONS_RGB_MAX) ) + 0.5 ), 00343 (unsigned char)( ( (a1>1.0 ? 1.0 : (a1<0.0 ? 0.0 : a1)) * 00344 double(VTK_EXTENSIONS_RGB_MAX) ) + 0.5 ), 00345 (unsigned char)( ( (a2>1.0 ? 1.0 : (a2<0.0 ? 0.0 : a2)) * 00346 double(VTK_EXTENSIONS_RGB_MAX) ) + 0.5 ), 00347 (unsigned char)( ( (aA>1.0 ? 1.0 : (aA<0.0 ? 0.0 : aA)) * 00348 double(VTK_EXTENSIONS_RGB_MAX) ) + 0.5 ), 00349 aColor ); 00350 } 00351 00352 inline void 00353 vtkPaletteElement::ConvertColor (vtkColorWord const& aColor, 00354 unsigned char & a0, 00355 unsigned char & a1, 00356 unsigned char & a2, 00357 unsigned char & aA) 00358 { 00359 a0 = VTK_EXTENSIONS_GET_RGBA_R(aColor); 00360 a1 = VTK_EXTENSIONS_GET_RGBA_G(aColor); 00361 a2 = VTK_EXTENSIONS_GET_RGBA_B(aColor); 00362 aA = VTK_EXTENSIONS_GET_RGBA_A(aColor); 00363 } 00364 00365 inline void 00366 vtkPaletteElement::ConvertColor (vtkColorWord const& aColor, 00367 double & a0, 00368 double & a1, 00369 double & a2, 00370 double & aA) 00371 { 00372 unsigned char r, g, b, a; 00373 00374 vtkPaletteElement::ConvertColor(aColor, r, g, b, a); 00375 00376 a0 = double(r) / double(VTK_EXTENSIONS_RGB_MAX); 00377 a1 = double(g) / double(VTK_EXTENSIONS_RGB_MAX); 00378 a2 = double(b) / double(VTK_EXTENSIONS_RGB_MAX); 00379 aA = double(a) / double(VTK_EXTENSIONS_RGB_MAX); 00380 } 00381 00382 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00383 inline void 00384 vtkPaletteElement::ConvertColor (double const& a0, 00385 double const& a1, 00386 double const& a2, 00387 double const& aA, 00388 vtkMaterial & aMaterial) 00389 { 00390 aMaterial.Ka[0] = aMaterial.Kd[0] = aMaterial.Ks[0] = a0; 00391 aMaterial.Ka[1] = aMaterial.Kd[1] = aMaterial.Ks[1] = a1; 00392 aMaterial.Ka[2] = aMaterial.Kd[2] = aMaterial.Ks[2] = a2; 00393 aMaterial.Kd[3] = aA; 00394 } 00395 00396 inline void 00397 vtkPaletteElement::ConvertColor (unsigned char const& a0, 00398 unsigned char const& a1, 00399 unsigned char const& a2, 00400 unsigned char const& aA, 00401 vtkMaterial & aMaterial) 00402 { 00403 vtkPaletteElement::ConvertColor( 00404 double(a0) / double(VTK_EXTENSIONS_RGB_MAX), 00405 double(a1) / double(VTK_EXTENSIONS_RGB_MAX), 00406 double(a2) / double(VTK_EXTENSIONS_RGB_MAX), 00407 double(aA) / double(VTK_EXTENSIONS_RGB_MAX), 00408 aMaterial ); 00409 } 00410 00411 inline void 00412 vtkPaletteElement::ConvertColor (vtkColorWord const& aColor, 00413 vtkMaterial & aMaterial) 00414 { 00415 vtkPaletteElement::ConvertColor( 00416 VTK_EXTENSIONS_GET_RGBA_R(aColor), 00417 VTK_EXTENSIONS_GET_RGBA_G(aColor), 00418 VTK_EXTENSIONS_GET_RGBA_B(aColor), 00419 VTK_EXTENSIONS_GET_RGBA_A(aColor), 00420 aMaterial ); 00421 } 00422 00423 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00424 #define MAX2(_a,_b) ((_a)>(_b) ? (_a) : (_b)) 00425 #define MAX3(_v) MAX2(MAX2((_v)[0],(_v)[1]), MAX2((_v)[0],(_v)[2])) 00426 00427 inline void 00428 vtkPaletteElement::ConvertMaterial (vtkMaterial const& aMaterial, 00429 double & a0, 00430 double & a1, 00431 double & a2, 00432 double & aA) 00433 { 00434 double magnitudeA = (MAX3(aMaterial.Ka) < 0.2 ? 0.2 : MAX3(aMaterial.Ka)); 00435 double magnitudeD = (MAX3(aMaterial.Kd) < 0.8 ? 0.8 : MAX3(aMaterial.Kd)); 00436 double magnitudeS = (MAX3(aMaterial.Ks) <= 0.f ? 0.f : MAX3(aMaterial.Ks)); 00437 double norm = 1.0 / (magnitudeA + magnitudeD + magnitudeS); 00438 00439 a0 = aMaterial.Ka[0] * magnitudeA * norm; 00440 a0 += aMaterial.Kd[0] * magnitudeD * norm; 00441 a0 += aMaterial.Ks[0] * magnitudeS * norm; 00442 00443 a1 = aMaterial.Ka[1] * magnitudeA * norm; 00444 a1 += aMaterial.Kd[1] * magnitudeD * norm; 00445 a1 += aMaterial.Ks[1] * magnitudeS * norm; 00446 00447 a2 = aMaterial.Ka[2] * magnitudeA * norm; 00448 a2 += aMaterial.Kd[2] * magnitudeD * norm; 00449 a2 += aMaterial.Ks[2] * magnitudeS * norm; 00450 00451 aA = aMaterial.Kd[3]; 00452 } 00453 00454 inline void 00455 vtkPaletteElement::ConvertMaterial (vtkMaterial const& aMaterial, 00456 unsigned char & a0, 00457 unsigned char & a1, 00458 unsigned char & a2, 00459 unsigned char & aA) 00460 { 00461 double c0, c1, c2, alpha; 00462 00463 vtkPaletteElement::ConvertMaterial(aMaterial, c0, c1, c2, alpha); 00464 00465 a0 = (unsigned char)( ( (c0>1.0 ? 1.0 : (c0<0.0 ? 0.0 : c0)) * 00466 double(VTK_EXTENSIONS_RGB_MAX) ) + 0.5 ); 00467 a1 = (unsigned char)( ( (c1>1.0 ? 1.0 : (c1<0.0 ? 0.0 : c1)) * 00468 double(VTK_EXTENSIONS_RGB_MAX) ) + 0.5 ); 00469 a2 = (unsigned char)( ( (c2>1.0 ? 1.0 : (c2<0.0 ? 0.0 : c2)) * 00470 double(VTK_EXTENSIONS_RGB_MAX) ) + 0.5 ); 00471 aA = (unsigned char)( ( (alpha>1.0 ? 1.0 : (alpha<0.0 ? 0.0 : alpha)) * 00472 double(VTK_EXTENSIONS_RGB_MAX) ) + 0.5 ); 00473 } 00474 00475 inline void 00476 vtkPaletteElement::ConvertMaterial (vtkMaterial const& aMaterial, 00477 vtkColorWord & aColor) 00478 { 00479 unsigned char c0, c1, c2, alpha; 00480 00481 vtkPaletteElement::ConvertMaterial(aMaterial, c0, c1, c2, alpha); 00482 00483 aColor = VTK_EXTENSIONS_MAKE_RGBA(c0, c1, c2, alpha); 00484 } 00485 00486 VTK_EXTENSIONS_PALETTE_NAMESPACE_END 00487 00488 #endif /* VTK_PALETTE_ELEMENT_H_ */ 00489 /* 00490 * End of: $Id: vtkPaletteElement.h,v 1.1 2004/06/02 11:35:08 xpxqx Exp $. 00491 * 00492 */

Generated on Tue Aug 10 03:38:11 2004 for vtkExtensions by doxygen 1.3.7