VTK
dox/Rendering/Core/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 "vtkRenderingCoreModule.h" // For export macro
00040 #include "vtkObject.h"
00041 
00042 // shading models
00043 #define VTK_FLAT    0
00044 #define VTK_GOURAUD 1
00045 #define VTK_PHONG   2
00046 
00047 // representation models
00048 #define VTK_POINTS    0
00049 #define VTK_WIREFRAME 1
00050 #define VTK_SURFACE   2
00051 
00052 class vtkActor;
00053 class vtkRenderer;
00054 class vtkShaderProgram;
00055 class vtkShaderDeviceAdapter2;
00056 class vtkTexture;
00057 class vtkWindow;
00058 class vtkXMLDataElement;
00059 class vtkXMLMaterial;
00060 
00061 class vtkPropertyInternals;
00062 
00063 class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject
00064 {
00065 public:
00066   vtkTypeMacro(vtkProperty,vtkObject);
00067   void PrintSelf(ostream& os, vtkIndent indent);
00068 
00074   static vtkProperty *New();
00075 
00077   void DeepCopy(vtkProperty *p);
00078 
00084   virtual void Render(vtkActor *, vtkRenderer *);
00085 
00091   virtual void BackfaceRender(vtkActor *, vtkRenderer *) {}
00092 
00093   //BTX
00095 
00097   virtual void PostRender(vtkActor*, vtkRenderer*);
00098   //ETX
00100 
00102 
00103   vtkGetMacro(Lighting, bool);
00104   vtkSetMacro(Lighting, bool);
00105   vtkBooleanMacro(Lighting, bool);
00107 
00109 
00110   vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PHONG);
00111   vtkGetMacro(Interpolation,int);
00112   void SetInterpolationToFlat()
00113     { this->SetInterpolation(VTK_FLAT); }
00114   void SetInterpolationToGouraud()
00115     { this->SetInterpolation(VTK_GOURAUD); }
00116   void SetInterpolationToPhong()
00117     { this->SetInterpolation(VTK_PHONG); }
00118   const char *GetInterpolationAsString();
00120 
00122 
00123   vtkSetClampMacro(Representation,int, VTK_POINTS, VTK_SURFACE);
00124   vtkGetMacro(Representation,int);
00125   void SetRepresentationToPoints()
00126     { this->SetRepresentation(VTK_POINTS); }
00127   void SetRepresentationToWireframe()
00128     { this->SetRepresentation(VTK_WIREFRAME); }
00129   void SetRepresentationToSurface()
00130     { this->SetRepresentation(VTK_SURFACE); }
00131   const char *GetRepresentationAsString();
00133 
00135 
00138   void SetColor(double r, double g, double b);
00139   void SetColor(double a[3])
00140     { this->SetColor(a[0], a[1], a[2]); }
00141   double *GetColor();
00142   void GetColor(double rgb[3]);
00143   void GetColor(double &r, double &g, double &b);
00145 
00147 
00148   vtkSetClampMacro(Ambient, double, 0.0, 1.0);
00149   vtkGetMacro(Ambient, double);
00151 
00153 
00154   vtkSetClampMacro(Diffuse, double, 0.0, 1.0);
00155   vtkGetMacro(Diffuse, double);
00157 
00159 
00160   vtkSetClampMacro(Specular, double, 0.0, 1.0);
00161   vtkGetMacro(Specular, double);
00163 
00165 
00166   vtkSetClampMacro(SpecularPower, double, 0.0, 128.0);
00167   vtkGetMacro(SpecularPower, double);
00169 
00171 
00173   vtkSetClampMacro(Opacity, double, 0.0, 1.0);
00174   vtkGetMacro(Opacity, double);
00176 
00178 
00182   vtkSetVector3Macro(AmbientColor, double);
00183   vtkGetVector3Macro(AmbientColor, double);
00185 
00187 
00188   vtkSetVector3Macro(DiffuseColor, double);
00189   vtkGetVector3Macro(DiffuseColor, double);
00191 
00193 
00194   vtkSetVector3Macro(SpecularColor, double);
00195   vtkGetVector3Macro(SpecularColor, double);
00197 
00199 
00202   vtkGetMacro(EdgeVisibility, int);
00203   vtkSetMacro(EdgeVisibility, int);
00204   vtkBooleanMacro(EdgeVisibility, int);
00206 
00208 
00209   vtkSetVector3Macro(EdgeColor, double);
00210   vtkGetVector3Macro(EdgeColor, double);
00212 
00214 
00216   vtkSetClampMacro(LineWidth, float, 0, VTK_FLOAT_MAX);
00217   vtkGetMacro(LineWidth, float);
00219 
00221 
00224   vtkSetMacro(LineStipplePattern, int);
00225   vtkGetMacro(LineStipplePattern, int);
00227 
00229 
00232   vtkSetClampMacro(LineStippleRepeatFactor, int, 1, VTK_INT_MAX);
00233   vtkGetMacro(LineStippleRepeatFactor, int);
00235 
00237 
00239   vtkSetClampMacro(PointSize, float, 0, VTK_FLOAT_MAX);
00240   vtkGetMacro(PointSize, float);
00242 
00244 
00247   vtkGetMacro(BackfaceCulling, int);
00248   vtkSetMacro(BackfaceCulling, int);
00249   vtkBooleanMacro(BackfaceCulling, int);
00251 
00253 
00256   vtkGetMacro(FrontfaceCulling, int);
00257   vtkSetMacro(FrontfaceCulling, int);
00258   vtkBooleanMacro(FrontfaceCulling, int);
00260 
00262 
00264   vtkGetObjectMacro(Material, vtkXMLMaterial);
00266 
00268 
00269   vtkGetStringMacro(MaterialName);
00271 
00274   void LoadMaterial(const char* name);
00275 
00277   void LoadMaterialFromString(const char* materialxml);
00278 
00280   void LoadMaterial(vtkXMLMaterial*);
00281 
00283 
00285   vtkSetMacro(Shading, int);
00286   vtkGetMacro(Shading, int);
00287   vtkBooleanMacro(Shading, int);
00289 
00291 
00293   vtkGetObjectMacro(ShaderProgram, vtkShaderProgram);
00295 
00297 
00298   virtual vtkShaderDeviceAdapter2* GetShaderDeviceAdapter2()
00299     { return NULL; }
00301 
00303 
00307   virtual void AddShaderVariable(const char *name, int numVars, int *x);
00308   virtual void AddShaderVariable(const char *name, int numVars, float *x);
00309   virtual void AddShaderVariable(const char *name, int numVars, double *x);
00311 
00313 
00314   void AddShaderVariable(const char* name, int v)
00315     { this->AddShaderVariable(name, 1, &v); }
00316   void AddShaderVariable(const char* name, float v)
00317     { this->AddShaderVariable(name, 1, &v); }
00318   void AddShaderVariable(const char* name, double v)
00319     { this->AddShaderVariable(name, 1, &v); }
00320   void AddShaderVariable(const char* name, int v1, int v2)
00321     {
00322     int v[2] = {v1, v2};
00323     this->AddShaderVariable(name, 2, v);
00324     }
00325   void AddShaderVariable(const char* name, float v1, float v2)
00326     {
00327     float v[2] = {v1, v2};
00328     this->AddShaderVariable(name, 2, v);
00329     }
00330   void AddShaderVariable(const char* name, double v1, double v2)
00331     {
00332     double v[2] = {v1, v2};
00333     this->AddShaderVariable(name, 2, v);
00334     }
00335   void AddShaderVariable(const char* name, int v1, int v2, int v3)
00336     {
00337     int v[3] = {v1, v2, v3};
00338     this->AddShaderVariable(name, 3, v);
00339     }
00340   void AddShaderVariable(const char* name, float v1, float v2, float v3)
00341     {
00342     float v[3] = {v1, v2, v3};
00343     this->AddShaderVariable(name, 3, v);
00344     }
00345   void AddShaderVariable(const char* name, double v1, double v2, double v3)
00346     {
00347     double v[3] = {v1, v2, v3};
00348     this->AddShaderVariable(name, 3, v);
00349     }
00351 
00353 
00357   void SetTexture(const char* name, vtkTexture* texture);
00358   vtkTexture* GetTexture(const char* name);
00360 
00362 
00366   void SetTexture(int unit, vtkTexture* texture);
00367   vtkTexture* GetTexture(int unit);
00368   void RemoveTexture(int unit);
00370 
00373   void RemoveTexture(const char* name);
00374 
00376   void RemoveAllTextures();
00377 
00379   int GetNumberOfTextures();
00380 
00384   virtual void ReleaseGraphicsResources(vtkWindow *win);
00385 
00386 //BTX
00388 
00390   enum VTKTextureUnit
00391   {
00392     VTK_TEXTURE_UNIT_0 = 0,
00393     VTK_TEXTURE_UNIT_1,
00394     VTK_TEXTURE_UNIT_2,
00395     VTK_TEXTURE_UNIT_3,
00396     VTK_TEXTURE_UNIT_4,
00397     VTK_TEXTURE_UNIT_5,
00398     VTK_TEXTURE_UNIT_6,
00399     VTK_TEXTURE_UNIT_7
00400   };
00401 //ETX
00403 
00404 protected:
00405   vtkProperty();
00406   ~vtkProperty();
00407 
00409 
00410   static void ComputeCompositeColor(double result[3],
00411     double ambient, const double ambient_color[3],
00412     double diffuse, const double diffuse_color[3],
00413     double specular, const double specular_color[3]);
00415 
00417 
00418   void LoadProperty();
00419   void LoadTextures();
00420   void LoadTexture(vtkXMLDataElement*);
00421   void LoadPerlineNoise(vtkXMLDataElement*);
00422   void LoadMember(vtkXMLDataElement*);
00424 
00425   double Color[3];
00426   double AmbientColor[3];
00427   double DiffuseColor[3];
00428   double SpecularColor[3];
00429   double EdgeColor[3];
00430   double Ambient;
00431   double Diffuse;
00432   double Specular;
00433   double SpecularPower;
00434   double Opacity;
00435   float PointSize;
00436   float LineWidth;
00437   int LineStipplePattern;
00438   int LineStippleRepeatFactor;
00439   int Interpolation;
00440   int Representation;
00441   int EdgeVisibility;
00442   int BackfaceCulling;
00443   int FrontfaceCulling;
00444   bool Lighting;
00445 
00446   int Shading;
00447 
00448   char* MaterialName;
00449   vtkSetStringMacro(MaterialName);
00450 
00451   vtkShaderProgram* ShaderProgram;
00452   void SetShaderProgram(vtkShaderProgram*);
00453 
00454   vtkXMLMaterial* Material; // TODO: I wonder if this reference needs to be maintained.
00455 
00458   virtual void ReadFrameworkMaterial();
00459 
00460 //BTX
00461   // These friends are provided only for the time being
00462   // till we device a graceful way of loading texturing for GLSL.
00463   friend class vtkGLSLShaderProgram;
00464   friend class vtkShader;
00465   // FIXME:
00466   // Don't use these methods. They will be removed. They are provided only
00467   // for the time-being.
00468   vtkTexture* GetTextureAtIndex(int index);
00469   int GetTextureUnitAtIndex(int index);
00470   int GetTextureUnit(const char* name);
00471 //ETX
00472 
00473 private:
00474   vtkProperty(const vtkProperty&);  // Not implemented.
00475   void operator=(const vtkProperty&);  // Not implemented.
00476 
00477   vtkPropertyInternals* Internals;
00478 };
00479 
00481 
00482 inline const char *vtkProperty::GetInterpolationAsString(void)
00483 {
00484   if (this->Interpolation == VTK_FLAT)
00485     {
00486     return "Flat";
00487     }
00488   else if (this->Interpolation == VTK_GOURAUD)
00489     {
00490     return "Gouraud";
00491     }
00492   else
00493     {
00494     return "Phong";
00495     }
00496 }
00498 
00500 
00501 inline const char *vtkProperty::GetRepresentationAsString(void)
00502 {
00503   if (this->Representation == VTK_POINTS)
00504     {
00505     return "Points";
00506     }
00507   else if (this->Representation == VTK_WIREFRAME)
00508     {
00509     return "Wireframe";
00510     }
00511   else
00512     {
00513     return "Surface";
00514     }
00515 }
00517 
00518 #endif