VTK  9.0.1
vtkUnstructuredGridPartialPreIntegration.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkUnstructuredGridPartialPreIntegration.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 /*
17  * Copyright 2004 Sandia Corporation.
18  * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
19  * license for use of this work by or on behalf of the
20  * U.S. Government. Redistribution and use in source and binary forms, with
21  * or without modification, are permitted provided that this Notice and any
22  * statement of authorship are reproduced on all copies.
23  */
24 
42 #ifndef vtkUnstructuredGridPartialPreIntegration_h
43 #define vtkUnstructuredGridPartialPreIntegration_h
44 
45 #include "vtkMath.h" // For all the inline methods
46 #include "vtkRenderingVolumeModule.h" // For export macro
48 
49 class vtkPartialPreIntegrationTransferFunction;
50 class vtkVolumeProperty;
51 
52 class VTKRENDERINGVOLUME_EXPORT vtkUnstructuredGridPartialPreIntegration
54 {
55 public:
58  void PrintSelf(ostream& os, vtkIndent indent) override;
59 
60  void Initialize(vtkVolume* volume, vtkDataArray* scalars) override;
61 
62  void Integrate(vtkDoubleArray* intersectionLengths, vtkDataArray* nearIntersections,
63  vtkDataArray* farIntersections, float color[4]) override;
64 
66 
70  static void IntegrateRay(double length, double intensity_front, double attenuation_front,
71  double intensity_back, double attenuation_back, float color[4]);
72  static void IntegrateRay(double length, const double color_front[3], double attenuation_front,
73  const double color_back[3], double attenuation_back, float color[4]);
75 
77 
83  static float Psi(float taufD, float taubD);
84  static float* GetPsiTable(int& size);
85  static void BuildPsiTable();
87 
88 protected:
91 
93 
94  vtkPartialPreIntegrationTransferFunction* TransferFunctions;
97 
98  enum
99  {
100  PSI_TABLE_SIZE = 512
101  };
102 
103  static float PsiTable[PSI_TABLE_SIZE * PSI_TABLE_SIZE];
104  static int PsiTableBuilt;
105 
106 private:
109  void operator=(const vtkUnstructuredGridPartialPreIntegration&) = delete;
110 };
111 
112 inline float vtkUnstructuredGridPartialPreIntegration::Psi(float taufD, float taubD)
113 {
114  float gammaf = taufD / (taufD + 1);
115  float gammab = taubD / (taubD + 1);
116  int gammafi = vtkMath::Floor(gammaf * PSI_TABLE_SIZE);
117  int gammabi = vtkMath::Floor(gammab * PSI_TABLE_SIZE);
118  return PsiTable[gammafi * PSI_TABLE_SIZE + gammabi];
119 }
120 
122 {
124  return PsiTable;
125 }
126 
128  double intensity_front, double attenuation_front, double intensity_back, double attenuation_back,
129  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  float newintensity =
138  (1 - color[3]) * (intensity_front * (1 - Psi) + intensity_back * (Psi - zeta));
139  // Is setting the RGB values the same the right thing to do?
140  color[0] += newintensity;
141  color[1] += newintensity;
142  color[2] += newintensity;
143  color[3] += (1 - color[3]) * alpha;
144 }
145 
147  const double color_front[3], double attenuation_front, const double color_back[3],
148  double attenuation_back, float color[4])
149 {
150  float taufD = length * attenuation_front;
151  float taubD = length * attenuation_back;
153  float zeta = static_cast<float>(exp(-0.5 * (taufD + taubD)));
154  float alpha = 1 - zeta;
155 
156  color[0] += (1 - color[3]) * (color_front[0] * (1 - Psi) + color_back[0] * (Psi - zeta));
157  color[1] += (1 - color[3]) * (color_front[1] * (1 - Psi) + color_back[1] * (Psi - zeta));
158  color[2] += (1 - color[3]) * (color_front[2] * (1 - Psi) + color_back[2] * (Psi - zeta));
159  color[3] += (1 - color[3]) * alpha;
160 }
161 
162 #endif // vtkUnstructuredGridPartialPreIntegration_h
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:34
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
Definition: vtkMath.h:1318
record modification and/or execution time
Definition: vtkTimeStamp.h:33
static vtkUnstructuredGridPartialPreIntegration * New()
void Integrate(vtkDoubleArray *intersectionLengths, vtkDataArray *nearIntersections, vtkDataArray *farIntersections, float color[4]) override
Given a set of intersections (defined by the three arrays), compute the piecewise integration of the ...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPartialPreIntegrationTransferFunction * TransferFunctions
void Initialize(vtkVolume *volume, vtkDataArray *scalars) override
Set up the integrator with the given properties and scalars.
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.
static float Psi(float taufD, float taubD)
Looks up Psi (as defined by Moreland and Angel, "A Fast High Accuracy Volume Renderer for Unstructure...
static float PsiTable[PSI_TABLE_SIZE *PSI_TABLE_SIZE]
a superclass for volume ray integration functions
represents the common properties for rendering a volume.
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:45
@ length
Definition: vtkX3D.h:399
@ alpha
Definition: vtkX3D.h:256
@ color
Definition: vtkX3D.h:227
@ size
Definition: vtkX3D.h:259