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
44VTK_ABI_NAMESPACE_BEGIN
45class vtkActor;
46class vtkInformation;
47class vtkRenderer;
49class vtkTexture;
50class vtkWindow;
52class vtkXMLMaterial;
53
54class vtkPropertyInternals;
55
56class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject
57{
58public:
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
91
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
751protected:
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;
774 double BaseIOR;
775 double CoatIOR;
776 double CoatColor[3];
782 double EmissiveFactor[3];
783 double Specular;
785 double Opacity;
786 double EdgeOpacity = 1.0;
787 double EdgeTint[3];
790 float SelectionPointSize = 2.f;
791 float SelectionLineWidth = 2.f;
804
806
808
809 typedef std::map<std::string, vtkTexture*> MapOfTextures;
811
812 // Arbitrary extra information associated with this Property.
814
815private:
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
862VTK_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:49
represent surface properties of a geometric object
Definition vtkProperty.h:57
MapOfTextures Textures
static vtkProperty * New()
Construct object with object color, ambient color, diffuse color, specular color, and edge color whit...
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
double CoatRoughness
~vtkProperty() override
void SetRepresentationToPoints()
Control the surface geometry representation for the object.
double CoatNormalScale
int LineStipplePattern
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.
virtual void SetInformation(vtkInformation *)
Set/Get the information object associated with the Property.
int LineStippleRepeatFactor
double AnisotropyRotation
double * GetColor()
Set the color of the object.
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
double Diffuse
void AddShaderVariable(const char *name, double v1, double v2)
Methods to provide to add shader variables from wrappers.
virtual void BackfaceRender(vtkActor *, vtkRenderer *)
This method renders the property as a backface property.
Definition vtkProperty.h:90
double Opacity
void SetNormalTexture(vtkTexture *texture)
Set the normal texture.
float LineWidth
int GetNumberOfTextures()
Returns the number of textures in this property.
double CoatStrength
void SetEmissiveTexture(vtkTexture *texture)
Set the emissive texture.
void SetInterpolationToFlat()
Set the shading interpolation method for an object.
void RemoveAllTextures()
Remove all the textures.
void SetBaseColorTexture(vtkTexture *texture)
Set the base color texture.
double Metallic
void SetCoatNormalTexture(vtkTexture *texture)
Set the coat normal texture.
void SetInterpolationToGouraud()
Set the shading interpolation method for an object.
vtkTypeBool BackfaceCulling
void DeepCopy(vtkProperty *p)
Assign one property to another.
double Anisotropy
vtkTexture * GetTexture(const char *name)
Set/Get the texture object to control rendering texture maps.
void AddShaderVariable(const char *name, double v)
Methods to provide to add shader variables from wrappers.
void SetInterpolationToPBR()
Set the shading interpolation method for an object.
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.
void SetRepresentationToSurface()
Control the surface geometry representation for the object.
void SetInterpolationToPhong()
Set the shading interpolation method for an object.
double Roughness
double BaseIOR
void AddShaderVariable(const char *name, double v1, double v2, double v3)
Methods to provide to add shader variables from wrappers.
bool RenderPointsAsSpheres
vtkTypeBool Shading
float PointSize
void SetORMTexture(vtkTexture *texture)
Set the ORM texture.
void AddShaderVariable(const char *name, int v1, int v2, int v3)
Methods to provide to add shader variables from wrappers.
virtual void SetColor(double r, double g, double b)
Set the color of the object.
vtkInformation * Information
static double ComputeReflectanceFromIOR(double IORTo, double IORFrom)
For PBR, calculate the reflectance from the refractive index of ingoing and outgoing interfaces.
void AddShaderVariable(const char *name, float v1, float v2, float v3)
Methods to provide to add shader variables from wrappers.
double Specular
double NormalScale
bool RenderLinesAsTubes
virtual void ReleaseGraphicsResources(vtkWindow *win)
Release any graphics resources that are being consumed by this property.
vtkTypeBool EdgeVisibility
vtkTypeBool VertexVisibility
void AddShaderVariable(const char *name, int v)
Methods to provide to add shader variables from wrappers.
double SpecularPower
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.
vtkTypeBool FrontfaceCulling
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.
bool ShowTexturesOnBackface
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
double CoatIOR
void AddShaderVariable(const char *name, int v1, int v2)
Methods to provide to add shader variables from wrappers.
std::map< std::string, vtkTexture * > & GetAllTextures()
Returns all the textures in this property and their names.
const char * GetRepresentationAsString()
Return the method of shading as a descriptive character string.
void AddShaderVariable(const char *name, float v)
Methods to provide to add shader variables from wrappers.
char * MaterialName
abstract specification for renderers
Definition vtkRenderer.h:59
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:25
Represents an XML element and those nested inside.
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(...)