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

mip.cpp

00001 #include "lifevariables.h"
00002 #include "CScanner.h"
00003 
00004 static unsigned gVolumeInterpolation = 0x0601;
00005 
00006 #define NEAREST 0x0600
00007 #define TRILIN  0x0601
00008 
00009 /*
00010  *  Generate MIP view
00011  *
00012  */
00013 
00014 void CScanner::GenerateMIP()
00015 {
00016     int i, j;   // loop counters
00017     sPoint3f    eye = _eye;
00018     sVector3f   ray = _ray;
00019     long        pixelIndex = 0;
00020     float       currentDensity = 0;
00021     bool        bNewRow = true;
00022     unsigned    xRes;
00023     sVector3f   imageScale( 1,1,0 );
00024 
00025     if ( !refresh ) 
00026         return;
00027     else
00028         refresh = false;
00029     stateBar->updateRenderInfo("Volume Rendering: Generating Max. Intensity Projection 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 = SampleMIPAlongRay(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: Max. Intensity Projection Image Generated.");
00081 }
00082 
00083 float CScanner::SampleMIPAlongRay(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     unsigned  newDensity = 0;
00097 
00098     vStep       = samplingDirection.GetNormalized();
00099     samplePoint = beginCoord;
00100 
00101     float length = samplingDirection.GetMagnitude() - 1;
00102 
00103     for ( int i = 0; i < length; i++ )
00104     {
00105         samplePoint = samplePoint + vStep;
00106         sampleCoordinates = samplePoint;
00107 
00108         sampleCoordinates.x = _range.x + sampleCoordinates.x;
00109         sampleCoordinates.y = _range.y - sampleCoordinates.y;
00110         sampleCoordinates.z = _range.z + sampleCoordinates.z;
00111         
00112         switch ( optionPanel->volumeInterpolationMode )
00113         {
00114         case NEAREST_VOLUME:
00115             sampleDensity = GVolVoxels.GetVoxelValue(sampleCoordinates.x,sampleCoordinates.y,sampleCoordinates.z);
00116             GVolVoxels.GetGradient(sampleCoordinates.x, sampleCoordinates.y, sampleCoordinates.z, &grad);
00117 
00118             break;
00119         case TRILINEAR_VOLUME:
00120             sampleDensity = GVolVoxels.GetDensityTriLinear(sampleCoordinates);
00121             GVolVoxels.GetGradient(sampleCoordinates.x, sampleCoordinates.y, sampleCoordinates.z, &grad);
00122             break;
00123 
00124         default:
00125             break;
00126         }
00127 
00128         if ( newDensity < sampleDensity )
00129             newDensity = sampleDensity;
00130     }
00131 
00132     return newDensity;
00133 }

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