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

raycaster.cpp

Go to the documentation of this file.
00001 #include "stdafx.h"
00002 #include "raycaster.h"
00003 
00004 #include "messages.h"
00005 
00006 
00007 Raycaster::Raycaster() {
00008         ready = false;
00009         
00010         m_specular = 0.2f;
00011         m_highlight = 8;
00012         m_lightpos = VECTOR(300,300,300);
00013         m_light = false;
00014         m_image = NULL;
00015         m_ambient = 0.2f;
00016         m_diffuse = 0.2f;
00017         m_height = 0;
00018         m_width = 0;
00019         m_viewingplane = NULL;
00020         m_viewingtoworld = NULL;
00021         m_stepX = 1.0;
00022         m_stepY = 1.0;
00023         m_data = NULL;
00024         m_tf = NULL;
00025         m_xdir = VECTOR(1,0,0);
00026         m_ydir = VECTOR(0,1,0);
00027         m_treshold = 1500;
00028         m_rendermode = STANDARD;
00029         m_raytype = NN;
00030         m_precalc = false;
00031         m_zoom = 1.0;
00032 
00033         m_dOwnType = RAYCASTER;
00034 }
00035 
00036 Raycaster::~Raycaster() {
00037         if(m_image != NULL) delete m_image;
00038         if(m_viewingplane != NULL) delete m_viewingplane;
00039         if(m_viewingtoworld != NULL) delete m_viewingtoworld;
00040         m_image = NULL;
00041         m_viewingplane = NULL;
00042         m_viewingtoworld = NULL;
00043 }
00044 
00045 bool
00046 Raycaster::SetViewingCondition(VECTOR lightpos, Color background, float ambient, float diffuse, float specular, int highlight) {
00047         m_ambient = ambient;
00048         m_diffuse = diffuse;
00049         m_background = background;
00050         m_specular = specular;
00051         m_highlight = highlight;
00052         m_lightpos = lightpos;
00053         return true;
00054 }
00055 
00056 
00057 bool
00058 Raycaster::Render(int width, int height) {
00059 
00060         int m_x = width / 2 - m_width / 2;
00061         int m_y = height / 2 - m_height / 2;
00062 
00063 
00064         if (!ready)
00065                 return false;
00066 
00067         glRasterPos2i(m_x, m_y);
00068         glPixelStorei(GL_UNPACK_ALIGNMENT,1);
00069         glDrawPixels(m_width, m_height, GL_RGB, GL_UNSIGNED_BYTE, m_image);
00070         return true;
00071 }
00072 
00073 bool
00074 Raycaster::Initialize(VECTOR viewingplanepos, int width, int height, float steplength, Data *data, Transfunc *tf) {
00075         m_data = data;
00076         m_tf = tf;
00077         m_width = width;
00078         m_height = height;
00079         m_steplength = steplength;
00080         int maxX = m_data->GetXDim()-1;
00081         int maxY = m_data->GetYDim()-1;
00082         int maxZ = m_data->GetZDim()-1;
00083         VECTOR viewingplanenormal = VECTOR(maxX/2,maxY/2,maxZ/2)-viewingplanepos;
00084         viewingplanenormal.normalize();
00085         m_viewingplane = new Plane(viewingplanenormal,viewingplanepos);
00086 
00087         //set zoom and viewingtoworld matrix
00088         Zoom(m_zoom);
00089 
00090 
00091         if(m_viewingplane == NULL) return false;
00092         if(m_data == NULL) return false;
00093         if(m_tf == NULL) return false;
00094         return true;
00095 }
00096 
00097 
00098 void Raycaster::SetViewingPlanePos(float x, float y, float z) {
00099         if (!m_data)
00100                 return;
00101         
00102         VECTOR viewingplanepos = VECTOR(x, y, z);
00103         int maxX = m_data->GetXDim()-1;
00104         int maxY = m_data->GetYDim()-1;
00105         int maxZ = m_data->GetZDim()-1;
00106         VECTOR viewingplanenormal = VECTOR(maxX/2,maxY/2,maxZ/2)-viewingplanepos;
00107         viewingplanenormal.normalize();
00108         m_viewingplane = new Plane(viewingplanenormal,viewingplanepos);
00109 }
00110 
00111 
00112 
00113 
00114 bool
00115 Raycaster::Raycast() {
00116 
00117         CWnd* pFrame = AfxGetMainWnd();
00118 
00119 
00120         m_data->SetPreCalc(m_precalc);
00121         m_image = new rgb[m_width*m_height];
00122         
00123         VECTOR pos =  m_viewingplane->point-m_width/2*m_xdir-m_height/2*m_ydir;
00124         VECTOR backup = pos;
00125         
00126         int loadSize = (m_height * m_width) / 100;
00127         int counter = loadSize / 100;
00128         int progPos = 0;
00129 
00130 
00131 
00132         Ray *r;
00133 
00134         switch (m_rendermode) {
00135                 case STANDARD:
00136                         if (m_raytype == NN)
00137                                 r = new Ray();
00138                         else if (m_raytype == TRI)
00139                                 r = new Trilinear();
00140                         break;
00141                 case FH:
00142                         if (m_raytype == NN) {
00143                                 r = new FirstHitNN();
00144                                 ((FirstHitNN *)r)->SetTreshold(m_treshold);
00145                         }
00146                         else if (m_raytype == TRI) {
00147                                 r = new FirstHitTRI();
00148                                 ((FirstHitTRI *)r)->SetTreshold(m_treshold);
00149                         }
00150                         break;
00151                 case MI:
00152                         if (m_raytype == NN)
00153                                 r = new MaxIntensityNN();
00154                         else if (m_raytype == TRI)
00155                                 r = new MaxIntensityTRI();
00156                         break;
00157                 case XRAY:
00158                         if (m_raytype == NN)
00159                                 r = new XRayNN();
00160                         else if (m_raytype == TRI)
00161                                 r = new XRayTRI();
00162                         break;
00163         }
00164         
00165         r->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00166         r->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00167         r->SetLight(m_light);
00168 
00169         for(int j = 0; j < m_height; j++) {
00170                 for(int i = 0; i < m_width; i++) {
00171                         r->Reset();
00172                         r->SetPosDir(pos, m_viewingplane->normal);
00173                         r->CastNext();
00174                         m_image[j * m_width + i] = r->GetCurrentColor().toRGB();
00175 
00176                         pos += m_xdir;
00177 
00178                         if ((counter-- <= 0) && (progPos < 100)) {
00179                                 counter = loadSize;
00180                                 pFrame->SendMessage(MYWM_PROGRESS, progPos++);
00181                         }
00182 
00183 
00184                 } // inner for
00185                 pos = backup;
00186                 pos += j*m_ydir;
00187 
00188                 pFrame->SendMessage(MYWM_PROGRESS, 0);
00189         
00190         }
00191 
00192         
00193 /*
00194         Ray *r;
00195         Trilinear *tri;
00196         FirstHitNN *fhnn;
00197         FirstHitTRI *fhtri;
00198         MaxIntensityNN *minn;
00199         MaxIntensityTRI *mitri;
00200         XRayNN *xraynn;
00201         XRayTRI *xraytri;
00202 
00203         if(m_raytype == NN && m_rendermode == STANDARD) {
00204                 r = new Ray();
00205                 r->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00206                 r->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00207                 r->SetLight(m_light);
00208         }
00209         if(m_raytype == TRI && m_rendermode == STANDARD) {
00210                 tri = new Trilinear();
00211                 tri->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00212                 tri->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00213                 tri->SetLight(m_light);
00214         }
00215         if(m_raytype == NN && m_rendermode == FH) {
00216                 fhnn = new FirstHitNN();
00217                 fhnn->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00218                 fhnn->SetTreshold(m_treshold);
00219                 fhnn->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00220                 fhnn->SetLight(m_light);
00221         }
00222         if(m_raytype == TRI && m_rendermode == FH) {
00223                 fhtri = new FirstHitTRI();
00224                 fhtri->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00225                 fhtri->SetTreshold(m_treshold);
00226                 fhtri->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00227                 fhtri->SetLight(m_light);
00228         }
00229         if(m_raytype == NN && m_rendermode == MI) {
00230                 minn = new MaxIntensityNN();
00231                 minn->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00232                 minn->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00233         }
00234         if(m_raytype == TRI && m_rendermode == MI) {
00235                 mitri = new MaxIntensityTRI();
00236                 mitri->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00237                 mitri->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00238         }
00239         if(m_raytype == NN && m_rendermode == XRAY) {
00240                 xraynn = new XRayNN();
00241                 xraynn->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00242                 xraynn->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00243         }
00244         if(m_raytype == TRI && m_rendermode == XRAY) {
00245                 xraytri = new XRayTRI();
00246                 xraytri->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00247                 xraytri->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00248         }
00249 
00250         
00251         for(int j = 0; j < m_height; j++) {
00252                 for(int i = 0; i < m_width; i++) {
00253                         if(m_raytype == NN && m_rendermode == STANDARD) {
00254                                 r->Reset();
00255                                 r->SetPosDir(pos,m_viewingplane->normal);
00256                                 r->CastNext();
00257                                 m_image[j*m_width+i] = r->GetCurrentColor().toRGB();
00258                         }
00259                         if(m_raytype == TRI && m_rendermode == STANDARD) {
00260                                 tri->Reset();
00261                                 tri->SetPosDir(pos,m_viewingplane->normal);
00262                                 tri->CastNext();
00263                                 m_image[j*m_width+i] = tri->GetCurrentColor().toRGB();
00264                         }
00265                         if(m_raytype == NN && m_rendermode == FH) {
00266                                 fhnn->Reset();
00267                                 fhnn->SetPosDir(pos,m_viewingplane->normal);
00268                                 fhnn->CastNext();
00269                                 m_image[j*m_width+i] = fhnn->GetCurrentColor().toRGB();
00270                         }
00271                         if(m_raytype == TRI && m_rendermode == FH) {
00272                                 fhtri->Reset();
00273                                 fhtri->SetPosDir(pos,m_viewingplane->normal);
00274                                 fhtri->CastNext();
00275                                 m_image[j*m_width+i] = fhtri->GetCurrentColor().toRGB();
00276                         }
00277                         if(m_raytype == NN && m_rendermode == MI) {
00278                                 minn->Reset();
00279                                 minn->SetPosDir(pos,m_viewingplane->normal);
00280                                 minn->CastNext();
00281                                 m_image[j*m_width+i] = minn->GetCurrentColor().toRGB();
00282                         }
00283                         if(m_raytype == TRI && m_rendermode == MI) {
00284                                 mitri->Reset();
00285                                 mitri->SetPosDir(pos,m_viewingplane->normal);
00286                                 mitri->CastNext();
00287                                 m_image[j*m_width+i] = mitri->GetCurrentColor().toRGB();
00288                         }
00289                         if(m_raytype == NN && m_rendermode == XRAY) {
00290                                 xraynn->Reset();
00291                                 xraynn->SetPosDir(pos,m_viewingplane->normal);
00292                                 xraynn->CastNext();
00293                                 m_image[j*m_width+i] = xraynn->GetCurrentColor().toRGB();
00294                         }
00295                         if(m_raytype == TRI && m_rendermode == XRAY) {
00296                                 xraytri->Reset();
00297                                 xraytri->SetPosDir(pos,m_viewingplane->normal);
00298                                 xraytri->CastNext();
00299                                 m_image[j*m_width+i] = xraytri->GetCurrentColor().toRGB();
00300                         }
00301 
00302                         pos += m_xdir;
00303 
00304                         if ((counter-- <= 0) && (progPos < 100)) {
00305                                 counter = loadSize;
00306                                 pFrame->SendMessage(MYWM_PROGRESS, progPos++);
00307                         }
00308 
00309 
00310                 } // inner for
00311                 pos = backup;
00312                 pos += j*m_ydir;
00313 
00314                 pFrame->SendMessage(MYWM_PROGRESS, 0);
00315         
00316         }
00317         */
00318         if (r)
00319                 delete r;
00320         
00321         ready = true;
00322         return true;
00323 }
00324 
00325 
00326 bool
00327 Raycaster::Zoom(float zoom) {
00328         int maxX = m_data->GetXDim()-1;
00329         int maxY = m_data->GetYDim()-1;
00330         int maxZ = m_data->GetZDim()-1;
00331         m_zoom = zoom;
00332         float maxlength = sqrtf(powf((float)maxX,2.0)+powf((float)maxY,2.0)+powf((float)maxZ,2.0));
00333         m_stepX = (1/m_zoom)*maxlength/(m_width-1);
00334         m_stepY = (1/m_zoom)*maxlength/(m_height-1);
00335 
00336         SetViewingMatrix();
00337         return true;
00338 }
00339 
00340 
00341 bool
00342 Raycaster::SetViewingMatrix() {
00343         VECTOR zaxis = VECTOR(0,0,1);
00344         if(m_viewingtoworld == NULL) m_viewingtoworld = new Matrix4x4();
00345         m_viewingtoworld->rotation(zaxis,m_viewingplane->normal);
00346 
00347         m_xdir = VECTOR(1,0,0);
00348         m_ydir = VECTOR(0,1,0);
00349 
00350         m_xdir = *m_viewingtoworld*m_xdir;
00351         m_ydir = *m_viewingtoworld*m_ydir;
00352         m_xdir.normalize();
00353         m_ydir.normalize();
00354         m_xdir = m_stepX * m_xdir;
00355         m_ydir = m_stepY * m_ydir;
00356 
00357         return true;
00358 }
00359         
00360 bool
00361 Raycaster::RotateX(float alpha) {
00362         Matrix4x4 rotmat;
00363         rotmat.rotateX(-alpha);
00364         m_viewingplane->point = rotmat*m_viewingplane->point;
00365         int maxX = m_data->GetXDim()-1;
00366         int maxY = m_data->GetYDim()-1;
00367         int maxZ = m_data->GetZDim()-1;
00368         m_viewingplane->normal = VECTOR(maxX/2,maxY/2,maxZ/2)-m_viewingplane->point;
00369         m_viewingplane->normal.normalize();
00370         SetViewingMatrix();
00371         return true;
00372 }
00373 
00374 bool
00375 Raycaster::RotateY(float alpha) {
00376         Matrix4x4 rotmat;
00377         rotmat.rotateY(-alpha);
00378         m_viewingplane->point = rotmat*m_viewingplane->point;
00379         int maxX = m_data->GetXDim()-1;
00380         int maxY = m_data->GetYDim()-1;
00381         int maxZ = m_data->GetZDim()-1;
00382         m_viewingplane->normal = VECTOR(maxX/2,maxY/2,maxZ/2)-m_viewingplane->point;
00383         m_viewingplane->normal.normalize();
00384         SetViewingMatrix();
00385         return true;
00386 }
00387 
00388 bool
00389 Raycaster::RotateZ(float alpha) {
00390         Matrix4x4 rotmat;
00391         rotmat.rotateZ(-alpha);
00392         m_viewingplane->point = rotmat*m_viewingplane->point;
00393         int maxX = m_data->GetXDim()-1;
00394         int maxY = m_data->GetYDim()-1;
00395         int maxZ = m_data->GetZDim()-1;
00396         m_viewingplane->normal = VECTOR(maxX/2,maxY/2,maxZ/2)-m_viewingplane->point;
00397         m_viewingplane->normal.normalize();
00398         SetViewingMatrix();
00399         return true;
00400 }
00401 
00402 
00403 Perspective::Perspective() {
00404         m_eye = VECTOR(0,0,-10);
00405         m_dist = 0;
00406 
00407         m_dOwnType = PERSPECTIVE;
00408 }
00409 
00410 Perspective::~Perspective() {}
00411 
00412 bool
00413 Perspective::Initialize(VECTOR eye, float dist, int width, int height,float steplength,Data *data,Transfunc *tf) {
00414         m_eye = eye;
00415         m_data = data;
00416         m_tf = tf;
00417         m_width = width;
00418         m_height = height;
00419         m_steplength = steplength;
00420         m_dist = dist;
00421         int maxX = m_data->GetXDim()-1;
00422         int maxY = m_data->GetYDim()-1;
00423         int maxZ = m_data->GetZDim()-1;
00424         VECTOR viewingplanenormal = VECTOR(maxX/2,maxY/2,maxZ/2)-m_eye;
00425         viewingplanenormal.normalize();
00426 
00427         VECTOR viewingplanepos = m_eye + m_dist * viewingplanenormal;
00428         m_viewingplane = new Plane(viewingplanenormal,viewingplanepos);
00429 
00430         Zoom(m_zoom);
00431 
00432         if(m_viewingplane == NULL) return false;
00433         if(m_data == NULL) return false;
00434         if(m_tf == NULL) return false;
00435         return true;
00436 }
00437 
00438 
00439 bool
00440 Perspective::Raycast() {
00441 
00442         CWnd* pFrame = AfxGetMainWnd();
00443 
00444 
00445         m_data->SetPreCalc(m_precalc);
00446         m_image = new rgb[m_width*m_height];
00447         
00448         VECTOR pos =  m_viewingplane->point-m_width/2*m_xdir-m_height/2*m_ydir;
00449         VECTOR backup = pos;
00450 
00451         VECTOR direction;
00452         
00453         int loadSize = (m_height * m_width) / 100;
00454         int counter = loadSize / 100;
00455         int progPos = 0;
00456 
00457 
00458 
00459         Ray *r;
00460 
00461         switch (m_rendermode) {
00462                 case STANDARD:
00463                         if (m_raytype == NN)
00464                                 r = new Ray();
00465                         else if (m_raytype == TRI)
00466                                 r = new Trilinear();
00467                         break;
00468                 case FH:
00469                         if (m_raytype == NN) {
00470                                 r = new FirstHitNN();
00471                                 ((FirstHitNN *)r)->SetTreshold(m_treshold);
00472                         }
00473                         else if (m_raytype == TRI) {
00474                                 r = new FirstHitTRI();
00475                                 ((FirstHitTRI *)r)->SetTreshold(m_treshold);
00476                         }
00477                         break;
00478                 case MI:
00479                         if (m_raytype == NN)
00480                                 r = new MaxIntensityNN();
00481                         else if (m_raytype == TRI)
00482                                 r = new MaxIntensityTRI();
00483                         break;
00484                 case XRAY:
00485                         if (m_raytype == NN)
00486                                 r = new XRayNN();
00487                         else if (m_raytype == TRI)
00488                                 r = new XRayTRI();
00489                         break;
00490         }
00491         
00492         r->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00493         r->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00494         r->SetLight(m_light);
00495 
00496         for(int j = 0; j < m_height; j++) {
00497                 for(int i = 0; i < m_width; i++) {
00498                         r->Reset();
00499                         direction = pos-m_eye;
00500                         r->SetPosDir(m_eye,direction);
00501                         r->CastNext();
00502                         m_image[j*m_width+i] = r->GetCurrentColor().toRGB();
00503 
00504 
00505                         pos += m_xdir;
00506 
00507                         if ((counter-- <= 0) && (progPos < 100)) {
00508                                 counter = loadSize;
00509                                 pFrame->SendMessage(MYWM_PROGRESS, progPos++);
00510                         }
00511 
00512 
00513                 } // inner for
00514                 pos = backup;
00515                 pos += j*m_ydir;
00516 
00517                 pFrame->SendMessage(MYWM_PROGRESS, 0);
00518         
00519         }
00520 
00521 
00522 
00523 
00524 
00525 /*
00526         Ray *r;
00527         Trilinear *tri;
00528         FirstHitNN *fhnn;
00529         FirstHitTRI *fhtri;
00530         MaxIntensityNN *minn;
00531         MaxIntensityTRI *mitri;
00532         XRayNN *xraynn;
00533         XRayTRI *xraytri;
00534 
00535         if(m_raytype == NN && m_rendermode == STANDARD) {
00536                 r = new Ray();
00537                 r->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00538                 r->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00539                 r->SetLight(m_light);
00540         }
00541         if(m_raytype == TRI && m_rendermode == STANDARD) {
00542                 tri = new Trilinear();
00543                 tri->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00544                 tri->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00545                 tri->SetLight(m_light);
00546         }
00547         if(m_raytype == NN && m_rendermode == FH) {
00548                 fhnn = new FirstHitNN();
00549                 fhnn->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00550                 fhnn->SetTreshold(m_treshold);
00551                 fhnn->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00552                 fhnn->SetLight(m_light);
00553         }
00554         if(m_raytype == TRI && m_rendermode == FH) {
00555                 fhtri = new FirstHitTRI();
00556                 fhtri->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00557                 fhtri->SetTreshold(m_treshold);
00558                 fhtri->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00559                 fhtri->SetLight(m_light);
00560         }
00561         if(m_raytype == NN && m_rendermode == MI) {
00562                 minn = new MaxIntensityNN();
00563                 minn->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00564                 minn->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00565         }
00566         if(m_raytype == TRI && m_rendermode == MI) {
00567                 mitri = new MaxIntensityTRI();
00568                 mitri->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00569                 mitri->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00570         }
00571         if(m_raytype == NN && m_rendermode == XRAY) {
00572                 xraynn = new XRayNN();
00573                 xraynn->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00574                 xraynn->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00575         }
00576         if(m_raytype == TRI && m_rendermode == XRAY) {
00577                 xraytri = new XRayTRI();
00578                 xraytri->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00579                 xraytri->Initialize(m_background,m_background,m_steplength,m_viewingplane,m_data,m_tf);
00580         }
00581         
00582         for(int j = 0; j < m_height; j++) {
00583                 for(int i = 0; i < m_width; i++) {
00584                         if(m_raytype == NN && m_rendermode == STANDARD) {
00585                                 r->Reset();
00586                                 direction = pos-m_eye;
00587                                 r->SetPosDir(m_eye,direction);
00588                                 r->CastNext();
00589                                 m_image[j*m_width+i] = r->GetCurrentColor().toRGB();
00590                         }
00591                         if(m_raytype == TRI && m_rendermode == STANDARD) {
00592                                 tri->Reset();
00593                                 direction = pos-m_eye;
00594                                 tri->SetPosDir(m_eye,direction);
00595                                 tri->CastNext();
00596                                 m_image[j*m_width+i] = tri->GetCurrentColor().toRGB();
00597                         }
00598                         if(m_raytype == NN && m_rendermode == FH) {
00599                                 fhnn->Reset();
00600                                 direction = pos-m_eye;
00601                                 fhnn->SetPosDir(m_eye,direction);
00602                                 fhnn->CastNext();
00603                                 m_image[j*m_width+i] = fhnn->GetCurrentColor().toRGB();
00604                         }
00605                         if(m_raytype == TRI && m_rendermode == FH) {
00606                                 fhtri->Reset();
00607                                 direction = pos-m_eye;
00608                                 fhtri->SetPosDir(m_eye,direction);
00609                                 fhtri->CastNext();
00610                                 m_image[j*m_width+i] = fhtri->GetCurrentColor().toRGB();
00611                         }
00612                         if(m_raytype == NN && m_rendermode == MI) {
00613                                 minn->Reset();
00614                                 direction = pos-m_eye;
00615                                 minn->SetPosDir(m_eye,direction);
00616                                 minn->CastNext();
00617                                 m_image[j*m_width+i] = minn->GetCurrentColor().toRGB();
00618                         }
00619                         if(m_raytype == TRI && m_rendermode == MI) {
00620                                 mitri->Reset();
00621                                 direction = pos-m_eye;
00622                                 mitri->SetPosDir(m_eye,direction);
00623                                 mitri->CastNext();
00624                                 m_image[j*m_width+i] = mitri->GetCurrentColor().toRGB();
00625                         }
00626                         if(m_raytype == NN && m_rendermode == XRAY) {
00627                                 xraynn->Reset();
00628                                 direction = pos-m_eye;
00629                                 xraynn->SetPosDir(m_eye,direction);
00630                                 xraynn->CastNext();
00631                                 m_image[j*m_width+i] = xraynn->GetCurrentColor().toRGB();
00632                         }
00633                         if(m_raytype == TRI && m_rendermode == XRAY) {
00634                                 xraytri->Reset();
00635                                 direction = pos-m_eye;
00636                                 xraytri->SetPosDir(m_eye,direction);
00637                                 xraytri->CastNext();
00638                                 m_image[j*m_width+i] = xraytri->GetCurrentColor().toRGB();
00639                         }
00640                         
00641                         
00642                         pos += m_xdir;
00643 
00644 
00645                         if ((counter-- <= 0) && (progPos < 100)) {
00646                                 counter = loadSize;
00647                                 pFrame->SendMessage(MYWM_PROGRESS, progPos++);
00648                         }
00649 
00650 
00651                 } // inner for
00652                 pos = backup;
00653                 pos += j*m_ydir;
00654 
00655                 pFrame->SendMessage(MYWM_PROGRESS, 0);
00656         
00657         }
00658 */
00659         if (r)
00660                 delete r;
00661 
00662         ready = true;
00663         return true;
00664 }
00665 
00666 
00667 bool
00668 Perspective::RotateX(float alpha) {
00669         int maxX = m_data->GetXDim()-1;
00670         int maxY = m_data->GetYDim()-1;
00671         int maxZ = m_data->GetZDim()-1;
00672         Matrix4x4 rotmat;
00673         rotmat.rotateX(-alpha);
00674         m_eye = rotmat*m_eye;
00675         m_viewingplane->normal = VECTOR(maxX/2,maxY/2,maxZ/2)-m_eye;
00676         m_viewingplane->normal.normalize();
00677         m_viewingplane->point = m_eye + m_dist*m_viewingplane->normal;
00678         
00679         SetViewingMatrix();
00680         return true;
00681 }
00682 
00683 bool
00684 Perspective::RotateY(float alpha) {
00685         int maxX = m_data->GetXDim()-1;
00686         int maxY = m_data->GetYDim()-1;
00687         int maxZ = m_data->GetZDim()-1;
00688         Matrix4x4 rotmat;
00689         rotmat.rotateY(-alpha);
00690         m_eye = rotmat*m_eye;
00691         m_viewingplane->normal = VECTOR(maxX/2,maxY/2,maxZ/2)-m_eye;
00692         m_viewingplane->normal.normalize();
00693         m_viewingplane->point = m_eye + m_dist*m_viewingplane->normal;
00694         
00695         SetViewingMatrix();
00696         return true;
00697 }
00698 
00699 bool
00700 Perspective::RotateZ(float alpha) {
00701         int maxX = m_data->GetXDim()-1;
00702         int maxY = m_data->GetYDim()-1;
00703         int maxZ = m_data->GetZDim()-1;
00704         Matrix4x4 rotmat;
00705         rotmat.rotateZ(-alpha);
00706         m_eye = rotmat*m_eye;
00707         m_viewingplane->normal = VECTOR(maxX/2,maxY/2,maxZ/2)-m_eye;
00708         m_viewingplane->normal.normalize();
00709         m_viewingplane->point = m_eye + m_dist*m_viewingplane->normal;
00710         
00711         SetViewingMatrix();
00712         return true;
00713 }

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