00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "ray.h"
00008
00009
00010 Ray::Ray() {
00011
00012 m_direction = VECTOR(1,0,0);
00013
00014 m_currentpos = VECTOR(0,0,0);
00015
00016 m_ambient = 0.2f;
00017
00018 m_diffuse = 0.2f;
00019
00020 m_tf = NULL;
00021
00022 m_data = NULL;
00023
00024 m_backgroundcolor = Color(0.0,0.0,0.0);
00025
00026 m_currentcolor = Color(0.0,0.0,0.0);
00027
00028 m_alpha = 0.0;
00029
00030 m_startpoint = VECTOR(0,0,0);
00031
00032 m_steplength = 1.0;
00033 m_specular = 0.2f;
00034
00035 m_highlight = 8;
00036
00037 m_light = false;
00038 m_viewingplane = NULL;
00039 mx = 0.0f;
00040 my = 0.0f;
00041 mz = 0.0f;
00042
00043 m_minDens = 0;
00044 m_maxDens = 4095;
00045 }
00046
00047 Ray::~Ray() {}
00048
00050 bool
00051 Ray::SetViewingCondition(VECTOR lightpos, float ambient, float diffuse, float specular, int highlight) {
00052
00053 if (ambient > 1.0) ambient = 1.0;
00054 if (ambient < 0.0) ambient = 0.0;
00055 if (diffuse > 1.0) diffuse = 1.0;
00056 if (diffuse < 0.0) diffuse = 0.0;
00057 if (specular > 1.0) specular = 1.0;
00058 if (specular < 0.0) specular = 0.0;
00059 if(highlight < 0) highlight = 0;
00060
00061 m_highlight = highlight;
00062 m_specular = specular;
00063 m_ambient = ambient;
00064 m_diffuse = diffuse;
00065 return true;
00066 }
00067
00068
00069
00071 Color
00072 Ray::Lighting(Color color) {
00073 gradient_t grad = m_data->CalcGrad((int)ROUND(m_currentpos.x),(int)ROUND(m_currentpos.y),(int)ROUND(m_currentpos.z));
00074 VECTOR normal = VECTOR(grad.x, grad.y, grad.z);
00075 normal.normalize();
00076 VECTOR len = m_currentpos - m_startpoint;
00077 Color ret;
00078 if(m_light) {
00079 VECTOR v = -m_direction;
00080 v.normalize();
00081 VECTOR l = m_lightpos-m_currentpos;
00082 l.normalize();
00083 VECTOR h = (v+l);
00084 h.normalize();
00085 ret = color*m_ambient + color*((m_diffuse*(normal.dot(m_direction))) + (m_specular*pow(normal.dot(h),m_highlight)))+ color/(4.0f+1000000.0f*len.length());
00086 }
00087 else ret = color*m_ambient + color*(m_diffuse*(normal.dot(m_direction))) + color/(4.0f+1000000.0f*len.length());
00088 return ret;
00089 }
00090
00092 Color
00093 Ray::GetCurrentColor() {
00094 return m_currentcolor;
00095 }
00096
00098 bool
00099 Ray::Initialize(Color background,Color current, float steplength, Plane* viewingplane, Data *data, Transfunc *tf) {
00100 m_backgroundcolor = background;
00101 m_currentcolor = current;
00102 m_data = data;
00103 m_tf = tf;
00104 m_steplength = steplength;
00105 m_viewingplane = viewingplane;
00106 mx = (float)m_data->GetXDim();
00107 my = (float)m_data->GetYDim();
00108 mz = (float)m_data->GetZDim();
00109 m_radius = sqrt(pow(mx/2.0f,2)+pow(my/2.0f,2)+pow(mz/2.0f,2));
00110 return true;
00111 }
00112
00114 bool
00115 Ray::SetPosDir(VECTOR currentpos, VECTOR direction) {
00116 m_currentpos = currentpos;
00117 m_direction = direction;
00118 return true;
00119 }
00120
00125 bool
00126 Ray::CastNext() {
00127
00128 if(m_data == NULL) return false;
00129 if(m_tf == NULL) return false;
00130
00131 bool first = true;
00132 int step_count = 0;
00133 VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f)-m_currentpos;
00134 int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00135 do {
00136 if(m_alpha > 0.99) break;
00137 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00138 if(first) {
00139 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00140 first = false;
00141 }
00142 int d = m_data->GetDensity((int)ROUND(m_currentpos.x),(int)ROUND(m_currentpos.y),(int)ROUND(m_currentpos.z));
00143
00144 Color help_color = m_tf->GetDensityColor(d);
00145 float help_alpha = m_tf->GetOpacity(d);
00146
00147 help_color = Lighting(help_color);
00148
00149 m_currentcolor += help_color*(1-m_alpha)*help_alpha;
00150
00151 m_alpha += (1-m_alpha)*help_alpha;
00152 }
00153
00154 m_currentpos += m_steplength*m_direction;
00155
00156 step_count++;
00157 }while(step_count <= steps);
00158 if(m_alpha < 1.0 ) {
00159 m_currentcolor += m_backgroundcolor*(1.0f-m_alpha);
00160 }
00161 return true;
00162 }
00163
00165 float
00166 Trilinear::CalcAlphaTrilinear(VECTOR pos) {
00167
00168 float a000 = m_tf->GetOpacity(m_data->GetDensity(floorf(pos.x),floorf(pos.y),floorf(pos.z)));
00169 float a001 = m_tf->GetOpacity(m_data->GetDensity(floorf(pos.x),floorf(pos.y),ceilf(pos.z)));
00170 float a010 = m_tf->GetOpacity(m_data->GetDensity(floorf(pos.x),ceilf(pos.y),floorf(pos.z)));
00171 float a011 = m_tf->GetOpacity(m_data->GetDensity(floorf(pos.x),ceilf(pos.y),ceilf(pos.z)));
00172 float a100 = m_tf->GetOpacity(m_data->GetDensity(ceilf(pos.x),floorf(pos.y),floorf(pos.z)));
00173 float a101 = m_tf->GetOpacity(m_data->GetDensity(ceilf(pos.x),floorf(pos.y),ceilf(pos.z)));
00174 float a110 = m_tf->GetOpacity(m_data->GetDensity(ceilf(pos.x),ceilf(pos.y),floorf(pos.z)));
00175 float a111 = m_tf->GetOpacity(m_data->GetDensity(ceilf(pos.x),ceilf(pos.y),ceilf(pos.z)));
00176
00177 float difX = abs(pos.x - floorf(pos.x));
00178 float difY = abs(pos.y - floorf(pos.y));
00179 float difZ = abs(pos.z - floorf(pos.z));
00180
00181 float aA = a000*difX + a100*abs(1.0f-difX);
00182 float aB = a010*difX + a110*abs(1.0f-difX);
00183 float aC = a011*difX + a111*abs(1.0f-difX);
00184 float aD = a001*difX + a101*abs(1.0f-difX);
00185
00186 float aE = aA*difZ + aD*abs(1.0f-difZ);
00187 float aF = aB*difZ + aC*abs(1.0f-difZ);
00188
00189 float a = aE*difY + aF*abs(1.0f-difY);
00190 return a;
00191 }
00192
00194 gradient_t
00195 Trilinear::CalcGradTrilinear(VECTOR pos) {
00196 gradient_t grad000 = m_data->CalcGrad(floorf(pos.x),floorf(pos.y),floorf(pos.z));
00197 gradient_t grad001 = m_data->CalcGrad(floorf(pos.x),floorf(pos.y),ceilf(pos.z));
00198 gradient_t grad010 = m_data->CalcGrad(floorf(pos.x),ceilf(pos.y),floorf(pos.z));
00199 gradient_t grad011 = m_data->CalcGrad(floorf(pos.x),ceilf(pos.y),ceilf(pos.z));
00200 gradient_t grad100 = m_data->CalcGrad(ceilf(pos.x),floorf(pos.y),floorf(pos.z));
00201 gradient_t grad101 = m_data->CalcGrad(ceilf(pos.x),floorf(pos.y),ceilf(pos.z));
00202 gradient_t grad110 = m_data->CalcGrad(ceilf(pos.x),ceilf(pos.y),floorf(pos.z));
00203 gradient_t grad111 = m_data->CalcGrad(ceilf(pos.x),ceilf(pos.y),ceilf(pos.z));
00204
00205 float difX = abs(pos.x - floorf(pos.x));
00206 float difY = abs(pos.y - floorf(pos.y));
00207 float difZ = abs(pos.z - floorf(pos.z));
00208
00209 gradient_t gradA = grad000*difX + grad100*abs(1.0f-difX);
00210 gradient_t gradB = grad010*difX + grad110*abs(1.0f-difX);
00211 gradient_t gradC = grad011*difX + grad111*abs(1.0f-difX);
00212 gradient_t gradD = grad001*difX + grad101*abs(1.0f-difX);
00213
00214 gradient_t gradE = gradA*difZ + gradD*abs(1.0f-difZ);
00215 gradient_t gradF = gradB*difZ + gradC*abs(1.0f-difZ);
00216
00217 gradient_t grad = gradE*difY + gradF*abs(1.0f-difY);
00218 return grad;
00219 }
00220
00222 Color
00223 Trilinear::CalcColorTrilinear(VECTOR pos) {
00224 Color col000 = m_tf->GetDensityColor(m_data->GetDensity(floorf(pos.x),floorf(pos.y),floorf(pos.z)));
00225 Color col001 = m_tf->GetDensityColor(m_data->GetDensity(floorf(pos.x),floorf(pos.y),ceilf(pos.z)));
00226 Color col010 = m_tf->GetDensityColor(m_data->GetDensity(floorf(pos.x),ceilf(pos.y),floorf(pos.z)));
00227 Color col011 = m_tf->GetDensityColor(m_data->GetDensity(floorf(pos.x),ceilf(pos.y),ceilf(pos.z)));
00228 Color col100 = m_tf->GetDensityColor(m_data->GetDensity(ceilf(pos.x),floorf(pos.y),floorf(pos.z)));
00229 Color col101 = m_tf->GetDensityColor(m_data->GetDensity(ceilf(pos.x),floorf(pos.y),ceilf(pos.z)));
00230 Color col110 = m_tf->GetDensityColor(m_data->GetDensity(ceilf(pos.x),ceilf(pos.y),floorf(pos.z)));
00231 Color col111 = m_tf->GetDensityColor(m_data->GetDensity(ceilf(pos.x),ceilf(pos.y),ceilf(pos.z)));
00232
00233
00234 float difX = abs(pos.x - floorf(pos.x));
00235 float difY = abs(pos.y - floorf(pos.y));
00236 float difZ = abs(pos.z - floorf(pos.z));
00237
00238 Color colA = col000*difX + col100*abs(1.0f-difX);
00239 Color colB = col010*difX + col110*abs(1.0f-difX);
00240 Color colC = col011*difX + col111*abs(1.0f-difX);
00241 Color colD = col001*difX + col101*abs(1.0f-difX);
00242
00243 Color colE = colA*difZ + colD*abs(1.0f-difZ);
00244 Color colF = colB*difZ + colC*abs(1.0f-difZ);
00245
00246 Color col = colE*difY + colF*abs(1.0f-difY);
00247 return col;
00248 }
00249
00251 Color
00252 Trilinear::Lighting(Color color) {
00253 gradient_t g = CalcGradTrilinear(m_currentpos);
00254 VECTOR normal = VECTOR(g.x, g.y, g.z);
00255 normal.normalize();
00256
00257 VECTOR len = m_currentpos-m_startpoint;
00258 Color ret;
00259 if(m_light) {
00260 VECTOR v = -m_direction;
00261 v.normalize();
00262 VECTOR l = m_lightpos-m_currentpos;
00263 l.normalize();
00264 VECTOR h = (v+l);
00265 h.normalize();
00266 ret = color*m_ambient + color*((m_diffuse*(normal.dot(m_direction))) + (m_specular*pow(normal.dot(h),m_highlight)))+ color/(4.0f+1000000.0f*len.length());
00267 }
00268 else ret = color*m_ambient + color*(m_diffuse*(normal.dot(m_direction))) + color/(4.0f+1000000.0f*len.length());
00269 return ret;
00270 }
00271
00272
00277
00278 bool
00279 Trilinear::CastNext() {
00280
00281 if(m_data == NULL) return false;
00282 if(m_tf == NULL) return false;
00283
00284 int step_count = 0;
00285 bool first = true;
00286 VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f)-m_currentpos;
00287 int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00288
00289 do {
00290 if(m_alpha > 0.99) break;
00291 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00292 if(first) {
00293 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00294 first = false;
00295 }
00296 Color help_color = CalcColorTrilinear(m_currentpos);
00297 float help_alpha = CalcAlphaTrilinear(m_currentpos);
00298
00299 help_color = Lighting(help_color);
00300
00301 m_currentcolor += help_color*(1-m_alpha)*help_alpha;
00302
00303 m_alpha += (1-m_alpha)*help_alpha;
00304 }
00305
00306 m_currentpos += m_steplength*m_direction;
00307
00308 step_count++;
00309 }while(step_count <= steps);
00310 if(m_alpha < 1.0 ) {
00311 m_currentcolor += m_backgroundcolor*(1.0-m_alpha);
00312 }
00313 return true;
00314 }
00315
00316
00317
00322
00323 bool
00324 FirstHitNN::CastNext() {
00325
00326 if(m_data == NULL) return false;
00327 if(m_tf == NULL) return false;
00328
00329 int step_count = 0;
00330 bool first = true;
00331 VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f)-m_currentpos;
00332 int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00333 do {
00334
00335 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00336 if(first) {
00337 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00338 first = false;
00339 }
00340 int d = m_data->GetDensity((int)ROUND(m_currentpos.x),(int)ROUND(m_currentpos.y),(int)ROUND(m_currentpos.z));
00341 if(d > m_treshold) {
00342 Color help_color = m_tf->GetDensityColor(d);
00343 float help_alpha = m_tf->GetOpacity(d);
00344
00345 help_color = Lighting(help_color);
00346
00347 m_currentcolor = help_color;
00348
00349 m_alpha = help_alpha;
00350 break;
00351 }
00352 }
00353
00354 m_currentpos += m_steplength*m_direction;
00355
00356 step_count++;
00357 }while(step_count <= steps);
00358 if(m_alpha < 1.0 ) m_currentcolor += m_backgroundcolor*(1.0 - m_alpha);
00359 return true;
00360 }
00361
00364 float
00365 FirstHitTRI::GetDensity(VECTOR pos) {
00366 int dat000 = m_data->GetDensity(floorf(pos.x),floorf(pos.y),floorf(pos.z));
00367 int dat001 = m_data->GetDensity(floorf(pos.x),floorf(pos.y),ceilf(pos.z));
00368 int dat010 = m_data->GetDensity(floorf(pos.x),ceilf(pos.y),floorf(pos.z));
00369 int dat011 = m_data->GetDensity(floorf(pos.x),ceilf(pos.y),ceilf(pos.z));
00370 int dat100 = m_data->GetDensity(ceilf(pos.x),floorf(pos.y),floorf(pos.z));
00371 int dat101 = m_data->GetDensity(ceilf(pos.x),floorf(pos.y),ceilf(pos.z));
00372 int dat110 = m_data->GetDensity(ceilf(pos.x),ceilf(pos.y),floorf(pos.z));
00373 int dat111 = m_data->GetDensity(ceilf(pos.x),ceilf(pos.y),ceilf(pos.z));
00374
00375 float difX = abs(pos.x - floorf(pos.x));
00376 float difY = abs(pos.y - floorf(pos.y));
00377 float difZ = abs(pos.z - floorf(pos.z));
00378
00379 int datA = dat000*difX + dat100*abs(1.0f-difX);
00380 int datB = dat010*difX + dat110*abs(1.0f-difX);
00381 int datC = dat011*difX + dat111*abs(1.0f-difX);
00382 int datD = dat001*difX + dat101*abs(1.0f-difX);
00383
00384 int datE = datA*difZ + datD*abs(1.0f-difZ);
00385 int datF = datB*difZ + datC*abs(1.0f-difZ);
00386
00387 int dat = datE*difY + datF*abs(1.0f-difY);
00388 return dat;
00389 }
00390
00395
00396 bool
00397 FirstHitTRI::CastNext() {
00398
00399 if(m_data == NULL) return false;
00400 if(m_tf == NULL) return false;
00401
00402 int step_count = 0;
00403 VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f)-m_currentpos;
00404 int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00405 bool first = true;
00406 do {
00407
00408 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00409 if(first) {
00410 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00411 first = false;
00412 }
00413 float d = GetDensity(m_currentpos);
00414 if(d > (float)m_treshold) {
00415 Color help_color = CalcColorTrilinear(m_currentpos);
00416 float help_alpha = CalcAlphaTrilinear(m_currentpos);
00417
00418 help_color = Lighting(help_color);
00419
00420 m_currentcolor = help_color;
00421
00422 m_alpha = help_alpha;
00423 break;
00424 }
00425
00426 }
00427 m_currentpos += m_steplength*m_direction;
00428 step_count++;
00429 }while(step_count <= steps);
00430 if(m_alpha < 1.0 ) {
00431 m_currentcolor += m_backgroundcolor*(1.0f-m_alpha);
00432 }
00433 return true;
00434 }
00435
00439
00440 bool
00441 MaxIntensityNN::CastNext() {
00442 if(m_data == NULL) return false;
00443 if(m_tf == NULL) return false;
00444 int maxdens = 0;
00445 float maxintens = 0.0f;
00446 int step_count = 0;
00447 bool first = true;
00448 VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f)-m_currentpos;
00449 int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00450 do {
00451
00452 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00453 if(first) {
00454 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00455 first = false;
00456 }
00457 int d = m_data->GetDensity((int)ROUND(m_currentpos.x),(int)ROUND(m_currentpos.y),(int)ROUND(m_currentpos.z));
00458 float intens = m_tf->GetOpacity(d);
00459 if(intens > maxintens) {
00460 maxintens = intens;
00461 maxdens = d;
00462 }
00463 }
00464
00465 m_currentpos += m_steplength*m_direction;
00466
00467 step_count++;
00468 }while(step_count <= steps);
00469 m_light = false;
00470 m_currentcolor = m_tf->GetDensityColor(maxdens);
00471 m_alpha = maxintens;
00472 if(maxdens == 0) {
00473 m_currentcolor = Color(0,0,0);
00474 m_alpha = 1.0;
00475 }
00476 if(m_alpha < 1.0 ) m_currentcolor += m_backgroundcolor*(1.0 - m_alpha);
00477 return true;
00478 }
00479
00483
00484 bool
00485 MaxIntensityTRI::CastNext() {
00486 if(m_data == NULL) return false;
00487 if(m_tf == NULL) return false;
00488 float maxintensity = 0.0f;
00489 int maxdens = 0;
00490 int step_count = 0;
00491 VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f)-m_currentpos;
00492 int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00493 bool first = true;
00494 do {
00495
00496 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00497 if(first) {
00498 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00499 first = false;
00500 }
00501 float d = GetDensity(m_currentpos);
00502 float intens = m_tf->GetOpacity((int)d);
00503 if(intens > maxintensity) {
00504 maxintensity = intens;
00505 maxdens = d;
00506 }
00507
00508 }
00509 m_currentpos += m_steplength*m_direction;
00510 step_count++;
00511 }while(step_count <= steps);
00512
00513 m_currentcolor = m_tf->GetDensityColor(maxdens);
00514 m_alpha = maxintensity;
00515 if(maxdens == 0) {
00516 m_currentcolor = Color(0,0,0);
00517 m_alpha = 1.0;
00518 }
00519 if(m_alpha < 1.0 ) {
00520 m_currentcolor += m_backgroundcolor*(1.0f-m_alpha);
00521 }
00522 return true;
00523 }
00524
00525 bool
00526 XRayNN::CastNext() {
00527 if(m_data == NULL) return false;
00528 if(m_tf == NULL) return false;
00529 int density = 0;
00530 int step_count = 0;
00531 bool first = true;
00532 int counter = 0;
00533
00534 VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f) - m_currentpos;
00535 int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00536 do {
00537
00538 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00539 if(first) {
00540 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00541 first = false;
00542 }
00543 int d = m_data->GetDensity((int)ROUND(m_currentpos.x),(int)ROUND(m_currentpos.y),(int)ROUND(m_currentpos.z));
00544 density += d;
00545 counter++;
00546 }
00547
00548 m_currentpos += m_steplength*m_direction;
00549
00550 step_count++;
00551 }while(step_count <= steps);
00552
00553
00554 float colormodifyer = (float) ((m_maxDens - m_minDens - 1) / 255);
00555
00556 if (colormodifyer > 0)
00557 colormodifyer = 1.0f / colormodifyer;
00558
00559 if (counter <= 0)
00560 m_currentcolor = Color(0, 0, 0);
00561 else {
00562 unsigned char col = (unsigned char) ((density / counter) * colormodifyer);
00563 m_currentcolor = Color(col, col, col);
00564 }
00565
00566 m_alpha = 1.0f;
00567
00568 return true;
00569 }
00570
00571 bool
00572 XRayTRI::CastNext() {
00573 if(m_data == NULL) return false;
00574 if(m_tf == NULL) return false;
00575 int density = 0;
00576 int step_count = 0;
00577 VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f)-m_currentpos;
00578 int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00579 bool first = true;
00580 int counter = 0;
00581
00582 do {
00583
00584 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00585 if(first) {
00586 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00587 first = false;
00588 }
00589 float d = GetDensity(m_currentpos);
00590 density += d;
00591 counter++;
00592
00593
00594 }
00595 m_currentpos += m_steplength*m_direction;
00596 step_count++;
00597 }while(step_count <= steps);
00598
00599 float colormodifyer = (float) ((m_maxDens - m_minDens - 1) / 255);
00600
00601 if (colormodifyer > 0)
00602 colormodifyer = 1.0f / colormodifyer;
00603
00604 if (counter <= 0)
00605 m_currentcolor = Color(0, 0, 0);
00606 else {
00607 unsigned char col = (unsigned char) ((density / counter) * colormodifyer);
00608 m_currentcolor = Color(col, col, col);
00609 }
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622 return true;
00623 }
00624