C:/Users/thebigMuh/Documents/Visual Studio 2005/Projects/Volumizer/Volumizer/OrthoWnd.cpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 #include "Volumizer.h"
00008 
00012 ATOM RegisterOrthoClass(HINSTANCE hInstance)
00013 {
00014         WNDCLASSEX wcex;
00015 
00016         wcex.cbSize = sizeof(WNDCLASSEX);
00017 
00018         wcex.style                      = CS_HREDRAW | CS_VREDRAW;
00019         wcex.lpfnWndProc        = OrthoProc;
00020         wcex.cbClsExtra         = 0;
00021         wcex.cbWndExtra         = 0;
00022         wcex.hInstance          = hInstance;
00023         wcex.hIcon                      = NULL;
00024         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
00025         wcex.hbrBackground      = NULL;//(HBRUSH)(COLOR_ACTIVECAPTION);
00026         wcex.lpszMenuName       = NULL;
00027         wcex.lpszClassName      = L"OrthoWnd";
00028         wcex.hIconSm            = NULL;
00029 
00030         return RegisterClassEx(&wcex);
00031 }
00032 
00034 struct GLstruct {
00035         HDC hdc;                                                
00036         HGLRC hglrc;                                    
00037         float hHandleMin, hHandleMax;   
00038         float vHandleMin, vHandleMax;   
00039         float hQuadExt, vQuadExt;               
00040 };
00041 
00042 GLstruct GLfront, GLleft, GLtop;        
00043 
00044 int xslice, yslice, zslice;                     
00045 float *frontslice, *leftslice, *topslice;
00046 
00050 void InitOrtho(HWND hWnd, GLstruct &cur)
00051 {
00052         cur.hdc = GetDC(hWnd);
00053 
00054         PIXELFORMATDESCRIPTOR pfd = { 
00055     sizeof(PIXELFORMATDESCRIPTOR),    // size of this pfd 
00056     1,                                // version number 
00057     PFD_DRAW_TO_WINDOW |              // support window 
00058     PFD_SUPPORT_OPENGL |              // support OpenGL 
00059     PFD_DOUBLEBUFFER,                 // double buffered 
00060     PFD_TYPE_RGBA,                    // RGBA type 
00061     32,                               // 32-bit color depth 
00062     0, 0, 0, 0, 0, 0,                 // color bits ignored 
00063     0,                                // no alpha buffer 
00064     0,                                // shift bit ignored 
00065     0,                                // no accumulation buffer 
00066     0, 0, 0, 0,                       // accum bits ignored 
00067     32,                               // 32-bit z-buffer     
00068     0,                                // no stencil buffer 
00069     0,                                // no auxiliary buffer 
00070     PFD_MAIN_PLANE,                   // main layer 
00071     0,                                // reserved 
00072     0, 0, 0                           // layer masks ignored 
00073         }; 
00074         
00075         int  iPixelFormat; 
00076 
00078 // TODO: Insert better pfd selecting code... too lazy now. //
00080         
00081 
00082         // get the device context's best, available pixel format match 
00083         iPixelFormat = ChoosePixelFormat(cur.hdc, &pfd); 
00084  
00085         // make that match the device context's current pixel format 
00086         SetPixelFormat(cur.hdc, iPixelFormat, &pfd); 
00087 
00088     if (cur.hglrc = wglCreateContext( cur.hdc ) ) 
00089         { 
00090         // try to make it the thread's current rendering context 
00091         wglMakeCurrent(cur.hdc, cur.hglrc) ; 
00092     } 
00093 
00095 // All the basic things that never change //
00097 
00098         glEnable(GL_DEPTH_TEST);
00099         glEnable(GL_POINT_SMOOTH);
00100         glEnable(GL_LINE_SMOOTH);
00101         glEnable(GL_TEXTURE_2D);
00102 
00103         glEnable(GL_BLEND);
00104         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00105 
00106         glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
00107         glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
00108 
00109         glDepthFunc(GL_LEQUAL);
00110 
00111         glClearColor(0.44f,0.44f,0.44f,0.0f);
00112 
00113         glLineWidth(1.0f);
00114 
00115         // init our font display lists
00116         HFONT neuro;
00117 
00118         neuro = CreateFontW(0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, L"Arial");
00119 
00120         SelectObject(cur.hdc, neuro);
00121 
00122         wglUseFontOutlines(cur.hdc, 0, 255, 1000, 0.0f, 0.0f,  
00123                 WGL_FONT_LINES, NULL); 
00124 }
00125 
00129 void DeInitOrtho(HWND hWnd, GLstruct &cur)
00130 {
00132 // Kill the context & free it //
00134     if(cur.hglrc = wglGetCurrentContext()) { 
00135  
00136         // obtain its associated device context 
00137         cur.hdc = wglGetCurrentDC() ; 
00138  
00139         // make the rendering context not current 
00140         wglMakeCurrent(NULL, NULL) ; 
00141  
00142         // release the device context 
00143         ReleaseDC(hWnd, cur.hdc) ; 
00144  
00145         // delete the rendering context 
00146         wglDeleteContext(cur.hglrc); 
00147     } 
00148 }
00149 
00153 void DrawOrtho(HWND hWnd)
00154 {
00155         GLstruct cur;
00156 
00157         if (hWnd == wnd_front)
00158                 cur = GLfront;
00159 
00160         if (hWnd == wnd_left)
00161                 cur = GLleft;
00162 
00163         if (hWnd == wnd_top)
00164                 cur = GLtop;
00165 
00166         wglMakeCurrent(cur.hdc, cur.hglrc);
00167 
00168         RECT clientRect;
00169         GetClientRect(hWnd, &clientRect);
00170 
00171         glViewport(0, 0, clientRect.right, clientRect.bottom);
00172 
00173         glMatrixMode(GL_PROJECTION);
00174         glLoadIdentity();
00175 
00176         float windowaspect = (float)clientRect.right / (float)clientRect.bottom;
00177 
00178         gluOrtho2D(-windowaspect, windowaspect, -1.0f, 1.0f);
00179 
00180         glMatrixMode(GL_MODELVIEW);
00181 
00182         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00183 
00185         if (voldat)
00186         {
00188                 float aspect = 1.0f;
00189 
00190                 char infotext[50];
00191 
00192                 if (hWnd == wnd_front)
00193                 {
00194                         aspect = (float)volx / (float)volz;
00195 
00196                         _snprintf_s(infotext, 50, 50, "Front, slice %d of %d", yslice + 1, voly);
00197                 }
00198                 if (hWnd == wnd_left)
00199                 {
00200                         aspect = (float)voly / (float)volz;
00201 
00202                         _snprintf_s(infotext, 50, 50, "Left, slice %d of %d", xslice + 1, volx);
00203                 }
00204                 if (hWnd == wnd_top)
00205                 {
00206                         aspect = (float)volx / (float)voly;
00207 
00208                         _snprintf_s(infotext, 50, 50, "Top, slice %d of %d", zslice + 1, volz);
00209                 }
00210 
00211                 float extx, exty;
00212 
00213                 if (aspect < windowaspect)
00214                 {
00215                         extx = aspect; exty = 1.0f;
00216                 }
00217                 else
00218                 {
00219                         extx = windowaspect; exty = windowaspect / aspect;
00220                 }
00221 
00223                 glEnable(GL_TEXTURE_2D);
00224 
00225                 glBindTexture(GL_TEXTURE_2D, 1);
00226 
00227                 glBegin(GL_QUADS);
00228                         glColor3f(1.0f, 1.0f, 1.0f);
00229 
00230                         glTexCoord2f(1.0f, 1.0f); glVertex2f(-extx, exty);
00231                         glTexCoord2f(1.0f, 0.0f); glVertex2f(extx, exty);
00232                         glTexCoord2f(0.0f, 0.0f); glVertex2f(extx, -exty);
00233                         glTexCoord2f(0.0f, 1.0f); glVertex2f(-extx, -exty);
00234 
00235                 glEnd();
00236 
00237                 glDisable(GL_TEXTURE_2D);
00238 
00239                 glPushMatrix();
00240                         glTranslatef(-windowaspect, 0.88f, 0.1f);
00241                         glScalef(0.12f, 0.12f, 0.12f);
00242                         glListBase(1000);
00243                         glColor3f(1.0f, 1.0f, 1.0f);
00244 
00245                         glCallLists((int)strlen(infotext), GL_UNSIGNED_BYTE, infotext);
00246                 glPopMatrix();
00247 
00249                 if (hWnd == wnd_front)
00250                 {
00251                         GLfront.hQuadExt = extx;
00252                         GLfront.vQuadExt = exty;
00253 
00254                         // draw x and z axis handles
00255                         glBegin(GL_LINES);
00256                                 glColor3f(1.0f, 0.0f, 0.0f);
00257 
00258                                 float xpos = (float)xslice / (float)volx;
00259                                 xpos = extx - (xpos * extx * 2.0f);
00260 
00261                                 glVertex3f(xpos, -1.0f, 0.1f);
00262                                 glVertex3f(xpos, 1.0f, 0.1f);
00263                                 glVertex3f(xpos - 2.0f * extx / (float)volx, -1.0f, 0.1f);
00264                                 glVertex3f(xpos - 2.0f * extx / (float)volx, 1.0f, 0.1f);
00265 
00266                                 glColor3f(0.0f, 0.0f, 1.0f);
00267                                 float zpos = (float)zslice / (float)volz;
00268                                 zpos = -exty + (zpos * exty * 2.0f);
00269 
00270                                 glVertex3f(-windowaspect, zpos, 0.1f);
00271                                 glVertex3f(windowaspect, zpos, 0.1f);
00272                                 glVertex3f(-windowaspect, zpos + 2.0f * exty / (float)volz, 0.1f);
00273                                 glVertex3f(windowaspect, zpos + 2.0f * exty / (float)volz, 0.1f);
00274 
00275                                 // fill Handle values
00276                                 GLfront.hHandleMax = xpos;
00277                                 GLfront.hHandleMin = xpos - 2.0f * extx / (float)volx;
00278 
00279                                 GLfront.vHandleMax = -zpos;
00280                                 GLfront.vHandleMin = -zpos - 2.0f * exty / (float)volz;
00281                         glEnd();
00282                 }
00283                 if (hWnd == wnd_left)
00284                 {
00285                         GLleft.hQuadExt = extx;
00286                         GLleft.vQuadExt = exty;
00287 
00288                         // draw y and z axis handles
00289                         glBegin(GL_LINES);
00290                                 glColor3f(0.0f, 1.0f, 0.0f);
00291 
00292                                 float ypos = (float)yslice / (float)voly;
00293                                 ypos = extx - (ypos * extx * 2.0f);
00294 
00295                                 glVertex3f(ypos, -1.0f, 0.1f);
00296                                 glVertex3f(ypos, 1.0f, 0.1f);
00297                                 glVertex3f(ypos - 2.0f * extx / (float)voly, -1.0f, 0.1f);
00298                                 glVertex3f(ypos - 2.0f * extx / (float)voly, 1.0f, 0.1f);
00299 
00300                                 glColor3f(0.0f, 0.0f, 1.0f);
00301                                 float zpos = (float)zslice / (float)volz;
00302                                 zpos = -exty + (zpos * exty * 2.0f);
00303 
00304                                 glVertex3f(-windowaspect, zpos, 0.1f);
00305                                 glVertex3f(windowaspect, zpos, 0.1f);
00306                                 glVertex3f(-windowaspect, zpos + 2.0f * exty / (float)volz, 0.1f);
00307                                 glVertex3f(windowaspect, zpos + 2.0f * exty / (float)volz, 0.1f);
00308 
00309                                 // fill Handle values
00310                                 GLleft.hHandleMax = ypos;
00311                                 GLleft.hHandleMin = ypos - 2.0f * extx / (float)voly;
00312 
00313                                 GLleft.vHandleMax = -zpos;
00314                                 GLleft.vHandleMin = -zpos - 2.0f * exty / (float)volz;
00315                         glEnd();
00316                 }
00317                 if (hWnd == wnd_top)
00318                 {
00319                         GLtop.hQuadExt = extx;
00320                         GLtop.vQuadExt = exty;
00321 
00322                         // draw x and y axis handles
00323                         glBegin(GL_LINES);
00324                                 glColor3f(1.0f, 0.0f, 0.0f);
00325 
00326                                 float xpos = (float)xslice / (float)volx;
00327                                 xpos = extx - (xpos * extx * 2.0f);
00328 
00329                                 glVertex3f(xpos, -1.0f, 0.1f);
00330                                 glVertex3f(xpos, 1.0f, 0.1f);
00331                                 glVertex3f(xpos - 2.0f * extx / (float)volx, -1.0f, 0.1f);
00332                                 glVertex3f(xpos - 2.0f * extx / (float)volx, 1.0f, 0.1f);
00333 
00334                                 glColor3f(0.0f, 1.0f, 0.0f);
00335 
00336                                 float ypos = (float)yslice / (float)voly;
00337                                 ypos = -exty + (ypos * exty * 2.0f);
00338 
00339                                 glVertex3f(-windowaspect, ypos, 0.1f);
00340                                 glVertex3f(windowaspect, ypos, 0.1f);
00341                                 glVertex3f(-windowaspect, ypos + 2.0f * exty / (float)voly, 0.1f);
00342                                 glVertex3f(windowaspect, ypos + 2.0f * exty / (float)voly, 0.1f);
00343 
00344                                 // fill Handle values
00345                                 GLtop.hHandleMax = xpos;
00346                                 GLtop.hHandleMin = xpos - 2.0f * extx / (float)volx;
00347 
00348                                 GLtop.vHandleMax = -ypos;
00349                                 GLtop.vHandleMin = -ypos - 2.0f * exty / (float)voly;
00350                         glEnd();
00351                 }
00352         }
00353 
00354         glFinish();
00355 
00356         SwapBuffers(cur.hdc);
00357 }
00358 
00362 void BuildOrthoSlice(HWND hWnd)
00363 {
00366 
00367         if (voldat)
00368         {
00369                 if (hWnd == wnd_front)
00370                 {
00371                         frontslice = new float[volx * volz];
00372 
00373                         for (unsigned int x = 0; x < volx; x++)
00374                         {
00375                                 for (unsigned int z = 0; z < volz; z++)
00376                                 {
00377                                         frontslice[x*volz + z] = voldat[x + yslice*volx + z*volx*voly];
00378                                 }
00379                         }
00380 
00381                         wglMakeCurrent(GLfront.hdc, GLfront.hglrc);
00382 
00383                         float *fronttex = new float[512*512];
00384 
00385                         gluScaleImage(GL_LUMINANCE,
00386                                 volz, volx, GL_FLOAT, frontslice,
00387                                 512, 512, GL_FLOAT, fronttex);
00388 
00389                         glBindTexture(GL_TEXTURE_2D, 1);
00390 
00391                         glTexImage2D(GL_TEXTURE_2D,
00392                                 0,
00393                                 GL_LUMINANCE,
00394                                 512,
00395                                 512,
00396                                 0,
00397                                 GL_LUMINANCE,
00398                                 GL_FLOAT,
00399                                 fronttex);
00400 
00401                         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
00402                         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
00403 
00404                         delete [] fronttex;
00405                         delete [] frontslice;
00406                 }
00407                 if (hWnd == wnd_left)
00408                 {
00409                         leftslice = new float[voly * volz];
00410 
00411                         for (unsigned int y = 0; y < voly; y++)
00412                         {
00413                                 for (unsigned int z = 0; z < volz; z++)
00414                                 {
00415                                         leftslice[y*volz + z] = voldat[xslice + y*volx + z*voly*volx];
00416                                 }
00417                         }
00418 
00419                         wglMakeCurrent(GLleft.hdc, GLleft.hglrc);
00420 
00421                         float *lefttex = new float[512*512];
00422 
00423                         gluScaleImage(GL_LUMINANCE,
00424                                 volz, voly, GL_FLOAT, leftslice,
00425                                 512, 512, GL_FLOAT, lefttex);
00426 
00427                         glBindTexture(GL_TEXTURE_2D, 1);
00428 
00429                         glTexImage2D(GL_TEXTURE_2D,
00430                                 0,
00431                                 GL_LUMINANCE,
00432                                 512,
00433                                 512,
00434                                 0,
00435                                 GL_LUMINANCE,
00436                                 GL_FLOAT,
00437                                 lefttex);
00438 
00439                         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
00440                         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
00441 
00442                         delete [] leftslice;
00443                         delete [] lefttex;
00444                 }
00445                 if (hWnd == wnd_top)
00446                 {
00447                         topslice = new float[512 * 512];
00448 
00449                         for (unsigned int x = 0; x < volx; x++)
00450                         {
00451                                 for (unsigned int y = 0; y < voly; y++)
00452                                 {
00453                                         topslice[x*voly + y] = voldat[x + y*volx + zslice*voly*volx];
00454                                 }
00455                         }
00456 
00457                         wglMakeCurrent(GLtop.hdc, GLtop.hglrc);
00458 
00459                         float *toptex = new float[512*512];
00460 
00461                         gluScaleImage(GL_LUMINANCE,
00462                                 voly, volx, GL_FLOAT, topslice,
00463                                 512, 512, GL_FLOAT, toptex);
00464 
00465                         glBindTexture(GL_TEXTURE_2D, 1);
00466 
00467                         glTexImage2D(GL_TEXTURE_2D,
00468                                 0,
00469                                 GL_LUMINANCE,
00470                                 512,
00471                                 512,
00472                                 0,
00473                                 GL_LUMINANCE,
00474                                 GL_FLOAT,
00475                                 toptex);
00476 
00477                         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
00478                         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
00479 
00480                         delete [] toptex;
00481                         delete [] topslice;
00482                 }
00483         }
00484 }
00485 
00489 int GropeForHandle(HWND hWnd)
00490 {
00491         POINT cpos;
00492         int handle = 0;
00493 
00494         GetCursorPos(&cpos);
00495 
00496         // fill the four handle minima/maxima
00497         // with the correct values
00498         if (hWnd == wnd_front)
00499         {
00500                 ScreenToClient(wnd_front, &cpos);
00501 
00502                 wglMakeCurrent(GLfront.hdc, GLfront.hglrc);
00503 
00504                 double mvm[16];
00505                 glGetDoublev(GL_MODELVIEW_MATRIX, mvm);
00506                 double pm[16];
00507                 glGetDoublev(GL_PROJECTION_MATRIX, pm);
00508                 int view[4];
00509                 glGetIntegerv(GL_VIEWPORT, view);
00510 
00511                 double ox, oy, oz;
00512 
00513                 gluUnProject(cpos.x, cpos.y, 0.0, mvm, pm, view, &ox, &oy, &oz);
00514 
00515                 if (ox >= GLfront.hHandleMin &&
00516                         ox <= GLfront.hHandleMax)
00517                         handle |= 1;
00518 
00519                 if (oy >= GLfront.vHandleMin &&
00520                         oy <= GLfront.vHandleMax)
00521                         handle |= 2;
00522         }
00523         if (hWnd == wnd_left)
00524         {
00525                 ScreenToClient(wnd_left, &cpos);
00526 
00527                 wglMakeCurrent(GLleft.hdc, GLleft.hglrc);
00528 
00529                 double mvm[16];
00530                 glGetDoublev(GL_MODELVIEW_MATRIX, mvm);
00531                 double pm[16];
00532                 glGetDoublev(GL_PROJECTION_MATRIX, pm);
00533                 int view[4];
00534                 glGetIntegerv(GL_VIEWPORT, view);
00535 
00536                 double ox, oy, oz;
00537 
00538                 gluUnProject(cpos.x, cpos.y, 0.0, mvm, pm, view, &ox, &oy, &oz);
00539 
00540                 if (ox >= GLleft.hHandleMin &&
00541                         ox <= GLleft.hHandleMax)
00542                         handle |= 1;
00543 
00544                 if (oy >= GLleft.vHandleMin &&
00545                         oy <= GLleft.vHandleMax)
00546                         handle |= 2;
00547         }
00548         if (hWnd == wnd_top)
00549         {
00550                 ScreenToClient(wnd_top, &cpos);
00551 
00552                 wglMakeCurrent(GLtop.hdc, GLtop.hglrc);
00553 
00554                 double mvm[16];
00555                 glGetDoublev(GL_MODELVIEW_MATRIX, mvm);
00556                 double pm[16];
00557                 glGetDoublev(GL_PROJECTION_MATRIX, pm);
00558                 int view[4];
00559                 glGetIntegerv(GL_VIEWPORT, view);
00560 
00561                 double ox, oy, oz;
00562 
00563                 gluUnProject(cpos.x, cpos.y, 0.0, mvm, pm, view, &ox, &oy, &oz);
00564 
00565                 if (ox >= GLtop.hHandleMin &&
00566                         ox <= GLtop.hHandleMax)
00567                         handle |= 1;
00568 
00569                 if (oy >= GLtop.vHandleMin &&
00570                         oy <= GLtop.vHandleMax)
00571                         handle |= 2;
00572         }
00573 
00574         if (handle == 1)
00575                 SetCursor(LoadCursor(NULL, IDC_SIZEWE));
00576         else if (handle == 2)
00577                 SetCursor(LoadCursor(NULL, IDC_SIZENS));
00578         else if (handle == 3)
00579                 SetCursor(LoadCursor(NULL, IDC_SIZEALL));
00580 
00581         return handle;
00582 }
00583 
00587 void MoveHandle(HWND hWnd, int handle)
00588 {
00589         POINT cpos;
00590 
00591         GetCursorPos(&cpos);
00592 
00593         if (hWnd == wnd_front)
00594         {
00595                 ScreenToClient(wnd_front, &cpos);
00596 
00597                 wglMakeCurrent(GLfront.hdc, GLfront.hglrc);
00598 
00599                 double mvm[16];
00600                 glGetDoublev(GL_MODELVIEW_MATRIX, mvm);
00601                 double pm[16];
00602                 glGetDoublev(GL_PROJECTION_MATRIX, pm);
00603                 int view[4];
00604                 glGetIntegerv(GL_VIEWPORT, view);
00605 
00606                 double ox, oy, oz;
00607 
00608                 gluUnProject(cpos.x, cpos.y, 0.0, mvm, pm, view, &ox, &oy, &oz);
00609 
00610                 // front window
00611                 if (handle & 1)
00612                 {
00613                         // vertical bar
00614                         
00615                         if (ox < -GLfront.hQuadExt)
00616                                 xslice = volx - 1;
00617                         else if (ox > GLfront.hQuadExt)
00618                                 xslice = 0;
00619                         else
00620                                 xslice = (int)((1.0f - (ox + GLfront.hQuadExt) / (2.0f * GLfront.hQuadExt)) * volx);
00621 
00622                         BuildOrthoSlice(wnd_left);
00623                 }
00624 
00625                 if (handle & 2)
00626                 {
00627                         // horizontal bar
00628 
00629                         if (oy < -GLfront.vQuadExt)
00630                                 zslice = volz - 1;
00631                         else if (oy > GLfront.vQuadExt)
00632                                 zslice = 0;
00633                         else
00634                                 zslice = (int)((1.0f - (oy + GLfront.vQuadExt) / (2.0f * GLfront.vQuadExt)) * volz);
00635 
00636                         BuildOrthoSlice(wnd_top);
00637                 }
00638         }
00639         if (hWnd == wnd_left)
00640         {
00641                 ScreenToClient(wnd_left, &cpos);
00642 
00643                 wglMakeCurrent(GLleft.hdc, GLleft.hglrc);
00644 
00645                 double mvm[16];
00646                 glGetDoublev(GL_MODELVIEW_MATRIX, mvm);
00647                 double pm[16];
00648                 glGetDoublev(GL_PROJECTION_MATRIX, pm);
00649                 int view[4];
00650                 glGetIntegerv(GL_VIEWPORT, view);
00651 
00652                 double ox, oy, oz;
00653 
00654                 gluUnProject(cpos.x, cpos.y, 0.0, mvm, pm, view, &ox, &oy, &oz);
00655 
00656                 // left window
00657                 if (handle & 1)
00658                 {
00659                         // vertical bar
00660                         
00661                         if (ox < -GLleft.hQuadExt)
00662                                 yslice = voly - 1;
00663                         else if (ox > GLleft.hQuadExt)
00664                                 yslice = 0;
00665                         else
00666                                 yslice = (int)((1.0f - (ox + GLleft.hQuadExt) / (2.0f * GLleft.hQuadExt)) * voly);
00667 
00668                         BuildOrthoSlice(wnd_front);
00669                 }
00670 
00671                 if (handle & 2)
00672                 {
00673                         // horizontal bar
00674 
00675                         if (oy < -GLleft.vQuadExt)
00676                                 zslice = volz - 1;
00677                         else if (oy > GLleft.vQuadExt)
00678                                 zslice = 0;
00679                         else
00680                                 zslice = (int)((1.0f - (oy + GLleft.vQuadExt) / (2.0f * GLleft.vQuadExt)) * volz);
00681 
00682                         BuildOrthoSlice(wnd_top);
00683                 }
00684         }
00685         if (hWnd == wnd_top)
00686         {
00687                 ScreenToClient(wnd_top, &cpos);
00688 
00689                 wglMakeCurrent(GLtop.hdc, GLtop.hglrc);
00690 
00691                 double mvm[16];
00692                 glGetDoublev(GL_MODELVIEW_MATRIX, mvm);
00693                 double pm[16];
00694                 glGetDoublev(GL_PROJECTION_MATRIX, pm);
00695                 int view[4];
00696                 glGetIntegerv(GL_VIEWPORT, view);
00697 
00698                 double ox, oy, oz;
00699 
00700                 gluUnProject(cpos.x, cpos.y, 0.0, mvm, pm, view, &ox, &oy, &oz);
00701 
00702                 // left window
00703                 if (handle & 1)
00704                 {
00705                         // vertical bar
00706                         
00707                         if (ox < -GLtop.hQuadExt)
00708                                 xslice = volx - 1;
00709                         else if (ox > GLtop.hQuadExt)
00710                                 xslice = 0;
00711                         else
00712                                 xslice = (int)((1.0f - (ox + GLtop.hQuadExt) / (2.0f * GLtop.hQuadExt)) * volx);
00713 
00714                         BuildOrthoSlice(wnd_left);
00715                 }
00716 
00717                 if (handle & 2)
00718                 {
00719                         // horizontal bar
00720 
00721                         if (oy < -GLtop.vQuadExt)
00722                                 yslice = volz - 1;
00723                         else if (oy > GLtop.vQuadExt)
00724                                 yslice = 0;
00725                         else
00726                                 yslice = (int)((1.0f - (oy + GLtop.vQuadExt) / (2.0f * GLtop.vQuadExt)) * voly);
00727 
00728                         BuildOrthoSlice(wnd_front);
00729                 }
00730         }
00731         DrawOrtho(wnd_front);
00732         DrawOrtho(wnd_left);
00733         DrawOrtho(wnd_top);
00734 }
00735 
00740 void ShiftSlice(HWND hWnd, int amt)
00741 {
00742         if (hWnd == wnd_front)
00743         {
00744                 yslice += amt;
00745 
00746                 if (yslice < 0) yslice = 0;
00747                 if ((unsigned int)yslice >= voly)       yslice = voly - 1;
00748 
00749                 BuildOrthoSlice(wnd_front);
00750         }
00751 
00752         if (hWnd == wnd_left)
00753         {
00754                 xslice += amt;
00755 
00756                 if (xslice < 0) xslice = 0;
00757                 if ((unsigned int)xslice >= volx)       xslice = volx - 1;
00758 
00759                 BuildOrthoSlice(wnd_left);
00760         }
00761 
00762         if (hWnd == wnd_top)
00763         {
00764                 zslice += amt;
00765                 
00766                 if (zslice < 0) zslice = 0;
00767                 if ((unsigned int)zslice >= volz)       zslice = volz - 1;
00768 
00769                 BuildOrthoSlice(wnd_top);
00770         }
00771 
00772         DrawOrtho(wnd_front);
00773         DrawOrtho(wnd_left);
00774         DrawOrtho(wnd_top);
00775 }
00776 
00780 LRESULT CALLBACK OrthoProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00781 {
00782         PAINTSTRUCT ps;
00783         HDC hdc;
00784         int zDelta, fwKeys;
00785         static int handle;
00786         static POINT spos;
00787 
00789         switch (message)
00790         {
00791         case WM_LBUTTONDOWN:
00793                 handle = GropeForHandle(hWnd);
00794                 SetCapture(hWnd);
00795                 GetCursorPos(&spos);
00796                 break;
00797         case WM_LBUTTONUP:
00798                 ReleaseCapture();
00799         case WM_MOUSEMOVE:
00800                 if (GetCapture() == hWnd)
00801                 {
00802                         if (handle)
00803                         {
00805                                 MoveHandle(hWnd, handle);
00806 
00807                         }
00808                         else
00809                         {
00812                                 POINT mpos;
00813 
00814                                 GetCursorPos(&mpos);
00815 
00816                                 int diff = (spos.x - mpos.x) + (spos.y - mpos.y);
00817 
00818                                 ShiftSlice(hWnd, diff);
00819 
00820                                 spos = mpos;
00821                         }
00822                 }
00823                 else
00824                 {
00826                         GropeForHandle(hWnd);
00827                 }
00828                 break;
00829         case WM_MOUSEWHEEL:
00831                 if (!voldat)
00832                         break;
00833 
00834                 zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
00835                 fwKeys = GET_KEYSTATE_WPARAM(wParam);
00836 
00837                 if (fwKeys & MK_SHIFT)
00838                         fwKeys = 10;
00839                 else 
00840                         fwKeys = 1;
00841 
00842                 fwKeys *= (zDelta > 0?1:-1);
00843 
00844                 ShiftSlice(hWnd, fwKeys);
00845 
00846                 break;
00847         case WM_PAINT:
00848                 hdc = BeginPaint(hWnd, &ps);
00849                 if (hWnd == wnd_front)
00850                         DrawOrtho(hWnd);
00851                 if (hWnd == wnd_left)
00852                         DrawOrtho(hWnd);
00853                 if (hWnd == wnd_top)
00854                         DrawOrtho(hWnd);
00855                 EndPaint(hWnd, &ps);
00856                 break;
00857         case WM_SHOWWINDOW:
00858                 if (hWnd == wnd_front)
00859                         InitOrtho(wnd_front, GLfront);
00860                 if (hWnd == wnd_left)
00861                         InitOrtho(wnd_left, GLleft);
00862                 if (hWnd == wnd_top)
00863                         InitOrtho(wnd_top, GLtop);
00864                 break;
00865         case WM_DESTROY:
00866                 if (hWnd == wnd_front)
00867                         DeInitOrtho(wnd_front, GLfront);
00868                 if (hWnd == wnd_left)
00869                         DeInitOrtho(wnd_left, GLleft);
00870                 if (hWnd == wnd_top)
00871                         DeInitOrtho(wnd_top, GLtop);
00872                 PostQuitMessage(0);
00873                 break;
00874         default:
00875                 return DefWindowProc(hWnd, message, wParam, lParam);
00876         }
00877         return 0;
00878 }

Generated on Wed Dec 5 12:07:30 2007 for Volumizer by  doxygen 1.5.4