Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vuBCCShearWarp.cpp

Go to the documentation of this file.
00001 #include "vuBCCShearWarp.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 //-- The vuBCCShearWarp event table                                        ---
00012 //----------------------------------------------------------------------------
00013 enum
00014 {
00015   idTRANSFERFUNCTION,
00016   idSPECULAR,
00017   idPROJECTION,
00018   idAPPLYVIEWING,
00019   idSCROLL,
00020   idWARP_OPENGL
00021 };
00022 
00023 
00024 BEGIN_EVENT_TABLE(vuBCCShearWarp, vuBasicUtility)
00025     EVT_BUTTON     (idTRANSFERFUNCTION, vuBCCShearWarp::OnButtonTransferFunction)
00026     EVT_BUTTON     (idAPPLYVIEWING, vuBCCShearWarp::OnButtonApplyViewing)
00027     EVT_CHECKBOX   (idSPECULAR, vuBCCShearWarp::OnCheckBoxSpecular)
00028     EVT_CHECKBOX   (idWARP_OPENGL, vuBCCShearWarp::OnCheckBoxWarpOpenGL)
00029     EVT_RADIOBOX   (idPROJECTION, vuBCCShearWarp::OnRadioBoxProjection)
00030     EVT_COMMAND_SCROLL (idSCROLL, vuBCCShearWarp::OnScrollPerspective)
00031 END_EVENT_TABLE()
00032 
00033 //----------------------------------------------------------------------------
00034 //-- Constructor                                                           ---
00035 //----------------------------------------------------------------------------
00036 vuBCCShearWarp::vuBCCShearWarp()
00037 {
00038     m_Data = 0;
00039     m_ViewScale = 1.0f;
00040 }
00041 
00042 //----------------------------------------------------------------------------
00043 //-- Destructor                                                            ---
00044 //----------------------------------------------------------------------------
00045 vuBCCShearWarp::~vuBCCShearWarp()
00046 {
00047     if (m_Data != 0) delete m_Data;
00048 }
00049 
00050 void vuBCCShearWarp::DrawAgain() {
00051 }
00052 
00053 void vuBCCShearWarp::DrawFromImage() {
00054 }
00055 
00056 vuCamera *vuBCCShearWarp::getCamera() {
00057     return new vuCamera();
00058 }
00059 
00060 vuImage *vuBCCShearWarp::getCurrentImage() {
00061     return new vuImage();
00062 }
00063 
00064 //----------------------------------------------------------------------------
00065 //-- Returns the file type processed by this class                         ---
00066 //----------------------------------------------------------------------------
00067 const char* vuBCCShearWarp::getFileType()
00068 {
00069     return "15121";
00070 }
00071 
00072 //----------------------------------------------------------------------------
00073 //-- Initialization                                                        ---
00074 //----------------------------------------------------------------------------
00075 bool vuBCCShearWarp::init(const char* DataFile)
00076 {
00077     //Set up the window
00078     int x = 0;
00079     int y = 0;
00080     int z = 0;
00081     vuString dimX_str;
00082     vuString dimY_str;
00083     vuString dimZ_str;
00084 
00085     CreateStatusBar();
00086 
00087     useOpenGL(true);
00088 
00089     //Create a volume data instance.
00090     m_Data = new vu1512119;
00091     m_Data->setFileName(DataFile);
00092 
00093     //Set the transfer function for the data.
00094     m_TFunc.addOpacity(64,0.0);
00095     m_TFunc.addOpacity(65,1.0);
00096     m_TFunc.addOpacity(140,1.0);
00097     m_TFunc.addOpacity(249,1.0);
00098     m_TFunc.addOpacity(250,0.0);
00099 /*
00100     m_TFunc.addColour(0,0,0,0);
00101     m_TFunc.addColour(250,0.0,0.0,1.0);
00102 */
00103     m_TFunc.setOpacitySmoothing(0);
00104     m_TFunc.setColourSmoothing(0);
00105     m_TFunc.generateFunction();
00106 
00107     m_Data->setTransferFunc(m_TFunc);
00108 
00109     //Read in the data.
00110     bool success = m_Data->read();
00111     if (success)
00112     {
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         // find the end of the String
00126         for ( ; totalFileName[end] != '\0'; ++end);
00127         start = end;
00128 
00129         // find the last '/' in the string
00130         for ( ; ((start > 0) && (totalFileName[start] != '/')); --start);
00131 
00132         // copy the file name without the path name
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         // construct the window-title
00140         char buffer[200] = "vuVolume: Shear Warp (BCC-Grids) - ";
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         // set the window title
00152         SetTitle(title);
00153 
00154         m_glCanvas->SetSize(725,512);
00155         glResize();
00156         Fit();
00157     }
00158     else
00159     {
00160         wxMessageDialog dlg(this,m_Data->getErrorMessage(),"vuBCCShearWarp",wxOK);
00161         dlg.ShowModal();
00162     }
00163 
00164     return success;
00165 };
00166 
00167 
00168 //----------------------------------------------------------------------------
00169 //------------------------- public: addLeft() --------------------------------
00170 //----------------------------------------------------------------------------
00171 void vuBCCShearWarp::addLeft(wxSizer *sizer) 
00172 {
00173     //========================================================================
00174     //Add the elements for the general settings
00175     //========================================================================
00176     //Box around the general settings
00177     wxBoxSizer *BoxGeneralSettings = new wxStaticBoxSizer(
00178         new wxStaticBox(this,
00179                         401,
00180                         " general settings "),
00181         wxVERTICAL);
00182 
00183     //Check Box for turning on/off specular light
00184     specularCheckBox = new wxCheckBox(this, idSPECULAR, "Specular Light");
00185     BoxGeneralSettings->Add( specularCheckBox, 0, wxALL | wxGROW, 2);
00186 
00187     BoxGeneralSettings->Add(
00188         new wxCheckBox(this, 
00189                        idWARP_OPENGL, 
00190                        "use OpenGL for ortho warping"), 
00191         0, wxALL, 2);
00192 
00193     sizer->Add( BoxGeneralSettings, 0, wxEXPAND | wxALL, 10 );
00194 
00195     //========================================================================
00196     // Add wxRadioBox for choosing between orthogonal 
00197     // and perspective projection
00198     //========================================================================
00199     //Radio Box for choosing between orthogonal and perspective viewing
00200     wxString *choices = new wxString[2];
00201     choices[0] = "Orthogonal";
00202     choices[1] = "Perspective";
00203     projectionRadioBox = new wxRadioBox(
00204         this, idPROJECTION, "Viewing", wxDefaultPosition,
00205         wxDefaultSize, 2, choices,
00206         2, wxRA_SPECIFY_ROWS, wxDefaultValidator, "radioBox");
00207     sizer->Add(projectionRadioBox, 0, wxLEFT | wxRIGHT | wxEXPAND, 10);
00208 
00209     //========================================================================
00210     //Add ScrollBar for choosing distance between eye and projection plane
00211     //========================================================================
00212     wxBoxSizer *BoxPerspectiveSettings = new wxBoxSizer(wxHORIZONTAL);
00213     wxScrollBar *ScrollPerspective = new wxScrollBar(this,
00214                                                     idSCROLL,
00215                                                     wxPoint(40,40),
00216                                                     wxSize(100,20),
00217                                                     wxHORIZONTAL,
00218                                                     wxDefaultValidator,
00219                                                     "ScrollbarPerspective");
00220     ScrollPerspective->SetScrollbar(0,20,120,120,TRUE);
00221     BoxPerspectiveSettings->Add(new wxStaticText(this, 300, "Perspective "));
00222     BoxPerspectiveSettings->Add(ScrollPerspective);
00223     sizer->Add(BoxPerspectiveSettings, 0, wxEXPAND | wxALL, 15);
00224 
00225     //==========================================================================
00226     //Add elements for choosing specific viewing view- and up-vectors
00227     //==========================================================================
00228     //Text fields for entering a specific viewing-position
00229     viewXTextCtrl = new wxTextCtrl(this, 201, "");
00230     viewYTextCtrl = new wxTextCtrl(this, 202, "");
00231     viewZTextCtrl = new wxTextCtrl(this, 203, "");
00232     upXTextCtrl = new wxTextCtrl(this, 211, "");
00233     upYTextCtrl = new wxTextCtrl(this, 212, "");
00234     upZTextCtrl = new wxTextCtrl(this, 213, "");
00235 
00236     //Box around the input of the camera position
00237     wxBoxSizer *BoxNewCameraSettings = new wxStaticBoxSizer(
00238         new wxStaticBox(this,
00239                         401,
00240                         " define camera position "),
00241         wxVERTICAL);
00242 
00243     //BoxSizer for input of look-at-vector
00244     wxBoxSizer *BoxViewX = new wxBoxSizer(wxHORIZONTAL);
00245     wxBoxSizer *BoxViewY = new wxBoxSizer(wxHORIZONTAL);
00246     wxBoxSizer *BoxViewZ = new wxBoxSizer(wxHORIZONTAL);
00247 
00248     //BoxSizer for input of up-vector
00249     wxBoxSizer *BoxUpX = new wxBoxSizer(wxHORIZONTAL);
00250     wxBoxSizer *BoxUpY = new wxBoxSizer(wxHORIZONTAL);
00251     wxBoxSizer *BoxUpZ = new wxBoxSizer(wxHORIZONTAL);
00252 
00253     BoxNewCameraSettings->Add(
00254         new wxStaticText(this, 102, "new look-at-vector: "), 
00255         0, wxEXPAND | wxALL, 5);
00256 
00257     BoxViewX->Add(new wxStaticText(this, 103, "X: "), 
00258                   0, wxALIGN_CENTER | wxLEFT, 25);
00259     BoxViewX->Add(viewXTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00260     BoxNewCameraSettings->Add(BoxViewX,0,wxALL,0);
00261 
00262     BoxViewY->Add(new wxStaticText(this, 104, "Y: "), 
00263                   0, wxALIGN_CENTER | wxLEFT, 25);
00264     BoxViewY->Add(viewYTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00265     BoxNewCameraSettings->Add(BoxViewY,0,wxALL,0);
00266 
00267     BoxViewZ->Add(new wxStaticText(this, 105, "Z: "), 
00268                   0, wxALIGN_CENTER | wxLEFT, 25);
00269     BoxViewZ->Add(viewZTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00270     BoxNewCameraSettings->Add(BoxViewZ,0,wxALL,0);
00271 
00272     BoxNewCameraSettings->Add(
00273         new wxStaticText(this, 106, "new up-vector: "), 0, wxLEFT, 15);
00274 
00275     BoxUpX->Add(new wxStaticText(this, 107, "X: "), 
00276                 0, wxALIGN_CENTER | wxLEFT, 25);
00277     BoxUpX->Add(upXTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00278     BoxNewCameraSettings->Add(BoxUpX,0,wxALL,0);
00279 
00280     BoxUpY->Add(new wxStaticText(this, 108, "Y: "), 
00281                 0, wxALIGN_CENTER | wxLEFT, 25);
00282     BoxUpY->Add(upYTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00283     BoxNewCameraSettings->Add(BoxUpY,0,wxALL,0);
00284 
00285     BoxUpZ->Add(new wxStaticText(this, 109, "Z: "), 
00286                 0, wxALIGN_CENTER | wxLEFT, 25);
00287     BoxUpZ->Add(upZTextCtrl, 0, wxALIGN_CENTER | wxALL, 0);
00288     BoxNewCameraSettings->Add(BoxUpZ,0,wxALL,0);
00289 
00290     applyViewingButton = new wxButton(this, idAPPLYVIEWING, "Apply Viewing");
00291     BoxNewCameraSettings->Add(applyViewingButton, 0, wxEXPAND | wxALL, 5);
00292 
00293     sizer->Add(BoxNewCameraSettings, 0, wxALL | wxEXPAND ,10);
00294 
00295     //========================================================================
00296     //Add button to open transfer-function editor
00297     //========================================================================
00298     sizer->Add(new wxButton(
00299         this, idTRANSFERFUNCTION, "Edit Transferfunction..."),
00300                0, wxALL | wxEXPAND, 10);
00301 }
00302 
00303 
00304 //----------------------------------------------------------------------------
00305 //-- Add Bottom                                                            ---
00306 //----------------------------------------------------------------------------
00307 void vuBCCShearWarp::addBottom(wxSizer *sizer)
00308 {
00309 
00310 }
00311 
00312 //----------------------------------------------------------------------------
00313 //-- Initialize OpenGL                                                     ---
00314 //----------------------------------------------------------------------------
00315 bool vuBCCShearWarp::glInit(void)
00316 {
00317     if (m_Data == 0) return false;
00318 
00319     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00320 
00321     glEnable(GL_LIGHTING);
00322     glEnable(GL_LIGHT0);
00323     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00324 
00325     m_Data->initOpenGL();
00326 
00327     return true;
00328 }
00329 
00330 //----------------------------------------------------------------------------
00331 //-- Calls method render() of the data-object                              ---
00332 //----------------------------------------------------------------------------
00333 void vuBCCShearWarp::glRender()
00334 {
00335     wxStopWatch watch;
00336     watch.Start();
00337 
00338     m_Data->setViewVectors(m_Camera.getLookAtVector(),
00339                            m_Camera.getUpVector(),
00340                            m_Camera.getRightVector());
00341     m_Data->render();
00342 
00343     SetStatusText(wxString("RenderTime: ") + vuString(watch.Time()).c_str() + "ms");
00344 
00345 }
00346 
00347 //----------------------------------------------------------------------------
00348 //-- Resizes OpenGL-Viewport                                               ---
00349 //----------------------------------------------------------------------------
00350 void vuBCCShearWarp::glResize()
00351 {
00352     //Resize viewport.
00353     glViewport(0,0,(GLint)m_glCanvas->getWidth(),(GLint)m_glCanvas->getHeight());
00354 
00355     m_Data->setCanvasSize(m_glCanvas->getWidth(),m_glCanvas->getHeight());
00356     glInit();
00357 }
00358 
00359 //----------------------------------------------------------------------------
00360 //-- Check Box "Warp with OpenGL" selected                                 ---
00361 //----------------------------------------------------------------------------
00362 void vuBCCShearWarp::OnCheckBoxWarpOpenGL( wxCommandEvent& event)
00363 {
00364     if (event.IsChecked()) {
00365         m_Data->setOrthogonalWarpOpenGL(1);
00366     } else {
00367         m_Data->setOrthogonalWarpOpenGL(0);
00368     }
00369 }
00370 
00371 //----------------------------------------------------------------------------
00372 //-- Scrollbar for distance between eye and projection plane changed       ---
00373 //----------------------------------------------------------------------------
00374 #if wxMINOR_VERSION < 5
00375 void vuBCCShearWarp::OnScrollPerspective( wxCommandEvent& event) {
00376 #else
00377 void vuBCCShearWarp::OnScrollPerspective( wxScrollEvent& event) {
00378 #endif
00379     m_Data->setEyeDistance(m_Data->getMinEyeDistance() + 
00380                            (event.GetInt() * m_Data->getMaxSize() / 50));
00381     m_Data->render();
00382     m_glCanvas->redraw();
00383 }
00384 
00385 //----------------------------------------------------------------------------
00386 //-- Check Box "Specular light" selected                                   ---
00387 //----------------------------------------------------------------------------
00388 void vuBCCShearWarp::OnCheckBoxSpecular( wxCommandEvent& event)
00389 {
00390     if (event.IsChecked()) {
00391         m_Data->setSpecular(1);
00392     } else {
00393         m_Data->setSpecular(0);
00394     }
00395 }
00396 
00397 //----------------------------------------------------------------------------
00398 //-- Button "Apply Viewing" pressed                                        ---
00399 //----------------------------------------------------------------------------
00400 void vuBCCShearWarp::OnButtonApplyViewing( wxCommandEvent& event) 
00401 {
00402     // get the coordinates of the new viewing vector as string
00403     wxString viewXStr = viewXTextCtrl->GetValue();
00404     wxString viewYStr = viewYTextCtrl->GetValue();
00405     wxString viewZStr = viewZTextCtrl->GetValue();
00406 
00407     // get the coordinates of the new up vector as string
00408     wxString upXStr = upXTextCtrl->GetValue();
00409     wxString upYStr = upYTextCtrl->GetValue();
00410     wxString upZStr = upZTextCtrl->GetValue();
00411 
00412     bool success = true;
00413 
00414     // get the coordinates of the new viewing vector as double
00415     double viewXDouble = 0.0;
00416     double viewYDouble = 0.0;
00417     double viewZDouble = 0.0;
00418     if (viewXStr.ToDouble(&viewXDouble) == 0) success = false;
00419     if (viewYStr.ToDouble(&viewYDouble) == 0) success = false;
00420     if (viewZStr.ToDouble(&viewZDouble) == 0) success = false;
00421 
00422     // get the coordinates of the new up vector as double
00423     double upXDouble = 0.0;
00424     double upYDouble = 0.0;
00425     double upZDouble = 0.0;
00426     if (upXStr.ToDouble(&upXDouble) == 0) success = false;
00427     if (upYStr.ToDouble(&upYDouble) == 0) success = false;
00428     if (upZStr.ToDouble(&upZDouble) == 0) success = false;
00429 
00430     if (success) {
00431         vuVector newLookAtVector = vuVector((float)viewXDouble,
00432                                             (float)viewYDouble,
00433                                             (float)viewZDouble);
00434 
00435         vuVector newUpVector = vuVector((float)upXDouble,
00436                                         (float)upYDouble,
00437                                         (float)upZDouble);
00438 
00439         vuVector newRightVector = newLookAtVector.cross(newUpVector);
00440         newUpVector = newRightVector.cross(newLookAtVector);
00441 
00442         newLookAtVector.makeUnit();
00443         newUpVector.makeUnit();
00444 
00445         m_Camera.setLookAtVector(newLookAtVector);
00446         m_Camera.setUpVector(newUpVector);
00447 
00448         m_Data->setViewVectors(m_Camera.getLookAtVector(),
00449                                m_Camera.getUpVector(),
00450                                m_Camera.getRightVector());
00451 
00452         m_Data->render();
00453         m_glCanvas->redraw();
00454 
00455     } else {
00456         wxMessageDialog dlg(this,"The coordinates have to be numbers!","vuBCCShearWarp",wxOK);
00457         dlg.ShowModal();
00458     }
00459 }
00460 
00461 //----------------------------------------------------------------------------
00462 //-- Open transfer-function-editor                                         ---
00463 //----------------------------------------------------------------------------
00464 void vuBCCShearWarp::OnButtonTransferFunction( wxCommandEvent& event)
00465 {
00466     //Pop up the transfer function editor
00467     vuTransferDialog dlg(this,m_TFunc);
00468 
00469     if (dlg.ShowModal() == wxID_OK)
00470     {
00471         m_TFunc = dlg.getTransferFunc();
00472         m_Data->setTransferFunc(m_TFunc);
00473         m_Data->runlengthEncode();
00474         m_Data->render();
00475         m_glCanvas->redraw();
00476     }
00477 }
00478 
00479 //----------------------------------------------------------------------------
00480 //-- Radio Box "Projection" selected                                       ---
00481 //----------------------------------------------------------------------------
00482 void vuBCCShearWarp::OnRadioBoxProjection(wxCommandEvent &event) 
00483 {
00484     m_Data->setViewing(event.GetSelection());
00485     m_Data->render();
00486     m_glCanvas->redraw();
00487 }
00488 
00489 //----------------------------------------------------------------------------
00490 //-- Mouse event                                                           ---
00491 //----------------------------------------------------------------------------
00492 void vuBCCShearWarp::glOnMouse(wxMouseEvent &ev)
00493 {
00494     if (ev.LeftDown() || ev.RightDown())
00495     {
00496         //Store the click position.
00497         m_x = (int) ev.GetX();
00498         m_y = (int) ev.GetY();
00499     }
00500     else if (ev.LeftIsDown() && ev.Moving())
00501     {
00502         //Rotate the volume
00503         vuVector t = m_Camera.getPosition();
00504         float d = t.norm();
00505 
00506         m_Camera.translateXYZ(0.0f, 0.0f, d);
00507         m_Camera.rotateAboutUp((ev.GetX() - m_x));
00508         m_Camera.rotateAboutRight(m_y - ev.GetY());
00509 
00510         m_Camera.translateXYZ(0.0f, 0.0f, -d);
00511         glResize();
00512         m_glCanvas->redraw();
00513 
00514         //Store the click position.
00515         m_x = (int) ev.GetX();
00516         m_y = (int) ev.GetY();
00517     }
00518     else if (ev.RightIsDown() && ev.Moving())
00519     {
00520         //Zoom the volume.
00521         m_ViewScale -= ((float)ev.GetY() - m_y)/500.0f;
00522         m_Data->zoom(m_ViewScale);
00523         glResize();
00524         m_glCanvas->redraw();
00525 
00526         //Store the click position.
00527         m_x = (int) ev.GetX();
00528         m_y = (int) ev.GetY();
00529     } else if (ev.LeftDClick())
00530     {
00531         //Pop up the transfer function editor
00532         vuTransferDialog dlg(this,m_TFunc);
00533 
00534         if (dlg.ShowModal() == wxID_OK)
00535         {
00536             m_TFunc = dlg.getTransferFunc();
00537             m_Data->setTransferFunc(m_TFunc);
00538             m_Data->runlengthEncode();
00539             m_glCanvas->redraw();
00540             glResize();
00541         }
00542     }
00543 }
00544 
00545 
00546 
00547 
00548 
00549 
00550 
00551 
00552 
00553 
00554 
00555 
00556 

Generated on Wed Dec 15 21:20:33 2004 for vuVolume by  doxygen 1.3.9.1