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 =========================================================================*/
15 /**
16  * @class   vtkProperty
17  * @brief   represent surface properties of a geometric object
18  *
19  * vtkProperty is an object that represents lighting and other surface
20  * properties of a geometric object. The primary properties that can be
21  * set are colors (overall, ambient, diffuse, specular, and edge color);
22  * specular power; opacity of the object; the representation of the
23  * object (points, wireframe, or surface); and the shading method to be
24  * used (flat, Gouraud, and Phong). Also, some special graphics features
25  * like backface properties can be set and manipulated with this object.
26  *
27  * @sa
28  * vtkActor vtkPropertyDevice
29  */
30 
31 #ifndef vtkProperty_h
32 #define vtkProperty_h
33 
34 #include "vtkObject.h"
35 #include "vtkRenderingCoreModule.h" // For export macro
36 #include <map>                      // used for ivar
37 #include <string>                   // used for ivar
38 
39 // shading models
40 #define VTK_FLAT 0
41 #define VTK_GOURAUD 1
42 #define VTK_PHONG 2
43 #define VTK_PBR 3
44 
45 // representation models
46 #define VTK_POINTS 0
47 #define VTK_WIREFRAME 1
48 #define VTK_SURFACE 2
49 
50 class vtkActor;
51 class vtkInformation;
52 class vtkRenderer;
53 class vtkShaderProgram;
54 class vtkTexture;
55 class vtkWindow;
56 class vtkXMLDataElement;
57 class vtkXMLMaterial;
58 
59 class vtkPropertyInternals;
60 
61 class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject
62 {
63 public:
64   vtkTypeMacro(vtkProperty, vtkObject);
65   void PrintSelf(ostream& os, vtkIndent indent) override;
66 
67   /**
68    * Construct object with object color, ambient color, diffuse color,
69    * specular color, and edge color white; ambient coefficient=0; diffuse
70    * coefficient=0; specular coefficient=0; specular power=1; Gouraud shading;
71    * and surface representation. Backface and frontface culling are off.
72    */
73   static vtkProperty* New();
74 
75   /**
76    * Assign one property to another.
77    */
78   void DeepCopy(vtkProperty* p);
79 
80   /**
81    * This method causes the property to set up whatever is required for
82    * its instance variables. This is actually handled by a subclass of
83    * vtkProperty, which is created automatically. This
84    * method includes the invoking actor as an argument which can
85    * be used by property devices that require the actor.
86    */
87   virtual void Render(vtkActor*, vtkRenderer*);
88 
89   /**
90    * This method renders the property as a backface property. TwoSidedLighting
91    * must be turned off to see any backface properties. Note that only
92    * colors and opacity are used for backface properties. Other properties
93    * such as Representation, Culling are specified by the Property.
94    */
BackfaceRender(vtkActor *,vtkRenderer *)95   virtual void BackfaceRender(vtkActor*, vtkRenderer*) {}
96 
97   /**
98    * This method is called after the actor has been rendered.
99    * Don't call this directly. This method cleans up
100    * any shaders allocated.
101    */
102   virtual void PostRender(vtkActor*, vtkRenderer*);
103 
104   ///@{
105   /**
106    * Set/Get lighting flag for an object. Initial value is true.
107    */
108   vtkGetMacro(Lighting, bool);
109   vtkSetMacro(Lighting, bool);
110   vtkBooleanMacro(Lighting, bool);
111   ///@}
112 
113   ///@{
114   /**
115    * Set/Get rendering of points as spheres. The size of the
116    * sphere in pixels is controlled by the PointSize
117    * attribute. Note that half spheres may be rendered
118    * instead of spheres.
119    */
120   vtkGetMacro(RenderPointsAsSpheres, bool);
121   vtkSetMacro(RenderPointsAsSpheres, bool);
122   vtkBooleanMacro(RenderPointsAsSpheres, bool);
123   ///@}
124 
125   ///@{
126   /**
127    * Set/Get rendering of lines as tubes. The width of the
128    * line in pixels is controlled by the LineWidth
129    * attribute. May not be supported on every platform
130    * and the implementation may be half tubes, or something
131    * only tube like in appearance.
132    */
133   vtkGetMacro(RenderLinesAsTubes, bool);
134   vtkSetMacro(RenderLinesAsTubes, bool);
135   vtkBooleanMacro(RenderLinesAsTubes, bool);
136   ///@}
137 
138   ///@{
139   /**
140    * Set the shading interpolation method for an object.
141    */
142   vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PBR);
143   vtkGetMacro(Interpolation, int);
SetInterpolationToFlat()144   void SetInterpolationToFlat() { this->SetInterpolation(VTK_FLAT); }
SetInterpolationToGouraud()145   void SetInterpolationToGouraud() { this->SetInterpolation(VTK_GOURAUD); }
SetInterpolationToPhong()146   void SetInterpolationToPhong() { this->SetInterpolation(VTK_PHONG); }
SetInterpolationToPBR()147   void SetInterpolationToPBR() { this->SetInterpolation(VTK_PBR); }
148   const char* GetInterpolationAsString();
149   ///@}
150 
151   ///@{
152   /**
153    * Control the surface geometry representation for the object.
154    */
155   vtkSetClampMacro(Representation, int, VTK_POINTS, VTK_SURFACE);
156   vtkGetMacro(Representation, int);
SetRepresentationToPoints()157   void SetRepresentationToPoints() { this->SetRepresentation(VTK_POINTS); }
SetRepresentationToWireframe()158   void SetRepresentationToWireframe() { this->SetRepresentation(VTK_WIREFRAME); }
SetRepresentationToSurface()159   void SetRepresentationToSurface() { this->SetRepresentation(VTK_SURFACE); }
160   const char* GetRepresentationAsString();
161   ///@}
162 
163   ///@{
164   /**
165    * Set the color of the object. Has the side effect of setting the
166    * ambient diffuse and specular colors as well. This is basically
167    * a quick overall color setting method.
168    */
169   virtual void SetColor(double r, double g, double b);
170   virtual void SetColor(double a[3]);
171   double* GetColor() VTK_SIZEHINT(3);
172   void GetColor(double rgb[3]);
173   void GetColor(double& r, double& g, double& b);
174   ///@}
175 
176   ///@{
177   /**
178    * Set/Get the Index Of Refraction of the base layer.
179    * It controls the amount of light reflected at normal incidence (the reflectance F0),
180    * depending on the IOR of the upper layer (eg. coat layer, or environment).
181    * For example, with a base IOR of 1.5 and an IOR of 1.0 outside (IOR of the air),
182    * 4% of the amount of the light is reflected at normal incidence.
183    * Notice that modifying this value is only useful for dielectrics materials, as
184    * the reflectance for metallic is the albedo.
185    * This parameter is only used by PBR Interpolation.
186    * Default value is 1.5
187    */
188   vtkSetClampMacro(BaseIOR, double, 1.0, VTK_FLOAT_MAX);
189   vtkGetMacro(BaseIOR, double);
190   ///@}
191 
192   ///@{
193   /**
194    * Set/Get the metallic coefficient.
195    * Usually this value is either 0 or 1 for real material but any value in between is valid.
196    * This parameter is only used by PBR Interpolation.
197    * Default value is 0.0
198    */
199   vtkSetClampMacro(Metallic, double, 0.0, 1.0);
200   vtkGetMacro(Metallic, double);
201   ///@}
202 
203   ///@{
204   /**
205    * Set/Get the roughness coefficient.
206    * This value has to be between 0 (glossy) and 1 (rough).
207    * A glossy material has reflections and a high specular part.
208    * This parameter is only used by PBR Interpolation.
209    * Default value is 0.5
210    */
211   vtkSetClampMacro(Roughness, double, 0.0, 1.0);
212   vtkGetMacro(Roughness, double);
213   ///@}
214 
215   ///@{
216   /**
217    * Set/Get the anisotropy coefficient.
218    * This value controls the anisotropy of the material (0.0 means isotropic)
219    * This parameter is only used by PBR Interpolation.
220    * Default value is 0.0
221    */
222   vtkSetClampMacro(Anisotropy, double, 0.0, 1.0);
223   vtkGetMacro(Anisotropy, double);
224   ///@}
225 
226   ///@{
227   /**
228    * Set/Get the anisotropy rotation coefficient.
229    * This value controls the rotation of the direction of the anisotropy.
230    * This parameter is only used by PBR Interpolation.
231    * Default value is 0.0
232    */
233   vtkSetClampMacro(AnisotropyRotation, double, 0.0, 1.0);
234   vtkGetMacro(AnisotropyRotation, double);
235   ///@}
236 
237   ///@{
238   /**
239    * Set/Get the coat layer Index Of Refraction.
240    * This parameter is only used by PBR Interpolation.
241    * Default value is 2.0
242    */
243   vtkSetClampMacro(CoatIOR, double, 1.0, VTK_FLOAT_MAX);
244   vtkGetMacro(CoatIOR, double);
245   ///@}
246 
247   ///@{
248   /**
249    * Set/Get the coat layer roughness coefficient.
250    * This value has to be between 0 (glossy) and 1 (rough).
251    * This parameter is only used by PBR Interpolation.
252    * Default value is 0.0
253    */
254   vtkSetClampMacro(CoatRoughness, double, 0.0, 1.0);
255   vtkGetMacro(CoatRoughness, double);
256   ///@}
257 
258   ///@{
259   /**
260    * Set/Get the coat layer strength coefficient.
261    * This value affects the strength of the coat layer reflection.
262    * This parameter is only used by PBR Interpolation.
263    * Default value is 0.0
264    */
265   vtkSetClampMacro(CoatStrength, double, 0.0, 1.0);
266   vtkGetMacro(CoatStrength, double);
267   ///@}
268 
269   ///@{
270   /**
271    * Set/Get the color of the coat layer.
272    * This value is only used by PBR Interpolation.
273    * Default value is white [1.0, 1.0, 1.0]
274    */
275   vtkSetVector3Macro(CoatColor, double);
276   vtkGetVector3Macro(CoatColor, double);
277   ///@}
278 
279   ///@{
280   /**
281    * Set/Get the coat layer normal scale coefficient.
282    * This value affects the strength of the normal deviation from the coat normal texture.
283    * This parameter is only used by PBR Interpolation.
284    * Default value is 1.0
285    */
286   vtkSetClampMacro(CoatNormalScale, double, 0.0, 1.0);
287   vtkGetMacro(CoatNormalScale, double);
288   ///@}
289 
290   ///@{
291   /**
292    * Set/Get the normal scale coefficient.
293    * This value affects the strength of the normal deviation from the texture.
294    * Default value is 1.0
295    */
296   vtkSetMacro(NormalScale, double);
297   vtkGetMacro(NormalScale, double);
298   ///@}
299 
300   ///@{
301   /**
302    * Set/Get the occlusion strength coefficient.
303    * This value affects the strength of the occlusion if a material texture is present.
304    * This parameter is only used by PBR Interpolation.
305    * Default value is 1.0
306    */
307   vtkSetClampMacro(OcclusionStrength, double, 0.0, 1.0);
308   vtkGetMacro(OcclusionStrength, double);
309   ///@}
310 
311   ///@{
312   /**
313    * Set/Get the emissive factor.
314    * This value is multiplied with the emissive color when an emissive texture is present.
315    * This parameter is only used by PBR Interpolation.
316    * Default value is [1.0, 1.0, 1.0]
317    */
318   vtkSetVector3Macro(EmissiveFactor, double);
319   vtkGetVector3Macro(EmissiveFactor, double);
320   ///@}
321 
322   ///@{
323   /**
324    * Set/Get the edge tint (for metals only).
325    * Set the color at grazing angle (fresnel reflectance).
326    * This parameter is only used by PBR Interpolation.
327    * Default value is [1.0, 1.0, 1.0]
328    */
329   vtkSetVector3Macro(EdgeTint, double);
330   vtkGetVector3Macro(EdgeTint, double);
331   ///@}
332 
333   ///@{
334   /**
335    * Set/Get the ambient lighting coefficient.
336    */
337   vtkSetClampMacro(Ambient, double, 0.0, 1.0);
338   vtkGetMacro(Ambient, double);
339   ///@}
340 
341   ///@{
342   /**
343    * Set/Get the diffuse lighting coefficient.
344    */
345   vtkSetClampMacro(Diffuse, double, 0.0, 1.0);
346   vtkGetMacro(Diffuse, double);
347   ///@}
348 
349   ///@{
350   /**
351    * Set/Get the specular lighting coefficient.
352    */
353   vtkSetClampMacro(Specular, double, 0.0, 1.0);
354   vtkGetMacro(Specular, double);
355   ///@}
356 
357   ///@{
358   /**
359    * Set/Get the specular power.
360    */
361   vtkSetClampMacro(SpecularPower, double, 0.0, 128.0);
362   vtkGetMacro(SpecularPower, double);
363   ///@}
364 
365   ///@{
366   /**
367    * Set/Get the object's opacity. 1.0 is totally opaque and 0.0 is completely
368    * transparent.
369    */
370   vtkSetClampMacro(Opacity, double, 0.0, 1.0);
371   vtkGetMacro(Opacity, double);
372   ///@}
373 
374   ///@{
375   /**
376    * Set/Get the ambient surface color. Not all renderers support separate
377    * ambient and diffuse colors. From a physical standpoint it really
378    * doesn't make too much sense to have both. For the rendering
379    * libraries that don't support both, the diffuse color is used.
380    */
381   vtkSetVector3Macro(AmbientColor, double);
382   vtkGetVector3Macro(AmbientColor, double);
383   ///@}
384 
385   ///@{
386   /**
387    * Set/Get the diffuse surface color.
388    * For PBR Interpolation, DiffuseColor is used as the base color
389    */
390   vtkSetVector3Macro(DiffuseColor, double);
391   vtkGetVector3Macro(DiffuseColor, double);
392   ///@}
393 
394   ///@{
395   /**
396    * Set/Get the specular surface color.
397    */
398   vtkSetVector3Macro(SpecularColor, double);
399   vtkGetVector3Macro(SpecularColor, double);
400   ///@}
401 
402   ///@{
403   /**
404    * Turn on/off the visibility of edges. On some renderers it is
405    * possible to render the edges of geometric primitives separately
406    * from the interior.
407    */
408   vtkGetMacro(EdgeVisibility, vtkTypeBool);
409   vtkSetMacro(EdgeVisibility, vtkTypeBool);
410   vtkBooleanMacro(EdgeVisibility, vtkTypeBool);
411   ///@}
412 
413   ///@{
414   /**
415    * Set/Get the color of primitive edges (if edge visibility is enabled).
416    */
417   vtkSetVector3Macro(EdgeColor, double);
418   vtkGetVector3Macro(EdgeColor, double);
419   ///@}
420 
421   ///@{
422   /**
423    * Turn on/off the visibility of vertices. On some renderers it is
424    * possible to render the vertices of geometric primitives separately
425    * from the interior.
426    */
427   vtkGetMacro(VertexVisibility, vtkTypeBool);
428   vtkSetMacro(VertexVisibility, vtkTypeBool);
429   vtkBooleanMacro(VertexVisibility, vtkTypeBool);
430   ///@}
431 
432   ///@{
433   /**
434    * Set/Get the color of primitive vertices (if vertex visibility is enabled).
435    */
436   vtkSetVector3Macro(VertexColor, double);
437   vtkGetVector3Macro(VertexColor, double);
438   ///@}
439 
440   ///@{
441   /**
442    * Set/Get the RGBA color of selection primitives (if a selection is active on the mapper).
443    * Default is red and opaque.
444    */
445   vtkSetVector4Macro(SelectionColor, double);
446   vtkGetVector4Macro(SelectionColor, double);
447   ///@}
448 
449   ///@{
450   /**
451    * Set/Get the selection line width.
452    * Default is 2.
453    */
454   vtkSetMacro(SelectionLineWidth, float);
455   vtkGetMacro(SelectionLineWidth, float);
456   ///@}
457 
458   ///@{
459   /**
460    * Set/Get the selection point size.
461    * Default is 2.
462    */
463   vtkSetMacro(SelectionPointSize, float);
464   vtkGetMacro(SelectionPointSize, float);
465   ///@}
466 
467   ///@{
468   /**
469    * Set/Get the width of a Line. The width is expressed in screen units.
470    * This is only implemented for OpenGL. The default is 1.0.
471    */
472   vtkSetClampMacro(LineWidth, float, 0, VTK_FLOAT_MAX);
473   vtkGetMacro(LineWidth, float);
474   ///@}
475 
476   ///@{
477   /**
478    * Set/Get the stippling pattern of a Line, as a 16-bit binary pattern
479    * (1 = pixel on, 0 = pixel off).
480    * This is only implemented for OpenGL, not OpenGL2. The default is 0xFFFF.
481    */
482   vtkSetMacro(LineStipplePattern, int);
483   vtkGetMacro(LineStipplePattern, int);
484   ///@}
485 
486   ///@{
487   /**
488    * Set/Get the stippling repeat factor of a Line, which specifies how
489    * many times each bit in the pattern is to be repeated.
490    * This is only implemented for OpenGL, not OpenGL2. The default is 1.
491    */
492   vtkSetClampMacro(LineStippleRepeatFactor, int, 1, VTK_INT_MAX);
493   vtkGetMacro(LineStippleRepeatFactor, int);
494   ///@}
495 
496   ///@{
497   /**
498    * Set/Get the diameter of a point. The size is expressed in screen units.
499    * This is only implemented for OpenGL. The default is 1.0.
500    */
501   vtkSetClampMacro(PointSize, float, 0, VTK_FLOAT_MAX);
502   vtkGetMacro(PointSize, float);
503   ///@}
504 
505   ///@{
506   /**
507    * Turn on/off fast culling of polygons based on orientation of normal
508    * with respect to camera. If backface culling is on, polygons facing
509    * away from camera are not drawn.
510    */
511   vtkGetMacro(BackfaceCulling, vtkTypeBool);
512   vtkSetMacro(BackfaceCulling, vtkTypeBool);
513   vtkBooleanMacro(BackfaceCulling, vtkTypeBool);
514   ///@}
515 
516   ///@{
517   /**
518    * Turn on/off fast culling of polygons based on orientation of normal
519    * with respect to camera. If frontface culling is on, polygons facing
520    * towards camera are not drawn.
521    */
522   vtkGetMacro(FrontfaceCulling, vtkTypeBool);
523   vtkSetMacro(FrontfaceCulling, vtkTypeBool);
524   vtkBooleanMacro(FrontfaceCulling, vtkTypeBool);
525   ///@}
526 
527   ///@{
528   /**
529    * Returns the name of the material currently loaded, if any.
530    */
531   vtkSetStringMacro(MaterialName);
532   vtkGetStringMacro(MaterialName);
533   ///@}
534 
535   ///@{
536   /**
537    * Enable/Disable shading. When shading is enabled, the
538    * Material must be set.
539    */
540   vtkSetMacro(Shading, vtkTypeBool);
541   vtkGetMacro(Shading, vtkTypeBool);
542   vtkBooleanMacro(Shading, vtkTypeBool);
543   ///@}
544 
545   ///@{
546   /**
547    * Provide values to initialize shader variables.
548    * Useful to initialize shader variables that change over time
549    * (animation, GUI widgets inputs, etc. )
550    * - \p name - hardware name of the uniform variable
551    * - \p numVars - number of variables being set
552    * - \p x - values
553    */
554   virtual void AddShaderVariable(const char* name, int numVars, int* x);
555   virtual void AddShaderVariable(const char* name, int numVars, float* x);
556   virtual void AddShaderVariable(const char* name, int numVars, double* x);
557   ///@}
558 
559   ///@{
560   /**
561    * Methods to provide to add shader variables from wrappers.
562    */
AddShaderVariable(const char * name,int v)563   void AddShaderVariable(const char* name, int v) { this->AddShaderVariable(name, 1, &v); }
AddShaderVariable(const char * name,float v)564   void AddShaderVariable(const char* name, float v) { this->AddShaderVariable(name, 1, &v); }
AddShaderVariable(const char * name,double v)565   void AddShaderVariable(const char* name, double v) { this->AddShaderVariable(name, 1, &v); }
AddShaderVariable(const char * name,int v1,int v2)566   void AddShaderVariable(const char* name, int v1, int v2)
567   {
568     int v[2] = { v1, v2 };
569     this->AddShaderVariable(name, 2, v);
570   }
AddShaderVariable(const char * name,float v1,float v2)571   void AddShaderVariable(const char* name, float v1, float v2)
572   {
573     float v[2] = { v1, v2 };
574     this->AddShaderVariable(name, 2, v);
575   }
AddShaderVariable(const char * name,double v1,double v2)576   void AddShaderVariable(const char* name, double v1, double v2)
577   {
578     double v[2] = { v1, v2 };
579     this->AddShaderVariable(name, 2, v);
580   }
AddShaderVariable(const char * name,int v1,int v2,int v3)581   void AddShaderVariable(const char* name, int v1, int v2, int v3)
582   {
583     int v[3] = { v1, v2, v3 };
584     this->AddShaderVariable(name, 3, v);
585   }
AddShaderVariable(const char * name,float v1,float v2,float v3)586   void AddShaderVariable(const char* name, float v1, float v2, float v3)
587   {
588     float v[3] = { v1, v2, v3 };
589     this->AddShaderVariable(name, 3, v);
590   }
AddShaderVariable(const char * name,double v1,double v2,double v3)591   void AddShaderVariable(const char* name, double v1, double v2, double v3)
592   {
593     double v[3] = { v1, v2, v3 };
594     this->AddShaderVariable(name, 3, v);
595   }
596   ///@}
597 
598   ///@{
599   /**
600    * Show texture maps when the geometry is backfacing. Texture maps are
601    * always shown when frontfacing. By default this is true.
602    */
603   vtkSetMacro(ShowTexturesOnBackface, bool);
604   vtkGetMacro(ShowTexturesOnBackface, bool);
605   vtkBooleanMacro(ShowTexturesOnBackface, bool);
606   ///@}
607 
608   ///@{
609   /**
610    * Set/Get the texture object to control rendering texture maps. This will
611    * be a vtkTexture object. A property does not need to have an associated
612    * texture map and multiple properties can share one texture. Textures
613    * must be assigned unique names. Note that for texture blending the
614    * textures will be rendering is alphabetical order and after any texture
615    * defined in the actor.
616    * There exists 6 special textures with reserved names: "albedoTex", "materialTex", "normalTex",
617    * "emissiveTex", "anisotropyTex" and "coatNormalTex". While these textures can be added with the
618    * regular SetTexture method, it is preferred to use the methods SetBaseColorTexture,
619    * SetORMTexture, SetNormalTexture, SetEmissiveTexture, SetAnisotropyTexture and SetCoatNormalTex
620    * respectively.
621    */
622   void SetTexture(const char* name, vtkTexture* texture);
623   vtkTexture* GetTexture(const char* name);
624   ///@}
625 
626   /**
627    * Set the base color texture. Also called albedo, this texture is only used while rendering
628    * with PBR interpolation. This is the color of the object.
629    * This texture must be in sRGB color space.
630    * @sa SetInterpolationToPBR vtkTexture::UseSRGBColorSpaceOn
631    */
SetBaseColorTexture(vtkTexture * texture)632   void SetBaseColorTexture(vtkTexture* texture) { this->SetTexture("albedoTex", texture); }
633 
634   /**
635    * Set the ORM texture. This texture contains three RGB independent components corresponding to
636    * the Occlusion value, Roughness value and Metallic value respectively.
637    * Each texture value is scaled by the Occlusion strength, roughness coefficient and metallic
638    * coefficient.
639    * This texture must be in linear color space.
640    * This is only used by the PBR shading model.
641    * @sa SetInterpolationToPBR SetOcclusionStrength SetMetallic SetRoughness
642    */
SetORMTexture(vtkTexture * texture)643   void SetORMTexture(vtkTexture* texture) { this->SetTexture("materialTex", texture); }
644 
645   /**
646    * Set the anisotropy texture. This texture contains two independent components corresponding to
647    * the anisotropy value and anisotropy rotation. The last component (blue channel) is discarded.
648    * The anisotropy value is scaled by the anisotropy coefficient of the material. The anisotropy
649    * rotation rotates the direction of the anisotropy (ie. the tangent) around the normal and is not
650    * scaled by the anisotropy rotation coefficient.
651    * This texture must be in linear color space.
652    * This is only used by the PBR shading model.
653    * @sa SetInterpolationToPBR SetAnisotropy
654    */
SetAnisotropyTexture(vtkTexture * texture)655   void SetAnisotropyTexture(vtkTexture* texture) { this->SetTexture("anisotropyTex", texture); }
656 
657   /**
658    * Set the normal texture. This texture is required for normal mapping. It is valid for both PBR
659    * and Phong interpolation.
660    * The normal mapping is enabled if this texture is present and both normals and tangents are
661    * presents in the vtkPolyData.
662    * This texture must be in linear color space.
663    * @sa vtkPolyDataTangents SetNormalScale
664    */
SetNormalTexture(vtkTexture * texture)665   void SetNormalTexture(vtkTexture* texture) { this->SetTexture("normalTex", texture); }
666 
667   /**
668    * Set the emissive texture. When present, this RGB texture provides location and color to the
669    * shader where the vtkPolyData should emit light. Emited light is scaled by EmissiveFactor.
670    * This is only supported by PBR interpolation model.
671    * This texture must be in sRGB color space.
672    * @sa SetInterpolationToPBR SetEmissiveFactor vtkTexture::UseSRGBColorSpaceOn
673    */
SetEmissiveTexture(vtkTexture * texture)674   void SetEmissiveTexture(vtkTexture* texture) { this->SetTexture("emissiveTex", texture); }
675 
676   /**
677    * Set the coat normal texture. This texture is required for coat normal mapping.
678    * It is valid only for PBR interpolation.
679    * The coat normal mapping is enabled if this texture is present and both normals and tangents are
680    * presents in the vtkPolyData.
681    * This texture must be in linear color space.
682    * @sa vtkPolyDataTangents SetCoatNormalScale
683    */
SetCoatNormalTexture(vtkTexture * texture)684   void SetCoatNormalTexture(vtkTexture* texture) { this->SetTexture("coatNormalTex", texture); }
685 
686   /**
687    * Remove a texture from the collection.
688    */
689   void RemoveTexture(const char* name);
690 
691   /**
692    * Remove all the textures.
693    */
694   void RemoveAllTextures();
695 
696   /**
697    * Returns the number of textures in this property.
698    */
699   int GetNumberOfTextures();
700 
701   /**
702    * Returns all the textures in this property and their names
703    */
GetAllTextures()704   std::map<std::string, vtkTexture*>& GetAllTextures() { return this->Textures; }
705 
706   /**
707    * Release any graphics resources that are being consumed by this
708    * property. The parameter window could be used to determine which graphic
709    * resources to release.
710    */
711   virtual void ReleaseGraphicsResources(vtkWindow* win);
712 
713   ///@{
714   /**
715    * Set/Get the information object associated with the Property.
716    */
717   vtkGetObjectMacro(Information, vtkInformation);
718   virtual void SetInformation(vtkInformation*);
719   ///@}
720 
721   ///@{
722   /**
723    * For PBR, calculate the reflectance from the refractive index of
724    * ingoing and outgoing interfaces.
725    */
726   static double ComputeReflectanceFromIOR(double IORTo, double IORFrom);
727   ///@}
728 
729   ///@{
730   /**
731    * For PBR, calculate the refractive index from the reflectance of the interface
732    * and the refractive index of one of both medium.
733    */
734   static double ComputeIORFromReflectance(double reflectance, double ior);
735   ///@}
736 
737   ///@{
738   /**
739    * For PBR, calculate the reflectance of the base layer depending on the presence
740    * of a coat layer. If there is no coat layer, the reflectance is the one at the
741    * interface environment - base layer. If a coat layer is present, the reflectance
742    * is the one at the interface between the base and the coat layer.
743    */
744   double ComputeReflectanceOfBaseLayer();
745   ///@}
746 
747 protected:
748   vtkProperty();
749   ~vtkProperty() override;
750 
751   /**
752    * Computes composite color. Used by GetColor().
753    */
754   static void ComputeCompositeColor(double result[3], double ambient, const double ambient_color[3],
755     double diffuse, const double diffuse_color[3], double specular, const double specular_color[3]);
756 
757   double Color[3];
758   double AmbientColor[3];
759   double DiffuseColor[3];
760   double SpecularColor[3];
761   double EdgeColor[3];
762   double VertexColor[3];
763   double SelectionColor[4] = { 1.0, 0.0, 0.0, 1.0 };
764   double Ambient;
765   double Diffuse;
766   double Metallic;
767   double Roughness;
768   double Anisotropy;
769   double AnisotropyRotation;
770   double BaseIOR;
771   double CoatIOR;
772   double CoatColor[3];
773   double CoatRoughness;
774   double CoatStrength;
775   double CoatNormalScale;
776   double NormalScale;
777   double OcclusionStrength;
778   double EmissiveFactor[3];
779   double Specular;
780   double SpecularPower;
781   double Opacity;
782   double EdgeTint[3];
783   float PointSize;
784   float LineWidth;
785   float SelectionPointSize = 2.f;
786   float SelectionLineWidth = 2.f;
787   int LineStipplePattern;
788   int LineStippleRepeatFactor;
789   int Interpolation;
790   int Representation;
791   vtkTypeBool EdgeVisibility;
792   vtkTypeBool VertexVisibility;
793   vtkTypeBool BackfaceCulling;
794   vtkTypeBool FrontfaceCulling;
795   bool Lighting;
796   bool RenderPointsAsSpheres;
797   bool RenderLinesAsTubes;
798   bool ShowTexturesOnBackface;
799 
800   vtkTypeBool Shading;
801 
802   char* MaterialName;
803 
804   typedef std::map<std::string, vtkTexture*> MapOfTextures;
805   MapOfTextures Textures;
806 
807   // Arbitrary extra information associated with this Property.
808   vtkInformation* Information;
809 
810 private:
811   vtkProperty(const vtkProperty&) = delete;
812   void operator=(const vtkProperty&) = delete;
813 };
814 
815 /**
816  * Return the method of shading as a descriptive character string.
817  */
GetInterpolationAsString()818 inline const char* vtkProperty::GetInterpolationAsString()
819 {
820   if (this->Interpolation == VTK_FLAT)
821   {
822     return "Flat";
823   }
824   else if (this->Interpolation == VTK_GOURAUD)
825   {
826     return "Gouraud";
827   }
828   else if (this->Interpolation == VTK_PHONG)
829   {
830     return "Phong";
831   }
832   else // if (this->Interpolation == VTK_PBR)
833   {
834     return "Physically based rendering";
835   }
836 }
837 
838 /**
839  * Return the method of shading as a descriptive character string.
840  */
GetRepresentationAsString()841 inline const char* vtkProperty::GetRepresentationAsString()
842 {
843   if (this->Representation == VTK_POINTS)
844   {
845     return "Points";
846   }
847   else if (this->Representation == VTK_WIREFRAME)
848   {
849     return "Wireframe";
850   }
851   else
852   {
853     return "Surface";
854   }
855 }
856 
857 #endif
858