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 
44 #ifndef __vtkUnstructuredGridPartialPreIntegration_h
45 #define __vtkUnstructuredGridPartialPreIntegration_h
46 
48 #include "vtkMath.h" // For all the inline methods
49 
50 class vtkPartialPreIntegrationTransferFunction;
51 class vtkVolumeProperty;
52 
54 {
55 public:
59  virtual void PrintSelf(ostream &os, vtkIndent indent);
60 
61  virtual void Initialize(vtkVolume *volume, vtkDataArray *scalars);
62 
63  virtual void Integrate(vtkDoubleArray *intersectionLengths,
64  vtkDataArray *nearIntersections,
65  vtkDataArray *farIntersections,
66  float color[4]);
67 
69 
71  static void IntegrateRay(double length,
72  double intensity_front, double attenuation_front,
73  double intensity_back, double attenuation_back,
74  float color[4]);
75  static void IntegrateRay(double length,
76  const double color_front[3],
77  double attenuation_front,
78  const double color_back[3],
79  double attenuation_back,
80  float color[4]);
82 
84 
88  static float Psi(float taufD, float taubD);
89  static float *GetPsiTable(int &size);
90  static void BuildPsiTable();
92 
93 protected:
96 
98 
99  vtkPartialPreIntegrationTransferFunction *TransferFunctions;
102 
103 //BTX
104  enum {PSI_TABLE_SIZE = 512};
105 //ETX
106  static float PsiTable[PSI_TABLE_SIZE*PSI_TABLE_SIZE];
107  static int PsiTableBuilt;
108 
109 private:
111  void operator=(const vtkUnstructuredGridPartialPreIntegration&); // Not implemented.
112 };
113 
115  float taubD)
116 {
117  float gammaf = taufD/(taufD+1);
118  float gammab = taubD/(taubD+1);
119  int gammafi = vtkMath::Floor(gammaf*PSI_TABLE_SIZE);
120  int gammabi = vtkMath::Floor(gammab*PSI_TABLE_SIZE);
121  return PsiTable[gammafi*PSI_TABLE_SIZE + gammabi];
122 }
123 
125 {
126  size = PSI_TABLE_SIZE;
127  return PsiTable;
128 }
129 
131  double length,
132  double intensity_front,
133  double attenuation_front,
134  double intensity_back,
135  double attenuation_back,
136  float color[4])
137 {
138  float taufD = length*attenuation_front;
139  float taubD = length*attenuation_back;
141  float zeta = static_cast<float>(exp(-0.5*(taufD+taubD)));
142  float alpha = 1-zeta;
143 
144  float newintensity = (1-color[3])*( intensity_front*(1-Psi)
145  + intensity_back*(Psi-zeta) );
146  // Is setting the RGB values the same the right thing to do?
147  color[0] += newintensity;
148  color[1] += newintensity;
149  color[2] += newintensity;
150  color[3] += (1-color[3])*alpha;
151 }
152 
154  double length,
155  const double color_front[3],
156  double attenuation_front,
157  const double color_back[3],
158  double attenuation_back,
159  float color[4])
160 {
161  float taufD = length*attenuation_front;
162  float taubD = length*attenuation_back;
164  float zeta = static_cast<float>(exp(-0.5*(taufD+taubD)));
165  float alpha = 1-zeta;
166 
167  color[0] += (1-color[3])*(color_front[0]*(1-Psi) + color_back[0]*(Psi-zeta));
168  color[1] += (1-color[3])*(color_front[1]*(1-Psi) + color_back[1]*(Psi-zeta));
169  color[2] += (1-color[3])*(color_front[2]*(1-Psi) + color_back[2]*(Psi-zeta));
170  color[3] += (1-color[3])*alpha;
171 }
172 
173 #endif //__vtkUnstructuredGridPartialPreIntegration_h