00001 #include "lifevariables.h"
00002 #include "CScanner.h"
00003
00004 void CScanner::GenerateFirstHit()
00005 {
00006 int i, j;
00007 sPoint3f eye = _eye;
00008 sVector3f ray = _ray;
00009 long pixelIndex = 0;
00010 CVoxelValue voxelValue;
00011 sVector3f imageScale( 1,1,0 );
00012 sRGBA rgba;
00013 bool bNewRow;
00014 unsigned xRes;
00015 float currentDensity = 0;
00016
00017 if ( !refresh )
00018 return;
00019 else
00020 refresh = false;
00021
00022 stateBar->updateRenderInfo("Volume Rendering: Generating First Hit Image.");
00023
00024
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 SampleFHAlongRay(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
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 stateBar->updateRenderInfo("Volume Rendering: First Hit Image Generated.");
00073 }
00074
00075 void CScanner::SampleFHAlongRay(sPoint3f beginCoord, sPoint3f endCoord, sRGBA *pRGBA)
00076 {
00077
00078 CVector3f samplingDirection( endCoord.x - beginCoord.x,
00079 endCoord.y - beginCoord.y,
00080 endCoord.z - beginCoord.z );
00081 sVector3f vStep;
00082 sPoint3f samplePoint, sampleCoordinates;
00083 float sampleDensity = 0;
00084 float diffuseValue = 1;
00085 float maxDensity = GVolVoxels.GetMaxValue();
00086
00087
00088 sRGBA *tempRGBA = pRGBA;
00089
00090
00091 vStep = samplingDirection.GetNormalized();
00092 samplePoint = beginCoord;
00093
00094 float length = samplingDirection.GetMagnitude() - 1;
00095
00096 for ( int i = 0; i < length; i++ )
00097 {
00098 samplePoint = samplePoint + vStep;
00099 sampleCoordinates = samplePoint;
00100
00101 sampleCoordinates.x = _range.x + sampleCoordinates.x;
00102 sampleCoordinates.y = _range.y - sampleCoordinates.y;
00103 sampleCoordinates.z = _range.z + sampleCoordinates.z;
00104
00105
00106 switch ( optionPanel->volumeInterpolationMode )
00107 {
00108 case NEAREST_VOLUME:
00109 sampleDensity = GVolVoxels.GetVoxelValue(sampleCoordinates.x,
00110 sampleCoordinates.y,
00111 sampleCoordinates.z);
00112 break;
00113
00114
00115
00116 case TRILINEAR_VOLUME:
00117 sampleDensity = GVolVoxels.GetDensityTriLinear(sampleCoordinates);
00118 break;
00119
00120 default:
00121 break;
00122 }
00123
00124 diffuseValue = GetDiffuseValue(sampleCoordinates) + 0.5;
00125
00126
00127 histogram->getSolidVoxelColorByDensity(sampleDensity,
00128 tempRGBA->r,
00129 tempRGBA->g,
00130 tempRGBA->b);
00131
00132
00133
00134 tempRGBA->r *= diffuseValue;
00135 tempRGBA->g *= diffuseValue;
00136 tempRGBA->b *= diffuseValue;
00137 tempRGBA->a = 1;
00138
00139
00140 *pRGBA = *tempRGBA;
00141
00142 if ( sampleDensity >= optionPanel->currLowerThreshold )
00143 return;
00144 }
00145 return;
00146 }