00001
00008 #include "MainWindow.h"
00009 #include "Error.h"
00010 #include <wx/busyinfo.h>
00011 #include <sstream>
00012
00013 const float MAX_FPS = 60.0f;
00014 const float MAX_FRAMETIME = 1000.0f / MAX_FPS;
00015
00016 const int ID_DRAWCUBE_CHECKBOX = wxID_HIGHEST + 1;
00017 const int ID_DRAWOUTLINE_CHECKBOX = wxID_HIGHEST + 2;
00018 const int ID_DRAWPLANES_CHECKBOX = wxID_HIGHEST + 3;
00019 const int ID_USETEX_CHECKBOX = wxID_HIGHEST + 4;
00020 const int ID_DETACHCAMERA_CHECKBOX = wxID_HIGHEST + 5;
00021 const int ID_REALTIME_CHECKBOX = wxID_HIGHEST + 6;
00022 const int ID_PLANES_SLIDER = wxID_HIGHEST + 7;
00023 const int ID_LOAD_DATASET_BUTTON = wxID_HIGHEST + 8;
00024 const int ID_BG_COLORBOX_PANEL = wxID_HIGHEST + 9;
00025 const int ID_CUBE_COLORBOX_PANEL = wxID_HIGHEST + 10;
00026 const int ID_OUTLINE_COLORBOX_PANEL = wxID_HIGHEST + 11;
00027 const int ID_PLANE_COLORBOX_PANEL = wxID_HIGHEST + 12;
00028 const int ID_LIGHT_COLORBOX_PANEL = wxID_HIGHEST + 13;
00029 const int ID_SET_LIGHTDIR_BUTTON = wxID_HIGHEST + 14;
00030 const int ID_RESET_LIGHTDIR_BUTTON = wxID_HIGHEST + 15;
00031 const int ID_RESOLUTION_PULLDOWN = wxID_HIGHEST + 16;
00032
00033 const long MAINWINDOW_STYLE = wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN;
00034
00035
00036 const wxString FPS_TOOLTIP = wxT("The frames per second of the volume renderer (fixd at 60fps).");
00037 const wxString RESOLUTION_PULLDOWN_TOOLTIP = wxT("Select the resolution of the volume renderer.");
00038 const wxString DRAW_CUBE_TOOLTIP = wxT("Enable/Diable drawing the faces of the bonding cube.");
00039 const wxString DRAW_CUBEOUTLINE_TOOLTIP = wxT("Enable/Diable drawing the outline of the bonding cube.");
00040 const wxString DRAW_PLANES_TOOLTIP = wxT("Enable/Diable drawing the volume slicing planes.");
00041 const wxString USE_TEXTURE_TOOLTIP = wxT("Enable/Diable display of the loaded data set.");
00042 const wxString DETACH_CAMERA_TOOLTIP = wxT("Detach/Attach slicing planes to the viewing direction of the camera.");
00043 const wxString REALTIME_TOOLTIP = wxT("Disable to only render the volume data set when something changes.");
00044 const wxString BG_COLOR_TOOLTIP = wxT("Set the background color of the volume renderer.");
00045 const wxString CUBE_COLOR_TOOLTIP = wxT("Set the color of the bounding cube faces.");
00046 const wxString CUBEOUTLINE_COLOR_TOOLTIP = wxT("Set the color of the bounding cube outline.");
00047 const wxString PLANE_COLOR_TOOLTIP = wxT("Set the color of the slicing planes.");
00048 const wxString LIGHT_COLOR_TOOLTIP = wxT("Set the color of the directional light used by the volume renderer.");
00049 const wxString XDIR_TOOLTIP = wxT("Set the x component of the light direction vector.");
00050 const wxString YDIR_TOOLTIP = wxT("Set the y component of the light direction vector.");
00051 const wxString ZDIR_TOOLTIP = wxT("Set the z component of the light direction vector.");
00052 const wxString LIGHT_RESET_TOOLTIP = wxT("Resets the light direction to its default setting.");
00053 const wxString LIGHT_SET_TOOLTIP = wxT("Sets the light direction.");
00054 const wxString PLANE_SLIDER_TOOLTIP = wxT("Sets the number of slicing planes.");
00055 const wxString LOAD_DATASET_TOOLTIP = wxT("Loads a data set.");
00056
00057 BEGIN_EVENT_TABLE(MainWindow, wxFrame)
00058 EVT_IDLE(MainWindow::OnIdle)
00059 EVT_SIZE(MainWindow::OnReSize)
00060 EVT_COMMAND_SCROLL(ID_PLANES_SLIDER, MainWindow::OnPlanesSliderScroll)
00061 EVT_COMBOBOX(ID_RESOLUTION_PULLDOWN, MainWindow::OnResolutionSelection)
00062 EVT_CHECKBOX(ID_DRAWCUBE_CHECKBOX, MainWindow::OnDrawCubeClick)
00063 EVT_CHECKBOX(ID_DRAWOUTLINE_CHECKBOX, MainWindow::OnDrawOutlineClick)
00064 EVT_CHECKBOX(ID_DRAWPLANES_CHECKBOX, MainWindow::OnDrawPlanesClick)
00065 EVT_CHECKBOX(ID_USETEX_CHECKBOX, MainWindow::OnUseTexClick)
00066 EVT_CHECKBOX(ID_DETACHCAMERA_CHECKBOX, MainWindow::OnDetachCameraClick)
00067 EVT_CHECKBOX(ID_REALTIME_CHECKBOX, MainWindow::OnRealTimeClick)
00068 EVT_BUTTON(ID_SET_LIGHTDIR_BUTTON, MainWindow::OnSetLightDirButtonClick)
00069 EVT_BUTTON(ID_RESET_LIGHTDIR_BUTTON, MainWindow::OnResetLightDirButtonClick)
00070 EVT_BUTTON(ID_LOAD_DATASET_BUTTON, MainWindow::OnLoadDataSetButtonClick)
00071 END_EVENT_TABLE()
00072
00073
00074 MainWindow::MainWindow(const wxString &name)
00075 :
00076 wxFrame(NULL, wxID_ANY, name, wxDefaultPosition, wxSize(MIN_WIDTH, MIN_HEIGHT), MAINWINDOW_STYLE),
00077 timer(0.0f),
00078 fps(0.0f),
00079 counter(0),
00080 lightDirection(0.0f, 0.0f, 1.0f)
00081 {
00082
00083 aboutInfo.SetName(wxT("RT Volume Rendering"));
00084 aboutInfo.AddDeveloper(wxT("Joe Forte"));
00085 aboutInfo.SetDescription(wxT("The RT Volume Rendering program provides a Real-Time texture based approch for rendering volume data."));
00086 aboutInfo.SetVersion(wxT("v1.0"));
00087
00088 #ifdef _WIN32
00089
00090 SetIcon( wxIcon(wxT("icon.ico"), wxBITMAP_TYPE_ICO) );
00091 #else
00092 #ifndef APPLE_APPLICATION_BUNDLE
00093
00094 SetIcon( wxIcon(wxT("icon.png")) );
00095
00096 #endif
00097 #endif
00098
00099
00100 #ifdef __APPLE__
00101
00102
00103 wxMenuBar *menuBar = new wxMenuBar;
00104 wxMenu *helpMenu = new wxMenu;
00105
00106 helpMenu->Append(wxApp::s_macAboutMenuItemId, wxT("About..."), wxT("Presents information about this application."));
00107
00108 Connect(wxID_CLOSE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnQuit));
00109 Connect(wxApp::s_macAboutMenuItemId, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnAbout));
00110
00111 menuBar->Append(helpMenu, wxApp::s_macHelpMenuTitleName);
00112
00113 SetMenuBar(menuBar);
00114
00115 #else
00116
00117
00118 wxMenuBar *menuBar = new wxMenuBar;
00119 wxMenu *fileMenu = new wxMenu;
00120 wxMenu *helpMenu = new wxMenu;
00121
00122 fileMenu->Append(wxID_CLOSE, wxT("Exit"), wxT("Exits the Volume Rendering Application"));
00123 helpMenu->Append(wxID_ABOUT, wxT("About"), wxT("Presents information about this application."));
00124
00125 Connect(wxID_CLOSE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnQuit));
00126 Connect(wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnAbout));
00127
00128 menuBar->Append(fileMenu, wxT("File"));
00129 menuBar->Append(helpMenu, wxT("Help"));
00130
00131 SetMenuBar(menuBar);
00132
00133 #endif
00134
00135 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
00136
00137
00138 Show(true);
00139
00140 renderer = new RTVolumeRenderer(this, 640, 480);
00141
00142
00143 topLevel = new wxBoxSizer(wxHORIZONTAL);
00144 wxSizer *vertical = new wxBoxSizer(wxVERTICAL);
00145 topLevel->Add(vertical, 1, wxEXPAND, 5);
00146 vertical->Add(renderer, 0, wxALL | wxALIGN_CENTER, 5);
00147
00148 wxSizer *sideBar = new wxBoxSizer(wxVERTICAL);
00149 topLevel->Add(sideBar);
00150
00151
00152 wxStaticBoxSizer *drawOptionsSizer = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("Runtime Settings")), wxVERTICAL);
00153 sideBar->Add(drawOptionsSizer, 0, wxALL, 5);
00154
00155
00156 fpsDisplay = new wxStaticText(this, wxID_ANY, wxT("FPS: 00.0000"));
00157 fpsDisplay->SetToolTip(FPS_TOOLTIP);
00158 drawOptionsSizer->Add(fpsDisplay, 0, wxBOTTOM, 5);
00159
00160
00161 wxArrayString activePlotStrings;
00162 activePlotStrings.Add(wxT("320x240"));
00163 activePlotStrings.Add(wxT("640x480"));
00164 activePlotStrings.Add(wxT("800x600"));
00165 activePlotStrings.Add(wxT("1024x768"));
00166
00167 wxComboBox *activePlot = new wxComboBox(this,
00168 ID_RESOLUTION_PULLDOWN,
00169 wxT("Resolution"),
00170 wxDefaultPosition,
00171 wxDefaultSize,
00172 activePlotStrings,
00173 wxCB_DROPDOWN | wxCB_READONLY);
00174 activePlot->Select(1);
00175 activePlot->SetToolTip(RESOLUTION_PULLDOWN_TOOLTIP);
00176
00177 wxSizer *resSizer = new wxBoxSizer(wxHORIZONTAL);
00178 resSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Resolution: ")), 0, wxALIGN_CENTER | wxBOTTOM, 4);
00179 resSizer->Add(activePlot);
00180 drawOptionsSizer->Add(resSizer, 0, wxBOTTOM, 5);
00181
00182
00183 wxGridSizer *drawGridSizer = new wxGridSizer(2, 2, 0, 0);
00184 drawOptionsSizer->Add(drawGridSizer, 0, wxALIGN_CENTER);
00185
00186 wxCheckBox *drawCubes = new wxCheckBox(this, ID_DRAWCUBE_CHECKBOX, wxT("Draw Cube"));
00187 wxCheckBox *drawOutline = new wxCheckBox(this, ID_DRAWOUTLINE_CHECKBOX, wxT("Draw Outline"));
00188 wxCheckBox *drawPlanes = new wxCheckBox(this, ID_DRAWPLANES_CHECKBOX, wxT("Draw Planes"));
00189 wxCheckBox *useTex = new wxCheckBox(this, ID_USETEX_CHECKBOX, wxT("Use Texture"));
00190 wxCheckBox *detachCamera = new wxCheckBox(this, ID_DETACHCAMERA_CHECKBOX, wxT("Detach Camera"));
00191 wxCheckBox *realTime = new wxCheckBox(this, ID_REALTIME_CHECKBOX, wxT("Real-Time"));
00192 drawOutline->SetValue(true);
00193 drawPlanes->SetValue(true);
00194 realTime->SetValue(true);
00195
00196 drawCubes->SetToolTip(DRAW_CUBE_TOOLTIP);
00197 drawOutline->SetToolTip(DRAW_CUBEOUTLINE_TOOLTIP);
00198 drawPlanes->SetToolTip(DRAW_PLANES_TOOLTIP);
00199 useTex->SetToolTip(USE_TEXTURE_TOOLTIP);
00200 detachCamera->SetToolTip(DETACH_CAMERA_TOOLTIP);
00201 realTime->SetToolTip(REALTIME_TOOLTIP);
00202
00203 drawGridSizer->Add(drawCubes);
00204 drawGridSizer->Add(drawOutline);
00205 drawGridSizer->Add(drawPlanes);
00206 drawGridSizer->Add(useTex);
00207 drawGridSizer->Add(detachCamera);
00208 drawGridSizer->Add(realTime);
00209 drawGridSizer->AddSpacer(0);
00210 drawGridSizer->AddSpacer(0);
00211
00212 drawGridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Backgound Color ")), 0, wxALIGN_RIGHT);
00213 bgColorBox = new ColorBox(this, ID_BG_COLORBOX_PANEL, Color4f(0.0f, 0.0f, 0.0f));
00214 bgColorBox->SetListner(this);
00215 bgColorBox->SetToolTip(BG_COLOR_TOOLTIP);
00216 drawGridSizer->Add(bgColorBox);
00217
00218 drawGridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Cube Color ")), 0, wxALIGN_RIGHT);
00219 cubeColorBox = new ColorBox(this, ID_CUBE_COLORBOX_PANEL, Color4f(0.0f, 0.0f, 1.0f));
00220 cubeColorBox->SetListner(this);
00221 cubeColorBox->SetToolTip(CUBE_COLOR_TOOLTIP);
00222 drawGridSizer->Add(cubeColorBox);
00223
00224 drawGridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Outline Color ")), 0, wxALIGN_RIGHT);
00225 outlineColorBox = new ColorBox(this, ID_OUTLINE_COLORBOX_PANEL, Color4f(0.0f, 0.0f, 1.0f));
00226 outlineColorBox->SetListner(this);
00227 outlineColorBox->SetToolTip(CUBEOUTLINE_COLOR_TOOLTIP);
00228 drawGridSizer->Add(outlineColorBox);
00229
00230 drawGridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Plane Color ")), 0, wxALIGN_RIGHT);
00231 planeColorBox = new ColorBox(this, ID_PLANE_COLORBOX_PANEL, Color4f(0.5f, 0.5f, 0.5f));
00232 planeColorBox->SetListner(this);
00233 planeColorBox->SetToolTip(PLANE_COLOR_TOOLTIP);
00234 drawGridSizer->Add(planeColorBox);
00235
00236 drawGridSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Light Color ")), 0, wxALIGN_RIGHT);
00237 lightColorBox = new ColorBox(this, ID_LIGHT_COLORBOX_PANEL, Color4f(1.0f, 1.0f, 1.0f));
00238 lightColorBox->SetListner(this);
00239 lightColorBox->SetToolTip(LIGHT_COLOR_TOOLTIP);
00240 drawGridSizer->Add(lightColorBox);
00241
00242 drawOptionsSizer->AddSpacer(10);
00243 drawOptionsSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Light Direction")), 0, wxALIGN_CENTER | wxBOTTOM, 5);
00244
00245 xDir = new wxTextCtrl(this, wxID_ANY, wxT("0.0"), wxDefaultPosition, wxSize(60, -1));
00246 yDir = new wxTextCtrl(this, wxID_ANY, wxT("0.0"), wxDefaultPosition, wxSize(60, -1));
00247 zDir = new wxTextCtrl(this, wxID_ANY, wxT("1.0"), wxDefaultPosition, wxSize(60, -1));
00248
00249 xDir->SetToolTip(XDIR_TOOLTIP);
00250 yDir->SetToolTip(YDIR_TOOLTIP);
00251 zDir->SetToolTip(ZDIR_TOOLTIP);
00252
00253 wxSizer *dirBox = new wxBoxSizer(wxHORIZONTAL);
00254 dirBox->Add(new wxStaticText(this, wxID_ANY, wxT("X:")), 0, wxALIGN_CENTER_VERTICAL);
00255 dirBox->Add(xDir);
00256 dirBox->AddSpacer(10);
00257 dirBox->Add(new wxStaticText(this, wxID_ANY, wxT("Y:")), 0, wxALIGN_CENTER_VERTICAL);
00258 dirBox->Add(yDir);
00259 dirBox->AddSpacer(10);
00260 dirBox->Add(new wxStaticText(this, wxID_ANY, wxT("Z:")), 0, wxALIGN_CENTER_VERTICAL);
00261 dirBox->Add(zDir);
00262 drawOptionsSizer->Add(dirBox, 0, wxALIGN_CENTER);
00263
00264 wxButton *lightReset = new wxButton(this, ID_RESET_LIGHTDIR_BUTTON, wxT("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
00265 lightReset->SetToolTip(LIGHT_RESET_TOOLTIP);
00266
00267 wxSizer *lightButtons = new wxBoxSizer(wxHORIZONTAL);
00268 lightButtons->Add(lightReset);
00269 lightButtons->AddSpacer(5);
00270
00271 wxButton *lightSet = new wxButton(this, ID_SET_LIGHTDIR_BUTTON, wxT("Set"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
00272 lightSet->SetToolTip(LIGHT_SET_TOOLTIP);
00273
00274 lightButtons->Add(lightSet);
00275 drawOptionsSizer->Add(lightButtons, 0, wxALIGN_CENTER | wxTOP, 4);
00276
00277 drawOptionsSizer->AddSpacer(10);
00278 drawOptionsSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Planes")), 0, wxALIGN_CENTER);
00279
00280 wxSlider *planeSlider = new wxSlider(this,
00281 ID_PLANES_SLIDER,
00282 1, 1, MAX_PLANES,
00283 wxDefaultPosition,
00284 wxSize(230, -1),
00285 wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS);
00286 planeSlider->SetToolTip(PLANE_SLIDER_TOOLTIP);
00287 drawOptionsSizer->Add(planeSlider, 0, wxALIGN_CENTER);
00288
00289
00290 drawOptionsSizer->AddSpacer(10);
00291 drawOptionsSizer->Add(new wxStaticText(this, wxID_ANY, wxT("Data Set")), 0, wxALIGN_CENTER);
00292 volTexName = new wxStaticText(this, wxID_ANY, wxT("(none)"));
00293 volTexSize = new wxStaticText(this, wxID_ANY, wxT("0x0x0"));
00294 drawOptionsSizer->Add(volTexName, 0, wxALIGN_CENTER);
00295 drawOptionsSizer->Add(volTexSize, 0, wxALIGN_CENTER);
00296 drawOptionsSizer->AddSpacer(10);
00297
00298 wxButton *loadDataset = new wxButton(this, ID_LOAD_DATASET_BUTTON, wxT("Load..."));
00299 loadDataset->SetToolTip(LOAD_DATASET_TOOLTIP);
00300 drawOptionsSizer->Add(loadDataset, 0, wxALIGN_CENTER);
00301
00302
00303 transFunc = new TransferFunctionWidget(this);
00304 transFunc->SetListner(renderer);
00305 vertical->Add(transFunc, 0, wxBOTTOM | wxALIGN_CENTER, 5);
00306
00307 SetSizerAndFit(topLevel);
00308 Layout();
00309 Center();
00310
00311 currTime = wxGetLocalTimeMillis();
00312 lastTime = currTime;
00313 }
00314
00315
00316 MainWindow::~MainWindow() {}
00317
00318
00319 void MainWindow::OnQuit(wxCommandEvent &e)
00320 {
00321 Close(true);
00322 }
00323
00324
00325 void MainWindow::OnAbout(wxCommandEvent &e)
00326 {
00327 wxAboutBox(aboutInfo);
00328 }
00329
00330
00331 void MainWindow::OnReSize(wxSizeEvent &e) {}
00332
00333
00334 void MainWindow::OnDrawCubeClick(wxCommandEvent &e)
00335 {
00336 renderer->ShouldDrawCube(e.IsChecked());
00337 }
00338
00339
00340 void MainWindow::OnDrawOutlineClick(wxCommandEvent &e)
00341 {
00342 renderer->ShouldDrawCubeOutline(e.IsChecked());
00343 }
00344
00345
00346 void MainWindow::OnDrawPlanesClick(wxCommandEvent &e)
00347 {
00348 renderer->ShouldDrawPlanes(e.IsChecked());
00349 }
00350
00351
00352 void MainWindow::OnUseTexClick(wxCommandEvent &e)
00353 {
00354 renderer->UseVolumeTexture(e.IsChecked());
00355 }
00356
00357
00358 void MainWindow::OnDetachCameraClick(wxCommandEvent &e)
00359 {
00360 renderer->ToggleCameraAttachment();
00361 }
00362
00363
00364 void MainWindow::OnRealTimeClick(wxCommandEvent &e)
00365 {
00366 realTime = e.IsChecked();
00367 renderer->SetQuickMovmentRendering(!realTime);
00368 transFunc->DelayRealtimeUpdate(!realTime);
00369 }
00370
00371
00372 void MainWindow::OnDrawTimer(wxTimerEvent &e)
00373 {
00374 }
00375
00376
00377 void MainWindow::OnPlanesSliderScroll(wxScrollEvent &e)
00378 {
00379 renderer->SetPlanes(e.GetPosition());
00380 }
00381
00382
00383 void MainWindow::OnResolutionSelection(wxCommandEvent &e)
00384 {
00385 int sel = e.GetSelection();
00386 switch(sel)
00387 {
00388 case 0:
00389 renderer->ResizeRenderer(320, 240);
00390 break;
00391 case 1:
00392 renderer->ResizeRenderer(640, 480);
00393 break;
00394 case 2:
00395 renderer->ResizeRenderer(800, 600);
00396 break;
00397 case 3:
00398 renderer->ResizeRenderer(1024, 768);
00399 break;
00400 };
00401
00402 Fit();
00403 Layout();
00404 Fit();
00405 Refresh();
00406 }
00407
00408
00409 void MainWindow::OnSetLightDirButtonClick(wxCommandEvent &e)
00410 {
00411 double x = 0.0;
00412 double y = 0.0;
00413 double z = 0.0;
00414
00415 if(!xDir->GetLineText(0).ToDouble(&x))
00416 {
00417 x = 0.0;
00418 }
00419
00420 if(!yDir->GetLineText(0).ToDouble(&y))
00421 {
00422 y = 0.0;
00423 }
00424
00425 if(!zDir->GetLineText(0).ToDouble(&z))
00426 {
00427 z = 0.0;
00428 }
00429
00430 Vector3f dir((float)x, (float)y, (float)z);
00431 float len = dir.Length();
00432
00433 if(len == 0.0f)
00434 {
00435 dir = lightDirection;
00436 }
00437 else
00438 {
00439 lightDirection = dir / len;
00440 renderer->SetLightDirection(lightDirection);
00441 }
00442
00443 wxString nx, ny, nz;
00444 nx << lightDirection.x;
00445 ny << lightDirection.y;
00446 nz << lightDirection.z;
00447
00448 xDir->SetValue(nx);
00449 yDir->SetValue(ny);
00450 zDir->SetValue(nz);
00451 }
00452
00453
00454 void MainWindow::OnResetLightDirButtonClick(wxCommandEvent &e)
00455 {
00456 lightDirection = Vector3f(0.0f, 0.0f, 1.0f);
00457
00458 wxString nx, ny, nz;
00459 nx << lightDirection.x;
00460 ny << lightDirection.y;
00461 nz << lightDirection.z;
00462
00463 xDir->SetValue(nx);
00464 yDir->SetValue(ny);
00465 zDir->SetValue(nz);
00466
00467 renderer->SetLightDirection(lightDirection);
00468 }
00469
00470
00471 void MainWindow::ColorChanged(const ColorBox *cbox)
00472 {
00473 if(cbox == bgColorBox)
00474 renderer->SetBackgroundColor(cbox->color);
00475 else if(cbox == cubeColorBox)
00476 renderer->SetCubeColor(cbox->color);
00477 else if(cbox == outlineColorBox)
00478 renderer->SetOutlineColor(cbox->color);
00479 else if(cbox == planeColorBox)
00480 renderer->SetPlaneColor(cbox->color);
00481 else if(cbox == lightColorBox)
00482 renderer->SetLightDiffuseColor(cbox->color);
00483 }
00484
00485
00486 void MainWindow::OnLoadDataSetButtonClick(wxCommandEvent &e)
00487 {
00488 wxFileDialog dialog(this,
00489 wxT("Load Data Set"),
00490 wxT("./DataSets"),
00491 wxEmptyString,
00492 wxT("Volume Texture File (*.vt)|*.vt"),
00493 wxOPEN | wxFILE_MUST_EXIST);
00494
00495 if(dialog.ShowModal() == wxID_OK)
00496 {
00497 wxWindowDisabler disableAll;
00498
00499 wxString msg = "Loading ";
00500 msg += dialog.GetFilename();
00501 msg += "...";
00502
00503 wxBusyInfo info(msg, this);
00504
00505 wxString path = dialog.GetPath();
00506 wxString filename = dialog.GetFilename();
00507
00508 path.Remove(path.Length() - filename.Length());
00509
00510 VTInfo volInfo;
00511 if( !renderer->LoadVolumeDataSet(filename.c_str(), path.c_str(), volInfo) )
00512 return;
00513
00514 unsigned int histogram[256];
00515 renderer->CopyHistogram(histogram, 256);
00516 transFunc->SetHistogram(histogram);
00517
00518 wxString s;
00519 s << volInfo.width << "x" << volInfo.height << "x" << volInfo.depth;
00520 volTexSize->SetLabel(s);
00521
00522 volTexName->SetLabel(dialog.GetFilename());
00523 Layout();
00524 }
00525 }
00526
00527
00528 void MainWindow::OnIdle(wxIdleEvent &e)
00529 {
00530 currTime = wxGetLocalTimeMillis();
00531 wxLongLong diff = currTime - lastTime;
00532
00533 if(diff < MAX_FRAMETIME)
00534 {
00535 wxMilliSleep(MAX_FRAMETIME - diff.ToLong());
00536 currTime = wxGetLocalTimeMillis();
00537 diff = currTime - lastTime;
00538 }
00539
00540
00541 float dt = (float)(diff.ToDouble() / 1000.0);
00542 lastTime = currTime;
00543
00544 counter++;
00545 timer += dt;
00546 if(timer >= 1.0f)
00547 {
00548 fps = counter / timer;
00549 counter = 0;
00550 timer = 0.0f;
00551
00552 std::stringstream s;
00553 s << "FPS: " << fps;
00554 fpsDisplay->SetLabel(s.str().c_str());
00555 }
00556
00557 if(!realTime)
00558 renderer->SetFrameTime(MAX_FRAMETIME / 1000.0f);
00559 else
00560 renderer->SetFrameTime(dt);
00561
00562 Draw();
00563
00564 e.RequestMore();
00565 }
00566
00567
00568 void MainWindow::Update(float dt)
00569 {
00570 }
00571
00572
00573 void MainWindow::Draw()
00574 {
00575 renderer->Draw();
00576 }