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

composite.cpp

00001 #include "lifevariables.h"
00002 #include "CScanner.h"
00003 
00004 
00005 void CScanner::GenerateComposite()
00006 {
00007     int i, j;   // loop counters
00008     sPoint3f    eye = _eye;
00009     sVector3f   ray = _ray;
00010     long        pixelIndex = 0;
00011     CVoxelValue voxelValue;
00012     sVector3f   imageScale( 1,1,0 );
00013     sRGBA       rgba;
00014     bool        bNewRow;
00015     unsigned    xRes;
00016     float       currentDensity = 0;
00017 
00018     if ( !refresh ) 
00019         return;
00020     else
00021         refresh = false;
00022 
00023     //
00024     //  Define begin and end coordinates to some out-of-bound value
00025     //
00026     sPoint3f    beginCoord(-1000,-1000,-1000), endCoord(-1000,-1000,-1000);
00027     _xRes = 0; _yRes = 0;
00028 
00029     for ( i = 0, _yRes = 0;
00030           i <   _scanRange;
00031           i++,  
00032           bNewRow = true, 
00033           xRes = 0,
00034           eye.x = _eye.x,
00035           eye.y = eye.y - imageScale.y)
00036     {
00037         for ( j = 0 ; 
00038               j <  _scanRange;
00039               j++, eye.x = eye.x + imageScale.x)
00040         {
00041             SetProjEye(eye);
00042 
00043             if ( GetIntersectionPoints(&beginCoord, &endCoord, _projEye, _ray) ) 
00044             {
00045                 SampleAlongRay(beginCoord, endCoord, &rgba);                
00046 
00047                 _aView[pixelIndex].r = rgba.r;
00048                 _aView[pixelIndex].g = rgba.g;
00049                 _aView[pixelIndex].b = rgba.b;                
00050                
00051                 pixelIndex++; 
00052 
00053                 /*
00054                  * Determine the actual resolution of the image
00055                  */
00056                 if (bNewRow)
00057                 {
00058                     _yRes++;
00059                     bNewRow = false;
00060                 }
00061 
00062                 if (!bNewRow)
00063                 {
00064                     xRes++;
00065                     if ( xRes > _xRes )
00066                         _xRes = xRes; 
00067                 }
00068 
00069             }
00070         }
00071     }
00072 }
00073 
00074 void CScanner::SampleAlongRay(sPoint3f beginCoord, sPoint3f endCoord, sRGBA *pRGBA)
00075 {
00076 
00077     CVector3f samplingDirection( endCoord.x - beginCoord.x,
00078                                  endCoord.y - beginCoord.y,
00079                                  endCoord.z - beginCoord.z );    
00080     sVector3f vStep;
00081     sPoint3f  samplePoint, sampleCoordinates;
00082     float     sampleDensity = 0;
00083     float     diffuseValue = 0;
00084     float     maxDensity = GVolVoxels.GetMaxValue();
00085 
00086     // store the start value
00087     sRGBA *tempRGBA = pRGBA;
00088     
00089 
00090     vStep       = samplingDirection.GetNormalized();
00091     samplePoint = beginCoord;
00092 
00093     float length = samplingDirection.GetMagnitude() - 1;
00094 
00095     for ( int i = 0; i < length; i++ )
00096     {        
00097         samplePoint = samplePoint + vStep;
00098         sampleCoordinates = samplePoint;
00099 
00100         sampleCoordinates.x = _range.x + sampleCoordinates.x;
00101         sampleCoordinates.y = _range.y - sampleCoordinates.y;
00102         sampleCoordinates.z = _range.z + sampleCoordinates.z;
00103 
00104         switch ( optionPanel->volumeInterpolationMode )
00105         {
00106         case NEAREST_VOLUME:
00107             sampleDensity = GVolVoxels.GetVoxelValue(sampleCoordinates.x,sampleCoordinates.y,sampleCoordinates.z);
00108             break;
00109            /*
00110             *  Get interpolated density and gradient-based diffuse value at this sample point
00111             */
00112         case TRILINEAR_VOLUME:
00113            sampleDensity = GVolVoxels.GetDensityTriLinear(sampleCoordinates);
00114            break;
00115 
00116         default:
00117             break;
00118         }
00119 
00120        diffuseValue = GetDiffuseValue(sampleCoordinates);
00121        
00122        // get the color per density
00123        histogram->getVoxelColorByDensity(sampleDensity,
00124                                          tempRGBA->r,
00125                                          tempRGBA->g,
00126                                          tempRGBA->b);
00127 
00128        
00129        // calculate the shading for the surface
00130        tempRGBA->r *= diffuseValue;
00131        tempRGBA->g *= diffuseValue;
00132        tempRGBA->b *= diffuseValue;
00133 
00134        // accumulte the colors
00135        *pRGBA += *tempRGBA;
00136     }
00137 
00138     return;
00139 }

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