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

3dvis.cpp

Go to the documentation of this file.
00001 // 3dvis.cpp : Defines the class behaviors for the application.
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "3dvis.h"
00006 
00007 #include "MainFrm.h"
00008 #include "3dvisDoc.h"
00009 #include "3dvisView.h"
00010 
00011 #include "transfuncfile.h"
00012 #include "FileInfoDialog.h"
00013 #include "VolumeDialog.h"
00014 #include "IniFile.h"
00015 
00016 
00017 #ifdef _DEBUG
00018 #define new DEBUG_NEW
00019 #undef THIS_FILE
00020 static char THIS_FILE[] = __FILE__;
00021 #endif
00022 
00024 // CMy3dvisApp
00025 
00026 BEGIN_MESSAGE_MAP(CMy3dvisApp, CWinApp)
00027         //{{AFX_MSG_MAP(CMy3dvisApp)
00028         ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
00029         ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
00030         ON_COMMAND(ID_F_CLOSE, OnFClose)
00031         ON_COMMAND(ID_RENDER_VOLUME, OnRenderVolume)
00032         ON_COMMAND(ID_OPTIONS_TRANSFER, OnOptionsTransfer)
00033         ON_COMMAND(ID_PRESET_0, OnPreset0)      
00034         ON_COMMAND(ID_PRESET_1, OnPreset1)      
00035         ON_COMMAND(ID_PRESET_2, OnPreset2)      
00036         ON_COMMAND(ID_PRESET_3, OnPreset3)      
00037         ON_COMMAND(ID_PRESET_4, OnPreset4)      
00038         ON_COMMAND(ID_PRESET_5, OnPreset5)      
00039         ON_COMMAND(ID_PRESET_6, OnPreset6)      
00040         ON_COMMAND(ID_PRESET_7, OnPreset7)      
00041         ON_COMMAND(ID_PRESET_8, OnPreset8)      
00042         ON_COMMAND(ID_PRESET_9, OnPreset9)      
00043         ON_COMMAND(ID_FILE_INFO, OnFileInfo)
00044         ON_COMMAND(ID_MENU_VOLUME, OnMenuVolume)
00045         ON_COMMAND(ID_FILE_INI, OnFileIni)
00046         //}}AFX_MSG_MAP
00047         // Standard file based document commands
00048         ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
00049 END_MESSAGE_MAP()
00050 
00051 
00052 // CMy3dvisApp construction
00053 
00054 CMy3dvisApp::CMy3dvisApp()
00055 {
00056         // TODO: add construction code here,
00057         // Place all significant initialization in InitInstance
00058         m_bRenderVolume = false;
00059         m_bClicked = false;
00060         transferFunction = NULL;
00061 
00062         m_dFileThres = 40;
00063         m_dPacketSize = 10;
00064 
00065         m_dOperation = 0;
00066 
00067         char path[_MAX_PATH + 1];
00068 
00069         GetModuleFileName(m_hInstance, path, sizeof(path));
00070 
00071         string temp = path;
00072         int pos = temp.find_last_of('\\', temp.size());
00073         programPath = temp.substr(0, pos + 1);
00074 }
00075 
00077 // The one and only CMy3dvisApp object
00078 
00079 CMy3dvisApp theApp;
00080 
00082 // CMy3dvisApp initialization
00083 
00084 BOOL CMy3dvisApp::InitInstance()
00085 {
00086 
00087         CTransfuncFile funcFile;
00088         presetTransformFunctions = funcFile.LoadPresets(m_dNumPresets);
00089 
00090 
00091         // Standard initialization
00092         // If you are not using these features and wish to reduce the size
00093         //  of your final executable, you should remove from the following
00094         //  the specific initialization routines you do not need.
00095 
00096 #ifdef _AFXDLL
00097         Enable3dControls();                     // Call this when using MFC in a shared DLL
00098 #else
00099         Enable3dControlsStatic();       // Call this when linking to MFC statically
00100 #endif
00101 
00102         // Change the registry key under which our settings are stored.
00103         // TODO: You should modify this string to be something appropriate
00104         // such as the name of your company or organization.
00105         SetRegistryKey(_T("Local AppWizard-Generated Applications"));
00106 
00107         LoadStdProfileSettings();  // Load standard INI file options (including MRU)
00108 
00109         // Register the application's document templates.  Document templates
00110         //  serve as the connection between documents, frame windows and views.
00111 
00112         CSingleDocTemplate* pDocTemplate;
00113         pDocTemplate = new CSingleDocTemplate(
00114                 IDR_MAINFRAME,
00115                 RUNTIME_CLASS(CMy3dvisDoc),
00116                 RUNTIME_CLASS(CMainFrame),       // main SDI frame window
00117                 RUNTIME_CLASS(CMy3dvisView));
00118         AddDocTemplate(pDocTemplate);
00119 
00120         // Parse command line for standard shell commands, DDE, file open
00121         CCommandLineInfo cmdInfo;
00122         ParseCommandLine(cmdInfo);
00123 
00124         // Dispatch commands specified on the command line
00125         if (!ProcessShellCommand(cmdInfo))
00126                 return FALSE;
00127 
00128         
00129         m_ProcessIniFile();
00130 
00131 
00132         // The one and only window has been initialized, so show and update it.
00133         m_pMainWnd->ShowWindow(SW_SHOW);
00134         m_pMainWnd->UpdateWindow();
00135         return TRUE;
00136 }
00137 
00138 
00140 // CAboutDlg dialog used for App About
00141 
00142 class CAboutDlg : public CDialog
00143 {
00144 public:
00145         CAboutDlg();
00146 
00147 // Dialog Data
00148         //{{AFX_DATA(CAboutDlg)
00149         enum { IDD = IDD_ABOUTBOX };
00150         //}}AFX_DATA
00151 
00152         // ClassWizard generated virtual function overrides
00153         //{{AFX_VIRTUAL(CAboutDlg)
00154         protected:
00155         virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
00156         //}}AFX_VIRTUAL
00157 
00158 // Implementation
00159 protected:
00160         //{{AFX_MSG(CAboutDlg)
00161                 // No message handlers
00162         //}}AFX_MSG
00163         DECLARE_MESSAGE_MAP()
00164 };
00165 
00166 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
00167 {
00168         //{{AFX_DATA_INIT(CAboutDlg)
00169         //}}AFX_DATA_INIT
00170 }
00171 
00172 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
00173 {
00174         CDialog::DoDataExchange(pDX);
00175         //{{AFX_DATA_MAP(CAboutDlg)
00176         //}}AFX_DATA_MAP
00177 }
00178 
00179 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
00180         //{{AFX_MSG_MAP(CAboutDlg)
00181                 // No message handlers
00182         //}}AFX_MSG_MAP
00183 END_MESSAGE_MAP()
00184 
00185 // App command to run the dialog
00186 void CMy3dvisApp::OnAppAbout()
00187 {
00188         CAboutDlg aboutDlg;
00189         aboutDlg.DoModal();
00190 }
00191 
00193 // CMy3dvisApp message handlers
00194 
00195 
00196 int CMy3dvisApp::ExitInstance() 
00197 {
00198         // TODO: Add your specialized code here and/or call the base class
00199         if (data3D != NULL) {
00200                 delete data3D;
00201                 data3D = NULL;
00202         }
00203 
00204         if (slice != NULL) {
00205                 delete slice;
00206                 slice = NULL;
00207         }
00208 
00209         if (raycaster != NULL) {
00210                 delete raycaster;
00211                 raycaster = NULL;
00212         }
00213 
00214         if (transferFunction != NULL) {
00215                 delete transferFunction;
00216                 transferFunction = NULL;
00217         }
00218         
00219         return CWinApp::ExitInstance();
00220 }
00221 
00222 void CMy3dvisApp::OnFileOpen() 
00223 {
00224         // TODO: Add your command handler code here
00225         CFileDialog fd(TRUE, NULL, NULL, OFN_FILEMUSTEXIST,
00226                                         "Dat Files (*.dat)|*.dat| AllFiles (*.*)|* *|", m_pMainWnd);
00227         
00228 
00229         int returnVal = fd.DoModal();
00230 
00231         if(returnVal == IDOK) {
00232 
00233                 m_bOpen = true;
00234                 this->OnFClose();
00235                 m_bOpen = false;
00236                         
00237                 if (data3D != NULL) {
00238                         if (MessageBox(m_pMainWnd->m_hWnd, "Already data loaded! Unload currend data?",
00239                                                                                                         "load new data", MB_YESNO) == IDYES) {
00240                                 delete data3D;
00241                                 data3D = NULL;
00242                         }
00243                         else
00244                                 return;
00245                 }
00246 
00247 
00248                 CString filename = fd.GetFileName();
00249                 char *fn = new char[filename.GetLength() + 1];
00250                 for (int i = 0; i < filename.GetLength(); i++) {
00251                         fn[i] = filename.GetAt(i);
00252                 }
00253                 fn[i] = '\0';
00254 
00255                 
00256                 data3D = new Data();
00257                 m_ProcessIniFile();
00258 
00259 
00260                 SetWindowText(m_pMainWnd->m_hWnd, "3D Visualisation - loading visualisation data, please wait,...");
00261 
00262 
00263 //              AfxGetMainWnd()->SendMessage(MYWM_SHOWABORT, (WPARAM) 0, (LPARAM) 0);
00264 
00265                 data3D->LoadData(fn);
00266                 delete[] fn;
00267 
00268 //              AfxGetMainWnd()->SendMessage(MYWM_HIDEABORT, (WPARAM) 0, (LPARAM) 0);
00269                 
00270                 m_bRenderVolume = false;
00271 
00272 
00273                 if (slice == NULL)
00274                         slice = new Slice();
00275 
00276                 slice->SetPixels(data3D, 0);
00277                 int num = slice->GetSliceNumber(data3D);
00278 
00279 
00280                 
00281                 if (!m_bRenderVolume)
00282                         AfxGetMainWnd()->SendMessage(MYWM_SHOW_BAR, (WPARAM) 0, (LPARAM) 0);
00283                 else
00284                         AfxGetMainWnd()->SendMessage(MYWM_SHOW_BAR, (WPARAM) 1, (LPARAM) 0);
00285                 
00286 
00287                 SetWindowText(m_pMainWnd->m_hWnd, CString("3D Visualisation - loaded \"" + filename + "\""));
00288    }
00289 }
00290 
00291 void CMy3dvisApp::OnFClose() 
00292 {
00293         // TODO: Add your command handler code here
00294 
00295         if (data3D && !m_bOpen && MessageBox(m_pMainWnd->m_hWnd, "do you really want to close the\ncurrent data-set?",
00296                                         "close data-set", MB_YESNO) == IDNO)
00297                 return;
00298 
00299         
00300         AfxGetMainWnd()->SendMessage(MYWM_HIDE_BARS);
00301 
00302         
00303         if (slice != NULL) {
00304                 delete slice;
00305                 slice = NULL;
00306         }
00307 
00308         if (data3D != NULL) {
00309                 delete data3D;
00310                 data3D = NULL;
00311         }
00312 
00313         m_pMainWnd->SetWindowText("3D Visualisation");
00314 }
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322 void CMy3dvisApp::OnOptionsTransfer() 
00323 {
00324         // TODO: Add your command handler code here
00325         if (data3D == NULL)
00326                 return;
00327 
00328         int response = m_Transferdiag.DoModal();
00329 
00330 
00331         if (response == IDOK) {
00332                 int num = m_Transferdiag.m_vTransferIndices.size() - 1;
00333 
00334                 if (num <= 0)
00335                         return;
00336 
00337                 m_BuildTransferFunction(m_Transferdiag.m_vTransferIndices, num);
00338         }
00339 
00340 
00341         m_pMainWnd->Invalidate();
00342         m_pMainWnd->UpdateWindow();
00343 }
00344 
00345 
00346 void CMy3dvisApp::OnPreset0() {
00347         m_BuildTransferFunction(presetTransformFunctions[0],
00348                                                         presetTransformFunctions[0].size() - 1);
00349 }
00350 
00351 void CMy3dvisApp::OnPreset1() {
00352         m_BuildTransferFunction(presetTransformFunctions[1],
00353                                                         presetTransformFunctions[1].size() - 1);
00354 }
00355 
00356 void CMy3dvisApp::OnPreset2() {
00357         m_BuildTransferFunction(presetTransformFunctions[2],
00358                                                         presetTransformFunctions[2].size() - 1);
00359 }
00360 
00361 void CMy3dvisApp::OnPreset3() {
00362         m_BuildTransferFunction(presetTransformFunctions[3],
00363                                                         presetTransformFunctions[3].size() - 1);
00364 }
00365 
00366 void CMy3dvisApp::OnPreset4() {
00367         m_BuildTransferFunction(presetTransformFunctions[4],
00368                                                         presetTransformFunctions[4].size() - 1);
00369 }
00370 
00371 void CMy3dvisApp::OnPreset5() {
00372         m_BuildTransferFunction(presetTransformFunctions[5],
00373                                                         presetTransformFunctions[5].size() - 1);
00374 }
00375 
00376 void CMy3dvisApp::OnPreset6() {
00377         m_BuildTransferFunction(presetTransformFunctions[6],
00378                                                         presetTransformFunctions[6].size() - 1);
00379 }
00380 
00381 void CMy3dvisApp::OnPreset7() {
00382         m_BuildTransferFunction(presetTransformFunctions[7],
00383                                                         presetTransformFunctions[7].size() - 1);
00384 }
00385 
00386 void CMy3dvisApp::OnPreset8() {
00387         m_BuildTransferFunction(presetTransformFunctions[8],
00388                                                         presetTransformFunctions[8].size() - 1);
00389 }
00390 
00391 void CMy3dvisApp::OnPreset9() {
00392         m_BuildTransferFunction(presetTransformFunctions[9],
00393                                                         presetTransformFunctions[9].size() - 1);
00394 }
00395 
00396 
00397 void CMy3dvisApp::m_BuildTransferFunction(INDEXLIST &function, int num) {
00398         if (!data3D)
00399                 return;
00400         
00401         if (!transferFunction)
00402                 transferFunction = new Transfunc();
00403 
00404         rgb col;
00405 
00406         for (int i = 1; i <= num; i++) {
00407                 COLORREF c = function[i].m_scColor;
00408                 col.r = (unsigned char)(function[i].m_scColor & 0x000000FF);
00409                 col.g = (unsigned char)((function[i].m_scColor & 0x0000FF00) >> 8);
00410                 col.b = (unsigned char)((function[i].m_scColor & 0x00FF0000) >> 16);
00411 
00412                         float test = (float)function[i].m_ucAlpha / 255;
00413                 for (int j = function[i].m_sdBegin;     j < function[i].m_sdEnd; j++) {
00414                         transferFunction->SetDensityColor(j, col);
00415                         transferFunction->SetOpacity(j, ((float)function[i].m_ucAlpha / 255));
00416                 }
00417         }
00418 
00419         if (slice == NULL)
00420                 slice = new Slice();
00421 
00422         slice->SetTransferfunction(transferFunction);
00423         slice->SetPixels(data3D, -1);
00424 }
00425 
00426 
00427 void CMy3dvisApp::OnFileInfo() 
00428 {
00429         // TODO: Add your command handler code here
00430         if (!data3D)
00431                 return;
00432         
00433         CFileInfoDialog fid;
00434         fid.SetInfo(data3D->filename, data3D->GetXDim(), data3D->GetYDim(), data3D->GetZDim());
00435         fid.DoModal();
00436 }
00437 
00438 void CMy3dvisApp::OnMenuVolume() 
00439 {
00440         // TODO: Add your command handler code here
00441         AfxGetMainWnd()->SendMessage(MYWM_CHANGE_RENDERING, (WPARAM) 1, 1);
00442 }
00443 
00444 
00445 
00446 
00447 void CMy3dvisApp::m_ProcessIniFile(bool store) {
00448         FILE *file;
00449 
00450         string filename = programPath + "config.ini";
00451 
00452         if (!store && (file = fopen(filename.c_str(), "r")) != NULL) {
00453                 if (!data3D)
00454                         return;
00455                 
00456                 fscanf(file, "%d\n%d", &m_dFileThres, &m_dPacketSize);
00457                 data3D->SetFileThreshold(m_dFileThres);
00458                 data3D->SetDataPackets(m_dPacketSize);
00459 
00460                 fclose(file);
00461 
00462                 return;
00463         }
00464 
00465 
00466         if ((file = fopen(filename.c_str(), "w")) != NULL) {
00467                 m_dFileThres = 40;
00468                 m_dPacketSize = 10;
00469 
00470                 fprintf(file, "%d\n%d", m_dFileThres, m_dPacketSize);
00471                 fclose(file);
00472         }
00473 
00474 
00475 }
00476 
00477 void CMy3dvisApp::OnFileIni() 
00478 {
00479         // TODO: Add your command handler code here
00480         IniFile inifile;
00481         inifile.SetupData(m_dFileThres, m_dPacketSize);
00482         int answer = inifile.DoModal();
00483 
00484         if (answer == IDCANCEL)
00485                 return;
00486         
00487         
00488         inifile.GetData(m_dFileThres, m_dPacketSize);   
00489         m_ProcessIniFile(true);
00490 }
00491 
00492 
00493 
00494 
00495 
00496 void CMy3dvisApp::OnRenderVolume() 
00497 {
00498         // TODO: Add your command handler code here
00499         if (!data3D || !slice)
00500                 return;
00501 
00502         if (!((CMy3dvisApp *)AfxGetApp())->transferFunction) {
00503                 MessageBox(m_pMainWnd->m_hWnd,
00504                                         "please select or create a transferfunction",
00505                                         "transferfunction missing",
00506                                         MB_OK);
00507                 return;
00508         }
00509                 
00510 
00511         if (((CMy3dvisApp *)AfxGetApp())->m_bRenderVolume) {
00512                 ((CMy3dvisApp *)AfxGetApp())->m_bRenderVolume = false;
00513 
00514                 AfxGetMainWnd()->SendMessage(MYWM_CHANGE_RENDERING, (WPARAM) 0, (LPARAM) 0);
00515         }
00516         else {
00517                 ((CMy3dvisApp *)AfxGetApp())->m_bRenderVolume = true;
00518 
00519                 AfxGetMainWnd()->SendMessage(MYWM_CHANGE_RENDERING, (WPARAM) 1, (LPARAM) 0);
00520 
00521                 raycaster = new Raycaster();
00522                 raycaster->SetViewingCondition(VECTOR(300,300,300),Color(0.0f,1.0f,0.0f),0.2f,0.2f,0.2f,8);
00523 
00524                 raycaster->Initialize(VECTOR(92,-20,85),400,400,1.0f,data3D,((CMy3dvisApp *)AfxGetApp())->transferFunction);
00525                 raycaster->Zoom(1.1f); // werte > 1.0 hinein zoomen <1.0 wegzoomen
00526                 raycaster->SetLight(false);
00527                 raycaster->SetTreshold(1500);
00528                 raycaster->SetRaytype(NN);
00529                 raycaster->SetRendermode(FH);
00530                 raycaster->SetPreCalcGradients(true);
00531         }
00532 }
00533 
00534 
00535 
00536 void CMy3dvisApp::Abort() {
00537         switch (m_dOperation) {
00538                 case 0:
00539                         return;
00540                 case 1:
00541                         if (data3D) {
00542                                 data3D->SetAbort();
00543                         }
00544                         break;
00545                 case 2:
00546 
00547                         break;
00548         }
00549 }

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