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

CScanner.cpp

00001 #include "lifevariables.h"
00002 #include "iostream"
00003 #include "CScanner.h"
00004 
00005 //static unsigned gRequestedView = optionPanel->viewingDirection;//0x0502;
00006 //static unsigned int gRequestedView = FRONT_VIEW;
00007 
00008 void CScanner::SetProjEye(sPoint3f eye)
00009 {
00010     bool X_Rotation = false, Y_Rotation = false;
00011     
00012     switch ( direction )
00013     {
00014         
00015         case TOP_VIEW:
00016             cos_x_theta = 1;  
00017             sin_x_theta = 0;
00018             X_Rotation = true;
00019             //cout << "Top View" << endl;
00020             break;
00021 
00022         case FRONT_VIEW://BACK_VIEW:
00023             cos_x_theta = 0;
00024             sin_x_theta = -1;
00025             X_Rotation = true;
00026             //cout << "Back View" << endl;
00027             break;
00028 
00029         case SIDE_VIEW://SIDE_VIEW:
00030             cos_theta = 0;
00031             sin_theta = 1;
00032             Y_Rotation = true;
00033             //cout << "Side View" << endl;
00034             break;
00035     
00036         case BOTTOM_VIEW: //BOTTOM_VIEW:
00037             cos_theta = 1;
00038             sin_theta = 1;
00039             Y_Rotation = true;
00040             //cout << "Bottom View" << endl;
00041             break;
00042 
00043         default:
00044             break;
00045     }
00046 
00047     /*
00048      * x-axis rotation
00049      */
00050     if ( X_Rotation )
00051     {
00052         _projEye.z = eye.y * sin_x_theta + eye.z * cos_x_theta;
00053         _projEye.x = eye.x; 
00054         _projEye.y = eye.y * cos_x_theta - eye.z * sin_x_theta;
00055 
00056         if ( !_bRaySet )
00057         {
00058             _ray.Init(0,sin_x_theta, cos_x_theta);
00059             _bRaySet = true;
00060         }
00061 
00062     }
00063     else if ( Y_Rotation )
00064     {
00065         _projEye.z = eye.z * cos_theta - eye.x * sin_theta;
00066         _projEye.x = eye.z * sin_theta + eye.x * cos_theta;
00067         _projEye.y = eye.y;
00068 
00069         if ( !_bRaySet )
00070         {
00071             _ray.Init(sin_theta, 0, cos_theta);    
00072             _bRaySet = true;
00073         }
00074     }
00075 }
00076 
00077 CScanner::Init( /* sPoint3f eye, sVector3f dir, float stepSize */ )
00078 {
00079     _iXCount = 0;
00080     _fStepSize = 1;
00081 
00082     _range.x = ( GVolVoxels.GetDimX() / 2 ) - 1;
00083     _range.y = ( GVolVoxels.GetDimY() / 2 ) - 1;
00084     _range.z = ( GVolVoxels.GetDimZ() / 2 ) - 1;
00085 
00086     _scanRange = GVolVoxels.GetBoundingDim(); // GVolVoxels.GetBoundingDim();
00087     
00088     _wProjection = (float)  GVolVoxels.GetBoundingDim(); // need to fix this later...
00089     _hProjection = (float)  GVolVoxels.GetBoundingDim();
00090     
00091     _sizeProjection = _wProjection * _hProjection;
00092 
00093     _eye.Init(- _wProjection/2, _hProjection/2, -420 );  // eye;
00094     
00095     _bRaySet = false;
00096 
00097     SetProjEye(_eye);
00098 
00099     if ( _aView )
00100     {
00101         delete[] _aView;
00102         _aView = 0;
00103     }
00104 
00105     _aView = new sRGBA[ _sizeProjection];
00106     if ( !_aView )
00107         throw;
00108 
00109     for ( int i = 0; i < _sizeProjection; i++ )
00110     {
00111         _aView[i].r = 0;
00112         _aView[i].g = 0;
00113         _aView[i].b = 0;
00114         _aView[i].a = 0;
00115     }
00116 
00117   }
00118 
00123 void CScanner::ScanVolume()
00124 {    
00125     switch ( optionPanel->txFunction )
00126     {    
00127         case XRAY:
00128             GenerateXRAY();
00129             break;
00130 
00131         case COMPOSITING:
00132             GenerateComposite();
00133             break;
00134 
00135         case MIP:
00136             GenerateMIP();
00137             break;
00138 
00139         case FIRST_HIT:
00140             GenerateFirstHit();
00141             break;
00142 
00143         default:
00144             break;
00145     }
00146 }
00147 
00148 
00154 float CScanner::GetDiffuseValue(sPoint3f coordinate)
00155 {
00156 
00157     sGrad       grad;
00158     float       diffuseValue = 0;
00159     //CVector3f   LightRay(1,1,-1);
00160 
00161     switch ( optionPanel->volumeInterpolationMode )
00162     {
00163         case NEAREST_VOLUME:
00164             
00165                GVolVoxels.GetGradient(coordinate.x, coordinate.y, coordinate.z, &grad);
00166                break;
00167 
00168         case TRILINEAR_VOLUME:
00169 
00170                 GVolVoxels.GetGradientTriLinear(coordinate.x, coordinate.y, coordinate.z, &grad);
00171                 break;
00172         default:
00173             break;
00174     }
00175 
00176     CVector3f   nGrad(grad.x,grad.y,grad.z);
00177     CVector3f   LightRay(optionPanel->lightX,optionPanel->lightY,optionPanel->lightZ);
00178     //CVector3f   nRay(_ray.x,_ray.y,_ray.z);
00179 
00180     diffuseValue = dot(nGrad.GetNormalized(), LightRay.GetNormalized());
00181 
00182     if (diffuseValue < 0)
00183         diffuseValue = 0;
00184 
00185     return diffuseValue;
00186 }

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