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 
45 #ifndef vtkUnstructuredGridPartialPreIntegration_h
46 #define vtkUnstructuredGridPartialPreIntegration_h
47 
48 #include "vtkRenderingVolumeModule.h" // For export macro
50 #include "vtkMath.h" // For all the inline methods
51 
52 class vtkPartialPreIntegrationTransferFunction;
53 class vtkVolumeProperty;
54 
56 {
57 public:
61  virtual void PrintSelf(ostream &os, vtkIndent indent);
62 
63  virtual void Initialize(vtkVolume *volume, vtkDataArray *scalars);
64 
65  virtual void Integrate(vtkDoubleArray *intersectionLengths,
66  vtkDataArray *nearIntersections,
67  vtkDataArray *farIntersections,
68  float color[4]);
69 
71 
75  static void IntegrateRay(double length,
76  double intensity_front, double attenuation_front,
77  double intensity_back, double attenuation_back,
78  float color[4]);
79  static void IntegrateRay(double length,
80  const double color_front[3],
81  double attenuation_front,
82  const double color_back[3],
83  double attenuation_back,
84  float color[4]);
86 
88 
94  static float Psi(float taufD, float taubD);
95  static float *GetPsiTable(int &size);
96  static void BuildPsiTable();
98 
99 protected:
102 
104 
105  vtkPartialPreIntegrationTransferFunction *TransferFunctions;
108 
109  enum {PSI_TABLE_SIZE = 512};
110 
111  static float PsiTable[PSI_TABLE_SIZE*PSI_TABLE_SIZE];
112  static int PsiTableBuilt;
113 
114 private:
116  void operator=(const vtkUnstructuredGridPartialPreIntegration&) VTK_DELETE_FUNCTION;
117 };
118 
119 inline float vtkUnstructuredGridPartialPreIntegration::Psi(float taufD,
120  float taubD)
121 {
122  float gammaf = taufD/(taufD+1);
123  float gammab = taubD/(taubD+1);
124  int gammafi = vtkMath::Floor(gammaf*PSI_TABLE_SIZE);
125  int gammabi = vtkMath::Floor(gammab*PSI_TABLE_SIZE);
126  return PsiTable[gammafi*PSI_TABLE_SIZE + gammabi];
127 }
128 
130 {
131  size = PSI_TABLE_SIZE;
132  return PsiTable;
133 }
134 
136  double length,
137  double intensity_front,
138  double attenuation_front,
139  double intensity_back,
140  double attenuation_back,
141  float color[4])
142 {
143  float taufD = length*attenuation_front;
144  float taubD = length*attenuation_back;
145  float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD);
146  float zeta = static_cast<float>(exp(-0.5*(taufD+taubD)));
147  float alpha = 1-zeta;
148 
149  float newintensity = (1-color[3])*( intensity_front*(1-Psi)
150  + intensity_back*(Psi-zeta) );
151  // Is setting the RGB values the same the right thing to do?
152  color[0] += newintensity;
153  color[1] += newintensity;
154  color[2] += newintensity;
155  color[3] += (1-color[3])*alpha;
156 }
157 
159  double length,
160  const double color_front[3],
161  double attenuation_front,
162  const double color_back[3],
163  double attenuation_back,
164  float color[4])
165 {
166  float taufD = length*attenuation_front;
167  float taubD = length*attenuation_back;
168  float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD);
169  float zeta = static_cast<float>(exp(-0.5*(taufD+taubD)));
170  float alpha = 1-zeta;
171 
172  color[0] += (1-color[3])*(color_front[0]*(1-Psi) + color_back[0]*(Psi-zeta));
173  color[1] += (1-color[3])*(color_front[1]*(1-Psi) + color_back[1]*(Psi-zeta));
174  color[2] += (1-color[3])*(color_front[2]*(1-Psi) + color_back[2]*(Psi-zeta));
175  color[3] += (1-color[3])*alpha;
176 }
177 
178 #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:1244
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 peicewise integration of the ...