VTK
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 "vtkRenderingVolumeModule.h" // For export macro
47 #include "vtkMath.h" // For all the inline methods
48 
49 class vtkPartialPreIntegrationTransferFunction;
50 class vtkVolumeProperty;
51 
53 {
54 public:
58  void PrintSelf(ostream &os, vtkIndent indent) override;
59 
60  void Initialize(vtkVolume *volume, vtkDataArray *scalars) override;
61 
62  void Integrate(vtkDoubleArray *intersectionLengths,
63  vtkDataArray *nearIntersections,
64  vtkDataArray *farIntersections,
65  float color[4]) override;
66 
68 
72  static void IntegrateRay(double length,
73  double intensity_front, double attenuation_front,
74  double intensity_back, double attenuation_back,
75  float color[4]);
76  static void IntegrateRay(double length,
77  const double color_front[3],
78  double attenuation_front,
79  const double color_back[3],
80  double attenuation_back,
81  float color[4]);
83 
85 
91  static float Psi(float taufD, float taubD);
92  static float *GetPsiTable(int &size);
93  static void BuildPsiTable();
95 
96 protected:
99 
101 
102  vtkPartialPreIntegrationTransferFunction *TransferFunctions;
105 
106  enum {PSI_TABLE_SIZE = 512};
107 
108  static float PsiTable[PSI_TABLE_SIZE*PSI_TABLE_SIZE];
109  static int PsiTableBuilt;
110 
111 private:
113  void operator=(const vtkUnstructuredGridPartialPreIntegration&) = delete;
114 };
115 
117  float taubD)
118 {
119  float gammaf = taufD/(taufD+1);
120  float gammab = taubD/(taubD+1);
121  int gammafi = vtkMath::Floor(gammaf*PSI_TABLE_SIZE);
122  int gammabi = vtkMath::Floor(gammab*PSI_TABLE_SIZE);
123  return PsiTable[gammafi*PSI_TABLE_SIZE + gammabi];
124 }
125 
127 {
128  size = PSI_TABLE_SIZE;
129  return PsiTable;
130 }
131 
133  double length,
134  double intensity_front,
135  double attenuation_front,
136  double intensity_back,
137  double attenuation_back,
138  float color[4])
139 {
140  float taufD = length*attenuation_front;
141  float taubD = length*attenuation_back;
142  float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD);
143  float zeta = static_cast<float>(exp(-0.5*(taufD+taubD)));
144  float alpha = 1-zeta;
145 
146  float newintensity = (1-color[3])*( intensity_front*(1-Psi)
147  + intensity_back*(Psi-zeta) );
148  // Is setting the RGB values the same the right thing to do?
149  color[0] += newintensity;
150  color[1] += newintensity;
151  color[2] += newintensity;
152  color[3] += (1-color[3])*alpha;
153 }
154 
156  double length,
157  const double color_front[3],
158  double attenuation_front,
159  const double color_back[3],
160  double attenuation_back,
161  float color[4])
162 {
163  float taufD = length*attenuation_front;
164  float taubD = length*attenuation_back;
165  float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD);
166  float zeta = static_cast<float>(exp(-0.5*(taufD+taubD)));
167  float alpha = 1-zeta;
168 
169  color[0] += (1-color[3])*(color_front[0]*(1-Psi) + color_back[0]*(Psi-zeta));
170  color[1] += (1-color[3])*(color_front[1]*(1-Psi) + color_back[1]*(Psi-zeta));
171  color[2] += (1-color[3])*(color_front[2]*(1-Psi) + color_back[2]*(Psi-zeta));
172  color[3] += (1-color[3])*alpha;
173 }
174 
175 #endif //vtkUnstructuredGridPartialPreIntegration_h
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:50
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:35
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:39
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
Definition: vtkMath.h:1344
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
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 ...