00001 #include "vuShearWarp.h"
00002 #include "../../vuDrawTools.h"
00003 #include "../../wxUIElements/vuTransferDialog.h"
00004 #include <wx/wx.h>
00005 #include <wx/button.h>
00006 #include <wx/choice.h>
00007 #include <wx/gdicmn.h>
00008 #include <wx/string.h>
00009
00010
00011
00012
00013 enum
00014 {
00015 idTRANSFERFUNCTION,
00016 idSPECULAR,
00017 idPROJECTION,
00018 idAPPLYVIEWING,
00019 idSCROLL,
00020 idWARP_OPENGL,
00021 idFAST_CLASSIFICATION
00022 };
00023
00024 BEGIN_EVENT_TABLE(vuShearWarp, vuBasicUtility)
00025 EVT_BUTTON (idTRANSFERFUNCTION, vuShearWarp::OnButtonTransferFunction)
00026 EVT_BUTTON (idAPPLYVIEWING, vuShearWarp::OnButtonApplyViewing)
00027 EVT_CHECKBOX (idSPECULAR, vuShearWarp::OnCheckBoxSpecular)
00028 EVT_RADIOBOX (idPROJECTION, vuShearWarp::OnRadioBoxProjection)
00029 EVT_CHECKBOX (idFAST_CLASSIFICATION, vuShearWarp::OnCheckBoxFastClassification)
00030 EVT_CHECKBOX (idWARP_OPENGL, vuShearWarp::OnCheckBoxWarpOpenGL)
00031 EVT_COMMAND_SCROLL (idSCROLL, vuShearWarp::OnScrollPerspective)
00032 END_EVENT_TABLE()
00033
00034
00035
00036
00037 vuShearWarp::vuShearWarp()
00038 {
00039 m_Data = 0;
00040 m_ViewScale = 1.0f;
00041 }
00042
00043
00044
00045
00046 vuShearWarp::~vuShearWarp()
00047 {
00048 if (m_Data != 0) delete m_Data;
00049 }
00050
00051 void vuShearWarp::DrawAgain() {
00052 }
00053
00054 void vuShearWarp::DrawFromImage() {
00055 }
00056
00057 vuCamera *vuShearWarp::getCamera() {
00058 return new vuCamera();
00059 }
00060
00061 vuImage *vuShearWarp::getCurrentImage() {
00062 return new vuImage();
00063 }
00064
00065
00066
00067
00068 const char* vuShearWarp::getFileType()
00069 {
00070 return "11121";
00071 }
00072
00073
00074
00075
00076 bool vuShearWarp::init(const char* DataFile)
00077 {
00078
00079 int x = 0;
00080 int y = 0;
00081 int z = 0;
00082 vuString dimX_str;
00083 vuString dimY_str;
00084 vuString dimZ_str;
00085
00086 CreateStatusBar();
00087
00088 useOpenGL(true);
00089
00090
00091 m_Data = new vu111211A;
00092 m_Data->setFileName(DataFile);
00093
00094
00095 m_TFunc.addOpacity(64,0.0);
00096 m_TFunc.addOpacity(65,1.0);
00097 m_TFunc.addOpacity(140,1.0);
00098 m_TFunc.addOpacity(249,1.0);
00099 m_TFunc.addOpacity(250,0.0);
00100
00101
00102
00103
00104 m_TFunc.setOpacitySmoothing(0);
00105 m_TFunc.setColourSmoothing(0);
00106 m_TFunc.generateFunction();
00107
00108 m_Data->setTransferFunc(m_TFunc);
00109
00110
00111 bool success = m_Data->read();
00112 if (success) {
00113 m_Data->getDimensions(x, y, z);
00114
00115 dimX_str = x;
00116 dimY_str = y;
00117 dimZ_str = z;
00118
00119 char fileName[400];
00120 char totalFileName[400];
00121 strcpy(totalFileName,m_Data->getFileName());
00122 int start = 0;
00123 int end = 0;
00124
00125
00126 for ( ; totalFileName[end] != '\0'; ++end);
00127 start = end;
00128
00129
00130 for ( ; ((start > 0) && (totalFileName[start] != '/')); --start);
00131
00132
00133 int i = 0;
00134 for (i = 0; i < end-start; ++i) {
00135 fileName[i] = totalFileName[start+i+1];
00136 }
00137 fileName[i] = '\0';
00138
00139
00140 char buffer[200] = "vuVolume: Shear Warp (Regular) - ";
00141 char *seperate = " x ";
00142 char *title;
00143 title = strcat(buffer,fileName);
00144 title = strcat(title,": ");
00145 title = strcat(title,dimX_str);
00146 title = strcat(title,seperate);
00147 title = strcat(title,dimY_str);
00148 title = strcat(title,seperate);
00149 title = strcat(title,dimZ_str);
00150
00151
00152 SetTitle(title);
00153
00154 m_glCanvas->SetSize(725,512);
00155 glResize();
00156 Fit();
00157 }
00158 else {
00159 wxMessageDialog dlg(this,m_Data->getErrorMessage(),"vuShearWarp",wxOK);
00160 dlg.ShowModal();
00161 }
00162
00163 return success;
00164 };
00165
00166
00167
00168
00169
00170 void vuShearWarp::addLeft(wxSizer *sizer) {
00171
00172
00173
00174
00175 wxBoxSizer *BoxGeneralSettings = new wxStaticBoxSizer(
00176 new wxStaticBox(this,
00177 401,
00178 " general settings "),
00179 wxVERTICAL);
00180
00181
00182 specularCheckBox = new wxCheckBox(this, idSPECULAR, "Specular Light");
00183 BoxGeneralSettings->Add( specularCheckBox, 0, wxALL | wxGROW, 2);
00184
00185
00186 fastClassCheckBox = new wxCheckBox(this, idFAST_CLASSIFICATION, "Fast Classification");
00187 fastClassCheckBox->SetValue(0);
00188 BoxGeneralSettings->Add(fastClassCheckBox, 0, wxALL, 2);
00189
00190 BoxGeneralSettings->Add(
00191 new wxCheckBox(this,
00192 idWARP_OPENGL, "use OpenGL for ortho warping"),
00193 0, wxALL, 2);
00194
00195 sizer->Add( BoxGeneralSettings, 0, wxEXPAND | wxALL, 10 );
00196
00197
00198
00199
00200
00201
00202 wxString *choices = new wxString[2];
00203 choices[0] = "Orthogonal";
00204 choices[1] = "Perspective";
00205 projectionRadioBox = new wxRadioBox(this,
00206 idPROJECTION,
00207 "Viewing",
00208 wxDefaultPosition,
00209 wxDefaultSize, 2, choices,
00210 2, wxRA_SPECIFY_ROWS,
00211 wxDefaultValidator, "radioBox");
00212 sizer->Add(projectionRadioBox, 0, wxLEFT | wxRIGHT | wxEXPAND, 10);
00213
00214
00215
00216
00217 wxBoxSizer *BoxPerspectiveSettings = new wxBoxSizer(wxHORIZONTAL);
00218 wxScrollBar *ScrollPerspective = new wxScrollBar(this,
00219 idSCROLL,
00220 wxPoint(40,40),
00221 wxSize(100,20),
00222 wxHORIZONTAL,
00223 wxDefaultValidator,
00224 "ScrollbarPerspective");
00225 ScrollPerspective->SetScrollbar(0,20,120,120,TRUE);
00226
00227
00228 BoxPerspectiveSettings->Add(new wxStaticText(this, 300, "Perspective "));
00229 BoxPerspectiveSettings->Add(ScrollPerspective);
00230 sizer->Add(BoxPerspectiveSettings, 0, wxEXPAND | wxALL, 15);
00231
00232
00233
00234
00235
00236 viewXTextCtrl = new wxTextCtrl(this, 201, "");
00237 viewYTextCtrl = new wxTextCtrl(this, 202, "");
00238 viewZTextCtrl = new wxTextCtrl(this, 203, "");
00239 upXTextCtrl = new wxTextCtrl(this, 211, "");
00240 upYTextCtrl = new wxTextCtrl(this, 212, "");
00241 upZTextCtrl = new wxTextCtrl(this, 213, "");
00242
00243
00244 wxBoxSizer *BoxNewCameraSettings = new wxStaticBoxSizer(
00245 new wxStaticBox(this,
00246 401,
00247 " define camera position "),
00248 wxVERTICAL);
00249
00250
00251 wxBoxSizer *BoxViewX = new wxBoxSizer(wxHORIZONTAL);
00252 wxBoxSizer *BoxViewY = new wxBoxSizer(wxHORIZONTAL);
00253 wxBoxSizer *BoxViewZ = new wxBoxSizer(wxHORIZONTAL);
00254
00255
00256 wxBoxSizer *BoxUpX = new wxBoxSizer(wxHORIZONTAL);
00257 wxBoxSizer *BoxUpY = new wxBoxSizer(wxHORIZONTAL);
00258 wxBoxSizer *BoxUpZ = new wxBoxSizer(wxHORIZONTAL);
00259
00260 BoxNewCameraSettings->Add(
00261 new wxStaticText(this, 102, "new look-at-vector: "),
00262 0, wxEXPAND | wxALL, 5);
00263
00264 BoxViewX->Add(new wxStaticText(this, 103, "X: "),
00265 0, wxALIGN_CENTER | wxLEFT, 25);
00266 BoxViewX->Add(viewXTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00267 BoxNewCameraSettings->Add(BoxViewX,0,wxALL,0);
00268
00269 BoxViewY->Add(new wxStaticText(this, 104, "Y: "), 0,
00270 wxALIGN_CENTER | wxLEFT, 25);
00271 BoxViewY->Add(viewYTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00272 BoxNewCameraSettings->Add(BoxViewY,0,wxALL,0);
00273
00274 BoxViewZ->Add(new wxStaticText(this, 105, "Z: "), 0,
00275 wxALIGN_CENTER | wxLEFT, 25);
00276 BoxViewZ->Add(viewZTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00277 BoxNewCameraSettings->Add(BoxViewZ,0,wxALL,0);
00278
00279 BoxNewCameraSettings->Add(
00280 new wxStaticText(this, 106, "new up-vector: "),
00281 0, wxLEFT, 15);
00282
00283 BoxUpX->Add(new wxStaticText(this, 107, "X: "), 0,
00284 wxALIGN_CENTER | wxLEFT, 25);
00285 BoxUpX->Add(upXTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00286 BoxNewCameraSettings->Add(BoxUpX,0,wxALL,0);
00287
00288 BoxUpY->Add(new wxStaticText(this, 108, "Y: "), 0,
00289 wxALIGN_CENTER | wxLEFT, 25);
00290 BoxUpY->Add(upYTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00291 BoxNewCameraSettings->Add(BoxUpY,0,wxALL,0);
00292
00293 BoxUpZ->Add(new wxStaticText(this, 109, "Z: "), 0,
00294 wxALIGN_CENTER | wxLEFT, 25);
00295 BoxUpZ->Add(upZTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00296 BoxNewCameraSettings->Add(BoxUpZ,0,wxALL,0);
00297
00298 applyViewingButton = new wxButton(this, idAPPLYVIEWING, "Apply Viewing");
00299 BoxNewCameraSettings->Add(applyViewingButton, 0, wxEXPAND | wxALL, 5);
00300
00301 sizer->Add(BoxNewCameraSettings, 0, wxALL | wxEXPAND ,10);
00302
00303
00304
00305
00306 sizer->Add(new wxButton(this, idTRANSFERFUNCTION,
00307 "Edit Transferfunction..."),
00308 0, wxALL | wxEXPAND, 10);
00309 }
00310
00311
00312
00313
00314 void vuShearWarp::addBottom(wxSizer *sizer)
00315 {
00316 }
00317
00318
00319
00320
00321 bool vuShearWarp::glInit(void)
00322 {
00323 if (m_Data == 0) return false;
00324
00325 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00326
00327 glEnable(GL_LIGHTING);
00328 glEnable(GL_LIGHT0);
00329 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00330
00331 m_Data->initOpenGL();
00332
00333
00334
00335 return true;
00336 }
00337
00338
00339
00340
00341 void vuShearWarp::glRender()
00342 {
00343 wxStopWatch watch;
00344 watch.Start();
00345
00346 m_Data->setViewVectors(m_Camera.getLookAtVector(),
00347 m_Camera.getUpVector(),
00348 m_Camera.getRightVector());
00349 m_Data->render();
00350
00351 SetStatusText(wxString("RenderTime: ") +
00352 vuString(watch.Time()).c_str() + "ms");
00353
00354 }
00355
00356
00357
00358
00359 void vuShearWarp::glResize()
00360 {
00361
00362 glViewport(0,0,(GLint)m_glCanvas->getWidth(),(GLint)m_glCanvas->getHeight());
00363
00364 m_Data->setCanvasSize(m_glCanvas->getWidth(),m_glCanvas->getHeight());
00365 glInit();
00366 }
00367
00368
00369
00370
00371 void vuShearWarp::OnCheckBoxFastClassification( wxCommandEvent& event)
00372 {
00373 if (event.IsChecked()) {
00374 if (projectionRadioBox->GetSelection() == 1) {
00375 wxMessageDialog dlg(this,"Fast Classification with perspective viewing not implemented yet!","vuShearWarp",wxOK);
00376 dlg.ShowModal();
00377 fastClassCheckBox->SetValue(false);
00378 } else {
00379 m_Data->setFastClassification(1);
00380 }
00381 } else {
00382 m_Data->setFastClassification(0);
00383 }
00384 }
00385
00386
00387
00388
00389 void vuShearWarp::OnCheckBoxWarpOpenGL( wxCommandEvent& event)
00390 {
00391 if (event.IsChecked()) {
00392 m_Data->setOrthogonalWarpOpenGL(1);
00393 } else {
00394 m_Data->setOrthogonalWarpOpenGL(0);
00395 }
00396 }
00397
00398
00399
00400
00401 #if wxMINOR_VERSION < 5
00402 void vuShearWarp::OnScrollPerspective( wxCommandEvent& event) {
00403 #else
00404 void vuShearWarp::OnScrollPerspective( wxScrollEvent& event) {
00405 #endif
00406 m_Data->setEyeDistance(m_Data->getMinEyeDistance() +
00407 (event.GetInt() * m_Data->getMaxSize() / 50));
00408 m_Data->render();
00409 m_glCanvas->redraw();
00410 }
00411
00412
00413
00414
00415 void vuShearWarp::OnCheckBoxSpecular( wxCommandEvent& event)
00416 {
00417 if (event.IsChecked()) {
00418 m_Data->setSpecular(1);
00419 } else {
00420 m_Data->setSpecular(0);
00421 }
00422 }
00423
00424
00425
00426
00427 void vuShearWarp::OnButtonApplyViewing( wxCommandEvent& event)
00428 {
00429
00430 wxString viewXStr = viewXTextCtrl->GetValue();
00431 wxString viewYStr = viewYTextCtrl->GetValue();
00432 wxString viewZStr = viewZTextCtrl->GetValue();
00433
00434
00435 wxString upXStr = upXTextCtrl->GetValue();
00436 wxString upYStr = upYTextCtrl->GetValue();
00437 wxString upZStr = upZTextCtrl->GetValue();
00438
00439 bool success = true;
00440
00441
00442 double viewXDouble = 0.0;
00443 double viewYDouble = 0.0;
00444 double viewZDouble = 0.0;
00445 if (viewXStr.ToDouble(&viewXDouble) == 0) success = false;
00446 if (viewYStr.ToDouble(&viewYDouble) == 0) success = false;
00447 if (viewZStr.ToDouble(&viewZDouble) == 0) success = false;
00448
00449
00450 double upXDouble = 0.0;
00451 double upYDouble = 0.0;
00452 double upZDouble = 0.0;
00453 if (upXStr.ToDouble(&upXDouble) == 0) success = false;
00454 if (upYStr.ToDouble(&upYDouble) == 0) success = false;
00455 if (upZStr.ToDouble(&upZDouble) == 0) success = false;
00456
00457 if (success) {
00458 vuVector newLookAtVector = vuVector((float)viewXDouble,
00459 (float)viewYDouble,
00460 (float)viewZDouble);
00461
00462 vuVector newUpVector = vuVector((float)upXDouble,
00463 (float)upYDouble,
00464 (float)upZDouble);
00465
00466 vuVector newRightVector = newLookAtVector.cross(newUpVector);
00467 newUpVector = newRightVector.cross(newLookAtVector);
00468
00469 newLookAtVector.makeUnit();
00470 newUpVector.makeUnit();
00471
00472 m_Camera.setLookAtVector(newLookAtVector);
00473 m_Camera.setUpVector(newUpVector);
00474
00475 m_Data->setViewVectors(m_Camera.getLookAtVector(),
00476 m_Camera.getUpVector(),
00477 m_Camera.getRightVector());
00478
00479 m_Data->render();
00480 m_glCanvas->redraw();
00481
00482 } else {
00483 wxMessageDialog dlg(this,
00484 "The coordinates have to be numbers!",
00485 "vuShearWarp",wxOK);
00486 dlg.ShowModal();
00487 }
00488 }
00489
00490
00491
00492
00493 void vuShearWarp::OnButtonTransferFunction( wxCommandEvent& event)
00494 {
00495
00496 vuTransferDialog dlg(this,m_TFunc);
00497
00498 if (dlg.ShowModal() == wxID_OK) {
00499 m_TFunc = dlg.getTransferFunc();
00500 m_Data->setTransferFunc(m_TFunc);
00501 m_Data->runlengthEncode();
00502 m_Data->render();
00503 glResize();
00504 m_glCanvas->redraw();
00505 }
00506 }
00507
00508
00509
00510
00511
00512 void vuShearWarp::OnRadioBoxProjection(wxCommandEvent &event)
00513 {
00514 if ((fastClassCheckBox->GetValue() == true) && (event.GetSelection() == 1)) {
00515 wxMessageDialog dlg(this,
00516 "Fast Classification with perspective viewing not implemented yet!",
00517 "vuShearWarp",
00518 wxOK);
00519 dlg.ShowModal();
00520 projectionRadioBox->SetSelection(0);
00521 m_Data->render();
00522 m_glCanvas->redraw();
00523 }
00524 else {
00525 m_Data->setViewing(event.GetSelection());
00526 m_Data->render();
00527 m_glCanvas->redraw();
00528 }
00529 }
00530
00531
00532
00533
00534 void vuShearWarp::glOnMouse(wxMouseEvent &ev)
00535 {
00536 if (ev.LeftDown() || ev.RightDown()) {
00537
00538 m_x = (int) ev.GetX();
00539 m_y = (int) ev.GetY();
00540 }
00541 else if (ev.LeftIsDown() && ev.Moving()) {
00542
00543 vuVector t = m_Camera.getPosition();
00544 float d = t.norm();
00545
00546 m_Camera.translateXYZ(0.0f, 0.0f, d);
00547 m_Camera.rotateAboutUp((ev.GetX() - m_x));
00548 m_Camera.rotateAboutRight(m_y - ev.GetY());
00549
00550 m_Camera.translateXYZ(0.0f, 0.0f, -d);
00551 glResize();
00552 m_glCanvas->redraw();
00553
00554
00555 m_x = (int) ev.GetX();
00556 m_y = (int) ev.GetY();
00557 }
00558 else if (ev.RightIsDown() && ev.Moving()) {
00559
00560 m_ViewScale -= ((float)ev.GetY() - m_y)/500.0f;
00561 m_Data->zoom(m_ViewScale);
00562 m_glCanvas->redraw();
00563
00564
00565 m_x = (int) ev.GetX();
00566 m_y = (int) ev.GetY();
00567 }
00568 else if (ev.LeftDClick()) {
00569
00570 vuTransferDialog dlg(this,m_TFunc);
00571
00572 if (dlg.ShowModal() == wxID_OK) {
00573 m_TFunc = dlg.getTransferFunc();
00574 m_Data->setTransferFunc(m_TFunc);
00575 if (m_Data->getFastClassification() == 1) {
00576 m_Data->classify();
00577 }
00578 else {
00579 m_Data->runlengthEncode();
00580 }
00581 glResize();
00582 m_glCanvas->redraw();
00583 }
00584 }
00585 }
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598