VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkProperty.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 =========================================================================*/ 00036 #ifndef __vtkProperty_h 00037 #define __vtkProperty_h 00038 00039 #include "vtkObject.h" 00040 00041 // shading models 00042 #define VTK_FLAT 0 00043 #define VTK_GOURAUD 1 00044 #define VTK_PHONG 2 00045 00046 // representation models 00047 #define VTK_POINTS 0 00048 #define VTK_WIREFRAME 1 00049 #define VTK_SURFACE 2 00050 00051 class vtkActor; 00052 class vtkRenderer; 00053 class vtkShaderProgram; 00054 class vtkShaderDeviceAdapter2; 00055 class vtkTexture; 00056 class vtkWindow; 00057 class vtkXMLDataElement; 00058 class vtkXMLMaterial; 00059 00060 class vtkPropertyInternals; 00061 00062 class VTK_RENDERING_EXPORT vtkProperty : public vtkObject 00063 { 00064 public: 00065 vtkTypeMacro(vtkProperty,vtkObject); 00066 void PrintSelf(ostream& os, vtkIndent indent); 00067 00073 static vtkProperty *New(); 00074 00076 void DeepCopy(vtkProperty *p); 00077 00083 virtual void Render(vtkActor *,vtkRenderer *); 00084 00090 virtual void BackfaceRender(vtkActor *,vtkRenderer *) {}; 00091 00092 //BTX 00094 00096 virtual void PostRender(vtkActor*, vtkRenderer*); 00097 //ETX 00099 00101 00102 vtkGetMacro(Lighting,bool); 00103 vtkSetMacro(Lighting,bool); 00104 vtkBooleanMacro(Lighting,bool); 00106 00108 00109 vtkSetClampMacro(Interpolation,int,VTK_FLAT,VTK_PHONG); 00110 vtkGetMacro(Interpolation,int); 00111 void SetInterpolationToFlat() {this->SetInterpolation(VTK_FLAT);}; 00112 void SetInterpolationToGouraud() {this->SetInterpolation(VTK_GOURAUD);}; 00113 void SetInterpolationToPhong() {this->SetInterpolation(VTK_PHONG);}; 00114 const char *GetInterpolationAsString(); 00116 00118 00119 vtkSetClampMacro(Representation,int,VTK_POINTS,VTK_SURFACE); 00120 vtkGetMacro(Representation,int); 00121 void SetRepresentationToPoints() {this->SetRepresentation(VTK_POINTS);}; 00122 void SetRepresentationToWireframe() { 00123 this->SetRepresentation(VTK_WIREFRAME);}; 00124 void SetRepresentationToSurface() {this->SetRepresentation(VTK_SURFACE);}; 00125 const char *GetRepresentationAsString(); 00127 00129 00132 void SetColor(double r, double g, double b); 00133 void SetColor(double a[3]) { this->SetColor(a[0], a[1], a[2]); }; 00134 double *GetColor(); 00135 void GetColor(double rgb[3]); 00136 void GetColor(double &r, double &g, double &b); 00138 00140 00141 vtkSetClampMacro(Ambient,double,0.0,1.0); 00142 vtkGetMacro(Ambient,double); 00144 00146 00147 vtkSetClampMacro(Diffuse,double,0.0,1.0); 00148 vtkGetMacro(Diffuse,double); 00150 00152 00153 vtkSetClampMacro(Specular,double,0.0,1.0); 00154 vtkGetMacro(Specular,double); 00156 00158 00159 vtkSetClampMacro(SpecularPower,double,0.0,128.0); 00160 vtkGetMacro(SpecularPower,double); 00162 00164 00166 vtkSetClampMacro(Opacity,double,0.0,1.0); 00167 vtkGetMacro(Opacity,double); 00169 00171 00175 vtkSetVector3Macro(AmbientColor,double); 00176 vtkGetVector3Macro(AmbientColor,double); 00178 00180 00181 vtkSetVector3Macro(DiffuseColor,double); 00182 vtkGetVector3Macro(DiffuseColor,double); 00184 00186 00187 vtkSetVector3Macro(SpecularColor,double); 00188 vtkGetVector3Macro(SpecularColor,double); 00190 00192 00195 vtkGetMacro(EdgeVisibility,int); 00196 vtkSetMacro(EdgeVisibility,int); 00197 vtkBooleanMacro(EdgeVisibility,int); 00199 00201 00202 vtkSetVector3Macro(EdgeColor,double); 00203 vtkGetVector3Macro(EdgeColor,double); 00205 00207 00209 vtkSetClampMacro(LineWidth,float,0,VTK_LARGE_FLOAT); 00210 vtkGetMacro(LineWidth,float); 00212 00214 00217 vtkSetMacro(LineStipplePattern,int); 00218 vtkGetMacro(LineStipplePattern,int); 00220 00222 00225 vtkSetClampMacro(LineStippleRepeatFactor,int,1,VTK_LARGE_INTEGER); 00226 vtkGetMacro(LineStippleRepeatFactor,int); 00228 00230 00232 vtkSetClampMacro(PointSize,float,0,VTK_LARGE_FLOAT); 00233 vtkGetMacro(PointSize,float); 00235 00237 00240 vtkGetMacro(BackfaceCulling,int); 00241 vtkSetMacro(BackfaceCulling,int); 00242 vtkBooleanMacro(BackfaceCulling,int); 00244 00246 00249 vtkGetMacro(FrontfaceCulling,int); 00250 vtkSetMacro(FrontfaceCulling,int); 00251 vtkBooleanMacro(FrontfaceCulling,int); 00253 00255 00257 vtkGetObjectMacro(Material, vtkXMLMaterial); 00259 00261 00262 vtkGetStringMacro(MaterialName); 00264 00267 void LoadMaterial(const char* name); 00268 00270 void LoadMaterialFromString(const char* materialxml); 00271 00273 void LoadMaterial(vtkXMLMaterial*); 00274 00276 00278 vtkSetMacro(Shading, int); 00279 vtkGetMacro(Shading, int); 00280 vtkBooleanMacro(Shading, int); 00282 00284 00286 vtkGetObjectMacro(ShaderProgram, vtkShaderProgram); 00288 00290 virtual vtkShaderDeviceAdapter2* GetShaderDeviceAdapter2() { return NULL; } 00291 00293 00297 virtual void AddShaderVariable(const char *name, int numVars, int *x); 00298 virtual void AddShaderVariable(const char *name, int numVars, float *x); 00299 virtual void AddShaderVariable(const char *name, int numVars, double *x); 00301 00303 00304 void AddShaderVariable(const char* name, int v) 00305 { 00306 this->AddShaderVariable(name, 1, &v); 00307 } 00308 void AddShaderVariable(const char* name, float v) 00309 { 00310 this->AddShaderVariable(name, 1, &v); 00311 } 00312 void AddShaderVariable(const char* name, double v) 00313 { 00314 this->AddShaderVariable(name, 1, &v); 00315 } 00316 void AddShaderVariable(const char* name, int v1, int v2) 00317 { 00318 int v[2]; 00319 v[0] = v1; 00320 v[1] = v2; 00321 this->AddShaderVariable(name, 2, v); 00322 } 00323 void AddShaderVariable(const char* name, float v1, float v2) 00324 { 00325 float v[2]; 00326 v[0] = v1; 00327 v[1] = v2; 00328 this->AddShaderVariable(name, 2, v); 00329 } 00330 void AddShaderVariable(const char* name, double v1, double v2) 00331 { 00332 double v[2]; 00333 v[0] = v1; 00334 v[1] = v2; 00335 this->AddShaderVariable(name, 2, v); 00336 } 00337 void AddShaderVariable(const char* name, int v1, int v2, int v3) 00338 { 00339 int v[3]; 00340 v[0] = v1; 00341 v[1] = v2; 00342 v[2] = v3; 00343 this->AddShaderVariable(name, 3, v); 00344 } 00345 void AddShaderVariable(const char* name, float v1, float v2, float v3) 00346 { 00347 float v[3]; 00348 v[0] = v1; 00349 v[1] = v2; 00350 v[2] = v3; 00351 this->AddShaderVariable(name, 3, v); 00352 } 00353 void AddShaderVariable(const char* name, double v1, double v2, double v3) 00354 { 00355 double v[3]; 00356 v[0] = v1; 00357 v[1] = v2; 00358 v[2] = v3; 00359 this->AddShaderVariable(name, 3, v); 00360 } 00362 00364 00368 void SetTexture(const char* name, vtkTexture* texture); 00369 vtkTexture* GetTexture(const char* name); 00371 00373 00377 void SetTexture(int unit, vtkTexture* texture); 00378 vtkTexture* GetTexture(int unit); 00379 void RemoveTexture(int unit); 00381 00382 00385 void RemoveTexture(const char* name); 00386 00388 void RemoveAllTextures(); 00389 00391 int GetNumberOfTextures(); 00392 00396 virtual void ReleaseGraphicsResources(vtkWindow *win); 00397 00398 //BTX 00400 00402 enum VTKTextureUnit 00403 { 00404 VTK_TEXTURE_UNIT_0 = 0, 00405 VTK_TEXTURE_UNIT_1, 00406 VTK_TEXTURE_UNIT_2, 00407 VTK_TEXTURE_UNIT_3, 00408 VTK_TEXTURE_UNIT_4, 00409 VTK_TEXTURE_UNIT_5, 00410 VTK_TEXTURE_UNIT_6, 00411 VTK_TEXTURE_UNIT_7 00412 }; 00413 //ETX 00415 00416 protected: 00417 vtkProperty(); 00418 ~vtkProperty(); 00419 00421 00422 void LoadProperty(); 00423 void LoadTextures(); 00424 void LoadTexture(vtkXMLDataElement* elem); 00425 void LoadPerlineNoise(vtkXMLDataElement* ); 00426 void LoadMember(vtkXMLDataElement* elem); 00428 00429 double Color[3]; 00430 double AmbientColor[3]; 00431 double DiffuseColor[3]; 00432 double SpecularColor[3]; 00433 double EdgeColor[3]; 00434 double Ambient; 00435 double Diffuse; 00436 double Specular; 00437 double SpecularPower; 00438 double Opacity; 00439 float PointSize; 00440 float LineWidth; 00441 int LineStipplePattern; 00442 int LineStippleRepeatFactor; 00443 int Interpolation; 00444 int Representation; 00445 int EdgeVisibility; 00446 int BackfaceCulling; 00447 int FrontfaceCulling; 00448 bool Lighting; 00449 00450 int Shading; 00451 00452 char* MaterialName; 00453 vtkSetStringMacro(MaterialName); 00454 00455 vtkShaderProgram* ShaderProgram; 00456 void SetShaderProgram(vtkShaderProgram*); 00457 00458 vtkXMLMaterial* Material; // TODO: I wonder if this reference needs to be maintained. 00459 00462 virtual void ReadFrameworkMaterial(); 00463 00464 //BTX 00465 // These friends are provided only for the time being 00466 // till we device a graceful way of loading texturing for GLSL. 00467 friend class vtkGLSLShaderProgram; 00468 friend class vtkShader; 00469 // FIXME: 00470 // Don't use these methods. They will be removed. They are provided only 00471 // for the time-being. 00472 vtkTexture* GetTextureAtIndex(int index); 00473 int GetTextureUnitAtIndex(int index); 00474 int GetTextureUnit(const char* name); 00475 //ETX 00476 00477 private: 00478 vtkProperty(const vtkProperty&); // Not implemented. 00479 void operator=(const vtkProperty&); // Not implemented. 00480 00481 vtkPropertyInternals* Internals; 00482 }; 00483 00485 00486 inline const char *vtkProperty::GetInterpolationAsString(void) 00487 { 00488 if ( this->Interpolation == VTK_FLAT ) 00489 { 00490 return "Flat"; 00491 } 00492 else if ( this->Interpolation == VTK_GOURAUD ) 00493 { 00494 return "Gouraud"; 00495 } 00496 else 00497 { 00498 return "Phong"; 00499 } 00500 } 00502 00503 00505 00506 inline const char *vtkProperty::GetRepresentationAsString(void) 00507 { 00508 if ( this->Representation == VTK_POINTS ) 00509 { 00510 return "Points"; 00511 } 00512 else if ( this->Representation == VTK_WIREFRAME ) 00513 { 00514 return "Wireframe"; 00515 } 00516 else 00517 { 00518 return "Surface"; 00519 } 00520 } 00522 00523 00524 00525 #endif