Eigene Dateien/Vis/src/VSliceRenderer.cpp

Go to the documentation of this file.
00001 #include "VSliceRenderer.h"
00002 #include "glew.h"
00003 #include "VFramebufferObject.h"
00004 
00005 VSliceRenderer::VSliceRenderer() : m_ActiveSlice(ALL), m_active_saggital(1), m_active_corronal(1),
00006 m_active_transversal(1), m_ProgramLoaded(false), m_TransferFunctionHandle(0), m_tf_activated(0)
00007 {
00008         m_Volume = NULL;
00009 }
00010 
00011 
00012 VSliceRenderer::VSliceRenderer(VVolume * volume) : m_ActiveSlice(ALL), m_active_saggital(1),
00013 m_active_corronal(1), m_active_transversal(1), m_ProgramLoaded(false), m_TransferFunctionHandle(0)
00014 {
00015         m_Volume = volume;
00016 }
00017 
00018 void VSliceRenderer::draw()
00019 {
00020         switch (m_ActiveSlice)
00021         {
00022         case SAGGITAL:
00023                 this->drawSaggitalSlice();
00024                 break;
00025         case CORRONAL:
00026                 this->drawCorronalSlice();
00027                 break;
00028         case TRANSVERSAL:
00029                 this->drawTransversalSlice();
00030                 break;
00031         case ALL:
00032                 this->drawAllSlices();
00033                 break;
00034         }
00035 }
00036 
00037 void VSliceRenderer::processInput(guiInput input)
00038 {
00039         /*this->m_ActiveSlice = input.m_ActiveSlice;
00040         this->m_CorSliceNumber = input.m_CorronalSlice;
00041         this->m_SagSliceNumber = input.m_SaggitalSlice;
00042         this->m_TransSliceNumber = input.m_TransversalSlice;*/
00043 }
00044 
00045 void VSliceRenderer::drawAllSlices()
00046 {
00047         glActiveTextureARB(GL_TEXTURE0_ARB);
00048         glEnable(GL_TEXTURE_3D);
00049         glBindTexture(GL_TEXTURE_3D, m_Volume->getGLVolumeHandle());
00050 
00051         
00052         if (m_tf_activated)
00053         {
00054                 
00055                 glActiveTextureARB(GL_TEXTURE1_ARB);
00056                 glEnable(GL_TEXTURE_2D);
00057                 glBindTexture(GL_TEXTURE_2D, m_TransferFunctionHandle);
00058                 
00059                 m_Program_with_tf.bind();
00060                 glUniform1i(m_Program_with_tf.getUniformLocation("mVolume"),0);
00061                 glUniform1i(m_Program_with_tf.getUniformLocation("mTransfer"),1);
00062         }
00063         else
00064         {
00065                 m_Program_without_tf.bind();
00066                 glUniform1i(m_Program_without_tf.getUniformLocation("mVolume"),0);
00067         }
00068         
00069 
00070         
00071 
00072         const GLenum glError = glGetError();
00073 
00074         if (glError != GL_NO_ERROR)
00075                 std::cout << "Error in draw " << gluErrorString(glError) << std::endl;
00076 
00077         glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00078 
00079         //draw small corronal in lower left corner
00080         glBegin(GL_QUADS);
00081 
00082         float minx = 0.0f;
00083         float miny = 0.0f;
00084         float maxx = 0.0f;
00085         float maxy = 0.0f;
00086 
00087         float fw = 662.0f / (float)m_Width;
00088         float fh = 662.0f / (float)m_Height;
00089 
00090         float w0, h0;
00091         float aspect = ((float)m_Volume->getDimX()/(float)m_Volume->getDimZ());
00092 
00093         if(aspect < 1.0f)
00094         {
00095                 h0 = 0.5f;
00096                 w0 = 0.5f * aspect;
00097         }
00098         else
00099         {
00100                 w0 = 0.5f;
00101                 h0 = 0.5f / aspect;
00102         }
00103 
00104         //float aspect = ((float)m_Volume->getDimX()/(float)m_Volume->getDimZ());
00105 
00106         //if(windowaspect > 1.0f)
00107         //{
00108         //      higher width -> modify x
00109         //      minx += (1.0f - (1.0f/windowaspect))/2.0f;
00110         //      maxx -= (1.0f - (1.0f/windowaspect))/2.0f;
00111         //}
00112         //else if (windowaspect < 1.0f)
00113         //{
00114         //      higher height -> modify y
00115         //      miny += (1.0f - (windowaspect/1.0f))/2.0f;
00116         //      maxy -= (1.0f - (windowaspect/1.0f))/2.0f;
00117         //}
00118 
00119         //xsize = abs(minx) + abs(maxx);
00120         //ysize = abs(miny) + abs(maxy);
00121 
00122         //if(aspect > 1.0f)
00123         //{
00124         //      in y richtung drücken
00125         //      in x richtung auf 1.0 bringen
00126 
00127         //      miny /= aspect;
00128         //      maxy /= aspect;
00129         //      
00130         //      if(windowaspect >= 1.0f)
00131         //      {
00132         //              minx /= xsize/2.0f;
00133         //              maxx /= xsize/2.0f;
00134 
00135         //              miny /= xsize/2.0f;
00136         //              maxy /= xsize/2.0f;
00137         //      }
00138         //      else
00139         //      {
00140         //              minx /= xsize/2.0f;
00141         //              maxx /= xsize/2.0f;
00142 
00143         //              miny *= ysize/2.0f;
00144         //              maxy *= ysize/2.0f;
00145         //      }
00146         //      
00147 
00148         //      if((miny < -1.0f) && (maxy > 1.0f))
00149         //      {
00150         //              float smax = maxy;
00151 
00152         //              minx /= smax;
00153         //              miny /= smax;
00154 
00155         //              maxx /= smax;
00156         //              maxy /= smax;
00157         //      }
00158         //}
00159         //else if(aspect < 1.0f)
00160         //{
00161         //      in x richtung drücken
00162         //      in y richtung auf 1.0 bringen
00163         //      minx *= aspect;
00164         //      maxx *= aspect;
00165 
00166         //      if(windowaspect >= 1.0f)
00167         //      {
00168         //              minx *= xsize/2.0f;
00169         //              maxx *= xsize/2.0f;
00170 
00171         //              miny /= ysize/2.0f;
00172         //              maxy /= ysize/2.0f;
00173         //      }
00174         //      else
00175         //      {
00176         //              minx /= ysize/2.0f;
00177         //              maxx /= ysize/2.0f;
00178 
00179         //              miny /= ysize/2.0f;
00180         //              maxy /= ysize/2.0f;
00181         //      }
00182 
00183         //      if((minx < -1.0f) && (maxx > 1.0f))
00184         //      {
00185         //              float smax = maxx;
00186 
00187         //              minx /= smax;
00188         //              miny /= smax;
00189 
00190         //              maxx /= smax;
00191         //              maxy /= smax;
00192         //      }
00193         //}
00194 
00195         if (fw > fh)
00196         {
00197                 h0 /= fw;
00198                 h0 *= fh;
00199 
00200         }else
00201         {
00202                 w0 /= fh;
00203                 w0 *= fw;
00204         }
00205 
00206         minx = -0.5f - w0;
00207         maxx = -0.5f + w0;
00208         miny = -0.5f - h0;
00209         maxy = -0.5f + h0;
00210         
00211 
00212 
00213         //glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00214         glTexCoord3f(0.0f, (float)(m_active_corronal - 1)/(float)m_Volume->getDimY(), 0.0f);
00215         glVertex3f(minx, miny, 0.0f);
00216 
00217         //glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00218         glTexCoord3f(0.0f, (float)(m_active_corronal - 1)/(float)m_Volume->getDimY(), 1.0f);
00219         glVertex3f(minx, maxy, 0.0f);
00220 
00221         //glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00222         glTexCoord3f(1.0f, (float)(m_active_corronal - 1)/(float)m_Volume->getDimY(), 1.0f);
00223         glVertex3f(maxx, maxy, 0.0f);
00224 
00225         //glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
00226         glTexCoord3f(1.0f, (float)(m_active_corronal - 1)/(float)m_Volume->getDimY(), 0.0f);
00227         glVertex3f(maxx, miny, 0.0f);
00228         glEnd();
00229 
00230         //draw small saggital in upper left corner
00231         glBegin(GL_QUADS);
00232         
00233         
00234         aspect = ((float)m_Volume->getDimY()/(float)m_Volume->getDimZ());
00235         if(aspect < 1.0f)
00236         {
00237                 h0 = 0.5f;
00238                 w0 = 0.5f * aspect;
00239         }
00240         else
00241         {
00242                 w0 = 0.5f;
00243                 h0 = 0.5f / aspect;
00244         }
00245 
00246         //float aspect = ((float)m_Volume->getDimX()/(float)m_Volume->getDimZ());
00247 
00248         //if(windowaspect > 1.0f)
00249         //{
00250         //      higher width -> modify x
00251         //      minx += (1.0f - (1.0f/windowaspect))/2.0f;
00252         //      maxx -= (1.0f - (1.0f/windowaspect))/2.0f;
00253         //}
00254         //else if (windowaspect < 1.0f)
00255         //{
00256         //      higher height -> modify y
00257         //      miny += (1.0f - (windowaspect/1.0f))/2.0f;
00258         //      maxy -= (1.0f - (windowaspect/1.0f))/2.0f;
00259         //}
00260 
00261         //xsize = abs(minx) + abs(maxx);
00262         //ysize = abs(miny) + abs(maxy);
00263 
00264         //if(aspect > 1.0f)
00265         //{
00266         //      in y richtung drücken
00267         //      in x richtung auf 1.0 bringen
00268 
00269         //      miny /= aspect;
00270         //      maxy /= aspect;
00271         //      
00272         //      if(windowaspect >= 1.0f)
00273         //      {
00274         //              minx /= xsize/2.0f;
00275         //              maxx /= xsize/2.0f;
00276 
00277         //              miny /= xsize/2.0f;
00278         //              maxy /= xsize/2.0f;
00279         //      }
00280         //      else
00281         //      {
00282         //              minx /= xsize/2.0f;
00283         //              maxx /= xsize/2.0f;
00284 
00285         //              miny *= ysize/2.0f;
00286         //              maxy *= ysize/2.0f;
00287         //      }
00288         //      
00289 
00290         //      if((miny < -1.0f) && (maxy > 1.0f))
00291         //      {
00292         //              float smax = maxy;
00293 
00294         //              minx /= smax;
00295         //              miny /= smax;
00296 
00297         //              maxx /= smax;
00298         //              maxy /= smax;
00299         //      }
00300         //}
00301         //else if(aspect < 1.0f)
00302         //{
00303         //      in x richtung drücken
00304         //      in y richtung auf 1.0 bringen
00305         //      minx *= aspect;
00306         //      maxx *= aspect;
00307 
00308         //      if(windowaspect >= 1.0f)
00309         //      {
00310         //              minx *= xsize/2.0f;
00311         //              maxx *= xsize/2.0f;
00312 
00313         //              miny /= ysize/2.0f;
00314         //              maxy /= ysize/2.0f;
00315         //      }
00316         //      else
00317         //      {
00318         //              minx /= ysize/2.0f;
00319         //              maxx /= ysize/2.0f;
00320 
00321         //              miny /= ysize/2.0f;
00322         //              maxy /= ysize/2.0f;
00323         //      }
00324 
00325         //      if((minx < -1.0f) && (maxx > 1.0f))
00326         //      {
00327         //              float smax = maxx;
00328 
00329         //              minx /= smax;
00330         //              miny /= smax;
00331 
00332         //              maxx /= smax;
00333         //              maxy /= smax;
00334         //      }
00335         //}
00336 
00337         if (fw > fh)
00338         {
00339                 h0 /= fw;
00340                 h0 *= fh;
00341 
00342         }else
00343         {
00344                 w0 /= fh;
00345                 w0 *= fw;
00346         }
00347 
00348         minx = -0.5f - w0; 
00349         maxx = -0.5f + w0; 
00350         miny =  0.5f - h0; 
00351         maxy =  0.5f + h0; 
00352         
00353         glTexCoord3f((float)(m_active_saggital-1)/(float)m_Volume->getDimX(), 0.0f, 0.0f);
00354         glVertex3f(minx, miny, 0.0f);
00355 
00356         glTexCoord3f((float)(m_active_saggital-1)/(float)m_Volume->getDimX(), 0.0f, 1.0f);
00357         glVertex3f(minx, maxy, 0.0f);
00358 
00359         glTexCoord3f((float)(m_active_saggital-1)/(float)m_Volume->getDimX(), 1.0f, 1.0f);
00360         glVertex3f(maxx, maxy, 0.0f);
00361 
00362         glTexCoord3f((float)(m_active_saggital-1)/(float)m_Volume->getDimX(), 1.0f, 0.0f);
00363         glVertex3f(maxx, miny, 0.0f);
00364         glEnd();
00365 
00366         //draw small transversal in upper right corner
00367 
00368         glBegin(GL_QUADS);
00369         aspect = ((float)m_Volume->getDimY()/(float)m_Volume->getDimX());
00370 
00371         if(aspect < 1.0f)
00372         {
00373                 h0 = 0.5f;
00374                 w0 = 0.5f * aspect;
00375         }
00376         else
00377         {
00378                 w0 = 0.5f;
00379                 h0 = 0.5f / aspect;
00380         }
00381 
00382         //float aspect = ((float)m_Volume->getDimX()/(float)m_Volume->getDimZ());
00383 
00384         //if(windowaspect > 1.0f)
00385         //{
00386         //      higher width -> modify x
00387         //      minx += (1.0f - (1.0f/windowaspect))/2.0f;
00388         //      maxx -= (1.0f - (1.0f/windowaspect))/2.0f;
00389         //}
00390         //else if (windowaspect < 1.0f)
00391         //{
00392         //      higher height -> modify y
00393         //      miny += (1.0f - (windowaspect/1.0f))/2.0f;
00394         //      maxy -= (1.0f - (windowaspect/1.0f))/2.0f;
00395         //}
00396 
00397         //xsize = abs(minx) + abs(maxx);
00398         //ysize = abs(miny) + abs(maxy);
00399 
00400         //if(aspect > 1.0f)
00401         //{
00402         //      in y richtung drücken
00403         //      in x richtung auf 1.0 bringen
00404 
00405         //      miny /= aspect;
00406         //      maxy /= aspect;
00407         //      
00408         //      if(windowaspect >= 1.0f)
00409         //      {
00410         //              minx /= xsize/2.0f;
00411         //              maxx /= xsize/2.0f;
00412 
00413         //              miny /= xsize/2.0f;
00414         //              maxy /= xsize/2.0f;
00415         //      }
00416         //      else
00417         //      {
00418         //              minx /= xsize/2.0f;
00419         //              maxx /= xsize/2.0f;
00420 
00421         //              miny *= ysize/2.0f;
00422         //              maxy *= ysize/2.0f;
00423         //      }
00424         //      
00425 
00426         //      if((miny < -1.0f) && (maxy > 1.0f))
00427         //      {
00428         //              float smax = maxy;
00429 
00430         //              minx /= smax;
00431         //              miny /= smax;
00432 
00433         //              maxx /= smax;
00434         //              maxy /= smax;
00435         //      }
00436         //}
00437         //else if(aspect < 1.0f)
00438         //{
00439         //      in x richtung drücken
00440         //      in y richtung auf 1.0 bringen
00441         //      minx *= aspect;
00442         //      maxx *= aspect;
00443 
00444         //      if(windowaspect >= 1.0f)
00445         //      {
00446         //              minx *= xsize/2.0f;
00447         //              maxx *= xsize/2.0f;
00448 
00449         //              miny /= ysize/2.0f;
00450         //              maxy /= ysize/2.0f;
00451         //      }
00452         //      else
00453         //      {
00454         //              minx /= ysize/2.0f;
00455         //              maxx /= ysize/2.0f;
00456 
00457         //              miny /= ysize/2.0f;
00458         //              maxy /= ysize/2.0f;
00459         //      }
00460 
00461         //      if((minx < -1.0f) && (maxx > 1.0f))
00462         //      {
00463         //              float smax = maxx;
00464 
00465         //              minx /= smax;
00466         //              miny /= smax;
00467 
00468         //              maxx /= smax;
00469         //              maxy /= smax;
00470         //      }
00471         //}
00472 
00473         if (fw > fh)
00474         {
00475                 h0 /= fw;
00476                 h0 *= fh;
00477 
00478         }else
00479         {
00480                 w0 /= fh;
00481                 w0 *= fw;
00482         }
00483 
00484         minx = 0.5f - w0; 
00485         maxx = 0.5f + w0; 
00486         miny = 0.5f - h0; 
00487         maxy = 0.5f + h0; 
00488 
00489         glTexCoord3f(0.0f, 0.0f, (float)(m_active_transversal-1)/(float)m_Volume->getDimZ());
00490         glVertex3f(minx, miny, 0.0f);
00491 
00492         glTexCoord3f(0.0f, 1.0f, (float)(m_active_transversal-1)/(float)m_Volume->getDimZ());
00493         glVertex3f(minx, maxy, 0.0f);
00494 
00495         glTexCoord3f(1.0f, 1.0f, (float)(m_active_transversal-1)/(float)m_Volume->getDimZ());
00496         glVertex3f(maxx, maxy, 0.0f);
00497 
00498         glTexCoord3f(1.0f, 0.0f, (float)(m_active_transversal-1)/(float)m_Volume->getDimZ());
00499         glVertex3f(maxx, miny, 0.0f);
00500         glEnd();
00501 
00502         if(m_tf_activated)
00503         {
00504                 m_Program_with_tf.release();
00505 
00506                 glActiveTextureARB(GL_TEXTURE1_ARB);
00507                 glBindTexture(GL_TEXTURE_2D, 0);
00508                 glDisable(GL_TEXTURE_2D);
00509         }
00510         else
00511         {
00512                 m_Program_without_tf.release();
00513         }
00514         
00515         
00516         glActiveTextureARB(GL_TEXTURE0_ARB);
00517         glBindTexture(GL_TEXTURE_3D, 0);
00518         glDisable(GL_TEXTURE_3D);
00519         
00520         glBegin(GL_LINES);
00521         glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
00522         glVertex3f(0.0f, 1.0f, -1.0f);
00523         
00524         glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
00525         glVertex3f(0.0f, -1.0f, -1.0f);
00526 
00527         glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
00528         glVertex3f(1.0f, 0.0f, -1.0f);
00529         
00530         glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
00531         glVertex3f(-1.0f, 0.0f, -1.0f);
00532         glEnd();
00533 }
00534 
00535 void VSliceRenderer::drawCorronalSlice()
00536 {
00537         glActiveTextureARB(GL_TEXTURE0_ARB);
00538         glEnable(GL_TEXTURE_3D);
00539         glBindTexture(GL_TEXTURE_3D, m_Volume->getGLVolumeHandle());
00540 
00541 
00542         if (m_tf_activated)
00543         {
00544 
00545                 glActiveTextureARB(GL_TEXTURE1_ARB);
00546                 glEnable(GL_TEXTURE_2D);
00547                 glBindTexture(GL_TEXTURE_2D, m_TransferFunctionHandle);
00548 
00549                 m_Program_with_tf.bind();
00550                 glUniform1i(m_Program_with_tf.getUniformLocation("mVolume"),0);
00551                 glUniform1i(m_Program_with_tf.getUniformLocation("mTransfer"),1);
00552         }
00553         else
00554         {
00555                 m_Program_without_tf.bind();
00556                 glUniform1i(m_Program_without_tf.getUniformLocation("mVolume"),0);
00557         }
00558 
00559         float windowaspect = (float)m_Width / (float) m_Height;
00560 
00561         float minx = -1.0f;
00562         float miny = -1.0f;
00563         float maxx =  1.0f;
00564         float maxy =  1.0f;
00565         float xsize;
00566         float ysize;
00567 
00568         float aspect = ((float)m_Volume->getDimX()/(float)m_Volume->getDimZ());
00569 
00570 
00571         if(windowaspect > 1.0f)
00572         {
00573                 //higher width -> modify x
00574                 minx += (1.0f - (1.0f/windowaspect))/2.0f;
00575                 maxx -= (1.0f - (1.0f/windowaspect))/2.0f;
00576         }
00577         else if (windowaspect < 1.0f)
00578         {
00579                 //higher height -> modify y
00580                 miny += (1.0f - (windowaspect/1.0f))/2.0f;
00581                 maxy -= (1.0f - (windowaspect/1.0f))/2.0f;
00582         }
00583 
00584         xsize = abs(minx) + abs(maxx);
00585         ysize = abs(miny) + abs(maxy);
00586 
00587         if(aspect > 1.0f)
00588         {
00589                 //in y richtung drücken
00590                 //in x richtung auf 1.0 bringen
00591 
00592                 miny /= aspect;
00593                 maxy /= aspect;
00594 
00595                 if(windowaspect >= 1.0f)
00596                 {
00597                         minx /= xsize/2.0f;
00598                         maxx /= xsize/2.0f;
00599 
00600                         miny /= xsize/2.0f;
00601                         maxy /= xsize/2.0f;
00602                 }
00603                 else
00604                 {
00605                         minx /= xsize/2.0f;
00606                         maxx /= xsize/2.0f;
00607 
00608                         miny *= ysize/2.0f;
00609                         maxy *= ysize/2.0f;
00610                 }
00611 
00612 
00613                 if((miny < -1.0f) && (maxy > 1.0f))
00614                 {
00615                         float smax = maxy;
00616 
00617                         minx /= smax;
00618                         miny /= smax;
00619 
00620                         maxx /= smax;
00621                         maxy /= smax;
00622                 }
00623         }
00624         else if(aspect < 1.0f)
00625         {
00626                 //in x richtung drücken
00627                 //in y richtung auf 1.0 bringen
00628                 minx *= aspect;
00629                 maxx *= aspect;
00630 
00631                 if(windowaspect >= 1.0f)
00632                 {
00633                         minx *= xsize/2.0f;
00634                         maxx *= xsize/2.0f;
00635 
00636                         miny /= ysize/2.0f;
00637                         maxy /= ysize/2.0f;
00638                 }
00639                 else
00640                 {
00641                         minx /= ysize/2.0f;
00642                         maxx /= ysize/2.0f;
00643 
00644                         miny /= ysize/2.0f;
00645                         maxy /= ysize/2.0f;
00646                 }
00647 
00648                 if((minx < -1.0f) && (maxx > 1.0f))
00649                 {
00650                         float smax = maxx;
00651 
00652                         minx /= smax;
00653                         miny /= smax;
00654 
00655                         maxx /= smax;
00656                         maxy /= smax;
00657                 }
00658         }
00659 
00660         glBegin(GL_QUADS);
00661         glTexCoord3f(0.0f, (float)(m_active_corronal - 1)/(float)m_Volume->getDimY(), 0.0f);
00662         glVertex3f(minx, miny, 0.0f);
00663 
00664         glTexCoord3f(0.0f, (float)(m_active_corronal - 1)/(float)m_Volume->getDimY(), 1.0f);
00665         glVertex3f(minx, maxy, 0.0f);
00666 
00667         glTexCoord3f(1.0f, (float)(m_active_corronal - 1)/(float)m_Volume->getDimY(), 1.0f);
00668         glVertex3f(maxx, maxy, 0.0f);
00669 
00670         glTexCoord3f(1.0f, (float)(m_active_corronal - 1)/(float)m_Volume->getDimY(), 0.0f);
00671         glVertex3f(maxx, miny, 0.0f);
00672         glEnd();
00673 
00674         if(m_tf_activated)
00675         {
00676                 m_Program_with_tf.release();
00677 
00678                 glActiveTextureARB(GL_TEXTURE1_ARB);
00679                 glBindTexture(GL_TEXTURE_2D, 0);
00680                 glDisable(GL_TEXTURE_2D);
00681         }
00682         else
00683         {
00684                 m_Program_without_tf.release();
00685         }
00686 
00687 
00688         glActiveTextureARB(GL_TEXTURE0_ARB);
00689         glBindTexture(GL_TEXTURE_3D, 0);
00690         glDisable(GL_TEXTURE_3D);
00691 }
00692 
00693 void VSliceRenderer::drawSaggitalSlice()
00694 {
00695         glActiveTextureARB(GL_TEXTURE0_ARB);
00696         glEnable(GL_TEXTURE_3D);
00697         glBindTexture(GL_TEXTURE_3D, m_Volume->getGLVolumeHandle());
00698 
00699 
00700         if (m_tf_activated)
00701         {
00702 
00703                 glActiveTextureARB(GL_TEXTURE1_ARB);
00704                 glEnable(GL_TEXTURE_2D);
00705                 glBindTexture(GL_TEXTURE_2D, m_TransferFunctionHandle);
00706 
00707                 m_Program_with_tf.bind();
00708                 glUniform1i(m_Program_with_tf.getUniformLocation("mVolume"),0);
00709                 glUniform1i(m_Program_with_tf.getUniformLocation("mTransfer"),1);
00710         }
00711         else
00712         {
00713                 m_Program_without_tf.bind();
00714                 glUniform1i(m_Program_without_tf.getUniformLocation("mVolume"),0);
00715         }
00716 
00717         float windowaspect = (float)m_Width / (float) m_Height;
00718 
00719         float aspect = ((float)m_Volume->getDimY()/(float)m_Volume->getDimZ());
00720         float minx = -1.0f;
00721         float miny = -1.0f;
00722         float maxx =  1.0f;
00723         float maxy =  1.0f;
00724         float xsize;
00725         float ysize;
00726 
00727         if(windowaspect > 1.0f)
00728         {
00729                 //higher width -> modify x
00730                 minx += (1.0f - (1.0f/windowaspect))/2.0f;
00731                 maxx -= (1.0f - (1.0f/windowaspect))/2.0f;
00732         }
00733         else if (windowaspect < 1.0f)
00734         {
00735                 //higher height -> modify y
00736                 miny += (1.0f - (windowaspect/1.0f))/2.0f;
00737                 maxy -= (1.0f - (windowaspect/1.0f))/2.0f;
00738         }
00739 
00740         xsize = abs(minx) + abs(maxx);
00741         ysize = abs(miny) + abs(maxy);
00742 
00743         if(aspect > 1.0f)
00744         {
00745                 //in y richtung drücken
00746                 //in x richtung auf 1.0 bringen
00747 
00748                 miny /= aspect;
00749                 maxy /= aspect;
00750 
00751                 if(windowaspect >= 1.0f)
00752                 {
00753                         minx /= xsize/2.0f;
00754                         maxx /= xsize/2.0f;
00755 
00756                         miny /= xsize/2.0f;
00757                         maxy /= xsize/2.0f;
00758                 }
00759                 else
00760                 {
00761                         minx /= xsize/2.0f;
00762                         maxx /= xsize/2.0f;
00763 
00764                         miny *= ysize/2.0f;
00765                         maxy *= ysize/2.0f;
00766                 }
00767 
00768 
00769                 if((miny < -1.0f) && (maxy > 1.0f))
00770                 {
00771                         float smax = maxy;
00772 
00773                         minx /= smax;
00774                         miny /= smax;
00775 
00776                         maxx /= smax;
00777                         maxy /= smax;
00778                 }
00779         }
00780         else if(aspect < 1.0f)
00781         {
00782                 //in x richtung drücken
00783                 //in y richtung auf 1.0 bringen
00784                 minx *= aspect;
00785                 maxx *= aspect;
00786 
00787                 if(windowaspect >= 1.0f)
00788                 {
00789                         minx *= xsize/2.0f;
00790                         maxx *= xsize/2.0f;
00791 
00792                         miny /= ysize/2.0f;
00793                         maxy /= ysize/2.0f;
00794                 }
00795                 else
00796                 {
00797                         minx /= ysize/2.0f;
00798                         maxx /= ysize/2.0f;
00799 
00800                         miny /= ysize/2.0f;
00801                         maxy /= ysize/2.0f;
00802                 }
00803 
00804                 if((minx < -1.0f) && (maxx > 1.0f))
00805                 {
00806                         float smax = maxx;
00807 
00808                         minx /= smax;
00809                         miny /= smax;
00810 
00811                         maxx /= smax;
00812                         maxy /= smax;
00813                 }
00814         }
00815 
00816         glBegin(GL_QUADS);
00817         glTexCoord3f((float)(m_active_saggital-1)/(float)m_Volume->getDimX(), 0.0f, 0.0f);
00818         glVertex3f(minx, miny, 0.0f);
00819 
00820         glTexCoord3f((float)(m_active_saggital-1)/(float)m_Volume->getDimX(), 0.0f, 1.0f);
00821         glVertex3f(minx, maxy, 0.0f);
00822 
00823         glTexCoord3f((float)(m_active_saggital-1)/(float)m_Volume->getDimX(), 1.0f, 1.0f);
00824         glVertex3f(maxx, maxy, 0.0f);
00825 
00826         glTexCoord3f((float)(m_active_saggital-1)/(float)m_Volume->getDimX(), 1.0f, 0.0f);
00827         glVertex3f(maxx, miny, 0.0f);
00828         glEnd();
00829 
00830         if(m_tf_activated)
00831         {
00832                 m_Program_with_tf.release();
00833 
00834                 glActiveTextureARB(GL_TEXTURE1_ARB);
00835                 glBindTexture(GL_TEXTURE_2D, 0);
00836                 glDisable(GL_TEXTURE_2D);
00837         }
00838         else
00839         {
00840                 m_Program_without_tf.release();
00841         }
00842 
00843 
00844         glActiveTextureARB(GL_TEXTURE0_ARB);
00845         glBindTexture(GL_TEXTURE_3D, 0);
00846         glDisable(GL_TEXTURE_3D);
00847 }
00848 
00849 void VSliceRenderer::drawTransversalSlice()
00850 {
00851         glActiveTextureARB(GL_TEXTURE0_ARB);
00852         glEnable(GL_TEXTURE_3D);
00853         glBindTexture(GL_TEXTURE_3D, m_Volume->getGLVolumeHandle());
00854 
00855 
00856         if (m_tf_activated)
00857         {
00858 
00859                 glActiveTextureARB(GL_TEXTURE1_ARB);
00860                 glEnable(GL_TEXTURE_2D);
00861                 glBindTexture(GL_TEXTURE_2D, m_TransferFunctionHandle);
00862 
00863                 m_Program_with_tf.bind();
00864                 glUniform1i(m_Program_with_tf.getUniformLocation("mVolume"),0);
00865                 glUniform1i(m_Program_with_tf.getUniformLocation("mTransfer"),1);
00866         }
00867         else
00868         {
00869                 m_Program_without_tf.bind();
00870                 glUniform1i(m_Program_without_tf.getUniformLocation("mVolume"),0);
00871         }
00872 
00873         float windowaspect = (float)m_Width / (float) m_Height;
00874 
00875 
00876         float aspect = ((float)m_Volume->getDimY()/(float)m_Volume->getDimX());
00877         float minx = -1.0f;
00878         float miny = -1.0f;
00879         float maxx =  1.0f;
00880         float maxy =  1.0f;
00881         float xsize;
00882         float ysize;
00883 
00884         if(windowaspect > 1.0f)
00885         {
00886                 //higher width -> modify x
00887                 minx += (1.0f - (1.0f/windowaspect))/2.0f;
00888                 maxx -= (1.0f - (1.0f/windowaspect))/2.0f;
00889         }
00890         else if (windowaspect < 1.0f)
00891         {
00892                 //higher height -> modify y
00893                 miny += (1.0f - (windowaspect/1.0f))/2.0f;
00894                 maxy -= (1.0f - (windowaspect/1.0f))/2.0f;
00895         }
00896 
00897         xsize = abs(minx) + abs(maxx);
00898         ysize = abs(miny) + abs(maxy);
00899 
00900         if(aspect > 1.0f)
00901         {
00902                 //in y richtung drücken
00903                 //in x richtung auf 1.0 bringen
00904 
00905                 miny /= aspect;
00906                 maxy /= aspect;
00907 
00908                 if(windowaspect >= 1.0f)
00909                 {
00910                         minx /= xsize/2.0f;
00911                         maxx /= xsize/2.0f;
00912 
00913                         miny /= xsize/2.0f;
00914                         maxy /= xsize/2.0f;
00915                 }
00916                 else
00917                 {
00918                         minx /= xsize/2.0f;
00919                         maxx /= xsize/2.0f;
00920 
00921                         miny *= ysize/2.0f;
00922                         maxy *= ysize/2.0f;
00923                 }
00924 
00925 
00926                 if((miny < -1.0f) && (maxy > 1.0f))
00927                 {
00928                         float smax = maxy;
00929 
00930                         minx /= smax;
00931                         miny /= smax;
00932 
00933                         maxx /= smax;
00934                         maxy /= smax;
00935                 }
00936         }
00937         else if(aspect < 1.0f)
00938         {
00939                 //in x richtung drücken
00940                 //in y richtung auf 1.0 bringen
00941                 minx *= aspect;
00942                 maxx *= aspect;
00943 
00944                 if(windowaspect >= 1.0f)
00945                 {
00946                         minx *= xsize/2.0f;
00947                         maxx *= xsize/2.0f;
00948 
00949                         miny /= ysize/2.0f;
00950                         maxy /= ysize/2.0f;
00951                 }
00952                 else
00953                 {
00954                         minx /= ysize/2.0f;
00955                         maxx /= ysize/2.0f;
00956 
00957                         miny /= ysize/2.0f;
00958                         maxy /= ysize/2.0f;
00959                 }
00960 
00961                 if((minx < -1.0f) && (maxx > 1.0f))
00962                 {
00963                         float smax = maxx;
00964 
00965                         minx /= smax;
00966                         miny /= smax;
00967 
00968                         maxx /= smax;
00969                         maxy /= smax;
00970                 }
00971         }
00972 
00973         glBegin(GL_QUADS);
00974         glTexCoord3f(0.0f, 0.0f, (float)(m_active_transversal-1)/(float)m_Volume->getDimZ());
00975         glVertex3f(minx, miny, 0.0f);
00976 
00977         glTexCoord3f(0.0f, 1.0f, (float)(m_active_transversal-1)/(float)m_Volume->getDimZ());
00978         glVertex3f(minx, maxy, 0.0f);
00979 
00980         glTexCoord3f(1.0f, 1.0f, (float)(m_active_transversal-1)/(float)m_Volume->getDimZ());
00981         glVertex3f(maxx, maxy, 0.0f);
00982 
00983         glTexCoord3f(1.0f, 0.0f, (float)(m_active_transversal-1)/(float)m_Volume->getDimZ());
00984         glVertex3f(maxx, miny, 0.0f);
00985         glEnd();
00986 
00987         if(m_tf_activated)
00988         {
00989                 m_Program_with_tf.release();
00990 
00991                 glActiveTextureARB(GL_TEXTURE1_ARB);
00992                 glBindTexture(GL_TEXTURE_2D, 0);
00993                 glDisable(GL_TEXTURE_2D);
00994         }
00995         else
00996         {
00997                 m_Program_without_tf.release();
00998         }
00999 
01000 
01001         glActiveTextureARB(GL_TEXTURE0_ARB);
01002         glBindTexture(GL_TEXTURE_3D, 0);
01003         glDisable(GL_TEXTURE_3D);
01004 }

Generated on Wed Dec 5 05:15:09 2007 for VolRendering by  doxygen 1.5.4