vtkEncodedGradientShader.h 5.09 KB
Newer Older
1 2 3 4 5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkEncodedGradientShader.h

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13 14 15

=========================================================================*/

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * @class   vtkEncodedGradientShader
 * @brief   Compute shading tables for encoded normals.
 *
 *
 * vtkEncodedGradientShader computes shading tables for encoded normals
 * that indicates the amount of diffuse and specular illumination that is
 * received from all light sources at a surface location with that normal.
 * For diffuse illumination this is accurate, but for specular illumination
 * it is approximate for perspective projections since the center view
 * direction is always used as the view direction. Since the shading table is
 * dependent on the volume (for the transformation that must be applied to
 * the normals to put them into world coordinates) there is a shading table
 * per volume. This is necessary because multiple volumes can share a
 * volume mapper.
31
 */
32

33 34
#ifndef vtkEncodedGradientShader_h
#define vtkEncodedGradientShader_h
35 36

#include "vtkObject.h"
37
#include "vtkRenderingVolumeModule.h" // For export macro
38 39 40 41 42

class vtkVolume;
class vtkRenderer;
class vtkEncodedGradientEstimator;

43
#define VTK_MAX_SHADING_TABLES 100
44

45
class VTKRENDERINGVOLUME_EXPORT vtkEncodedGradientShader : public vtkObject
46 47
{
public:
48 49
  static vtkEncodedGradientShader* New();
  vtkTypeMacro(vtkEncodedGradientShader, vtkObject);
50

51 52 53
  /**
   * Print the vtkEncodedGradientShader
   */
54
  void PrintSelf(ostream& os, vtkIndent indent) override;
55

56 57 58 59 60
  //@{
  /**
   * Set / Get the intensity diffuse / specular light used for the
   * zero normals.
   */
61 62 63 64
  vtkSetClampMacro(ZeroNormalDiffuseIntensity, float, 0.0f, 1.0f);
  vtkGetMacro(ZeroNormalDiffuseIntensity, float);
  vtkSetClampMacro(ZeroNormalSpecularIntensity, float, 0.0f, 1.0f);
  vtkGetMacro(ZeroNormalSpecularIntensity, float);
65
  //@}
66

67 68 69
  /**
   * Cause the shading table to be updated
   */
70
  void UpdateShadingTable(vtkRenderer* ren, vtkVolume* vol, vtkEncodedGradientEstimator* gradest);
71

72 73 74 75
  //@{
  /**
   * Get the red/green/blue shading table.
   */
76 77 78 79 80 81
  float* GetRedDiffuseShadingTable(vtkVolume* vol);
  float* GetGreenDiffuseShadingTable(vtkVolume* vol);
  float* GetBlueDiffuseShadingTable(vtkVolume* vol);
  float* GetRedSpecularShadingTable(vtkVolume* vol);
  float* GetGreenSpecularShadingTable(vtkVolume* vol);
  float* GetBlueSpecularShadingTable(vtkVolume* vol);
82 83 84 85 86 87 88 89
  //@}

  //@{
  /**
   * Set the active component for shading. This component's
   * ambient / diffuse / specular / specular power values will
   * be used to create the shading table. The default is 1.0
   */
90 91
  vtkSetClampMacro(ActiveComponent, int, 0, 3);
  vtkGetMacro(ActiveComponent, int);
92
  //@}
93

94
protected:
95
  vtkEncodedGradientShader();
96
  ~vtkEncodedGradientShader() override;
97

98 99 100 101 102 103 104 105 106 107 108 109 110 111
  /**
   * Build a shading table for a light with the specified direction,
   * and color for an object of the specified material properties.
   * material[0] = ambient, material[1] = diffuse, material[2] = specular
   * and material[3] = specular exponent.  If the ambient flag is 1,
   * then ambient illumination is added. If not, then this means we
   * are calculating the "other side" of two sided lighting, so no
   * ambient intensity is added in. If the update flag is 0,
   * the shading table is overwritten with these new shading values.
   * If the updateFlag is 1, then the computed light contribution is
   * added to the current shading table values. There is one shading
   * table per volume, and the index value indicated which index table
   * should be used. It is computed in the UpdateShadingTable method.
   */
112 113 114 115
  void BuildShadingTable(int index, double lightDirection[3], double lightAmbientColor[3],
    double lightDiffuseColor[3], double lightSpecularColor[3], double lightIntensity,
    double viewDirection[3], double material[4], int twoSided, vtkEncodedGradientEstimator* gradest,
    int updateFlag);
116 117

  // The six shading tables (r diffuse ,g diffuse ,b diffuse,
118 119
  // r specular, g specular, b specular ) - with an entry for each
  // encoded normal plus one entry at the end for the zero normal
120 121
  // There is one shading table per volume listed in the ShadingTableVolume
  // array. A null entry indicates an available slot.
122 123 124
  float* ShadingTable[VTK_MAX_SHADING_TABLES][6];
  vtkVolume* ShadingTableVolume[VTK_MAX_SHADING_TABLES];
  int ShadingTableSize[VTK_MAX_SHADING_TABLES];
125

126
  int ActiveComponent;
127

128 129
  // The intensity of light used for the zero normals, since it
  // can not be computed from the normal angles. Defaults to 0.0.
130 131 132
  float ZeroNormalDiffuseIntensity;
  float ZeroNormalSpecularIntensity;

133
private:
134 135
  vtkEncodedGradientShader(const vtkEncodedGradientShader&) = delete;
  void operator=(const vtkEncodedGradientShader&) = delete;
136
};
137 138

#endif