VTK  9.2.6
vtkProperty.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkProperty.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
46 #ifndef vtkProperty_h
47 #define vtkProperty_h
48 
49 #include "vtkObject.h"
50 #include "vtkRenderingCoreModule.h" // For export macro
51 #include <map> // used for ivar
52 #include <string> // used for ivar
53 
54 // shading models
55 #define VTK_FLAT 0
56 #define VTK_GOURAUD 1
57 #define VTK_PHONG 2
58 #define VTK_PBR 3
59 
60 // representation models
61 #define VTK_POINTS 0
62 #define VTK_WIREFRAME 1
63 #define VTK_SURFACE 2
64 
65 class vtkActor;
66 class vtkInformation;
67 class vtkRenderer;
68 class vtkShaderProgram;
69 class vtkTexture;
70 class vtkWindow;
71 class vtkXMLDataElement;
72 class vtkXMLMaterial;
73 
74 class vtkPropertyInternals;
75 
76 class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject
77 {
78 public:
79  vtkTypeMacro(vtkProperty, vtkObject);
80  void PrintSelf(ostream& os, vtkIndent indent) override;
81 
88  static vtkProperty* New();
89 
94 
102  virtual void Render(vtkActor*, vtkRenderer*);
103 
110  virtual void BackfaceRender(vtkActor*, vtkRenderer*) {}
111 
117  virtual void PostRender(vtkActor*, vtkRenderer*);
118 
120 
123  vtkGetMacro(Lighting, bool);
124  vtkSetMacro(Lighting, bool);
125  vtkBooleanMacro(Lighting, bool);
127 
129 
135  vtkGetMacro(RenderPointsAsSpheres, bool);
136  vtkSetMacro(RenderPointsAsSpheres, bool);
137  vtkBooleanMacro(RenderPointsAsSpheres, bool);
139 
141 
148  vtkGetMacro(RenderLinesAsTubes, bool);
149  vtkSetMacro(RenderLinesAsTubes, bool);
150  vtkBooleanMacro(RenderLinesAsTubes, bool);
152 
154 
157  vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PBR);
158  vtkGetMacro(Interpolation, int);
159  void SetInterpolationToFlat() { this->SetInterpolation(VTK_FLAT); }
160  void SetInterpolationToGouraud() { this->SetInterpolation(VTK_GOURAUD); }
161  void SetInterpolationToPhong() { this->SetInterpolation(VTK_PHONG); }
162  void SetInterpolationToPBR() { this->SetInterpolation(VTK_PBR); }
163  const char* GetInterpolationAsString();
165 
167 
170  vtkSetClampMacro(Representation, int, VTK_POINTS, VTK_SURFACE);
171  vtkGetMacro(Representation, int);
172  void SetRepresentationToPoints() { this->SetRepresentation(VTK_POINTS); }
173  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_WIREFRAME); }
174  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SURFACE); }
175  const char* GetRepresentationAsString();
177 
179 
184  virtual void SetColor(double r, double g, double b);
185  virtual void SetColor(double a[3]);
186  double* GetColor() VTK_SIZEHINT(3);
187  void GetColor(double rgb[3]);
188  void GetColor(double& r, double& g, double& b);
190 
192 
203  vtkSetClampMacro(BaseIOR, double, 1.0, VTK_FLOAT_MAX);
204  vtkGetMacro(BaseIOR, double);
206 
208 
214  vtkSetClampMacro(Metallic, double, 0.0, 1.0);
215  vtkGetMacro(Metallic, double);
217 
219 
226  vtkSetClampMacro(Roughness, double, 0.0, 1.0);
227  vtkGetMacro(Roughness, double);
229 
231 
237  vtkSetClampMacro(Anisotropy, double, 0.0, 1.0);
238  vtkGetMacro(Anisotropy, double);
240 
242 
248  vtkSetClampMacro(AnisotropyRotation, double, 0.0, 1.0);
249  vtkGetMacro(AnisotropyRotation, double);
251 
253 
258  vtkSetClampMacro(CoatIOR, double, 1.0, VTK_FLOAT_MAX);
259  vtkGetMacro(CoatIOR, double);
261 
263 
269  vtkSetClampMacro(CoatRoughness, double, 0.0, 1.0);
270  vtkGetMacro(CoatRoughness, double);
272 
274 
280  vtkSetClampMacro(CoatStrength, double, 0.0, 1.0);
281  vtkGetMacro(CoatStrength, double);
283 
285 
290  vtkSetVector3Macro(CoatColor, double);
291  vtkGetVector3Macro(CoatColor, double);
293 
295 
301  vtkSetClampMacro(CoatNormalScale, double, 0.0, 1.0);
302  vtkGetMacro(CoatNormalScale, double);
304 
306 
311  vtkSetMacro(NormalScale, double);
312  vtkGetMacro(NormalScale, double);
314 
316 
322  vtkSetClampMacro(OcclusionStrength, double, 0.0, 1.0);
323  vtkGetMacro(OcclusionStrength, double);
325 
327 
333  vtkSetVector3Macro(EmissiveFactor, double);
334  vtkGetVector3Macro(EmissiveFactor, double);
336 
338 
344  vtkSetVector3Macro(EdgeTint, double);
345  vtkGetVector3Macro(EdgeTint, double);
347 
349 
352  vtkSetClampMacro(Ambient, double, 0.0, 1.0);
353  vtkGetMacro(Ambient, double);
355 
357 
360  vtkSetClampMacro(Diffuse, double, 0.0, 1.0);
361  vtkGetMacro(Diffuse, double);
363 
365 
368  vtkSetClampMacro(Specular, double, 0.0, 1.0);
369  vtkGetMacro(Specular, double);
371 
373 
376  vtkSetClampMacro(SpecularPower, double, 0.0, 128.0);
377  vtkGetMacro(SpecularPower, double);
379 
381 
385  vtkSetClampMacro(Opacity, double, 0.0, 1.0);
386  vtkGetMacro(Opacity, double);
388 
390 
396  vtkSetVector3Macro(AmbientColor, double);
397  vtkGetVector3Macro(AmbientColor, double);
399 
401 
405  vtkSetVector3Macro(DiffuseColor, double);
406  vtkGetVector3Macro(DiffuseColor, double);
408 
410 
413  vtkSetVector3Macro(SpecularColor, double);
414  vtkGetVector3Macro(SpecularColor, double);
416 
418 
423  vtkGetMacro(EdgeVisibility, vtkTypeBool);
424  vtkSetMacro(EdgeVisibility, vtkTypeBool);
425  vtkBooleanMacro(EdgeVisibility, vtkTypeBool);
427 
429 
432  vtkSetVector3Macro(EdgeColor, double);
433  vtkGetVector3Macro(EdgeColor, double);
435 
437 
442  vtkGetMacro(VertexVisibility, vtkTypeBool);
443  vtkSetMacro(VertexVisibility, vtkTypeBool);
444  vtkBooleanMacro(VertexVisibility, vtkTypeBool);
446 
448 
451  vtkSetVector3Macro(VertexColor, double);
452  vtkGetVector3Macro(VertexColor, double);
454 
456 
460  vtkSetVector4Macro(SelectionColor, double);
461  vtkGetVector4Macro(SelectionColor, double);
463 
465 
469  vtkSetMacro(SelectionLineWidth, float);
470  vtkGetMacro(SelectionLineWidth, float);
472 
474 
478  vtkSetMacro(SelectionPointSize, float);
479  vtkGetMacro(SelectionPointSize, float);
481 
483 
487  vtkSetClampMacro(LineWidth, float, 0, VTK_FLOAT_MAX);
488  vtkGetMacro(LineWidth, float);
490 
492 
497  vtkSetMacro(LineStipplePattern, int);
498  vtkGetMacro(LineStipplePattern, int);
500 
502 
507  vtkSetClampMacro(LineStippleRepeatFactor, int, 1, VTK_INT_MAX);
508  vtkGetMacro(LineStippleRepeatFactor, int);
510 
512 
516  vtkSetClampMacro(PointSize, float, 0, VTK_FLOAT_MAX);
517  vtkGetMacro(PointSize, float);
519 
521 
526  vtkGetMacro(BackfaceCulling, vtkTypeBool);
527  vtkSetMacro(BackfaceCulling, vtkTypeBool);
528  vtkBooleanMacro(BackfaceCulling, vtkTypeBool);
530 
532 
537  vtkGetMacro(FrontfaceCulling, vtkTypeBool);
538  vtkSetMacro(FrontfaceCulling, vtkTypeBool);
539  vtkBooleanMacro(FrontfaceCulling, vtkTypeBool);
541 
543 
546  vtkSetStringMacro(MaterialName);
547  vtkGetStringMacro(MaterialName);
549 
551 
555  vtkSetMacro(Shading, vtkTypeBool);
556  vtkGetMacro(Shading, vtkTypeBool);
557  vtkBooleanMacro(Shading, vtkTypeBool);
559 
561 
569  virtual void AddShaderVariable(const char* name, int numVars, int* x);
570  virtual void AddShaderVariable(const char* name, int numVars, float* x);
571  virtual void AddShaderVariable(const char* name, int numVars, double* x);
573 
575 
578  void AddShaderVariable(const char* name, int v) { this->AddShaderVariable(name, 1, &v); }
579  void AddShaderVariable(const char* name, float v) { this->AddShaderVariable(name, 1, &v); }
580  void AddShaderVariable(const char* name, double v) { this->AddShaderVariable(name, 1, &v); }
581  void AddShaderVariable(const char* name, int v1, int v2)
582  {
583  int v[2] = { v1, v2 };
584  this->AddShaderVariable(name, 2, v);
585  }
586  void AddShaderVariable(const char* name, float v1, float v2)
587  {
588  float v[2] = { v1, v2 };
589  this->AddShaderVariable(name, 2, v);
590  }
591  void AddShaderVariable(const char* name, double v1, double v2)
592  {
593  double v[2] = { v1, v2 };
594  this->AddShaderVariable(name, 2, v);
595  }
596  void AddShaderVariable(const char* name, int v1, int v2, int v3)
597  {
598  int v[3] = { v1, v2, v3 };
599  this->AddShaderVariable(name, 3, v);
600  }
601  void AddShaderVariable(const char* name, float v1, float v2, float v3)
602  {
603  float v[3] = { v1, v2, v3 };
604  this->AddShaderVariable(name, 3, v);
605  }
606  void AddShaderVariable(const char* name, double v1, double v2, double v3)
607  {
608  double v[3] = { v1, v2, v3 };
609  this->AddShaderVariable(name, 3, v);
610  }
612 
614 
618  vtkSetMacro(ShowTexturesOnBackface, bool);
619  vtkGetMacro(ShowTexturesOnBackface, bool);
620  vtkBooleanMacro(ShowTexturesOnBackface, bool);
622 
624 
637  void SetTexture(const char* name, vtkTexture* texture);
638  vtkTexture* GetTexture(const char* name);
640 
647  void SetBaseColorTexture(vtkTexture* texture) { this->SetTexture("albedoTex", texture); }
648 
658  void SetORMTexture(vtkTexture* texture) { this->SetTexture("materialTex", texture); }
659 
670  void SetAnisotropyTexture(vtkTexture* texture) { this->SetTexture("anisotropyTex", texture); }
671 
680  void SetNormalTexture(vtkTexture* texture) { this->SetTexture("normalTex", texture); }
681 
689  void SetEmissiveTexture(vtkTexture* texture) { this->SetTexture("emissiveTex", texture); }
690 
699  void SetCoatNormalTexture(vtkTexture* texture) { this->SetTexture("coatNormalTex", texture); }
700 
704  void RemoveTexture(const char* name);
705 
710 
715 
719  std::map<std::string, vtkTexture*>& GetAllTextures() { return this->Textures; }
720 
727 
729 
732  vtkGetObjectMacro(Information, vtkInformation);
735 
737 
741  static double ComputeReflectanceFromIOR(double IORTo, double IORFrom);
743 
745 
749  static double ComputeIORFromReflectance(double reflectance, double ior);
751 
753 
761 
762 protected:
764  ~vtkProperty() override;
765 
769  static void ComputeCompositeColor(double result[3], double ambient, const double ambient_color[3],
770  double diffuse, const double diffuse_color[3], double specular, const double specular_color[3]);
771 
772  double Color[3];
773  double AmbientColor[3];
774  double DiffuseColor[3];
775  double SpecularColor[3];
776  double EdgeColor[3];
777  double VertexColor[3];
778  double SelectionColor[4] = { 1.0, 0.0, 0.0, 1.0 };
779  double Ambient;
780  double Diffuse;
781  double Metallic;
782  double Roughness;
783  double Anisotropy;
785  double BaseIOR;
786  double CoatIOR;
787  double CoatColor[3];
789  double CoatStrength;
791  double NormalScale;
793  double EmissiveFactor[3];
794  double Specular;
796  double Opacity;
797  double EdgeTint[3];
798  float PointSize;
799  float LineWidth;
800  float SelectionPointSize = 2.f;
801  float SelectionLineWidth = 2.f;
810  bool Lighting;
814 
816 
818 
819  typedef std::map<std::string, vtkTexture*> MapOfTextures;
821 
822  // Arbitrary extra information associated with this Property.
824 
825 private:
826  vtkProperty(const vtkProperty&) = delete;
827  void operator=(const vtkProperty&) = delete;
828 };
829 
834 {
835  if (this->Interpolation == VTK_FLAT)
836  {
837  return "Flat";
838  }
839  else if (this->Interpolation == VTK_GOURAUD)
840  {
841  return "Gouraud";
842  }
843  else if (this->Interpolation == VTK_PHONG)
844  {
845  return "Phong";
846  }
847  else // if (this->Interpolation == VTK_PBR)
848  {
849  return "Physically based rendering";
850  }
851 }
852 
857 {
858  if (this->Representation == VTK_POINTS)
859  {
860  return "Points";
861  }
862  else if (this->Representation == VTK_WIREFRAME)
863  {
864  return "Wireframe";
865  }
866  else
867  {
868  return "Surface";
869  }
870 }
871 
872 #endif
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:61
a simple class to control print indentation
Definition: vtkIndent.h:49
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:72
represent surface properties of a geometric object
Definition: vtkProperty.h:77
MapOfTextures Textures
Definition: vtkProperty.h:820
double ComputeReflectanceOfBaseLayer()
For PBR, calculate the reflectance of the base layer depending on the presence of a coat layer.
std::map< std::string, vtkTexture * > MapOfTextures
Definition: vtkProperty.h:819
double CoatRoughness
Definition: vtkProperty.h:788
~vtkProperty() override
double * GetColor()
Set the color of the object.
void SetRepresentationToPoints()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:172
double CoatNormalScale
Definition: vtkProperty.h:790
int LineStipplePattern
Definition: vtkProperty.h:802
void SetTexture(const char *name, vtkTexture *texture)
Set/Get the texture object to control rendering texture maps.
void SetRepresentationToWireframe()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:173
virtual void SetInformation(vtkInformation *)
Set/Get the information object associated with the Property.
int LineStippleRepeatFactor
Definition: vtkProperty.h:803
double AnisotropyRotation
Definition: vtkProperty.h:784
static void ComputeCompositeColor(double result[3], double ambient, const double ambient_color[3], double diffuse, const double diffuse_color[3], double specular, const double specular_color[3])
Computes composite color.
virtual void SetColor(double a[3])
Set the color of the object.
double OcclusionStrength
Definition: vtkProperty.h:792
double Diffuse
Definition: vtkProperty.h:780
void AddShaderVariable(const char *name, double v1, double v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:591
virtual void BackfaceRender(vtkActor *, vtkRenderer *)
This method renders the property as a backface property.
Definition: vtkProperty.h:110
static vtkProperty * New()
Construct object with object color, ambient color, diffuse color, specular color, and edge color whit...
double Opacity
Definition: vtkProperty.h:796
void SetNormalTexture(vtkTexture *texture)
Set the normal texture.
Definition: vtkProperty.h:680
int Representation
Definition: vtkProperty.h:805
float LineWidth
Definition: vtkProperty.h:799
int GetNumberOfTextures()
Returns the number of textures in this property.
double CoatStrength
Definition: vtkProperty.h:789
void SetEmissiveTexture(vtkTexture *texture)
Set the emissive texture.
Definition: vtkProperty.h:689
void SetInterpolationToFlat()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:159
void RemoveAllTextures()
Remove all the textures.
void SetBaseColorTexture(vtkTexture *texture)
Set the base color texture.
Definition: vtkProperty.h:647
double Metallic
Definition: vtkProperty.h:781
void SetCoatNormalTexture(vtkTexture *texture)
Set the coat normal texture.
Definition: vtkProperty.h:699
void SetInterpolationToGouraud()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:160
vtkTypeBool BackfaceCulling
Definition: vtkProperty.h:808
void DeepCopy(vtkProperty *p)
Assign one property to another.
int Interpolation
Definition: vtkProperty.h:804
double Anisotropy
Definition: vtkProperty.h:783
void AddShaderVariable(const char *name, double v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:580
void SetInterpolationToPBR()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:162
virtual void Render(vtkActor *, vtkRenderer *)
This method causes the property to set up whatever is required for its instance variables.
const char * GetInterpolationAsString()
Return the method of shading as a descriptive character string.
Definition: vtkProperty.h:833
void SetRepresentationToSurface()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:174
void SetInterpolationToPhong()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:161
double Roughness
Definition: vtkProperty.h:782
double BaseIOR
Definition: vtkProperty.h:785
void AddShaderVariable(const char *name, double v1, double v2, double v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:606
bool RenderPointsAsSpheres
Definition: vtkProperty.h:811
vtkTypeBool Shading
Definition: vtkProperty.h:815
float PointSize
Definition: vtkProperty.h:798
void SetORMTexture(vtkTexture *texture)
Set the ORM texture.
Definition: vtkProperty.h:658
void AddShaderVariable(const char *name, int v1, int v2, int v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:596
virtual void SetColor(double r, double g, double b)
Set the color of the object.
vtkInformation * Information
Definition: vtkProperty.h:823
static double ComputeReflectanceFromIOR(double IORTo, double IORFrom)
For PBR, calculate the reflectance from the refractive index of ingoing and outgoing interfaces.
vtkTexture * GetTexture(const char *name)
Set/Get the texture object to control rendering texture maps.
void AddShaderVariable(const char *name, float v1, float v2, float v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:601
double Specular
Definition: vtkProperty.h:794
double NormalScale
Definition: vtkProperty.h:791
bool RenderLinesAsTubes
Definition: vtkProperty.h:812
virtual void ReleaseGraphicsResources(vtkWindow *win)
Release any graphics resources that are being consumed by this property.
vtkTypeBool EdgeVisibility
Definition: vtkProperty.h:806
vtkTypeBool VertexVisibility
Definition: vtkProperty.h:807
void AddShaderVariable(const char *name, int v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:578
double SpecularPower
Definition: vtkProperty.h:795
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetAnisotropyTexture(vtkTexture *texture)
Set the anisotropy texture.
Definition: vtkProperty.h:670
vtkTypeBool FrontfaceCulling
Definition: vtkProperty.h:809
void RemoveTexture(const char *name)
Remove a texture from the collection.
void AddShaderVariable(const char *name, float v1, float v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:586
bool ShowTexturesOnBackface
Definition: vtkProperty.h:813
static double ComputeIORFromReflectance(double reflectance, double ior)
For PBR, calculate the refractive index from the reflectance of the interface and the refractive inde...
virtual void PostRender(vtkActor *, vtkRenderer *)
This method is called after the actor has been rendered.
double Ambient
Definition: vtkProperty.h:779
double CoatIOR
Definition: vtkProperty.h:786
void AddShaderVariable(const char *name, int v1, int v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:581
const char * GetRepresentationAsString()
Return the method of shading as a descriptive character string.
Definition: vtkProperty.h:856
void AddShaderVariable(const char *name, float v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:579
char * MaterialName
Definition: vtkProperty.h:817
std::map< std::string, vtkTexture * > & GetAllTextures()
Returns all the textures in this property and their names.
Definition: vtkProperty.h:719
abstract specification for renderers
Definition: vtkRenderer.h:82
The ShaderProgram uses one or more Shader objects.
handles properties associated with a texture map
Definition: vtkTexture.h:78
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
Represents an XML element and those nested inside.
@ Color
Definition: vtkX3D.h:52
@ name
Definition: vtkX3D.h:225
int vtkTypeBool
Definition: vtkABI.h:69
#define VTK_POINTS
Definition: vtkProperty.h:61
#define VTK_WIREFRAME
Definition: vtkProperty.h:62
#define VTK_PHONG
Definition: vtkProperty.h:57
#define VTK_FLAT
Definition: vtkProperty.h:55
#define VTK_PBR
Definition: vtkProperty.h:58
#define VTK_SURFACE
Definition: vtkProperty.h:63
#define VTK_GOURAUD
Definition: vtkProperty.h:56
#define VTK_INT_MAX
Definition: vtkType.h:155
#define VTK_FLOAT_MAX
Definition: vtkType.h:163
#define VTK_SIZEHINT(...)