VTK  9.3.0
vtkProperty.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
34 #ifndef vtkProperty_h
35 #define vtkProperty_h
36 
37 #include "vtkObject.h"
38 #include "vtkRenderingCoreModule.h" // For export macro
39 #include <map> // used for ivar
40 #include <string> // used for ivar
41 
42 // shading models
43 #define VTK_FLAT 0
44 #define VTK_GOURAUD 1
45 #define VTK_PHONG 2
46 #define VTK_PBR 3
47 
48 // representation models
49 #define VTK_POINTS 0
50 #define VTK_WIREFRAME 1
51 #define VTK_SURFACE 2
52 
53 VTK_ABI_NAMESPACE_BEGIN
54 class vtkActor;
55 class vtkInformation;
56 class vtkRenderer;
57 class vtkShaderProgram;
58 class vtkTexture;
59 class vtkWindow;
60 class vtkXMLDataElement;
61 class vtkXMLMaterial;
62 
63 class vtkPropertyInternals;
64 
65 class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject
66 {
67 public:
68  vtkTypeMacro(vtkProperty, vtkObject);
69  void PrintSelf(ostream& os, vtkIndent indent) override;
70 
77  static vtkProperty* New();
78 
83 
91  virtual void Render(vtkActor*, vtkRenderer*);
92 
99  virtual void BackfaceRender(vtkActor*, vtkRenderer*) {}
100 
106  virtual void PostRender(vtkActor*, vtkRenderer*);
107 
109 
112  vtkGetMacro(Lighting, bool);
113  vtkSetMacro(Lighting, bool);
114  vtkBooleanMacro(Lighting, bool);
116 
118 
124  vtkGetMacro(RenderPointsAsSpheres, bool);
125  vtkSetMacro(RenderPointsAsSpheres, bool);
126  vtkBooleanMacro(RenderPointsAsSpheres, bool);
128 
130 
137  vtkGetMacro(RenderLinesAsTubes, bool);
138  vtkSetMacro(RenderLinesAsTubes, bool);
139  vtkBooleanMacro(RenderLinesAsTubes, bool);
141 
143 
146  vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PBR);
147  vtkGetMacro(Interpolation, int);
148  void SetInterpolationToFlat() { this->SetInterpolation(VTK_FLAT); }
149  void SetInterpolationToGouraud() { this->SetInterpolation(VTK_GOURAUD); }
150  void SetInterpolationToPhong() { this->SetInterpolation(VTK_PHONG); }
151  void SetInterpolationToPBR() { this->SetInterpolation(VTK_PBR); }
152  const char* GetInterpolationAsString();
154 
156 
159  vtkSetClampMacro(Representation, int, VTK_POINTS, VTK_SURFACE);
160  vtkGetMacro(Representation, int);
161  void SetRepresentationToPoints() { this->SetRepresentation(VTK_POINTS); }
162  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_WIREFRAME); }
163  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SURFACE); }
164  const char* GetRepresentationAsString();
166 
168 
173  virtual void SetColor(double r, double g, double b);
174  virtual void SetColor(double a[3]);
175  double* GetColor() VTK_SIZEHINT(3);
176  void GetColor(double rgb[3]);
177  void GetColor(double& r, double& g, double& b);
179 
181 
192  vtkSetClampMacro(BaseIOR, double, 1.0, VTK_FLOAT_MAX);
193  vtkGetMacro(BaseIOR, double);
195 
197 
203  vtkSetClampMacro(Metallic, double, 0.0, 1.0);
204  vtkGetMacro(Metallic, double);
206 
208 
215  vtkSetClampMacro(Roughness, double, 0.0, 1.0);
216  vtkGetMacro(Roughness, double);
218 
220 
226  vtkSetClampMacro(Anisotropy, double, 0.0, 1.0);
227  vtkGetMacro(Anisotropy, double);
229 
231 
237  vtkSetClampMacro(AnisotropyRotation, double, 0.0, 1.0);
238  vtkGetMacro(AnisotropyRotation, double);
240 
242 
247  vtkSetClampMacro(CoatIOR, double, 1.0, VTK_FLOAT_MAX);
248  vtkGetMacro(CoatIOR, double);
250 
252 
258  vtkSetClampMacro(CoatRoughness, double, 0.0, 1.0);
259  vtkGetMacro(CoatRoughness, double);
261 
263 
269  vtkSetClampMacro(CoatStrength, double, 0.0, 1.0);
270  vtkGetMacro(CoatStrength, double);
272 
274 
279  vtkSetVector3Macro(CoatColor, double);
280  vtkGetVector3Macro(CoatColor, double);
282 
284 
290  vtkSetClampMacro(CoatNormalScale, double, 0.0, 1.0);
291  vtkGetMacro(CoatNormalScale, double);
293 
295 
300  vtkSetMacro(NormalScale, double);
301  vtkGetMacro(NormalScale, double);
303 
305 
311  vtkSetClampMacro(OcclusionStrength, double, 0.0, 1.0);
312  vtkGetMacro(OcclusionStrength, double);
314 
316 
322  vtkSetVector3Macro(EmissiveFactor, double);
323  vtkGetVector3Macro(EmissiveFactor, double);
325 
327 
333  vtkSetVector3Macro(EdgeTint, double);
334  vtkGetVector3Macro(EdgeTint, double);
336 
338 
341  vtkSetClampMacro(Ambient, double, 0.0, 1.0);
342  vtkGetMacro(Ambient, double);
344 
346 
349  vtkSetClampMacro(Diffuse, double, 0.0, 1.0);
350  vtkGetMacro(Diffuse, double);
352 
354 
357  vtkSetClampMacro(Specular, double, 0.0, 1.0);
358  vtkGetMacro(Specular, double);
360 
362 
365  vtkSetClampMacro(SpecularPower, double, 0.0, 128.0);
366  vtkGetMacro(SpecularPower, double);
368 
370 
374  vtkSetClampMacro(Opacity, double, 0.0, 1.0);
375  vtkGetMacro(Opacity, double);
377 
379 
383  vtkSetClampMacro(EdgeOpacity, double, 0.0, 1.0);
384  vtkGetMacro(EdgeOpacity, double);
386 
388 
394  vtkSetVector3Macro(AmbientColor, double);
395  vtkGetVector3Macro(AmbientColor, double);
397 
399 
403  vtkSetVector3Macro(DiffuseColor, double);
404  vtkGetVector3Macro(DiffuseColor, double);
406 
408 
411  vtkSetVector3Macro(SpecularColor, double);
412  vtkGetVector3Macro(SpecularColor, double);
414 
416 
421  vtkGetMacro(EdgeVisibility, vtkTypeBool);
422  vtkSetMacro(EdgeVisibility, vtkTypeBool);
423  vtkBooleanMacro(EdgeVisibility, vtkTypeBool);
425 
427 
430  vtkSetVector3Macro(EdgeColor, double);
431  vtkGetVector3Macro(EdgeColor, double);
433 
435 
440  vtkGetMacro(VertexVisibility, vtkTypeBool);
441  vtkSetMacro(VertexVisibility, vtkTypeBool);
442  vtkBooleanMacro(VertexVisibility, vtkTypeBool);
444 
446 
449  vtkSetVector3Macro(VertexColor, double);
450  vtkGetVector3Macro(VertexColor, double);
452 
454 
458  vtkSetVector4Macro(SelectionColor, double);
459  vtkGetVector4Macro(SelectionColor, double);
461 
463 
467  vtkSetMacro(SelectionLineWidth, float);
468  vtkGetMacro(SelectionLineWidth, float);
470 
472 
476  vtkSetMacro(SelectionPointSize, float);
477  vtkGetMacro(SelectionPointSize, float);
479 
481 
485  vtkSetClampMacro(LineWidth, float, 0, VTK_FLOAT_MAX);
486  vtkGetMacro(LineWidth, float);
488 
490 
495  vtkSetMacro(LineStipplePattern, int);
496  vtkGetMacro(LineStipplePattern, int);
498 
500 
505  vtkSetClampMacro(LineStippleRepeatFactor, int, 1, VTK_INT_MAX);
506  vtkGetMacro(LineStippleRepeatFactor, int);
508 
510 
514  vtkSetClampMacro(PointSize, float, 0, VTK_FLOAT_MAX);
515  vtkGetMacro(PointSize, float);
517 
519 
524  vtkGetMacro(BackfaceCulling, vtkTypeBool);
525  vtkSetMacro(BackfaceCulling, vtkTypeBool);
526  vtkBooleanMacro(BackfaceCulling, vtkTypeBool);
528 
530 
535  vtkGetMacro(FrontfaceCulling, vtkTypeBool);
536  vtkSetMacro(FrontfaceCulling, vtkTypeBool);
537  vtkBooleanMacro(FrontfaceCulling, vtkTypeBool);
539 
541 
544  vtkSetStringMacro(MaterialName);
545  vtkGetStringMacro(MaterialName);
547 
549 
553  vtkSetMacro(Shading, vtkTypeBool);
554  vtkGetMacro(Shading, vtkTypeBool);
555  vtkBooleanMacro(Shading, vtkTypeBool);
557 
559 
567  virtual void AddShaderVariable(const char* name, int numVars, int* x);
568  virtual void AddShaderVariable(const char* name, int numVars, float* x);
569  virtual void AddShaderVariable(const char* name, int numVars, double* x);
571 
573 
576  void AddShaderVariable(const char* name, int v) { this->AddShaderVariable(name, 1, &v); }
577  void AddShaderVariable(const char* name, float v) { this->AddShaderVariable(name, 1, &v); }
578  void AddShaderVariable(const char* name, double v) { this->AddShaderVariable(name, 1, &v); }
579  void AddShaderVariable(const char* name, int v1, int v2)
580  {
581  int v[2] = { v1, v2 };
582  this->AddShaderVariable(name, 2, v);
583  }
584  void AddShaderVariable(const char* name, float v1, float v2)
585  {
586  float v[2] = { v1, v2 };
587  this->AddShaderVariable(name, 2, v);
588  }
589  void AddShaderVariable(const char* name, double v1, double v2)
590  {
591  double v[2] = { v1, v2 };
592  this->AddShaderVariable(name, 2, v);
593  }
594  void AddShaderVariable(const char* name, int v1, int v2, int v3)
595  {
596  int v[3] = { v1, v2, v3 };
597  this->AddShaderVariable(name, 3, v);
598  }
599  void AddShaderVariable(const char* name, float v1, float v2, float v3)
600  {
601  float v[3] = { v1, v2, v3 };
602  this->AddShaderVariable(name, 3, v);
603  }
604  void AddShaderVariable(const char* name, double v1, double v2, double v3)
605  {
606  double v[3] = { v1, v2, v3 };
607  this->AddShaderVariable(name, 3, v);
608  }
610 
612 
616  vtkSetMacro(ShowTexturesOnBackface, bool);
617  vtkGetMacro(ShowTexturesOnBackface, bool);
618  vtkBooleanMacro(ShowTexturesOnBackface, bool);
620 
622 
635  void SetTexture(const char* name, vtkTexture* texture);
636  vtkTexture* GetTexture(const char* name);
638 
645  void SetBaseColorTexture(vtkTexture* texture) { this->SetTexture("albedoTex", texture); }
646 
656  void SetORMTexture(vtkTexture* texture) { this->SetTexture("materialTex", texture); }
657 
668  void SetAnisotropyTexture(vtkTexture* texture) { this->SetTexture("anisotropyTex", texture); }
669 
678  void SetNormalTexture(vtkTexture* texture) { this->SetTexture("normalTex", texture); }
679 
687  void SetEmissiveTexture(vtkTexture* texture) { this->SetTexture("emissiveTex", texture); }
688 
697  void SetCoatNormalTexture(vtkTexture* texture) { this->SetTexture("coatNormalTex", texture); }
698 
702  void RemoveTexture(const char* name);
703 
708 
713 
717  std::map<std::string, vtkTexture*>& GetAllTextures() { return this->Textures; }
718 
725 
727 
730  vtkGetObjectMacro(Information, vtkInformation);
733 
735 
739  static double ComputeReflectanceFromIOR(double IORTo, double IORFrom);
741 
743 
747  static double ComputeIORFromReflectance(double reflectance, double ior);
749 
751 
759 
760 protected:
762  ~vtkProperty() override;
763 
767  static void ComputeCompositeColor(double result[3], double ambient, const double ambient_color[3],
768  double diffuse, const double diffuse_color[3], double specular, const double specular_color[3]);
769 
770  double Color[3];
771  double AmbientColor[3];
772  double DiffuseColor[3];
773  double SpecularColor[3];
774  double EdgeColor[3];
775  double VertexColor[3];
776  double SelectionColor[4] = { 1.0, 0.0, 0.0, 1.0 };
777  double Ambient;
778  double Diffuse;
779  double Metallic;
780  double Roughness;
781  double Anisotropy;
783  double BaseIOR;
784  double CoatIOR;
785  double CoatColor[3];
787  double CoatStrength;
789  double NormalScale;
791  double EmissiveFactor[3];
792  double Specular;
794  double Opacity;
795  double EdgeOpacity = 1.0;
796  double EdgeTint[3];
797  float PointSize;
798  float LineWidth;
799  float SelectionPointSize = 2.f;
800  float SelectionLineWidth = 2.f;
809  bool Lighting;
813 
815 
817 
818  typedef std::map<std::string, vtkTexture*> MapOfTextures;
820 
821  // Arbitrary extra information associated with this Property.
823 
824 private:
825  vtkProperty(const vtkProperty&) = delete;
826  void operator=(const vtkProperty&) = delete;
827 };
828 
833 {
834  if (this->Interpolation == VTK_FLAT)
835  {
836  return "Flat";
837  }
838  else if (this->Interpolation == VTK_GOURAUD)
839  {
840  return "Gouraud";
841  }
842  else if (this->Interpolation == VTK_PHONG)
843  {
844  return "Phong";
845  }
846  else // if (this->Interpolation == VTK_PBR)
847  {
848  return "Physically based rendering";
849  }
850 }
851 
856 {
857  if (this->Representation == VTK_POINTS)
858  {
859  return "Points";
860  }
861  else if (this->Representation == VTK_WIREFRAME)
862  {
863  return "Wireframe";
864  }
865  else
866  {
867  return "Surface";
868  }
869 }
870 
871 VTK_ABI_NAMESPACE_END
872 #endif
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:50
a simple class to control print indentation
Definition: vtkIndent.h:38
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:61
represent surface properties of a geometric object
Definition: vtkProperty.h:66
MapOfTextures Textures
Definition: vtkProperty.h:819
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:818
double CoatRoughness
Definition: vtkProperty.h:786
~vtkProperty() override
double * GetColor()
Set the color of the object.
void SetRepresentationToPoints()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:161
double CoatNormalScale
Definition: vtkProperty.h:788
int LineStipplePattern
Definition: vtkProperty.h:801
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:162
virtual void SetInformation(vtkInformation *)
Set/Get the information object associated with the Property.
int LineStippleRepeatFactor
Definition: vtkProperty.h:802
double AnisotropyRotation
Definition: vtkProperty.h:782
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:790
double Diffuse
Definition: vtkProperty.h:778
void AddShaderVariable(const char *name, double v1, double v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:589
virtual void BackfaceRender(vtkActor *, vtkRenderer *)
This method renders the property as a backface property.
Definition: vtkProperty.h:99
static vtkProperty * New()
Construct object with object color, ambient color, diffuse color, specular color, and edge color whit...
double Opacity
Definition: vtkProperty.h:794
void SetNormalTexture(vtkTexture *texture)
Set the normal texture.
Definition: vtkProperty.h:678
int Representation
Definition: vtkProperty.h:804
float LineWidth
Definition: vtkProperty.h:798
int GetNumberOfTextures()
Returns the number of textures in this property.
double CoatStrength
Definition: vtkProperty.h:787
void SetEmissiveTexture(vtkTexture *texture)
Set the emissive texture.
Definition: vtkProperty.h:687
void SetInterpolationToFlat()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:148
void RemoveAllTextures()
Remove all the textures.
void SetBaseColorTexture(vtkTexture *texture)
Set the base color texture.
Definition: vtkProperty.h:645
double Metallic
Definition: vtkProperty.h:779
void SetCoatNormalTexture(vtkTexture *texture)
Set the coat normal texture.
Definition: vtkProperty.h:697
void SetInterpolationToGouraud()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:149
vtkTypeBool BackfaceCulling
Definition: vtkProperty.h:807
void DeepCopy(vtkProperty *p)
Assign one property to another.
int Interpolation
Definition: vtkProperty.h:803
double Anisotropy
Definition: vtkProperty.h:781
void AddShaderVariable(const char *name, double v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:578
void SetInterpolationToPBR()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:151
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:832
void SetRepresentationToSurface()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:163
void SetInterpolationToPhong()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:150
double Roughness
Definition: vtkProperty.h:780
double BaseIOR
Definition: vtkProperty.h:783
void AddShaderVariable(const char *name, double v1, double v2, double v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:604
bool RenderPointsAsSpheres
Definition: vtkProperty.h:810
vtkTypeBool Shading
Definition: vtkProperty.h:814
float PointSize
Definition: vtkProperty.h:797
void SetORMTexture(vtkTexture *texture)
Set the ORM texture.
Definition: vtkProperty.h:656
void AddShaderVariable(const char *name, int v1, int v2, int v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:594
virtual void SetColor(double r, double g, double b)
Set the color of the object.
vtkInformation * Information
Definition: vtkProperty.h:822
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:599
double Specular
Definition: vtkProperty.h:792
double NormalScale
Definition: vtkProperty.h:789
bool RenderLinesAsTubes
Definition: vtkProperty.h:811
virtual void ReleaseGraphicsResources(vtkWindow *win)
Release any graphics resources that are being consumed by this property.
vtkTypeBool EdgeVisibility
Definition: vtkProperty.h:805
vtkTypeBool VertexVisibility
Definition: vtkProperty.h:806
void AddShaderVariable(const char *name, int v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:576
double SpecularPower
Definition: vtkProperty.h:793
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:668
vtkTypeBool FrontfaceCulling
Definition: vtkProperty.h:808
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:584
bool ShowTexturesOnBackface
Definition: vtkProperty.h:812
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:777
double CoatIOR
Definition: vtkProperty.h:784
void AddShaderVariable(const char *name, int v1, int v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:579
const char * GetRepresentationAsString()
Return the method of shading as a descriptive character string.
Definition: vtkProperty.h:855
void AddShaderVariable(const char *name, float v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:577
char * MaterialName
Definition: vtkProperty.h:816
std::map< std::string, vtkTexture * > & GetAllTextures()
Returns all the textures in this property and their names.
Definition: vtkProperty.h:717
abstract specification for renderers
Definition: vtkRenderer.h:71
The ShaderProgram uses one or more Shader objects.
handles properties associated with a texture map
Definition: vtkTexture.h:67
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
Represents an XML element and those nested inside.
@ Color
Definition: vtkX3D.h:46
@ name
Definition: vtkX3D.h:219
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_POINTS
Definition: vtkProperty.h:49
#define VTK_WIREFRAME
Definition: vtkProperty.h:50
#define VTK_PHONG
Definition: vtkProperty.h:45
#define VTK_FLAT
Definition: vtkProperty.h:43
#define VTK_PBR
Definition: vtkProperty.h:46
#define VTK_SURFACE
Definition: vtkProperty.h:51
#define VTK_GOURAUD
Definition: vtkProperty.h:44
#define VTK_INT_MAX
Definition: vtkType.h:144
#define VTK_FLOAT_MAX
Definition: vtkType.h:152
#define VTK_SIZEHINT(...)