00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00044 #ifndef __vtkUnstructuredGridPartialPreIntegration_h
00045 #define __vtkUnstructuredGridPartialPreIntegration_h
00046
00047 #include "vtkUnstructuredGridVolumeRayIntegrator.h"
00048 #include "vtkMath.h"
00049
00050 class vtkPartialPreIntegrationTransferFunction;
00051 class vtkVolumeProperty;
00052
00053 class VTK_VOLUMERENDERING_EXPORT vtkUnstructuredGridPartialPreIntegration : public vtkUnstructuredGridVolumeRayIntegrator
00054 {
00055 public:
00056 vtkTypeRevisionMacro(vtkUnstructuredGridPartialPreIntegration,
00057 vtkUnstructuredGridVolumeRayIntegrator);
00058 static vtkUnstructuredGridPartialPreIntegration *New();
00059 virtual void PrintSelf(ostream &os, vtkIndent indent);
00060
00061 virtual void Initialize(vtkVolume *volume, vtkDataArray *scalars);
00062
00063 virtual void Integrate(vtkDoubleArray *intersectionLengths,
00064 vtkDataArray *nearIntersections,
00065 vtkDataArray *farIntersections,
00066 float color[4]);
00067
00069
00071 static void IntegrateRay(double length,
00072 double intensity_front, double attenuation_front,
00073 double intensity_back, double attenuation_back,
00074 float color[4]);
00075 static void IntegrateRay(double length,
00076 const double color_front[3],
00077 double attenuation_front,
00078 const double color_back[3],
00079 double attenuation_back,
00080 float color[4]);
00082
00087 static float Psi(float taufD, float taubD);
00088
00089 static void BuildPsiTable();
00090
00091 protected:
00092 vtkUnstructuredGridPartialPreIntegration();
00093 ~vtkUnstructuredGridPartialPreIntegration();
00094
00095 vtkVolumeProperty *Property;
00096
00097 vtkPartialPreIntegrationTransferFunction *TransferFunctions;
00098 vtkTimeStamp TransferFunctionsModified;
00099 int NumIndependentComponents;
00100
00101
00102 enum {PSI_TABLE_SIZE = 512};
00103
00104 static float PsiTable[PSI_TABLE_SIZE*PSI_TABLE_SIZE];
00105 static int PsiTableBuilt;
00106
00107 private:
00108 vtkUnstructuredGridPartialPreIntegration(const vtkUnstructuredGridPartialPreIntegration&);
00109 void operator=(const vtkUnstructuredGridPartialPreIntegration&);
00110 };
00111
00112 inline float vtkUnstructuredGridPartialPreIntegration::Psi(float taufD,
00113 float taubD)
00114 {
00115 float gammaf = taufD/(taufD+1);
00116 float gammab = taubD/(taubD+1);
00117 int gammafi = vtkMath::Floor(gammaf*PSI_TABLE_SIZE);
00118 int gammabi = vtkMath::Floor(gammab*PSI_TABLE_SIZE);
00119 return PsiTable[gammafi*PSI_TABLE_SIZE + gammabi];
00120 }
00121
00122 inline void vtkUnstructuredGridPartialPreIntegration::IntegrateRay(
00123 double length,
00124 double intensity_front,
00125 double attenuation_front,
00126 double intensity_back,
00127 double attenuation_back,
00128 float color[4])
00129 {
00130 float taufD = length*attenuation_front;
00131 float taubD = length*attenuation_back;
00132 float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD);
00133 float zeta = (float)exp(-0.5*(taufD+taubD));
00134 float alpha = 1-zeta;
00135
00136 float newintensity = (1-color[3])*( intensity_front*(1-Psi)
00137 + intensity_back*(Psi-zeta) );
00138
00139 color[0] += newintensity;
00140 color[1] += newintensity;
00141 color[2] += newintensity;
00142 color[3] += (1-color[3])*alpha;
00143 }
00144
00145 inline void vtkUnstructuredGridPartialPreIntegration::IntegrateRay(
00146 double length,
00147 const double color_front[3],
00148 double attenuation_front,
00149 const double color_back[3],
00150 double attenuation_back,
00151 float color[4])
00152 {
00153 float taufD = length*attenuation_front;
00154 float taubD = length*attenuation_back;
00155 float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD);
00156 float zeta = (float)exp(-0.5*(taufD+taubD));
00157 float alpha = 1-zeta;
00158
00159 color[0] += (1-color[3])*(color_front[0]*(1-Psi) + color_back[0]*(Psi-zeta));
00160 color[1] += (1-color[3])*(color_front[1]*(1-Psi) + color_back[1]*(Psi-zeta));
00161 color[2] += (1-color[3])*(color_front[2]*(1-Psi) + color_back[2]*(Psi-zeta));
00162 color[3] += (1-color[3])*alpha;
00163 }
00164
00165 #endif //__vtkUnstructuredGridPartialPreIntegration_h