Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkUnstructuredGridPartialPreIntegration.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkUnstructuredGridPartialPreIntegration.h,v $
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 
00054 #ifndef __vtkUnstructuredGridPartialPreIntegration_h
00055 #define __vtkUnstructuredGridPartialPreIntegration_h
00056 
00057 #include "vtkUnstructuredGridVolumeRayIntegrator.h"
00058 #include "vtkMath.h" // For all the inline methods
00059 
00060 class vtkPartialPreIntegrationTransferFunction;
00061 
00062 class VTK_RENDERING_EXPORT vtkUnstructuredGridPartialPreIntegration : public vtkUnstructuredGridVolumeRayIntegrator
00063 {
00064 public:
00065   vtkTypeRevisionMacro(vtkUnstructuredGridPartialPreIntegration,
00066                        vtkUnstructuredGridVolumeRayIntegrator);
00067   static vtkUnstructuredGridPartialPreIntegration *New();
00068   virtual void PrintSelf(ostream &os, vtkIndent indent);
00069 
00070   virtual void Initialize(vtkVolumeProperty *property, vtkDataArray *scalars);
00071 
00072   virtual void Integrate(vtkDoubleArray *intersectionLengths,
00073                          vtkDataArray *nearIntersections,
00074                          vtkDataArray *farIntersections,
00075                          float color[4]);
00076 
00078 
00080   static void IntegrateRay(double length,
00081                            double intensity_front, double attenuation_front,
00082                            double intensity_back, double attenuation_back,
00083                            float color[4]);
00084   static void IntegrateRay(double length,
00085                            const double color_front[3],
00086                            double attenuation_front,
00087                            const double color_back[3],
00088                            double attenuation_back,
00089                            float color[4]);
00091 
00096   static float Psi(float taufD, float taubD);
00097 
00098   static void BuildPsiTable();
00099 
00100 protected:
00101   vtkUnstructuredGridPartialPreIntegration();
00102   ~vtkUnstructuredGridPartialPreIntegration();
00103 
00104   vtkVolumeProperty *Property;
00105 
00106   vtkPartialPreIntegrationTransferFunction *TransferFunctions;
00107   vtkTimeStamp TransferFunctionsModified;
00108   int NumIndependentComponents;
00109 
00110 //BTX
00111   enum {PSI_TABLE_SIZE = 512};
00112 //ETX
00113   static float PsiTable[PSI_TABLE_SIZE*PSI_TABLE_SIZE];
00114 
00115 private:
00116   vtkUnstructuredGridPartialPreIntegration(const vtkUnstructuredGridPartialPreIntegration&);  // Not implemented.
00117   void operator=(const vtkUnstructuredGridPartialPreIntegration&);  // Not implemented.
00118 };
00119 
00120 inline float vtkUnstructuredGridPartialPreIntegration::Psi(float taufD,
00121                                                            float taubD)
00122 {
00123   float gammaf = taufD/(taufD+1);
00124   float gammab = taubD/(taubD+1);
00125   int gammafi = vtkMath::Floor(gammaf*PSI_TABLE_SIZE);
00126   int gammabi = vtkMath::Floor(gammab*PSI_TABLE_SIZE);
00127   return PsiTable[gammafi*PSI_TABLE_SIZE + gammabi];
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 = (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 = (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