VTK  9.2.5
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 =========================================================================*/
146 #ifndef vtkProperty_h
147 #define vtkProperty_h
148 
149 #include "vtkObject.h"
150 #include "vtkRenderingCoreModule.h" // For export macro
151 #include <map> // used for ivar
152 #include <string> // used for ivar
153 
154 // shading models
155 #define VTK_FLAT 0
156 #define VTK_GOURAUD 1
157 #define VTK_PHONG 2
158 #define VTK_PBR 3
159 
160 // representation models
161 #define VTK_POINTS 0
162 #define VTK_WIREFRAME 1
163 #define VTK_SURFACE 2
164 
165 class vtkActor;
166 class vtkInformation;
167 class vtkRenderer;
168 class vtkShaderProgram;
169 class vtkTexture;
170 class vtkWindow;
171 class vtkXMLDataElement;
172 class vtkXMLMaterial;
173 
174 class vtkPropertyInternals;
175 
176 class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject
177 {
178 public:
179  vtkTypeMacro(vtkProperty, vtkObject);
180  void PrintSelf(ostream& os, vtkIndent indent) override;
181 
188  static vtkProperty* New();
189 
194 
202  virtual void Render(vtkActor*, vtkRenderer*);
203 
210  virtual void BackfaceRender(vtkActor*, vtkRenderer*) {}
211 
217  virtual void PostRender(vtkActor*, vtkRenderer*);
218 
220 
223  vtkGetMacro(Lighting, bool);
224  vtkSetMacro(Lighting, bool);
225  vtkBooleanMacro(Lighting, bool);
227 
229 
235  vtkGetMacro(RenderPointsAsSpheres, bool);
236  vtkSetMacro(RenderPointsAsSpheres, bool);
237  vtkBooleanMacro(RenderPointsAsSpheres, bool);
239 
241 
248  vtkGetMacro(RenderLinesAsTubes, bool);
249  vtkSetMacro(RenderLinesAsTubes, bool);
250  vtkBooleanMacro(RenderLinesAsTubes, bool);
252 
254 
257  vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PBR);
258  vtkGetMacro(Interpolation, int);
259  void SetInterpolationToFlat() { this->SetInterpolation(VTK_FLAT); }
260  void SetInterpolationToGouraud() { this->SetInterpolation(VTK_GOURAUD); }
261  void SetInterpolationToPhong() { this->SetInterpolation(VTK_PHONG); }
262  void SetInterpolationToPBR() { this->SetInterpolation(VTK_PBR); }
263  const char* GetInterpolationAsString();
265 
267 
270  vtkSetClampMacro(Representation, int, VTK_POINTS, VTK_SURFACE);
271  vtkGetMacro(Representation, int);
272  void SetRepresentationToPoints() { this->SetRepresentation(VTK_POINTS); }
273  void SetRepresentationToWireframe() { this->SetRepresentation(VTK_WIREFRAME); }
274  void SetRepresentationToSurface() { this->SetRepresentation(VTK_SURFACE); }
275  const char* GetRepresentationAsString();
277 
279 
284  virtual void SetColor(double r, double g, double b);
285  virtual void SetColor(double a[3]);
286  double* GetColor() VTK_SIZEHINT(3);
287  void GetColor(double rgb[3]);
288  void GetColor(double& r, double& g, double& b);
290 
292 
303  vtkSetClampMacro(BaseIOR, double, 1.0, VTK_FLOAT_MAX);
304  vtkGetMacro(BaseIOR, double);
306 
308 
314  vtkSetClampMacro(Metallic, double, 0.0, 1.0);
315  vtkGetMacro(Metallic, double);
317 
319 
326  vtkSetClampMacro(Roughness, double, 0.0, 1.0);
327  vtkGetMacro(Roughness, double);
329 
331 
337  vtkSetClampMacro(Anisotropy, double, 0.0, 1.0);
338  vtkGetMacro(Anisotropy, double);
340 
342 
348  vtkSetClampMacro(AnisotropyRotation, double, 0.0, 1.0);
349  vtkGetMacro(AnisotropyRotation, double);
351 
353 
358  vtkSetClampMacro(CoatIOR, double, 1.0, VTK_FLOAT_MAX);
359  vtkGetMacro(CoatIOR, double);
361 
363 
369  vtkSetClampMacro(CoatRoughness, double, 0.0, 1.0);
370  vtkGetMacro(CoatRoughness, double);
372 
374 
380  vtkSetClampMacro(CoatStrength, double, 0.0, 1.0);
381  vtkGetMacro(CoatStrength, double);
383 
385 
390  vtkSetVector3Macro(CoatColor, double);
391  vtkGetVector3Macro(CoatColor, double);
393 
395 
401  vtkSetClampMacro(CoatNormalScale, double, 0.0, 1.0);
402  vtkGetMacro(CoatNormalScale, double);
404 
406 
411  vtkSetMacro(NormalScale, double);
412  vtkGetMacro(NormalScale, double);
414 
416 
422  vtkSetClampMacro(OcclusionStrength, double, 0.0, 1.0);
423  vtkGetMacro(OcclusionStrength, double);
425 
427 
433  vtkSetVector3Macro(EmissiveFactor, double);
434  vtkGetVector3Macro(EmissiveFactor, double);
436 
438 
444  vtkSetVector3Macro(EdgeTint, double);
445  vtkGetVector3Macro(EdgeTint, double);
447 
449 
452  vtkSetClampMacro(Ambient, double, 0.0, 1.0);
453  vtkGetMacro(Ambient, double);
455 
457 
460  vtkSetClampMacro(Diffuse, double, 0.0, 1.0);
461  vtkGetMacro(Diffuse, double);
463 
465 
468  vtkSetClampMacro(Specular, double, 0.0, 1.0);
469  vtkGetMacro(Specular, double);
471 
473 
476  vtkSetClampMacro(SpecularPower, double, 0.0, 128.0);
477  vtkGetMacro(SpecularPower, double);
479 
481 
485  vtkSetClampMacro(Opacity, double, 0.0, 1.0);
486  vtkGetMacro(Opacity, double);
488 
490 
496  vtkSetVector3Macro(AmbientColor, double);
497  vtkGetVector3Macro(AmbientColor, double);
499 
501 
505  vtkSetVector3Macro(DiffuseColor, double);
506  vtkGetVector3Macro(DiffuseColor, double);
508 
510 
513  vtkSetVector3Macro(SpecularColor, double);
514  vtkGetVector3Macro(SpecularColor, double);
516 
518 
523  vtkGetMacro(EdgeVisibility, vtkTypeBool);
524  vtkSetMacro(EdgeVisibility, vtkTypeBool);
525  vtkBooleanMacro(EdgeVisibility, vtkTypeBool);
527 
529 
532  vtkSetVector3Macro(EdgeColor, double);
533  vtkGetVector3Macro(EdgeColor, double);
535 
537 
542  vtkGetMacro(VertexVisibility, vtkTypeBool);
543  vtkSetMacro(VertexVisibility, vtkTypeBool);
544  vtkBooleanMacro(VertexVisibility, vtkTypeBool);
546 
548 
551  vtkSetVector3Macro(VertexColor, double);
552  vtkGetVector3Macro(VertexColor, double);
554 
556 
560  vtkSetVector4Macro(SelectionColor, double);
561  vtkGetVector4Macro(SelectionColor, double);
563 
565 
569  vtkSetMacro(SelectionLineWidth, float);
570  vtkGetMacro(SelectionLineWidth, float);
572 
574 
578  vtkSetMacro(SelectionPointSize, float);
579  vtkGetMacro(SelectionPointSize, float);
581 
583 
587  vtkSetClampMacro(LineWidth, float, 0, VTK_FLOAT_MAX);
588  vtkGetMacro(LineWidth, float);
590 
592 
597  vtkSetMacro(LineStipplePattern, int);
598  vtkGetMacro(LineStipplePattern, int);
600 
602 
607  vtkSetClampMacro(LineStippleRepeatFactor, int, 1, VTK_INT_MAX);
608  vtkGetMacro(LineStippleRepeatFactor, int);
610 
612 
616  vtkSetClampMacro(PointSize, float, 0, VTK_FLOAT_MAX);
617  vtkGetMacro(PointSize, float);
619 
621 
626  vtkGetMacro(BackfaceCulling, vtkTypeBool);
627  vtkSetMacro(BackfaceCulling, vtkTypeBool);
628  vtkBooleanMacro(BackfaceCulling, vtkTypeBool);
630 
632 
637  vtkGetMacro(FrontfaceCulling, vtkTypeBool);
638  vtkSetMacro(FrontfaceCulling, vtkTypeBool);
639  vtkBooleanMacro(FrontfaceCulling, vtkTypeBool);
641 
643 
646  vtkSetStringMacro(MaterialName);
647  vtkGetStringMacro(MaterialName);
649 
651 
655  vtkSetMacro(Shading, vtkTypeBool);
656  vtkGetMacro(Shading, vtkTypeBool);
657  vtkBooleanMacro(Shading, vtkTypeBool);
659 
661 
669  virtual void AddShaderVariable(const char* name, int numVars, int* x);
670  virtual void AddShaderVariable(const char* name, int numVars, float* x);
671  virtual void AddShaderVariable(const char* name, int numVars, double* x);
673 
675 
678  void AddShaderVariable(const char* name, int v) { this->AddShaderVariable(name, 1, &v); }
679  void AddShaderVariable(const char* name, float v) { this->AddShaderVariable(name, 1, &v); }
680  void AddShaderVariable(const char* name, double v) { this->AddShaderVariable(name, 1, &v); }
681  void AddShaderVariable(const char* name, int v1, int v2)
682  {
683  int v[2] = { v1, v2 };
684  this->AddShaderVariable(name, 2, v);
685  }
686  void AddShaderVariable(const char* name, float v1, float v2)
687  {
688  float v[2] = { v1, v2 };
689  this->AddShaderVariable(name, 2, v);
690  }
691  void AddShaderVariable(const char* name, double v1, double v2)
692  {
693  double v[2] = { v1, v2 };
694  this->AddShaderVariable(name, 2, v);
695  }
696  void AddShaderVariable(const char* name, int v1, int v2, int v3)
697  {
698  int v[3] = { v1, v2, v3 };
699  this->AddShaderVariable(name, 3, v);
700  }
701  void AddShaderVariable(const char* name, float v1, float v2, float v3)
702  {
703  float v[3] = { v1, v2, v3 };
704  this->AddShaderVariable(name, 3, v);
705  }
706  void AddShaderVariable(const char* name, double v1, double v2, double v3)
707  {
708  double v[3] = { v1, v2, v3 };
709  this->AddShaderVariable(name, 3, v);
710  }
712 
714 
718  vtkSetMacro(ShowTexturesOnBackface, bool);
719  vtkGetMacro(ShowTexturesOnBackface, bool);
720  vtkBooleanMacro(ShowTexturesOnBackface, bool);
722 
724 
737  void SetTexture(const char* name, vtkTexture* texture);
738  vtkTexture* GetTexture(const char* name);
740 
747  void SetBaseColorTexture(vtkTexture* texture) { this->SetTexture("albedoTex", texture); }
748 
758  void SetORMTexture(vtkTexture* texture) { this->SetTexture("materialTex", texture); }
759 
770  void SetAnisotropyTexture(vtkTexture* texture) { this->SetTexture("anisotropyTex", texture); }
771 
780  void SetNormalTexture(vtkTexture* texture) { this->SetTexture("normalTex", texture); }
781 
789  void SetEmissiveTexture(vtkTexture* texture) { this->SetTexture("emissiveTex", texture); }
790 
799  void SetCoatNormalTexture(vtkTexture* texture) { this->SetTexture("coatNormalTex", texture); }
800 
804  void RemoveTexture(const char* name);
805 
810 
815 
819  std::map<std::string, vtkTexture*>& GetAllTextures() { return this->Textures; }
820 
827 
829 
832  vtkGetObjectMacro(Information, vtkInformation);
835 
837 
841  static double ComputeReflectanceFromIOR(double IORTo, double IORFrom);
843 
845 
849  static double ComputeIORFromReflectance(double reflectance, double ior);
851 
853 
861 
862 protected:
864  ~vtkProperty() override;
865 
869  static void ComputeCompositeColor(double result[3], double ambient, const double ambient_color[3],
870  double diffuse, const double diffuse_color[3], double specular, const double specular_color[3]);
871 
872  double Color[3];
873  double AmbientColor[3];
874  double DiffuseColor[3];
875  double SpecularColor[3];
876  double EdgeColor[3];
877  double VertexColor[3];
878  double SelectionColor[4] = { 1.0, 0.0, 0.0, 1.0 };
879  double Ambient;
880  double Diffuse;
881  double Metallic;
882  double Roughness;
883  double Anisotropy;
885  double BaseIOR;
886  double CoatIOR;
887  double CoatColor[3];
889  double CoatStrength;
891  double NormalScale;
893  double EmissiveFactor[3];
894  double Specular;
896  double Opacity;
897  double EdgeTint[3];
898  float PointSize;
899  float LineWidth;
900  float SelectionPointSize = 2.f;
901  float SelectionLineWidth = 2.f;
910  bool Lighting;
914 
916 
918 
919  typedef std::map<std::string, vtkTexture*> MapOfTextures;
921 
922  // Arbitrary extra information associated with this Property.
924 
925 private:
926  vtkProperty(const vtkProperty&) = delete;
927  void operator=(const vtkProperty&) = delete;
928 };
929 
934 {
935  if (this->Interpolation == VTK_FLAT)
936  {
937  return "Flat";
938  }
939  else if (this->Interpolation == VTK_GOURAUD)
940  {
941  return "Gouraud";
942  }
943  else if (this->Interpolation == VTK_PHONG)
944  {
945  return "Phong";
946  }
947  else // if (this->Interpolation == VTK_PBR)
948  {
949  return "Physically based rendering";
950  }
951 }
952 
957 {
958  if (this->Representation == VTK_POINTS)
959  {
960  return "Points";
961  }
962  else if (this->Representation == VTK_WIREFRAME)
963  {
964  return "Wireframe";
965  }
966  else
967  {
968  return "Surface";
969  }
970 }
971 
972 #endif
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:161
a simple class to control print indentation
Definition: vtkIndent.h:119
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:82
represent surface properties of a geometric object
Definition: vtkProperty.h:177
MapOfTextures Textures
Definition: vtkProperty.h:920
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:919
double CoatRoughness
Definition: vtkProperty.h:888
~vtkProperty() override
double * GetColor()
Set the color of the object.
void SetRepresentationToPoints()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:272
double CoatNormalScale
Definition: vtkProperty.h:890
int LineStipplePattern
Definition: vtkProperty.h:902
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:273
virtual void SetInformation(vtkInformation *)
Set/Get the information object associated with the Property.
int LineStippleRepeatFactor
Definition: vtkProperty.h:903
double AnisotropyRotation
Definition: vtkProperty.h:884
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:892
double Diffuse
Definition: vtkProperty.h:880
void AddShaderVariable(const char *name, double v1, double v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:691
virtual void BackfaceRender(vtkActor *, vtkRenderer *)
This method renders the property as a backface property.
Definition: vtkProperty.h:210
static vtkProperty * New()
Construct object with object color, ambient color, diffuse color, specular color, and edge color whit...
double Opacity
Definition: vtkProperty.h:896
void SetNormalTexture(vtkTexture *texture)
Set the normal texture.
Definition: vtkProperty.h:780
int Representation
Definition: vtkProperty.h:905
float LineWidth
Definition: vtkProperty.h:899
int GetNumberOfTextures()
Returns the number of textures in this property.
double CoatStrength
Definition: vtkProperty.h:889
void SetEmissiveTexture(vtkTexture *texture)
Set the emissive texture.
Definition: vtkProperty.h:789
void SetInterpolationToFlat()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:259
void RemoveAllTextures()
Remove all the textures.
void SetBaseColorTexture(vtkTexture *texture)
Set the base color texture.
Definition: vtkProperty.h:747
double Metallic
Definition: vtkProperty.h:881
void SetCoatNormalTexture(vtkTexture *texture)
Set the coat normal texture.
Definition: vtkProperty.h:799
void SetInterpolationToGouraud()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:260
vtkTypeBool BackfaceCulling
Definition: vtkProperty.h:908
void DeepCopy(vtkProperty *p)
Assign one property to another.
int Interpolation
Definition: vtkProperty.h:904
double Anisotropy
Definition: vtkProperty.h:883
void AddShaderVariable(const char *name, double v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:680
void SetInterpolationToPBR()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:262
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:933
void SetRepresentationToSurface()
Control the surface geometry representation for the object.
Definition: vtkProperty.h:274
void SetInterpolationToPhong()
Set the shading interpolation method for an object.
Definition: vtkProperty.h:261
double Roughness
Definition: vtkProperty.h:882
double BaseIOR
Definition: vtkProperty.h:885
void AddShaderVariable(const char *name, double v1, double v2, double v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:706
bool RenderPointsAsSpheres
Definition: vtkProperty.h:911
vtkTypeBool Shading
Definition: vtkProperty.h:915
float PointSize
Definition: vtkProperty.h:898
void SetORMTexture(vtkTexture *texture)
Set the ORM texture.
Definition: vtkProperty.h:758
void AddShaderVariable(const char *name, int v1, int v2, int v3)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:696
virtual void SetColor(double r, double g, double b)
Set the color of the object.
vtkInformation * Information
Definition: vtkProperty.h:923
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:701
double Specular
Definition: vtkProperty.h:894
double NormalScale
Definition: vtkProperty.h:891
bool RenderLinesAsTubes
Definition: vtkProperty.h:912
virtual void ReleaseGraphicsResources(vtkWindow *win)
Release any graphics resources that are being consumed by this property.
vtkTypeBool EdgeVisibility
Definition: vtkProperty.h:906
vtkTypeBool VertexVisibility
Definition: vtkProperty.h:907
void AddShaderVariable(const char *name, int v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:678
double SpecularPower
Definition: vtkProperty.h:895
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:770
vtkTypeBool FrontfaceCulling
Definition: vtkProperty.h:909
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:686
bool ShowTexturesOnBackface
Definition: vtkProperty.h:913
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:879
double CoatIOR
Definition: vtkProperty.h:886
void AddShaderVariable(const char *name, int v1, int v2)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:681
const char * GetRepresentationAsString()
Return the method of shading as a descriptive character string.
Definition: vtkProperty.h:956
void AddShaderVariable(const char *name, float v)
Methods to provide to add shader variables from wrappers.
Definition: vtkProperty.h:679
char * MaterialName
Definition: vtkProperty.h:917
std::map< std::string, vtkTexture * > & GetAllTextures()
Returns all the textures in this property and their names.
Definition: vtkProperty.h:819
abstract specification for renderers
Definition: vtkRenderer.h:182
The ShaderProgram uses one or more Shader objects.
handles properties associated with a texture map
Definition: vtkTexture.h:178
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
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:161
#define VTK_WIREFRAME
Definition: vtkProperty.h:162
#define VTK_PHONG
Definition: vtkProperty.h:157
#define VTK_FLAT
Definition: vtkProperty.h:155
#define VTK_PBR
Definition: vtkProperty.h:158
#define VTK_SURFACE
Definition: vtkProperty.h:163
#define VTK_GOURAUD
Definition: vtkProperty.h:156
#define VTK_INT_MAX
Definition: vtkType.h:155
#define VTK_FLOAT_MAX
Definition: vtkType.h:163
#define VTK_SIZEHINT(...)