VTK
dox/VolumeRendering/vtkUnstructuredGridPartialPreIntegration.h
Go to the documentation of this file.
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 "vtkUnstructuredGridVolumeRayIntegrator.h"
00048 #include "vtkMath.h" // For all the inline methods
00049 
00050 class vtkPartialPreIntegrationTransferFunction;
00051 class vtkVolumeProperty;
00052 
00053 class VTK_VOLUMERENDERING_EXPORT vtkUnstructuredGridPartialPreIntegration : public vtkUnstructuredGridVolumeRayIntegrator
00054 {
00055 public:
00056   vtkTypeMacro(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 
00084 
00088   static float Psi(float taufD, float taubD);
00089   static float *GetPsiTable(int &size);
00090   static void BuildPsiTable();
00092 
00093 protected:
00094   vtkUnstructuredGridPartialPreIntegration();
00095   ~vtkUnstructuredGridPartialPreIntegration();
00096 
00097   vtkVolumeProperty *Property;
00098  
00099   vtkPartialPreIntegrationTransferFunction *TransferFunctions;
00100   vtkTimeStamp TransferFunctionsModified;
00101   int NumIndependentComponents;
00102 
00103 //BTX
00104   enum {PSI_TABLE_SIZE = 512};
00105 //ETX
00106   static float PsiTable[PSI_TABLE_SIZE*PSI_TABLE_SIZE];
00107   static int PsiTableBuilt;
00108 
00109 private:
00110   vtkUnstructuredGridPartialPreIntegration(const vtkUnstructuredGridPartialPreIntegration&);  // Not implemented.
00111   void operator=(const vtkUnstructuredGridPartialPreIntegration&);  // Not implemented.
00112 };
00113 
00114 inline float vtkUnstructuredGridPartialPreIntegration::Psi(float taufD,
00115                                                            float taubD)
00116 {
00117   float gammaf = taufD/(taufD+1);
00118   float gammab = taubD/(taubD+1);
00119   int gammafi = vtkMath::Floor(gammaf*PSI_TABLE_SIZE);
00120   int gammabi = vtkMath::Floor(gammab*PSI_TABLE_SIZE);
00121   return PsiTable[gammafi*PSI_TABLE_SIZE + gammabi];
00122 }
00123 
00124 inline float *vtkUnstructuredGridPartialPreIntegration::GetPsiTable(int &size)
00125 {
00126   size = PSI_TABLE_SIZE;
00127   return PsiTable;
00128 }
00129 
00130 inline void vtkUnstructuredGridPartialPreIntegration::IntegrateRay(
00131                                                        double length,
00132                                                        double intensity_front,
00133                                                        double attenuation_front,
00134                                                        double intensity_back,
00135                                                        double attenuation_back,
00136                                                        float color[4])
00137 {
00138   float taufD = length*attenuation_front;
00139   float taubD = length*attenuation_back;
00140   float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD);
00141   float zeta = static_cast<float>(exp(-0.5*(taufD+taubD)));
00142   float alpha = 1-zeta;
00143 
00144   float newintensity = (1-color[3])*(  intensity_front*(1-Psi)
00145                                      + intensity_back*(Psi-zeta) );
00146   // Is setting the RGB values the same the right thing to do?
00147   color[0] += newintensity;
00148   color[1] += newintensity;
00149   color[2] += newintensity;
00150   color[3] += (1-color[3])*alpha;
00151 }
00152 
00153 inline void vtkUnstructuredGridPartialPreIntegration::IntegrateRay(
00154                                                     double length,
00155                                                     const double color_front[3],
00156                                                     double attenuation_front,
00157                                                     const double color_back[3],
00158                                                     double attenuation_back,
00159                                                     float color[4])
00160 {
00161   float taufD = length*attenuation_front;
00162   float taubD = length*attenuation_back;
00163   float Psi = vtkUnstructuredGridPartialPreIntegration::Psi(taufD, taubD);
00164   float zeta = static_cast<float>(exp(-0.5*(taufD+taubD)));
00165   float alpha = 1-zeta;
00166 
00167   color[0] += (1-color[3])*(color_front[0]*(1-Psi) + color_back[0]*(Psi-zeta));
00168   color[1] += (1-color[3])*(color_front[1]*(1-Psi) + color_back[1]*(Psi-zeta));
00169   color[2] += (1-color[3])*(color_front[2]*(1-Psi) + color_back[2]*(Psi-zeta));
00170   color[3] += (1-color[3])*alpha;
00171 }
00172 
00173 #endif //__vtkUnstructuredGridPartialPreIntegration_h