VTK  9.3.1
vtkUnstructuredGridPartialPreIntegration.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright 2004 Sandia Corporation
3 // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
4 
22 #ifndef vtkUnstructuredGridPartialPreIntegration_h
23 #define vtkUnstructuredGridPartialPreIntegration_h
24 
25 #include "vtkMath.h" // For all the inline methods
26 #include "vtkRenderingVolumeModule.h" // For export macro
28 
29 VTK_ABI_NAMESPACE_BEGIN
30 class vtkPartialPreIntegrationTransferFunction;
31 class vtkVolumeProperty;
32 
33 class VTKRENDERINGVOLUME_EXPORT vtkUnstructuredGridPartialPreIntegration
35 {
36 public:
39  void PrintSelf(ostream& os, vtkIndent indent) override;
40 
41  void Initialize(vtkVolume* volume, vtkDataArray* scalars) override;
42 
43  void Integrate(vtkDoubleArray* intersectionLengths, vtkDataArray* nearIntersections,
44  vtkDataArray* farIntersections, float color[4]) override;
45 
47 
51  static void IntegrateRay(double length, double intensity_front, double attenuation_front,
52  double intensity_back, double attenuation_back, float color[4]);
53  static void IntegrateRay(double length, const double color_front[3], double attenuation_front,
54  const double color_back[3], double attenuation_back, float color[4]);
56 
58 
64  static float Psi(float taufD, float taubD);
65  static float* GetPsiTable(int& size);
66  static void BuildPsiTable();
68 
69 protected:
72 
74 
75  vtkPartialPreIntegrationTransferFunction* TransferFunctions;
78 
79  enum
80  {
81  PSI_TABLE_SIZE = 512
82  };
83 
84  static float PsiTable[PSI_TABLE_SIZE * PSI_TABLE_SIZE];
85  static int PsiTableBuilt;
86 
87 private:
90  void operator=(const vtkUnstructuredGridPartialPreIntegration&) = delete;
91 };
92 
93 inline float vtkUnstructuredGridPartialPreIntegration::Psi(float taufD, float taubD)
94 {
95  float gammaf = taufD / (taufD + 1);
96  float gammab = taubD / (taubD + 1);
97  int gammafi = vtkMath::Floor(gammaf * static_cast<int>(PSI_TABLE_SIZE));
98  int gammabi = vtkMath::Floor(gammab * static_cast<int>(PSI_TABLE_SIZE));
99  return PsiTable[gammafi * PSI_TABLE_SIZE + gammabi];
100 }
101 
103 {
104  size = PSI_TABLE_SIZE;
105  return PsiTable;
106 }
107 
109  double intensity_front, double attenuation_front, double intensity_back, double attenuation_back,
110  float color[4])
111 {
112  float taufD = length * attenuation_front;
113  float taubD = length * attenuation_back;
115  float zeta = static_cast<float>(exp(-0.5 * (taufD + taubD)));
116  float alpha = 1 - zeta;
117 
118  float newintensity =
119  (1 - color[3]) * (intensity_front * (1 - Psi) + intensity_back * (Psi - zeta));
120  // Is setting the RGB values the same the right thing to do?
121  color[0] += newintensity;
122  color[1] += newintensity;
123  color[2] += newintensity;
124  color[3] += (1 - color[3]) * alpha;
125 }
126 
128  const double color_front[3], double attenuation_front, const double color_back[3],
129  double attenuation_back, float color[4])
130 {
131  float taufD = length * attenuation_front;
132  float taubD = length * attenuation_back;
134  float zeta = static_cast<float>(exp(-0.5 * (taufD + taubD)));
135  float alpha = 1 - zeta;
136 
137  color[0] += (1 - color[3]) * (color_front[0] * (1 - Psi) + color_back[0] * (Psi - zeta));
138  color[1] += (1 - color[3]) * (color_front[1] * (1 - Psi) + color_back[1] * (Psi - zeta));
139  color[2] += (1 - color[3]) * (color_front[2] * (1 - Psi) + color_back[2] * (Psi - zeta));
140  color[3] += (1 - color[3]) * alpha;
141 }
142 
143 VTK_ABI_NAMESPACE_END
144 #endif // vtkUnstructuredGridPartialPreIntegration_h
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:39
virtual void Initialize(vtkVolume *volume, vtkDataArray *scalars)=0
Set up the integrator with the given properties and scalars.
record modification and/or execution time
Definition: vtkTimeStamp.h:24
static float PsiTable[PSI_TABLE_SIZE *PSI_TABLE_SIZE]
vtkPartialPreIntegrationTransferFunction * TransferFunctions
dynamic, self-adjusting array of double
a superclass for volume ray integration functions
static void IntegrateRay(double length, double intensity_front, double attenuation_front, double intensity_back, double attenuation_back, float color[4])
Integrates a single ray segment.
a simple class to control print indentation
Definition: vtkIndent.h:28
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
Definition: vtkMath.h:1701
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
represents the common properties for rendering a volume.
static float * GetPsiTable(int &size)
Looks up Psi (as defined by Moreland and Angel, "A Fast High Accuracy Volume Renderer for Unstructure...
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
static float Psi(float taufD, float taubD)
Looks up Psi (as defined by Moreland and Angel, "A Fast High Accuracy Volume Renderer for Unstructure...
virtual void Integrate(vtkDoubleArray *intersectionLengths, vtkDataArray *nearIntersections, vtkDataArray *farIntersections, float color[4])=0
Given a set of intersections (defined by the three arrays), compute the piecewise integration of the ...