VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkUnstructuredGridPartialPreIntegration.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 00016 /* 00017 * Copyright 2004 Sandia Corporation. 00018 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00019 * license for use of this work by or on behalf of the 00020 * U.S. Government. Redistribution and use in source and binary forms, with 00021 * or without modification, are permitted provided that this Notice and any 00022 * statement of authorship are reproduced on all copies. 00023 */ 00024 00044 #ifndef __vtkUnstructuredGridPartialPreIntegration_h 00045 #define __vtkUnstructuredGridPartialPreIntegration_h 00046 00047 #include "vtkRenderingVolumeModule.h" // For export macro 00048 #include "vtkUnstructuredGridVolumeRayIntegrator.h" 00049 #include "vtkMath.h" // For all the inline methods 00050 00051 class vtkPartialPreIntegrationTransferFunction; 00052 class vtkVolumeProperty; 00053 00054 class VTKRENDERINGVOLUME_EXPORT vtkUnstructuredGridPartialPreIntegration : public vtkUnstructuredGridVolumeRayIntegrator 00055 { 00056 public: 00057 vtkTypeMacro(vtkUnstructuredGridPartialPreIntegration, 00058 vtkUnstructuredGridVolumeRayIntegrator); 00059 static vtkUnstructuredGridPartialPreIntegration *New(); 00060 virtual void PrintSelf(ostream &os, vtkIndent indent); 00061 00062 virtual void Initialize(vtkVolume *volume, vtkDataArray *scalars); 00063 00064 virtual void Integrate(vtkDoubleArray *intersectionLengths, 00065 vtkDataArray *nearIntersections, 00066 vtkDataArray *farIntersections, 00067 float color[4]); 00068 00070 00072 static void IntegrateRay(double length, 00073 double intensity_front, double attenuation_front, 00074 double intensity_back, double attenuation_back, 00075 float color[4]); 00076 static void IntegrateRay(double length, 00077 const double color_front[3], 00078 double attenuation_front, 00079 const double color_back[3], 00080 double attenuation_back, 00081 float color[4]); 00083 00085 00089 static float Psi(float taufD, float taubD); 00090 static float *GetPsiTable(int &size); 00091 static void BuildPsiTable(); 00093 00094 protected: 00095 vtkUnstructuredGridPartialPreIntegration(); 00096 ~vtkUnstructuredGridPartialPreIntegration(); 00097 00098 vtkVolumeProperty *Property; 00099 00100 vtkPartialPreIntegrationTransferFunction *TransferFunctions; 00101 vtkTimeStamp TransferFunctionsModified; 00102 int NumIndependentComponents; 00103 00104 //BTX 00105 enum {PSI_TABLE_SIZE = 512}; 00106 //ETX 00107 static float PsiTable[PSI_TABLE_SIZE*PSI_TABLE_SIZE]; 00108 static int PsiTableBuilt; 00109 00110 private: 00111 vtkUnstructuredGridPartialPreIntegration(const vtkUnstructuredGridPartialPreIntegration&); // Not implemented. 00112 void operator=(const vtkUnstructuredGridPartialPreIntegration&); // Not implemented. 00113 }; 00114 00115 inline float vtkUnstructuredGridPartialPreIntegration::Psi(float taufD, 00116 float taubD) 00117 { 00118 float gammaf = taufD/(taufD+1); 00119 float gammab = taubD/(taubD+1); 00120 int gammafi = vtkMath::Floor(gammaf*PSI_TABLE_SIZE); 00121 int gammabi = vtkMath::Floor(gammab*PSI_TABLE_SIZE); 00122 return PsiTable[gammafi*PSI_TABLE_SIZE + gammabi]; 00123 } 00124 00125 inline float *vtkUnstructuredGridPartialPreIntegration::GetPsiTable(int &size) 00126 { 00127 size = PSI_TABLE_SIZE; 00128 return PsiTable; 00129 } 00130 00131 inline void vtkUnstructuredGridPartialPreIntegration::IntegrateRay( 00132 double length, 00133 double intensity_front, 00134 double attenuation_front, 00135 double intensity_back, 00136 double attenuation_back, 00137 float color[4]) 00138 { 00139 float taufD = length*attenuation_front; 00140 float taubD = length*attenuation_back; 00141 float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD); 00142 float zeta = static_cast<float>(exp(-0.5*(taufD+taubD))); 00143 float alpha = 1-zeta; 00144 00145 float newintensity = (1-color[3])*( intensity_front*(1-Psi) 00146 + intensity_back*(Psi-zeta) ); 00147 // Is setting the RGB values the same the right thing to do? 00148 color[0] += newintensity; 00149 color[1] += newintensity; 00150 color[2] += newintensity; 00151 color[3] += (1-color[3])*alpha; 00152 } 00153 00154 inline void vtkUnstructuredGridPartialPreIntegration::IntegrateRay( 00155 double length, 00156 const double color_front[3], 00157 double attenuation_front, 00158 const double color_back[3], 00159 double attenuation_back, 00160 float color[4]) 00161 { 00162 float taufD = length*attenuation_front; 00163 float taubD = length*attenuation_back; 00164 float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD); 00165 float zeta = static_cast<float>(exp(-0.5*(taufD+taubD))); 00166 float alpha = 1-zeta; 00167 00168 color[0] += (1-color[3])*(color_front[0]*(1-Psi) + color_back[0]*(Psi-zeta)); 00169 color[1] += (1-color[3])*(color_front[1]*(1-Psi) + color_back[1]*(Psi-zeta)); 00170 color[2] += (1-color[3])*(color_front[2]*(1-Psi) + color_back[2]*(Psi-zeta)); 00171 color[3] += (1-color[3])*alpha; 00172 } 00173 00174 #endif //__vtkUnstructuredGridPartialPreIntegration_h