Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ray.cpp

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

Generated on Thu Jan 23 12:32:15 2003 by doxygen1.3-rc2