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
25 #ifndef vtkProperty_h
26 #define vtkProperty_h
27 
28 #include "vtkObject.h"
29 #include "vtkRenderingCoreModule.h" // For export macro
30 #include <map> // used for ivar
31 #include <string> // used for ivar
32 
33 // shading models
34 #define VTK_FLAT 0
35 #define VTK_GOURAUD 1
36 #define VTK_PHONG 2
37 #define VTK_PBR 3
38 
39 // representation models
40 #define VTK_POINTS 0
41 #define VTK_WIREFRAME 1
42 #define VTK_SURFACE 2
43 
44 VTK_ABI_NAMESPACE_BEGIN
45 class vtkActor;
46 class vtkInformation;
47 class vtkRenderer;
48 class vtkShaderProgram;
49 class vtkTexture;
50 class vtkWindow;
51 class vtkXMLDataElement;
52 class vtkXMLMaterial;
53 
54 class vtkPropertyInternals;
55 
56 class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject
57 {
58 public:
59  vtkTypeMacro(vtkProperty, vtkObject);
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
68  static vtkProperty* New();
69 
74 
82  virtual void Render(vtkActor*, vtkRenderer*);
83 
90  virtual void BackfaceRender(vtkActor*, vtkRenderer*) {}
91 
97  virtual void PostRender(vtkActor*, vtkRenderer*);
98 
100 
103  vtkGetMacro(Lighting, bool);
104  vtkSetMacro(Lighting, bool);
105  vtkBooleanMacro(Lighting, bool);
107 
109 
115  vtkGetMacro(RenderPointsAsSpheres, bool);
116  vtkSetMacro(RenderPointsAsSpheres, bool);
117  vtkBooleanMacro(RenderPointsAsSpheres, bool);
119 
121 
128  vtkGetMacro(RenderLinesAsTubes, bool);
129  vtkSetMacro(RenderLinesAsTubes, bool);
130  vtkBooleanMacro(RenderLinesAsTubes, bool);
132 
134 
137  vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PBR);
138  vtkGetMacro(Interpolation, int);
139  void SetInterpolationToFlat() { this->SetInterpolation(VTK_FLAT); }
140  void SetInterpolationToGouraud() { this->SetInterpolation(VTK_GOURAUD); }
141  void SetInterpolationToPhong() { this->SetInterpolation(VTK_PHONG); }
142  void SetInterpolationToPBR() { this->SetInterpolation(VTK_PBR); }
143  const char* GetInterpolationAsString();
145 
147 
150  vtkSetClampMacro(Representation, int, VTK_POINTS, VTK_SURFACE);
151  vtkGetMacro(Representation, int);
152  void SetRepresentationToPoints() { this->SetRepresentation(VTK_POINTS); }
153  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_WIREFRAME); }
154  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SURFACE); }
155  const char* GetRepresentationAsString();
157 
159 
164  virtual void SetColor(double r, double g, double b);
165  virtual void SetColor(double a[3]);
166  double* GetColor() VTK_SIZEHINT(3);
167  void GetColor(double rgb[3]);
168  void GetColor(double& r, double& g, double& b);
170 
172 
183  vtkSetClampMacro(BaseIOR, double, 1.0, VTK_FLOAT_MAX);
184  vtkGetMacro(BaseIOR, double);
186 
188 
194  vtkSetClampMacro(Metallic, double, 0.0, 1.0);
195  vtkGetMacro(Metallic, double);
197 
199 
206  vtkSetClampMacro(Roughness, double, 0.0, 1.0);
207  vtkGetMacro(Roughness, double);
209 
211 
217  vtkSetClampMacro(Anisotropy, double, 0.0, 1.0);
218  vtkGetMacro(Anisotropy, double);
220 
222 
228  vtkSetClampMacro(AnisotropyRotation, double, 0.0, 1.0);
229  vtkGetMacro(AnisotropyRotation, double);
231 
233 
238  vtkSetClampMacro(CoatIOR, double, 1.0, VTK_FLOAT_MAX);
239  vtkGetMacro(CoatIOR, double);
241 
243 
249  vtkSetClampMacro(CoatRoughness, double, 0.0, 1.0);
250  vtkGetMacro(CoatRoughness, double);
252 
254 
260  vtkSetClampMacro(CoatStrength, double, 0.0, 1.0);
261  vtkGetMacro(CoatStrength, double);
263 
265 
270  vtkSetVector3Macro(CoatColor, double);
271  vtkGetVector3Macro(CoatColor, double);
273 
275 
281  vtkSetClampMacro(CoatNormalScale, double, 0.0, 1.0);
282  vtkGetMacro(CoatNormalScale, double);
284 
286 
291  vtkSetMacro(NormalScale, double);
292  vtkGetMacro(NormalScale, double);
294 
296 
302  vtkSetClampMacro(OcclusionStrength, double, 0.0, 1.0);
303  vtkGetMacro(OcclusionStrength, double);
305 
307 
313  vtkSetVector3Macro(EmissiveFactor, double);
314  vtkGetVector3Macro(EmissiveFactor, double);
316 
318 
324  vtkSetVector3Macro(EdgeTint, double);
325  vtkGetVector3Macro(EdgeTint, double);
327 
329 
332  vtkSetClampMacro(Ambient, double, 0.0, 1.0);
333  vtkGetMacro(Ambient, double);
335 
337 
340  vtkSetClampMacro(Diffuse, double, 0.0, 1.0);
341  vtkGetMacro(Diffuse, double);
343 
345 
348  vtkSetClampMacro(Specular, double, 0.0, 1.0);
349  vtkGetMacro(Specular, double);
351 
353 
356  vtkSetClampMacro(SpecularPower, double, 0.0, 128.0);
357  vtkGetMacro(SpecularPower, double);
359 
361 
365  vtkSetClampMacro(Opacity, double, 0.0, 1.0);
366  vtkGetMacro(Opacity, double);
368 
370 
374  vtkSetClampMacro(EdgeOpacity, double, 0.0, 1.0);
375  vtkGetMacro(EdgeOpacity, double);
377 
379 
385  vtkSetVector3Macro(AmbientColor, double);
386  vtkGetVector3Macro(AmbientColor, double);
388 
390 
394  vtkSetVector3Macro(DiffuseColor, double);
395  vtkGetVector3Macro(DiffuseColor, double);
397 
399 
402  vtkSetVector3Macro(SpecularColor, double);
403  vtkGetVector3Macro(SpecularColor, double);
405 
407 
412  vtkGetMacro(EdgeVisibility, vtkTypeBool);
413  vtkSetMacro(EdgeVisibility, vtkTypeBool);
414  vtkBooleanMacro(EdgeVisibility, vtkTypeBool);
416 
418 
421  vtkSetVector3Macro(EdgeColor, double);
422  vtkGetVector3Macro(EdgeColor, double);
424 
426 
431  vtkGetMacro(VertexVisibility, vtkTypeBool);
432  vtkSetMacro(VertexVisibility, vtkTypeBool);
433  vtkBooleanMacro(VertexVisibility, vtkTypeBool);
435 
437 
440  vtkSetVector3Macro(VertexColor, double);
441  vtkGetVector3Macro(VertexColor, double);
443 
445 
449  vtkSetVector4Macro(SelectionColor, double);
450  vtkGetVector4Macro(SelectionColor, double);
452 
454 
458  vtkSetMacro(SelectionLineWidth, float);
459  vtkGetMacro(SelectionLineWidth, float);
461 
463 
467  vtkSetMacro(SelectionPointSize, float);
468  vtkGetMacro(SelectionPointSize, float);
470 
472 
476  vtkSetClampMacro(LineWidth, float, 0, VTK_FLOAT_MAX);
477  vtkGetMacro(LineWidth, float);
479 
481 
486  vtkSetMacro(LineStipplePattern, int);
487  vtkGetMacro(LineStipplePattern, int);
489 
491 
496  vtkSetClampMacro(LineStippleRepeatFactor, int, 1, VTK_INT_MAX);
497  vtkGetMacro(LineStippleRepeatFactor, int);
499 
501 
505  vtkSetClampMacro(PointSize, float, 0, VTK_FLOAT_MAX);
506  vtkGetMacro(PointSize, float);
508 
510 
515  vtkGetMacro(BackfaceCulling, vtkTypeBool);
516  vtkSetMacro(BackfaceCulling, vtkTypeBool);
517  vtkBooleanMacro(BackfaceCulling, vtkTypeBool);
519 
521 
526  vtkGetMacro(FrontfaceCulling, vtkTypeBool);
527  vtkSetMacro(FrontfaceCulling, vtkTypeBool);
528  vtkBooleanMacro(FrontfaceCulling, vtkTypeBool);
530 
532 
535  vtkSetStringMacro(MaterialName);
536  vtkGetStringMacro(MaterialName);
538 
540 
544  vtkSetMacro(Shading, vtkTypeBool);
545  vtkGetMacro(Shading, vtkTypeBool);
546  vtkBooleanMacro(Shading, vtkTypeBool);
548 
550 
558  virtual void AddShaderVariable(const char* name, int numVars, int* x);
559  virtual void AddShaderVariable(const char* name, int numVars, float* x);
560  virtual void AddShaderVariable(const char* name, int numVars, double* x);
562 
564 
567  void AddShaderVariable(const char* name, int v) { this->AddShaderVariable(name, 1, &v); }
568  void AddShaderVariable(const char* name, float v) { this->AddShaderVariable(name, 1, &v); }
569  void AddShaderVariable(const char* name, double v) { this->AddShaderVariable(name, 1, &v); }
570  void AddShaderVariable(const char* name, int v1, int v2)
571  {
572  int v[2] = { v1, v2 };
573  this->AddShaderVariable(name, 2, v);
574  }
575  void AddShaderVariable(const char* name, float v1, float v2)
576  {
577  float v[2] = { v1, v2 };
578  this->AddShaderVariable(name, 2, v);
579  }
580  void AddShaderVariable(const char* name, double v1, double v2)
581  {
582  double v[2] = { v1, v2 };
583  this->AddShaderVariable(name, 2, v);
584  }
585  void AddShaderVariable(const char* name, int v1, int v2, int v3)
586  {
587  int v[3] = { v1, v2, v3 };
588  this->AddShaderVariable(name, 3, v);
589  }
590  void AddShaderVariable(const char* name, float v1, float v2, float v3)
591  {
592  float v[3] = { v1, v2, v3 };
593  this->AddShaderVariable(name, 3, v);
594  }
595  void AddShaderVariable(const char* name, double v1, double v2, double v3)
596  {
597  double v[3] = { v1, v2, v3 };
598  this->AddShaderVariable(name, 3, v);
599  }
601 
603 
607  vtkSetMacro(ShowTexturesOnBackface, bool);
608  vtkGetMacro(ShowTexturesOnBackface, bool);
609  vtkBooleanMacro(ShowTexturesOnBackface, bool);
611 
613 
626  void SetTexture(const char* name, vtkTexture* texture);
627  vtkTexture* GetTexture(const char* name);
629 
636  void SetBaseColorTexture(vtkTexture* texture) { this->SetTexture("albedoTex", texture); }
637 
647  void SetORMTexture(vtkTexture* texture) { this->SetTexture("materialTex", texture); }
648 
659  void SetAnisotropyTexture(vtkTexture* texture) { this->SetTexture("anisotropyTex", texture); }
660 
669  void SetNormalTexture(vtkTexture* texture) { this->SetTexture("normalTex", texture); }
670 
678  void SetEmissiveTexture(vtkTexture* texture) { this->SetTexture("emissiveTex", texture); }
679 
688  void SetCoatNormalTexture(vtkTexture* texture) { this->SetTexture("coatNormalTex", texture); }
689 
693  void RemoveTexture(const char* name);
694 
699 
704 
708  std::map<std::string, vtkTexture*>& GetAllTextures() { return this->Textures; }
709 
716 
718 
721  vtkGetObjectMacro(Information, vtkInformation);
724 
726 
730  static double ComputeReflectanceFromIOR(double IORTo, double IORFrom);
732 
734 
738  static double ComputeIORFromReflectance(double reflectance, double ior);
740 
742 
750 
751 protected:
753  ~vtkProperty() override;
754 
758  static void ComputeCompositeColor(double result[3], double ambient, const double ambient_color[3],
759  double diffuse, const double diffuse_color[3], double specular, const double specular_color[3]);
760 
761  double Color[3];
762  double AmbientColor[3];
763  double DiffuseColor[3];
764  double SpecularColor[3];
765  double EdgeColor[3];
766  double VertexColor[3];
767  double SelectionColor[4] = { 1.0, 0.0, 0.0, 1.0 };
768  double Ambient;
769  double Diffuse;
770  double Metallic;
771  double Roughness;
772  double Anisotropy;
774  double BaseIOR;
775  double CoatIOR;
776  double CoatColor[3];
778  double CoatStrength;
780  double NormalScale;
782  double EmissiveFactor[3];
783  double Specular;
785  double Opacity;
786  double EdgeOpacity = 1.0;
787  double EdgeTint[3];
788  float PointSize;
789  float LineWidth;
790  float SelectionPointSize = 2.f;
791  float SelectionLineWidth = 2.f;
800  bool Lighting;
804 
806 
808 
809  typedef std::map<std::string, vtkTexture*> MapOfTextures;
811 
812  // Arbitrary extra information associated with this Property.
814 
815 private:
816  vtkProperty(const vtkProperty&) = delete;
817  void operator=(const vtkProperty&) = delete;
818 };
819 
824 {
825  if (this->Interpolation == VTK_FLAT)
826  {
827  return "Flat";
828  }
829  else if (this->Interpolation == VTK_GOURAUD)
830  {
831  return "Gouraud";
832  }
833  else if (this->Interpolation == VTK_PHONG)
834  {
835  return "Phong";
836  }
837  else // if (this->Interpolation == VTK_PBR)
838  {
839  return "Physically based rendering";
840  }
841 }
842 
847 {
848  if (this->Representation == VTK_POINTS)
849  {
850  return "Points";
851  }
852  else if (this->Representation == VTK_WIREFRAME)
853  {
854  return "Wireframe";
855  }
856  else
857  {
858  return "Surface";
859  }
860 }
861 
862 VTK_ABI_NAMESPACE_END
863 #endif
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
a simple class to control print indentation
Definition: vtkIndent.h:29
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:52
represent surface properties of a geometric object
Definition: vtkProperty.h:57
MapOfTextures Textures
Definition: vtkProperty.h:810
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:809
double CoatRoughness
Definition: vtkProperty.h:777
~vtkProperty() override
double * GetColor()
Set the color of the object.
void SetRepresentationToPoints()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:152
double CoatNormalScale
Definition: vtkProperty.h:779
int LineStipplePattern
Definition: vtkProperty.h:792
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:153
virtual void SetInformation(vtkInformation *)
Set/Get the information object associated with the Property.
int LineStippleRepeatFactor
Definition: vtkProperty.h:793
double AnisotropyRotation
Definition: vtkProperty.h:773
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:781
double Diffuse
Definition: vtkProperty.h:769
void AddShaderVariable(const char *name, double v1, double v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:580
virtual void BackfaceRender(vtkActor *, vtkRenderer *)
This method renders the property as a backface property.
Definition: vtkProperty.h:90
static vtkProperty * New()
Construct object with object color, ambient color, diffuse color, specular color, and edge color whit...
double Opacity
Definition: vtkProperty.h:785
void SetNormalTexture(vtkTexture *texture)
Set the normal texture.
Definition: vtkProperty.h:669
int Representation
Definition: vtkProperty.h:795
float LineWidth
Definition: vtkProperty.h:789
int GetNumberOfTextures()
Returns the number of textures in this property.
double CoatStrength
Definition: vtkProperty.h:778
void SetEmissiveTexture(vtkTexture *texture)
Set the emissive texture.
Definition: vtkProperty.h:678
void SetInterpolationToFlat()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:139
void RemoveAllTextures()
Remove all the textures.
void SetBaseColorTexture(vtkTexture *texture)
Set the base color texture.
Definition: vtkProperty.h:636
double Metallic
Definition: vtkProperty.h:770
void SetCoatNormalTexture(vtkTexture *texture)
Set the coat normal texture.
Definition: vtkProperty.h:688
void SetInterpolationToGouraud()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:140
vtkTypeBool BackfaceCulling
Definition: vtkProperty.h:798
void DeepCopy(vtkProperty *p)
Assign one property to another.
int Interpolation
Definition: vtkProperty.h:794
double Anisotropy
Definition: vtkProperty.h:772
void AddShaderVariable(const char *name, double v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:569
void SetInterpolationToPBR()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:142
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:823
void SetRepresentationToSurface()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:154
void SetInterpolationToPhong()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:141
double Roughness
Definition: vtkProperty.h:771
double BaseIOR
Definition: vtkProperty.h:774
void AddShaderVariable(const char *name, double v1, double v2, double v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:595
bool RenderPointsAsSpheres
Definition: vtkProperty.h:801
vtkTypeBool Shading
Definition: vtkProperty.h:805
float PointSize
Definition: vtkProperty.h:788
void SetORMTexture(vtkTexture *texture)
Set the ORM texture.
Definition: vtkProperty.h:647
void AddShaderVariable(const char *name, int v1, int v2, int v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:585
virtual void SetColor(double r, double g, double b)
Set the color of the object.
vtkInformation * Information
Definition: vtkProperty.h:813
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:590
double Specular
Definition: vtkProperty.h:783
double NormalScale
Definition: vtkProperty.h:780
bool RenderLinesAsTubes
Definition: vtkProperty.h:802
virtual void ReleaseGraphicsResources(vtkWindow *win)
Release any graphics resources that are being consumed by this property.
vtkTypeBool EdgeVisibility
Definition: vtkProperty.h:796
vtkTypeBool VertexVisibility
Definition: vtkProperty.h:797
void AddShaderVariable(const char *name, int v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:567
double SpecularPower
Definition: vtkProperty.h:784
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:659
vtkTypeBool FrontfaceCulling
Definition: vtkProperty.h:799
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:575
bool ShowTexturesOnBackface
Definition: vtkProperty.h:803
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:768
double CoatIOR
Definition: vtkProperty.h:775
void AddShaderVariable(const char *name, int v1, int v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:570
const char * GetRepresentationAsString()
Return the method of shading as a descriptive character string.
Definition: vtkProperty.h:846
void AddShaderVariable(const char *name, float v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:568
char * MaterialName
Definition: vtkProperty.h:807
std::map< std::string, vtkTexture * > & GetAllTextures()
Returns all the textures in this property and their names.
Definition: vtkProperty.h:708
abstract specification for renderers
Definition: vtkRenderer.h:62
The ShaderProgram uses one or more Shader objects.
handles properties associated with a texture map
Definition: vtkTexture.h:58
window superclass for vtkRenderWindow
Definition: vtkWindow.h:28
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:40
#define VTK_WIREFRAME
Definition: vtkProperty.h:41
#define VTK_PHONG
Definition: vtkProperty.h:36
#define VTK_FLAT
Definition: vtkProperty.h:34
#define VTK_PBR
Definition: vtkProperty.h:37
#define VTK_SURFACE
Definition: vtkProperty.h:42
#define VTK_GOURAUD
Definition: vtkProperty.h:35
#define VTK_INT_MAX
Definition: vtkType.h:144
#define VTK_FLOAT_MAX
Definition: vtkType.h:152
#define VTK_SIZEHINT(...)