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

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 #include "Volumizer.h"
00008 
00009 #define MAX_LOADSTRING 100
00010 
00011 // Global Variables:
00012 HINSTANCE hInst;                                                                // current instance
00013 TCHAR szTitle[MAX_LOADSTRING];                                  // The title bar text
00014 TCHAR szWindowClass[MAX_LOADSTRING];                    // the main window class name
00015 
00016 HWND wnd_main, wnd_splitter, wnd_3d, wnd_front, wnd_left, wnd_top, wnd_histogram, wnd_tool;
00017 
00018 float brightness, contrast, gamma;                              
00019 
00020 // Forward declarations of functions included in this code module:
00021 ATOM                            RegisterMainClass(HINSTANCE hInstance);
00022 BOOL                            InitInstance(HINSTANCE, int);
00023 LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);
00024 INT_PTR CALLBACK        About(HWND, UINT, WPARAM, LPARAM);
00025 
00029 int APIENTRY _tWinMain(HINSTANCE hInstance,
00030                      HINSTANCE hPrevInstance,
00031                      LPTSTR    lpCmdLine,
00032                      int       nCmdShow)
00033 {
00034         UNREFERENCED_PARAMETER(hPrevInstance);
00035         UNREFERENCED_PARAMETER(lpCmdLine);
00036 
00037         MSG msg;
00038         HACCEL hAccelTable;
00039 
00040         // Initialize global strings
00041         LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
00042         LoadString(hInstance, IDC_VOLUMIZER, szWindowClass, MAX_LOADSTRING);
00043 
00045         RegisterMainClass(hInstance);
00046         RegisterSplitterClass(hInstance);
00047         RegisterRayClass(hInstance);
00048         RegisterOrthoClass(hInstance);
00049         RegisterHistogramClass(hInstance);
00050 
00051         RegisterSwatchClass(hInstance);
00052 
00053         wnd_main = wnd_splitter = wnd_3d = wnd_top = wnd_front = wnd_left = NULL;
00054         brightness = 0.5f;
00055         contrast = 0.5f;
00056         gamma = 1.0f;
00057 
00058         InitOptions();
00059         CreateDefaultTransferFunction();
00060 
00061         // Perform application initialization:
00062         if (!InitInstance (hInstance, nCmdShow))
00063         {
00064                 return FALSE;
00065         }
00066 
00067         hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_VOLUMIZER));
00068 
00069         // Main message loop:
00070         while (GetMessage(&msg, NULL, 0, 0))
00071         {
00072                 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
00073                 {
00074                         TranslateMessage(&msg);
00075                         DispatchMessage(&msg);
00076                 }
00077         }
00078 
00079         return (int) msg.wParam;
00080 }
00081 
00082 
00083 
00084 ATOM RegisterMainClass(HINSTANCE hInstance)
00085 {
00086         WNDCLASSEX wcex;
00087 
00088         wcex.cbSize = sizeof(WNDCLASSEX);
00089 
00090         wcex.style                      = CS_HREDRAW | CS_VREDRAW;
00091         wcex.lpfnWndProc        = WndProc;
00092         wcex.cbClsExtra         = 0;
00093         wcex.cbWndExtra         = 0;
00094         wcex.hInstance          = hInstance;
00095         wcex.hIcon                      = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VOLUMIZER));
00096         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
00097         wcex.hbrBackground      = NULL;
00098         wcex.lpszMenuName       = MAKEINTRESOURCE(IDC_VOLUMIZER);
00099         wcex.lpszClassName      = szWindowClass;
00100         wcex.hIconSm            = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
00101 
00102         return RegisterClassEx(&wcex);
00103 }
00104 
00105 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
00106 {
00107    hInst = hInstance; // Store instance handle in our global variable
00108 
00109    wnd_main = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
00110       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
00111 
00112    if (!wnd_main)
00113    {
00114       return FALSE;
00115    }
00116 
00117    ShowWindow(wnd_main, nCmdShow);
00118    UpdateWindow(wnd_main);
00119 
00120    return TRUE;
00121 }
00122 
00126 void GetOpenFile()
00127 {
00128         OPENFILENAME ofn;
00129         ofn.lStructSize = sizeof(OPENFILENAME);
00130         ofn.hwndOwner = wnd_main;
00131         ofn.hInstance = NULL;
00132         ofn.lpstrFilter = L"Data File (*.dat)\0*.DAT\0All Files\0*.*\0\0";
00133         ofn.lpstrCustomFilter = NULL;
00134         ofn.nMaxCustFilter = 0;
00135         ofn.nFilterIndex = 1;
00136         ofn.lpstrFile = new wchar_t[500]; ofn.lpstrFile[0] = '\0';
00137         ofn.nMaxFile = 500;
00138         ofn.lpstrFileTitle = NULL;
00139         ofn.nMaxFileTitle = 0;
00140         ofn.lpstrInitialDir = NULL;
00141         ofn.lpstrTitle = NULL;
00142         ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST; 
00143         ofn.lpstrDefExt = NULL;
00144         ofn.pvReserved = NULL;
00145         ofn.dwReserved = 0;
00146         ofn.FlagsEx = 0;
00147 
00148         if (GetOpenFileName(&ofn))
00149         {
00150                 LoadDataFile(ofn.lpstrFile);
00151         }
00152 }
00153 
00157 BOOL CALLBACK ToolBarProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
00158 {
00159         char ntext[20];
00160 
00161         switch (uMsg)
00162         {
00163         case WM_INITDIALOG:
00164                 SendMessage(GetDlgItem(hwndDlg, IDC_BRIGHT), WM_SETTEXT, 0, (LPARAM)L"0.50");
00165                 SendMessage(GetDlgItem(hwndDlg, IDC_BRIGHT_SLIDE), TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0,100));
00166                 SendMessage(GetDlgItem(hwndDlg, IDC_BRIGHT_SLIDE), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)50);
00167 
00168                 SendMessage(GetDlgItem(hwndDlg, IDC_CONTRAST), WM_SETTEXT, 0, (LPARAM)L"0.50");
00169                 SendMessage(GetDlgItem(hwndDlg, IDC_CONTRAST_SLIDE), TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0,100));
00170                 SendMessage(GetDlgItem(hwndDlg, IDC_CONTRAST_SLIDE), TBM_SETPOS, (WPARAM)TRUE, 50);
00171 
00172                 SendMessage(GetDlgItem(hwndDlg, IDC_GAMMA), WM_SETTEXT, 0, (LPARAM)L"1.00");
00173                 SendMessage(GetDlgItem(hwndDlg, IDC_GAMMA_SLIDE), TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0,40));
00174                 SendMessage(GetDlgItem(hwndDlg, IDC_GAMMA_SLIDE), TBM_SETPOS, (WPARAM)TRUE, 10);
00175 
00176                 return TRUE;
00177         case WM_HSCROLL:
00178                 if (LOWORD(wParam) == SB_ENDSCROLL)
00179                         return 0;
00180 
00181                 if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_BRIGHT_SLIDE))
00182                 {
00183                         brightness = (float)(SendMessage((HWND)lParam, TBM_GETPOS, 0, 0)) / 100.0f;
00184                         swprintf((LPWSTR)ntext, L"%1.2f", brightness);
00185                         SendMessage(GetDlgItem(hwndDlg, IDC_BRIGHT), WM_SETTEXT, 0, (LPARAM)ntext);
00186 
00187                         brightness = clamp(brightness, 0.0001f, 0.9999f);
00188 
00189                         if (LOWORD(wParam) != SB_THUMBTRACK)
00190                         {
00191                                 ShovelData();
00192                         }
00193                 }
00194 
00195                 if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_CONTRAST_SLIDE))
00196                 {
00197                         contrast = (float)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0) / 100.0f;
00198                         swprintf((LPWSTR)ntext, L"%1.2f", contrast);
00199                         SendMessage(GetDlgItem(hwndDlg, IDC_CONTRAST), WM_SETTEXT, 0, (LPARAM)ntext);
00200 
00201                         contrast = clamp(contrast, 0.0001f, 0.9999f);
00202 
00203                         if (LOWORD(wParam) != SB_THUMBTRACK)
00204                         {
00205                                 ShovelData();
00206                         }
00207                 }
00208 
00209                 if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_GAMMA_SLIDE))
00210                 {
00211                         gamma = (float)SendMessage((HWND)lParam, TBM_GETPOS, 0, 0) / 10.0f;
00212                         swprintf((LPWSTR)ntext, L"%1.2f", gamma);
00213                         SendMessage(GetDlgItem(hwndDlg, IDC_GAMMA), WM_SETTEXT, 0, (LPARAM)ntext);
00214 
00215                         if (LOWORD(wParam) != SB_THUMBTRACK)
00216                         {
00217                                 ShovelData();
00218                         }
00219                 }
00220                 return 0;
00221         case WM_COMMAND:
00222                 break;
00223         }
00224         return FALSE;
00225 }
00226 
00230 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00231 {
00232         int wmId, wmEvent;
00233         PAINTSTRUCT ps;
00234         HDC hdc;
00235         RECT crect;
00236 
00237         switch (message)
00238         {
00239         case WM_MOUSEWHEEL:
00240                 // catch mousewheel movement and forward to child windows
00241                 POINT cpos;
00242 
00243                 GetCursorPos(&cpos);
00244 
00245                 // check each window if the cursor is in it
00246                 GetWindowRect(wnd_front, &crect);
00247                 if (cpos.x > crect.left && cpos.x < crect.right &&
00248                         cpos.y > crect.top && cpos.y < crect.bottom)
00249                 {
00250                         PostMessage(wnd_front, WM_MOUSEWHEEL, wParam, lParam);
00251                 }
00252 
00253                 GetWindowRect(wnd_left, &crect);
00254                 if (cpos.x > crect.left && cpos.x < crect.right &&
00255                         cpos.y > crect.top && cpos.y < crect.bottom)
00256                 {
00257                         PostMessage(wnd_left, WM_MOUSEWHEEL, wParam, lParam);
00258                 }
00259 
00260                 GetWindowRect(wnd_top, &crect);
00261                 if (cpos.x > crect.left && cpos.x < crect.right &&
00262                         cpos.y > crect.top && cpos.y < crect.bottom)
00263                 {
00264                         PostMessage(wnd_top, WM_MOUSEWHEEL, wParam, lParam);
00265                 }
00266 
00267                 break;
00268         case WM_COMMAND:
00269                 wmId    = LOWORD(wParam);
00270                 wmEvent = HIWORD(wParam);
00271                 // Parse the menu selections:
00272                 switch (wmId)
00273                 {
00274                 case IDM_ABOUT:
00275                         DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
00276                         break;
00277                 case IDM_EXIT:
00278                         DestroyWindow(hWnd);
00279                         break;
00280                 case ID_FILE_OPEN:
00281                         GetOpenFile();
00282                         break;
00283                 case ID_FILE_OPTIONS:
00284                         DialogBox(hInst, MAKEINTRESOURCE(IDD_OPTIONS), hWnd, OptionsProc);
00285                         break;
00286                 default:
00287                         return DefWindowProc(hWnd, message, wParam, lParam);
00288                 }
00289                 break;
00290         case WM_PAINT:
00291                 hdc = BeginPaint(hWnd, &ps);
00292                 EndPaint(hWnd, &ps);
00293                 break;
00294         case WM_SIZE:
00295                 // post the size message to our splitter, it takes care of
00296                 // resizing the child windows
00297                 if (wnd_splitter)
00298                 {
00299                         PostMessage(wnd_splitter, WM_SIZE, 0, 0);
00300                 }
00301                 // resize the toolbar
00302                 GetClientRect(hWnd, &crect);
00303 
00304                 SetWindowPos(wnd_tool, NULL, 0, 0, crect.right, TOOL_HEIGHT, SWP_NOMOVE);
00305                 break;
00306         case WM_CREATE:
00307                 // create the toolbar
00308                 wnd_tool = CreateDialog(hInst, MAKEINTRESOURCE(IDD_TOOL), hWnd, ToolBarProc);
00309                 // create the main splitter
00310                 wnd_splitter = CreateWindowEx(WS_EX_WINDOWEDGE,
00311                         L"SplitterWnd",
00312                         L"",
00313                         WS_CHILD,
00314                         300,
00315                         TOOL_HEIGHT,
00316                         SPLITTER_WIDTH,
00317                         500,
00318                         hWnd,
00319                         NULL, NULL, NULL);
00320                 // create the right ray casting window
00321                 wnd_3d = CreateWindowEx(WS_EX_CLIENTEDGE,
00322                         L"RayWnd",
00323                         L"",
00324                         WS_CHILD,
00325                         300 + SPLITTER_WIDTH, TOOL_HEIGHT, 500, 500, hWnd,
00326                         NULL, NULL, NULL);
00327 
00328                 //create the three orthographic views
00329                 wnd_front = CreateWindowEx(WS_EX_CLIENTEDGE,
00330                         L"OrthoWnd",
00331                         L"",
00332                         WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
00333                         0, TOOL_HEIGHT, 300, 200, hWnd,
00334                         NULL, NULL, NULL);
00335                 wnd_left = CreateWindowEx(WS_EX_CLIENTEDGE,
00336                         L"OrthoWnd",
00337                         L"",
00338                         WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
00339                         0, 300, 200, 200, hWnd,
00340                         NULL, NULL, NULL);
00341                 wnd_top = CreateWindowEx(WS_EX_CLIENTEDGE,
00342                         L"OrthoWnd",
00343                         L"",
00344                         WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
00345                         0, 300, 200, 200, hWnd,
00346                         NULL, NULL, NULL);
00347                 wnd_histogram = CreateWindowEx(WS_EX_CLIENTEDGE,
00348                         L"HistogramWnd",
00349                         L"",
00350                         WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
00351                         0, 300, 200, 200, hWnd,
00352                         NULL, NULL, NULL);
00353 
00354                 ShowWindow(wnd_splitter, SW_SHOW);
00355                 ShowWindow(wnd_3d, SW_SHOW);
00356 
00357                 ShowWindow(wnd_front, SW_SHOW);
00358                 ShowWindow(wnd_left, SW_SHOW);
00359                 ShowWindow(wnd_top, SW_SHOW);
00360 
00361                 ShowWindow(wnd_histogram, SW_SHOW);
00362 
00363                 break;
00364         case WM_DESTROY:
00365                 PostQuitMessage(0);
00366                 break;
00367         default:
00368                 return DefWindowProc(hWnd, message, wParam, lParam);
00369         }
00370         return 0;
00371 }
00372 
00376 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
00377 {
00378         UNREFERENCED_PARAMETER(lParam);
00379         switch (message)
00380         {
00381         case WM_INITDIALOG:
00382                 return (INT_PTR)TRUE;
00383 
00384         case WM_COMMAND:
00385                 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
00386                 {
00387                         EndDialog(hDlg, LOWORD(wParam));
00388                         return (INT_PTR)TRUE;
00389                 }
00390                 break;
00391         }
00392         return (INT_PTR)FALSE;
00393 }

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