VTK
dox/Rendering/vtkProperty.h
Go to the documentation of this file.
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 vtkTexture;
00055 class vtkWindow;
00056 class vtkXMLDataElement;
00057 class vtkXMLMaterial;
00058 
00059 class vtkPropertyInternals;
00060 
00061 class VTK_RENDERING_EXPORT vtkProperty : public vtkObject
00062 {
00063 public:
00064   vtkTypeMacro(vtkProperty,vtkObject);
00065   void PrintSelf(ostream& os, vtkIndent indent);
00066 
00072   static vtkProperty *New();
00073 
00075   void DeepCopy(vtkProperty *p);
00076 
00082   virtual void Render(vtkActor *,vtkRenderer *);
00083 
00089   virtual void BackfaceRender(vtkActor *,vtkRenderer *) {};
00090 
00091   //BTX
00093 
00095   virtual void PostRender(vtkActor*, vtkRenderer*);
00096   //ETX
00098 
00100 
00101   vtkGetMacro(Lighting,bool);
00102   vtkSetMacro(Lighting,bool);
00103   vtkBooleanMacro(Lighting,bool);
00105   
00107 
00108   vtkSetClampMacro(Interpolation,int,VTK_FLAT,VTK_PHONG);
00109   vtkGetMacro(Interpolation,int);
00110   void SetInterpolationToFlat() {this->SetInterpolation(VTK_FLAT);};
00111   void SetInterpolationToGouraud() {this->SetInterpolation(VTK_GOURAUD);};
00112   void SetInterpolationToPhong() {this->SetInterpolation(VTK_PHONG);};
00113   const char *GetInterpolationAsString();
00115 
00117 
00118   vtkSetClampMacro(Representation,int,VTK_POINTS,VTK_SURFACE);
00119   vtkGetMacro(Representation,int);
00120   void SetRepresentationToPoints() {this->SetRepresentation(VTK_POINTS);};
00121   void SetRepresentationToWireframe() {
00122     this->SetRepresentation(VTK_WIREFRAME);};
00123   void SetRepresentationToSurface() {this->SetRepresentation(VTK_SURFACE);};
00124   const char *GetRepresentationAsString();
00126 
00128 
00131   void SetColor(double r, double g, double b);
00132   void SetColor(double a[3]) { this->SetColor(a[0], a[1], a[2]); };
00133   double *GetColor();
00134   void GetColor(double rgb[3]);
00135   void GetColor(double &r, double &g, double &b);
00137 
00139 
00140   vtkSetClampMacro(Ambient,double,0.0,1.0);
00141   vtkGetMacro(Ambient,double);
00143 
00145 
00146   vtkSetClampMacro(Diffuse,double,0.0,1.0);
00147   vtkGetMacro(Diffuse,double);
00149 
00151 
00152   vtkSetClampMacro(Specular,double,0.0,1.0);
00153   vtkGetMacro(Specular,double);
00155 
00157 
00158   vtkSetClampMacro(SpecularPower,double,0.0,128.0);
00159   vtkGetMacro(SpecularPower,double);
00161 
00163 
00165   vtkSetClampMacro(Opacity,double,0.0,1.0);
00166   vtkGetMacro(Opacity,double);
00168 
00170 
00174   vtkSetVector3Macro(AmbientColor,double);
00175   vtkGetVector3Macro(AmbientColor,double);
00177 
00179 
00180   vtkSetVector3Macro(DiffuseColor,double);
00181   vtkGetVector3Macro(DiffuseColor,double);
00183 
00185 
00186   vtkSetVector3Macro(SpecularColor,double);
00187   vtkGetVector3Macro(SpecularColor,double);
00189 
00191 
00194   vtkGetMacro(EdgeVisibility,int);
00195   vtkSetMacro(EdgeVisibility,int);
00196   vtkBooleanMacro(EdgeVisibility,int);
00198 
00200 
00201   vtkSetVector3Macro(EdgeColor,double);
00202   vtkGetVector3Macro(EdgeColor,double);
00204 
00206 
00208   vtkSetClampMacro(LineWidth,float,0,VTK_LARGE_FLOAT);
00209   vtkGetMacro(LineWidth,float);
00211 
00213 
00216   vtkSetMacro(LineStipplePattern,int);
00217   vtkGetMacro(LineStipplePattern,int);
00219 
00221 
00224   vtkSetClampMacro(LineStippleRepeatFactor,int,1,VTK_LARGE_INTEGER);
00225   vtkGetMacro(LineStippleRepeatFactor,int);
00227 
00229 
00231   vtkSetClampMacro(PointSize,float,0,VTK_LARGE_FLOAT);
00232   vtkGetMacro(PointSize,float);
00234 
00236 
00239   vtkGetMacro(BackfaceCulling,int);
00240   vtkSetMacro(BackfaceCulling,int);
00241   vtkBooleanMacro(BackfaceCulling,int);
00243 
00245 
00248   vtkGetMacro(FrontfaceCulling,int);
00249   vtkSetMacro(FrontfaceCulling,int);
00250   vtkBooleanMacro(FrontfaceCulling,int);
00252 
00254 
00256   vtkGetObjectMacro(Material, vtkXMLMaterial);
00258 
00260 
00261   vtkGetStringMacro(MaterialName);
00263 
00266   void LoadMaterial(const char* name);
00267 
00269   void LoadMaterialFromString(const char* materialxml);
00270 
00272   void LoadMaterial(vtkXMLMaterial*);
00273 
00275 
00277   vtkSetMacro(Shading, int);
00278   vtkGetMacro(Shading, int);
00279   vtkBooleanMacro(Shading, int);
00281 
00283 
00285   vtkGetObjectMacro(ShaderProgram, vtkShaderProgram);
00287 
00289 
00293   virtual void AddShaderVariable(const char *name, int numVars, int *x);
00294   virtual void AddShaderVariable(const char *name, int numVars, float *x);
00295   virtual void AddShaderVariable(const char *name, int numVars, double *x);
00297 
00299 
00300   void AddShaderVariable(const char* name, int v)
00301     {
00302     this->AddShaderVariable(name, 1, &v);
00303     }
00304   void AddShaderVariable(const char* name, float v)
00305     {
00306     this->AddShaderVariable(name, 1, &v);
00307     }
00308   void AddShaderVariable(const char* name, double v)
00309     {
00310     this->AddShaderVariable(name, 1, &v);
00311     }
00312   void AddShaderVariable(const char* name, int v1, int v2)
00313     {
00314     int v[2];
00315     v[0] = v1;
00316     v[1] = v2;
00317     this->AddShaderVariable(name, 2, v);
00318     }
00319   void AddShaderVariable(const char* name, float v1, float v2)
00320     {
00321     float v[2];
00322     v[0] = v1;
00323     v[1] = v2;
00324     this->AddShaderVariable(name, 2, v);
00325     }
00326   void AddShaderVariable(const char* name, double v1, double v2)
00327     {
00328     double v[2];
00329     v[0] = v1;
00330     v[1] = v2;
00331     this->AddShaderVariable(name, 2, v);
00332     }
00333   void AddShaderVariable(const char* name, int v1, int v2, int v3)
00334     {
00335     int v[3];
00336     v[0] = v1;
00337     v[1] = v2;
00338     v[2] = v3;
00339     this->AddShaderVariable(name, 3, v);
00340     }
00341   void AddShaderVariable(const char* name, float v1, float v2, float v3)
00342     {
00343     float v[3];
00344     v[0] = v1;
00345     v[1] = v2;
00346     v[2] = v3;
00347     this->AddShaderVariable(name, 3, v);
00348     }
00349   void AddShaderVariable(const char* name, double v1, double v2, double v3)
00350     {
00351     double v[3];
00352     v[0] = v1;
00353     v[1] = v2;
00354     v[2] = v3;
00355     this->AddShaderVariable(name, 3, v);
00356     }
00358 
00360 
00364   void SetTexture(const char* name, vtkTexture* texture);
00365   vtkTexture* GetTexture(const char* name);
00367 
00369 
00373   void SetTexture(int unit, vtkTexture* texture);
00374   vtkTexture* GetTexture(int unit);
00375   void RemoveTexture(int unit);
00377 
00378 
00381   void RemoveTexture(const char* name);
00382 
00384   void RemoveAllTextures();
00385 
00387   int GetNumberOfTextures();
00388 
00392   virtual void ReleaseGraphicsResources(vtkWindow *win);
00393 
00395 
00397   enum VTKTextureUnit
00398   {
00399     VTK_TEXTURE_UNIT_0 = 0,
00400     VTK_TEXTURE_UNIT_1,
00401     VTK_TEXTURE_UNIT_2,
00402     VTK_TEXTURE_UNIT_3,
00403     VTK_TEXTURE_UNIT_4,
00404     VTK_TEXTURE_UNIT_5,
00405     VTK_TEXTURE_UNIT_6,
00406     VTK_TEXTURE_UNIT_7
00407   };
00409 //ETX
00410 
00411 protected:
00412   vtkProperty();
00413   ~vtkProperty();
00414 
00416 
00417   void LoadProperty();
00418   void LoadTextures();
00419   void LoadTexture(vtkXMLDataElement* elem);
00420   void LoadPerlineNoise(vtkXMLDataElement* );
00421   void LoadMember(vtkXMLDataElement* elem);
00423 
00424   double Color[3];
00425   double AmbientColor[3];
00426   double DiffuseColor[3];
00427   double SpecularColor[3];
00428   double EdgeColor[3];
00429   double Ambient;
00430   double Diffuse;
00431   double Specular;
00432   double SpecularPower;
00433   double Opacity;
00434   float PointSize;
00435   float LineWidth;
00436   int   LineStipplePattern;
00437   int   LineStippleRepeatFactor;
00438   int   Interpolation;
00439   int   Representation;
00440   int   EdgeVisibility;
00441   int   BackfaceCulling;
00442   int   FrontfaceCulling;
00443   bool Lighting;
00444 
00445   int Shading;
00446 
00447   char* MaterialName;
00448   vtkSetStringMacro(MaterialName);
00449 
00450   vtkShaderProgram* ShaderProgram;
00451   void SetShaderProgram(vtkShaderProgram*);
00452 
00453   vtkXMLMaterial* Material; // TODO: I wonder if this reference needs to be maintained.
00454 
00457   virtual void ReadFrameworkMaterial();
00458   
00459 //BTX
00460   // These friends are provided only for the time being
00461   // till we device a graceful way of loading texturing for GLSL.
00462   friend class vtkGLSLShaderProgram;
00463   friend class vtkShader;
00464   // FIXME:
00465   // Don't use these methods. They will be removed. They are provided only
00466   // for the time-being.
00467   vtkTexture* GetTextureAtIndex(int index);
00468   int GetTextureUnitAtIndex(int index);
00469   int GetTextureUnit(const char* name);
00470 //ETX
00471 
00472 private:
00473   vtkProperty(const vtkProperty&);  // Not implemented.
00474   void operator=(const vtkProperty&);  // Not implemented.
00475 
00476   vtkPropertyInternals* Internals;
00477 };
00478 
00480 inline const char *vtkProperty::GetInterpolationAsString(void)
00481 {
00482   if ( this->Interpolation == VTK_FLAT )
00483     {
00484     return "Flat";
00485     }
00486   else if ( this->Interpolation == VTK_GOURAUD )
00487     {
00488     return "Gouraud";
00489     }
00490   else
00491     {
00492     return "Phong";
00493     }
00494 }
00495 
00496 
00498 inline const char *vtkProperty::GetRepresentationAsString(void)
00499 {
00500   if ( this->Representation == VTK_POINTS )
00501     {
00502     return "Points";
00503     }
00504   else if ( this->Representation == VTK_WIREFRAME )
00505     {
00506     return "Wireframe";
00507     }
00508   else
00509     {
00510     return "Surface";
00511     }
00512 }
00513 
00514 
00515 
00516 #endif