Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

xray.cpp

00001 #include "lifevariables.h"
00002 #include "CScanner.h"
00003 
00004 /*
00005  *  Generate XRAY view
00006  *
00007  */
00008 
00009 static unsigned gVolumeInterpolation = 0x0601;
00010 #define NEAREST 0x0600
00011 #define TRILIN  0x0601
00012 
00013 void CScanner::GenerateXRAY()
00014 {
00015     int i, j;   // loop counters
00016     sPoint3f    eye = _eye;
00017     sVector3f   ray = _ray;
00018     long        pixelIndex = 0;
00019     float       currentDensity = 0;
00020     bool        bNewRow = true;
00021     unsigned    xRes = 0;
00022     sVector3f   imageScale( 1,1,0 );
00023 
00024     if ( !refresh ) 
00025         return;
00026     else
00027         refresh = false;
00028     
00029     stateBar->updateRenderInfo("Volume Rendering: Generating X-Ray Image");
00030     //
00031     //  Define begin and end coordinates to some out-of-bound value
00032     //
00033     sPoint3f    beginCoord(-1000,-1000,-1000), endCoord(-1000,-1000,-1000);
00034     _xRes = 0; _yRes = 0;
00035 
00036     for ( i = 0, _yRes = 0;
00037           i <   _scanRange;
00038           i++,  
00039           bNewRow = true, 
00040           xRes = 0,
00041           eye.x = _eye.x,
00042           eye.y = eye.y - imageScale.y)
00043     {
00044         for ( j = 0 ; 
00045               j <  _scanRange;
00046               j++, eye.x = eye.x + imageScale.x)
00047         {
00048             SetProjEye(eye);
00049 
00050             if ( GetIntersectionPoints(&beginCoord, &endCoord, _projEye, _ray) ) 
00051             {
00052                 currentDensity = SampleXRAYAlongRay(beginCoord, endCoord);                
00053 
00054                 histogram->getVoxelColorByDensity(currentDensity, 
00055                     _aView[pixelIndex].r,
00056                     _aView[pixelIndex].g,
00057                     _aView[pixelIndex].b ); 
00058                               
00059                 pixelIndex++; 
00060 
00061                 /*
00062                  * Determine the actual resolution of the image
00063                  */
00064                 if (bNewRow)
00065                 {
00066                     _yRes++;
00067                     bNewRow = false;
00068                 }
00069 
00070                 if (!bNewRow)
00071                 {
00072                     xRes++;
00073                     if ( xRes > _xRes )
00074                         _xRes = xRes; 
00075                 }
00076    
00077             }
00078         }
00079     }
00080     stateBar->updateRenderInfo("Volume Rendering: X-Ray Image generated");
00081 }
00082 
00083 float CScanner::SampleXRAYAlongRay(sPoint3f beginCoord, sPoint3f endCoord)
00084 {
00085 
00086     CVector3f samplingDirection( endCoord.x - beginCoord.x,
00087                                  endCoord.y - beginCoord.y,
00088                                  endCoord.z - beginCoord.z );    
00089 
00090     sVector3f vStep;
00091     sPoint3f  samplePoint, sampleCoordinates;
00092     float     sampleDensity = 0;
00093     float     maxDensity = GVolVoxels.GetMaxValue();
00094     sGrad     grad(0,0,0);
00095     sGrad     sampleGradient(0,0,0);
00096 
00097     vStep       = samplingDirection.GetNormalized();
00098     samplePoint = beginCoord;
00099 
00100     float length = samplingDirection.GetMagnitude() - 1;
00101 
00102     for ( int i = 0; i < length; i++ )
00103     {
00104         samplePoint = samplePoint + vStep;
00105         sampleCoordinates = samplePoint;
00106 
00107         sampleCoordinates.x = _range.x + sampleCoordinates.x;
00108         sampleCoordinates.y = _range.y - sampleCoordinates.y;
00109         sampleCoordinates.z = _range.z + sampleCoordinates.z;
00110 
00111         switch ( optionPanel->volumeInterpolationMode )
00112         {
00113         case NEAREST_VOLUME:
00114             sampleDensity += GVolVoxels.GetVoxelValue(sampleCoordinates.x,sampleCoordinates.y,sampleCoordinates.z);
00115             GVolVoxels.GetGradient(sampleCoordinates.x, sampleCoordinates.y, sampleCoordinates.z, &grad);
00116 
00117             break;
00118         case TRILINEAR_VOLUME:
00119             sampleDensity += GVolVoxels.GetDensityTriLinear(sampleCoordinates);
00120             GVolVoxels.GetGradient(sampleCoordinates.x, sampleCoordinates.y, sampleCoordinates.z, &grad);
00121             break;
00122 
00123         default:
00124             break;
00125         }
00126     }
00127 
00128     sampleDensity = sampleDensity / length;     // average
00129     
00130     return sampleDensity;
00131 }

Generated on Mon Dec 12 15:20:26 2005 for CCube by  doxygen 1.4.1