VTK  9.1.0
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 =========================================================================*/
140 #ifndef vtkProperty_h
141 #define vtkProperty_h
142 
143 #include "vtkObject.h"
144 #include "vtkRenderingCoreModule.h" // For export macro
145 #include <map> // used for ivar
146 #include <string> // used for ivar
147 
148 // shading models
149 #define VTK_FLAT 0
150 #define VTK_GOURAUD 1
151 #define VTK_PHONG 2
152 #define VTK_PBR 3
153 
154 // representation models
155 #define VTK_POINTS 0
156 #define VTK_WIREFRAME 1
157 #define VTK_SURFACE 2
158 
159 class vtkActor;
160 class vtkInformation;
161 class vtkRenderer;
162 class vtkShaderProgram;
163 class vtkTexture;
164 class vtkWindow;
165 class vtkXMLDataElement;
166 class vtkXMLMaterial;
167 
168 class vtkPropertyInternals;
169 
170 class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject
171 {
172 public:
173  vtkTypeMacro(vtkProperty, vtkObject);
174  void PrintSelf(ostream& os, vtkIndent indent) override;
175 
182  static vtkProperty* New();
183 
188 
196  virtual void Render(vtkActor*, vtkRenderer*);
197 
204  virtual void BackfaceRender(vtkActor*, vtkRenderer*) {}
205 
211  virtual void PostRender(vtkActor*, vtkRenderer*);
212 
214 
217  vtkGetMacro(Lighting, bool);
218  vtkSetMacro(Lighting, bool);
219  vtkBooleanMacro(Lighting, bool);
221 
223 
229  vtkGetMacro(RenderPointsAsSpheres, bool);
230  vtkSetMacro(RenderPointsAsSpheres, bool);
231  vtkBooleanMacro(RenderPointsAsSpheres, bool);
233 
235 
242  vtkGetMacro(RenderLinesAsTubes, bool);
243  vtkSetMacro(RenderLinesAsTubes, bool);
244  vtkBooleanMacro(RenderLinesAsTubes, bool);
246 
248 
251  vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PBR);
252  vtkGetMacro(Interpolation, int);
253  void SetInterpolationToFlat() { this->SetInterpolation(VTK_FLAT); }
254  void SetInterpolationToGouraud() { this->SetInterpolation(VTK_GOURAUD); }
255  void SetInterpolationToPhong() { this->SetInterpolation(VTK_PHONG); }
256  void SetInterpolationToPBR() { this->SetInterpolation(VTK_PBR); }
257  const char* GetInterpolationAsString();
259 
261 
264  vtkSetClampMacro(Representation, int, VTK_POINTS, VTK_SURFACE);
265  vtkGetMacro(Representation, int);
266  void SetRepresentationToPoints() { this->SetRepresentation(VTK_POINTS); }
267  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_WIREFRAME); }
268  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SURFACE); }
269  const char* GetRepresentationAsString();
271 
273 
278  virtual void SetColor(double r, double g, double b);
279  virtual void SetColor(double a[3]);
280  double* GetColor() VTK_SIZEHINT(3);
281  void GetColor(double rgb[3]);
282  void GetColor(double& r, double& g, double& b);
284 
286 
297  vtkSetClampMacro(BaseIOR, double, 1.0, VTK_FLOAT_MAX);
298  vtkGetMacro(BaseIOR, double);
300 
302 
308  vtkSetClampMacro(Metallic, double, 0.0, 1.0);
309  vtkGetMacro(Metallic, double);
311 
313 
320  vtkSetClampMacro(Roughness, double, 0.0, 1.0);
321  vtkGetMacro(Roughness, double);
323 
325 
331  vtkSetClampMacro(Anisotropy, double, 0.0, 1.0);
332  vtkGetMacro(Anisotropy, double);
334 
336 
342  vtkSetClampMacro(AnisotropyRotation, double, 0.0, 1.0);
343  vtkGetMacro(AnisotropyRotation, double);
345 
347 
352  vtkSetClampMacro(CoatIOR, double, 1.0, VTK_FLOAT_MAX);
353  vtkGetMacro(CoatIOR, double);
355 
357 
363  vtkSetClampMacro(CoatRoughness, double, 0.0, 1.0);
364  vtkGetMacro(CoatRoughness, double);
366 
368 
374  vtkSetClampMacro(CoatStrength, double, 0.0, 1.0);
375  vtkGetMacro(CoatStrength, double);
377 
379 
384  vtkSetVector3Macro(CoatColor, double);
385  vtkGetVector3Macro(CoatColor, double);
387 
389 
395  vtkSetClampMacro(CoatNormalScale, double, 0.0, 1.0);
396  vtkGetMacro(CoatNormalScale, double);
398 
400 
405  vtkSetMacro(NormalScale, double);
406  vtkGetMacro(NormalScale, double);
408 
410 
416  vtkSetClampMacro(OcclusionStrength, double, 0.0, 1.0);
417  vtkGetMacro(OcclusionStrength, double);
419 
421 
427  vtkSetVector3Macro(EmissiveFactor, double);
428  vtkGetVector3Macro(EmissiveFactor, double);
430 
432 
438  vtkSetVector3Macro(EdgeTint, double);
439  vtkGetVector3Macro(EdgeTint, double);
441 
443 
446  vtkSetClampMacro(Ambient, double, 0.0, 1.0);
447  vtkGetMacro(Ambient, double);
449 
451 
454  vtkSetClampMacro(Diffuse, double, 0.0, 1.0);
455  vtkGetMacro(Diffuse, double);
457 
459 
462  vtkSetClampMacro(Specular, double, 0.0, 1.0);
463  vtkGetMacro(Specular, double);
465 
467 
470  vtkSetClampMacro(SpecularPower, double, 0.0, 128.0);
471  vtkGetMacro(SpecularPower, double);
473 
475 
479  vtkSetClampMacro(Opacity, double, 0.0, 1.0);
480  vtkGetMacro(Opacity, double);
482 
484 
490  vtkSetVector3Macro(AmbientColor, double);
491  vtkGetVector3Macro(AmbientColor, double);
493 
495 
499  vtkSetVector3Macro(DiffuseColor, double);
500  vtkGetVector3Macro(DiffuseColor, double);
502 
504 
507  vtkSetVector3Macro(SpecularColor, double);
508  vtkGetVector3Macro(SpecularColor, double);
510 
512 
517  vtkGetMacro(EdgeVisibility, vtkTypeBool);
518  vtkSetMacro(EdgeVisibility, vtkTypeBool);
519  vtkBooleanMacro(EdgeVisibility, vtkTypeBool);
521 
523 
526  vtkSetVector3Macro(EdgeColor, double);
527  vtkGetVector3Macro(EdgeColor, double);
529 
531 
536  vtkGetMacro(VertexVisibility, vtkTypeBool);
537  vtkSetMacro(VertexVisibility, vtkTypeBool);
538  vtkBooleanMacro(VertexVisibility, vtkTypeBool);
540 
542 
545  vtkSetVector3Macro(VertexColor, double);
546  vtkGetVector3Macro(VertexColor, double);
548 
550 
554  vtkSetVector4Macro(SelectionColor, double);
555  vtkGetVector4Macro(SelectionColor, double);
557 
559 
563  vtkSetMacro(SelectionLineWidth, float);
564  vtkGetMacro(SelectionLineWidth, float);
566 
568 
572  vtkSetMacro(SelectionPointSize, float);
573  vtkGetMacro(SelectionPointSize, float);
575 
577 
581  vtkSetClampMacro(LineWidth, float, 0, VTK_FLOAT_MAX);
582  vtkGetMacro(LineWidth, float);
584 
586 
591  vtkSetMacro(LineStipplePattern, int);
592  vtkGetMacro(LineStipplePattern, int);
594 
596 
601  vtkSetClampMacro(LineStippleRepeatFactor, int, 1, VTK_INT_MAX);
602  vtkGetMacro(LineStippleRepeatFactor, int);
604 
606 
610  vtkSetClampMacro(PointSize, float, 0, VTK_FLOAT_MAX);
611  vtkGetMacro(PointSize, float);
613 
615 
620  vtkGetMacro(BackfaceCulling, vtkTypeBool);
621  vtkSetMacro(BackfaceCulling, vtkTypeBool);
622  vtkBooleanMacro(BackfaceCulling, vtkTypeBool);
624 
626 
631  vtkGetMacro(FrontfaceCulling, vtkTypeBool);
632  vtkSetMacro(FrontfaceCulling, vtkTypeBool);
633  vtkBooleanMacro(FrontfaceCulling, vtkTypeBool);
635 
637 
640  vtkSetStringMacro(MaterialName);
641  vtkGetStringMacro(MaterialName);
643 
645 
649  vtkSetMacro(Shading, vtkTypeBool);
650  vtkGetMacro(Shading, vtkTypeBool);
651  vtkBooleanMacro(Shading, vtkTypeBool);
653 
655 
663  virtual void AddShaderVariable(const char* name, int numVars, int* x);
664  virtual void AddShaderVariable(const char* name, int numVars, float* x);
665  virtual void AddShaderVariable(const char* name, int numVars, double* x);
667 
669 
672  void AddShaderVariable(const char* name, int v) { this->AddShaderVariable(name, 1, &v); }
673  void AddShaderVariable(const char* name, float v) { this->AddShaderVariable(name, 1, &v); }
674  void AddShaderVariable(const char* name, double v) { this->AddShaderVariable(name, 1, &v); }
675  void AddShaderVariable(const char* name, int v1, int v2)
676  {
677  int v[2] = { v1, v2 };
678  this->AddShaderVariable(name, 2, v);
679  }
680  void AddShaderVariable(const char* name, float v1, float v2)
681  {
682  float v[2] = { v1, v2 };
683  this->AddShaderVariable(name, 2, v);
684  }
685  void AddShaderVariable(const char* name, double v1, double v2)
686  {
687  double v[2] = { v1, v2 };
688  this->AddShaderVariable(name, 2, v);
689  }
690  void AddShaderVariable(const char* name, int v1, int v2, int v3)
691  {
692  int v[3] = { v1, v2, v3 };
693  this->AddShaderVariable(name, 3, v);
694  }
695  void AddShaderVariable(const char* name, float v1, float v2, float v3)
696  {
697  float v[3] = { v1, v2, v3 };
698  this->AddShaderVariable(name, 3, v);
699  }
700  void AddShaderVariable(const char* name, double v1, double v2, double v3)
701  {
702  double v[3] = { v1, v2, v3 };
703  this->AddShaderVariable(name, 3, v);
704  }
706 
708 
712  vtkSetMacro(ShowTexturesOnBackface, bool);
713  vtkGetMacro(ShowTexturesOnBackface, bool);
714  vtkBooleanMacro(ShowTexturesOnBackface, bool);
716 
718 
731  void SetTexture(const char* name, vtkTexture* texture);
732  vtkTexture* GetTexture(const char* name);
734 
741  void SetBaseColorTexture(vtkTexture* texture) { this->SetTexture("albedoTex", texture); }
742 
752  void SetORMTexture(vtkTexture* texture) { this->SetTexture("materialTex", texture); }
753 
764  void SetAnisotropyTexture(vtkTexture* texture) { this->SetTexture("anisotropyTex", texture); }
765 
774  void SetNormalTexture(vtkTexture* texture) { this->SetTexture("normalTex", texture); }
775 
783  void SetEmissiveTexture(vtkTexture* texture) { this->SetTexture("emissiveTex", texture); }
784 
793  void SetCoatNormalTexture(vtkTexture* texture) { this->SetTexture("coatNormalTex", texture); }
794 
798  void RemoveTexture(const char* name);
799 
804 
809 
813  std::map<std::string, vtkTexture*>& GetAllTextures() { return this->Textures; }
814 
821 
823 
826  vtkGetObjectMacro(Information, vtkInformation);
829 
831 
835  static double ComputeReflectanceFromIOR(double IORTo, double IORFrom);
837 
839 
843  static double ComputeIORFromReflectance(double reflectance, double ior);
845 
847 
855 
856 protected:
858  ~vtkProperty() override;
859 
863  static void ComputeCompositeColor(double result[3], double ambient, const double ambient_color[3],
864  double diffuse, const double diffuse_color[3], double specular, const double specular_color[3]);
865 
866  double Color[3];
867  double AmbientColor[3];
868  double DiffuseColor[3];
869  double SpecularColor[3];
870  double EdgeColor[3];
871  double VertexColor[3];
872  double SelectionColor[4] = { 1.0, 0.0, 0.0, 1.0 };
873  double Ambient;
874  double Diffuse;
875  double Metallic;
876  double Roughness;
877  double Anisotropy;
879  double BaseIOR;
880  double CoatIOR;
881  double CoatColor[3];
883  double CoatStrength;
885  double NormalScale;
887  double EmissiveFactor[3];
888  double Specular;
890  double Opacity;
891  double EdgeTint[3];
892  float PointSize;
893  float LineWidth;
894  float SelectionPointSize = 2.f;
895  float SelectionLineWidth = 2.f;
904  bool Lighting;
908 
910 
912 
913  typedef std::map<std::string, vtkTexture*> MapOfTextures;
915 
916  // Arbitrary extra information associated with this Property.
918 
919 private:
920  vtkProperty(const vtkProperty&) = delete;
921  void operator=(const vtkProperty&) = delete;
922 };
923 
928 {
929  if (this->Interpolation == VTK_FLAT)
930  {
931  return "Flat";
932  }
933  else if (this->Interpolation == VTK_GOURAUD)
934  {
935  return "Gouraud";
936  }
937  else if (this->Interpolation == VTK_PHONG)
938  {
939  return "Phong";
940  }
941  else // if (this->Interpolation == VTK_PBR)
942  {
943  return "Physically based rendering";
944  }
945 }
946 
951 {
952  if (this->Representation == VTK_POINTS)
953  {
954  return "Points";
955  }
956  else if (this->Representation == VTK_WIREFRAME)
957  {
958  return "Wireframe";
959  }
960  else
961  {
962  return "Surface";
963  }
964 }
965 
966 #endif
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:155
a simple class to control print indentation
Definition: vtkIndent.h:113
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:73
represent surface properties of a geometric object
Definition: vtkProperty.h:171
MapOfTextures Textures
Definition: vtkProperty.h:914
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:913
double CoatRoughness
Definition: vtkProperty.h:882
~vtkProperty() override
double * GetColor()
Set the color of the object.
void SetRepresentationToPoints()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:266
double CoatNormalScale
Definition: vtkProperty.h:884
int LineStipplePattern
Definition: vtkProperty.h:896
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:267
virtual void SetInformation(vtkInformation *)
Set/Get the information object associated with the Property.
int LineStippleRepeatFactor
Definition: vtkProperty.h:897
double AnisotropyRotation
Definition: vtkProperty.h:878
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:886
double Diffuse
Definition: vtkProperty.h:874
void AddShaderVariable(const char *name, double v1, double v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:685
virtual void BackfaceRender(vtkActor *, vtkRenderer *)
This method renders the property as a backface property.
Definition: vtkProperty.h:204
static vtkProperty * New()
Construct object with object color, ambient color, diffuse color, specular color, and edge color whit...
double Opacity
Definition: vtkProperty.h:890
void SetNormalTexture(vtkTexture *texture)
Set the normal texture.
Definition: vtkProperty.h:774
int Representation
Definition: vtkProperty.h:899
float LineWidth
Definition: vtkProperty.h:893
int GetNumberOfTextures()
Returns the number of textures in this property.
double CoatStrength
Definition: vtkProperty.h:883
void SetEmissiveTexture(vtkTexture *texture)
Set the emissive texture.
Definition: vtkProperty.h:783
void SetInterpolationToFlat()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:253
void RemoveAllTextures()
Remove all the textures.
void SetBaseColorTexture(vtkTexture *texture)
Set the base color texture.
Definition: vtkProperty.h:741
double Metallic
Definition: vtkProperty.h:875
void SetCoatNormalTexture(vtkTexture *texture)
Set the coat normal texture.
Definition: vtkProperty.h:793
void SetInterpolationToGouraud()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:254
vtkTypeBool BackfaceCulling
Definition: vtkProperty.h:902
void DeepCopy(vtkProperty *p)
Assign one property to another.
int Interpolation
Definition: vtkProperty.h:898
double Anisotropy
Definition: vtkProperty.h:877
void AddShaderVariable(const char *name, double v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:674
void SetInterpolationToPBR()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:256
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:927
void SetRepresentationToSurface()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:268
void SetInterpolationToPhong()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:255
double Roughness
Definition: vtkProperty.h:876
double BaseIOR
Definition: vtkProperty.h:879
void AddShaderVariable(const char *name, double v1, double v2, double v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:700
bool RenderPointsAsSpheres
Definition: vtkProperty.h:905
vtkTypeBool Shading
Definition: vtkProperty.h:909
float PointSize
Definition: vtkProperty.h:892
void SetORMTexture(vtkTexture *texture)
Set the ORM texture.
Definition: vtkProperty.h:752
void AddShaderVariable(const char *name, int v1, int v2, int v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:690
virtual void SetColor(double r, double g, double b)
Set the color of the object.
vtkInformation * Information
Definition: vtkProperty.h:917
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:695
double Specular
Definition: vtkProperty.h:888
double NormalScale
Definition: vtkProperty.h:885
bool RenderLinesAsTubes
Definition: vtkProperty.h:906
virtual void ReleaseGraphicsResources(vtkWindow *win)
Release any graphics resources that are being consumed by this property.
vtkTypeBool EdgeVisibility
Definition: vtkProperty.h:900
vtkTypeBool VertexVisibility
Definition: vtkProperty.h:901
void AddShaderVariable(const char *name, int v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:672
double SpecularPower
Definition: vtkProperty.h:889
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:764
vtkTypeBool FrontfaceCulling
Definition: vtkProperty.h:903
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:680
bool ShowTexturesOnBackface
Definition: vtkProperty.h:907
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:873
double CoatIOR
Definition: vtkProperty.h:880
void AddShaderVariable(const char *name, int v1, int v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:675
const char * GetRepresentationAsString()
Return the method of shading as a descriptive character string.
Definition: vtkProperty.h:950
void AddShaderVariable(const char *name, float v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:673
char * MaterialName
Definition: vtkProperty.h:911
std::map< std::string, vtkTexture * > & GetAllTextures()
Returns all the textures in this property and their names.
Definition: vtkProperty.h:813
abstract specification for renderers
Definition: vtkRenderer.h:173
The ShaderProgram uses one or more Shader objects.
handles properties associated with a texture map
Definition: vtkTexture.h:175
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
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:155
#define VTK_WIREFRAME
Definition: vtkProperty.h:156
#define VTK_PHONG
Definition: vtkProperty.h:151
#define VTK_FLAT
Definition: vtkProperty.h:149
#define VTK_PBR
Definition: vtkProperty.h:152
#define VTK_SURFACE
Definition: vtkProperty.h:157
#define VTK_GOURAUD
Definition: vtkProperty.h:150
#define VTK_INT_MAX
Definition: vtkType.h:155
#define VTK_FLOAT_MAX
Definition: vtkType.h:163
#define VTK_SIZEHINT(...)