00001 #include "lifevariables.h"
00002 #include "iostream"
00003 #include "CScanner.h"
00004
00005
00006
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
00020 break;
00021
00022 case FRONT_VIEW:
00023 cos_x_theta = 0;
00024 sin_x_theta = -1;
00025 X_Rotation = true;
00026
00027 break;
00028
00029 case SIDE_VIEW:
00030 cos_theta = 0;
00031 sin_theta = 1;
00032 Y_Rotation = true;
00033
00034 break;
00035
00036 case BOTTOM_VIEW:
00037 cos_theta = 1;
00038 sin_theta = 1;
00039 Y_Rotation = true;
00040
00041 break;
00042
00043 default:
00044 break;
00045 }
00046
00047
00048
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( )
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();
00087
00088 _wProjection = (float) GVolVoxels.GetBoundingDim();
00089 _hProjection = (float) GVolVoxels.GetBoundingDim();
00090
00091 _sizeProjection = _wProjection * _hProjection;
00092
00093 _eye.Init(- _wProjection/2, _hProjection/2, -420 );
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
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
00179
00180 diffuseValue = dot(nGrad.GetNormalized(), LightRay.GetNormalized());
00181
00182 if (diffuseValue < 0)
00183 diffuseValue = 0;
00184
00185 return diffuseValue;
00186 }