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

vuSpecFVR.cpp

Go to the documentation of this file.
00001 #include <wx/wx.h>
00002 #include <wx/button.h>
00003 
00004 #include "vuSpecFVR.h"
00005 #include "vuColourRGBa.h"
00006 #include "vuMatrix.h"
00007 #include "vuArcBall.h"
00008 #include "vuPreviewWin.h"
00009 #include "vuColour31a.h"
00010 #include "vuColour7a.h"
00011 
00012 //----------------------------------------------------------------------------
00013 //------------------------- The vuSpecFVR event table -----------------------
00014 //----------------------------------------------------------------------------
00015 
00016 enum
00017 {
00018     idCANVAS,
00019     idRENDER,
00020     idLOADSETUP,
00021     idLGTINT,
00022     idLGTCOL,
00023     idLIGHTPOS,
00024     idTRANSFORM,
00025 };
00026 
00027 BEGIN_EVENT_TABLE(vuSpecFVR, vuBasicUtility)
00028     EVT_COMMAND_SCROLL(idLGTINT, vuSpecFVR::OnSlideLight)
00029     EVT_COMMAND_SCROLL(idLGTCOL, vuSpecFVR::OnSlideLight)
00030     EVT_BUTTON  (idRENDER, vuSpecFVR::OnButtonRender)
00031     EVT_BUTTON  (idLIGHTPOS, vuSpecFVR::OnButtonLightPos)
00032     EVT_BUTTON  (idTRANSFORM, vuSpecFVR::OnButtonTransform)
00033 END_EVENT_TABLE();
00034 
00035 //----------------------------------------------------------------------------
00036 //------------------------- The constructor ----------------------------------
00037 //----------------------------------------------------------------------------
00038 
00039 vuSpecFVR::vuSpecFVR() : m_TFunc(32), m_TFuncDlg(this, m_TFunc),
00040                            m_LightDial(this, m_TFunc)
00041 {
00042     m_Data = NULL;
00043     m_DrawBBox = false;
00044 }
00045 
00046 //----------------------------------------------------------------------------
00047 //------------------------- The destructor -----------------------------------
00048 //----------------------------------------------------------------------------
00049 
00050 vuSpecFVR::~vuSpecFVR()
00051 {
00052     if (m_Data != 0) delete m_Data;
00053 }
00054 
00055 //----------------------------------------------------------------------------
00056 //------------------------- public: getFileType() ----------------------------
00057 //----------------------------------------------------------------------------
00058 
00059 const char* vuSpecFVR::getFileType()
00060 {
00061     return "11121";
00062 }
00063 
00064 //----------------------------------------------------------------------------
00065 //------------------------- public: init() -----------------------------------
00066 //----------------------------------------------------------------------------
00067 
00068 bool vuSpecFVR::init(const char* DataFile)
00069 {
00070     //Set up the window
00071     SetTitle("Spectral Volume Rendering");
00072     CreateStatusBar();
00073 
00074 
00075     //Create a volume data instance.
00076     m_Data = new vu1112118;
00077     m_Data->setFileName(DataFile);
00078 
00079     //Set the transfer function for the data.
00080     m_TFunc.addOpacity(  0, 0.0f);
00081     m_TFunc.addOpacity(255, 1.0f);
00082     m_TFunc.addColour(  0,vuColour31a(0.0f));
00083     m_TFunc.addColour(255,vuColour31a(1.0f));
00084     m_TFunc.setOpacitySmoothing(0);
00085     m_TFunc.setColourSmoothing(1.0f);
00086     m_TFunc.generateFunction();
00087     //don't set it yet
00088     //m_Data->setTransferFunc(m_TFunc);
00089 
00090     //Read in the data.
00091     bool success = m_Data->read();
00092     if (success)
00093     {
00094         m_glCanvas->SetSize(512,512);
00095         Fit();
00096 /*
00097         m_Preview->attachCamera(&m_Data->getCamera());
00098         m_Preview->setCubeSize(m_Data->getDim1Size(),
00099                                m_Data->getDim2Size(),
00100                                m_Data->getDim3Size());
00101 */
00102     }
00103     else
00104     {
00105         wxMessageDialog dlg(this,m_Data->getErrorMessage(),"vuSpecFVRVR",wxOK);
00106         dlg.ShowModal();
00107     }
00108 
00109     return success;
00110 }
00111 
00112 //----------------------------------------------------------------------------
00113 //------------------------- public: addRight() -------------------------------
00114 //----------------------------------------------------------------------------
00115 
00116 void vuSpecFVR::addRight(wxSizer *sizer)
00117 {
00118   //Add some control elements
00119     sizer->Add( new wxButton(this, idRENDER, "Render"),
00120                 0,           // make horizontally unstretchable
00121                 wxALL,       // make border all around (implicit top alignment)
00122                 10 );        // set border width to 10
00123     sizer->Add( new wxButton(this, idLIGHTPOS, "Place Light"),
00124                 0, wxALL, 10 );
00125     sizer->Add( new wxButton(this, idTRANSFORM, "Preprocess"),
00126                 0, wxALL, 10 );
00127 }
00128 
00129 //----------------------------------------------------------------------------
00130 //------------------------- public: OnSlideLight() -----------------
00131 //----------------------------------------------------------------------------
00132 
00133 void vuSpecFVR::OnSlideLight( wxScrollEvent& event)
00134 {
00135     // int w = m_LightColour->GetValue();
00136     //int l = m_LightIntensity->GetValue();
00137   m_glCanvas->redraw();
00138 }
00139 
00140 //----------------------------------------------------------------------------
00141 //------------------------- public: OnButtonRender() -------------------------
00142 //----------------------------------------------------------------------------
00143 
00144 void vuSpecFVR::OnButtonRender( wxCommandEvent& event)
00145 {
00146     m_Data->doRefresh();
00147     m_glCanvas->redraw();
00148 }
00149 
00150 void vuSpecFVR::OnButtonTransform( wxCommandEvent& event)
00151 {
00152     m_Data->doSpectral();       // enable spectral transfer functions
00153     m_Data->setTransferFunc(m_TFunc);
00154     m_Data->preprocess();
00155     m_Data->doRefresh();
00156     m_glCanvas->redraw();
00157 }
00158 
00160 void vuSpecFVR::OnChar(wxKeyEvent& event)
00161 {
00162     m_Data->keyboard(event.GetKeyCode(),0,0);
00163     m_glCanvas->redraw();
00164 }
00165 
00166 void vuSpecFVR::notifyDataChanged()
00167 {
00168     m_glCanvas->redraw();
00169 }
00170 
00171 //----------------------------------------------------------------------------
00172 //------------------------- protected: glInit() ------------------------------
00173 //----------------------------------------------------------------------------
00174 
00175 bool vuSpecFVR::glInit(void)
00176 {
00177     if (m_Data == 0) return false;
00178   /*
00179     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00180 
00181     glEnable(GL_LIGHTING);
00182     glEnable(GL_LIGHT0);
00183     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00184   */
00185     glEnable(GL_DEPTH_TEST);
00186     glDepthFunc(GL_LESS);
00187 
00188     return true;
00189 };
00190 
00191 //----------------------------------------------------------------------------
00192 //------------------------- protected: glRender() ----------------------------
00193 //----------------------------------------------------------------------------
00194 void vuSpecFVR::glRender()
00195 {
00196     if(m_TFuncDlg.isUpdated() || m_LightDial.isUpdated()) {
00197         m_TFuncDlg.unsetUpdated();
00198         vuColour31a light(m_TFunc.getLight());
00199         //light /= vuColourXYZa(light)[1]; no constant light intensity
00200         m_Data->setLight(light);
00201         m_Data->doSpectral();   //enable spectral transfer function
00202         m_Data->setTransferFunc(m_TFunc);
00203     }
00204     
00205     wxStopWatch watch;
00206     watch.Start();
00207     
00208     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
00209     glMatrixMode(GL_PROJECTION);
00210     glLoadIdentity();
00211     glOrtho(0,m_glCanvas->getWidth(),
00212                 0,m_glCanvas->getHeight(),-1,1);
00213     glMatrixMode(GL_MODELVIEW);
00214     glLoadIdentity();
00215     
00216     m_Data->render();
00217     
00218     watch.Pause();
00219     SetStatusText(wxString("Render Time: ") + vuString(watch.Time()).c_str() + "ms");
00220 }
00221 
00222 
00223 //----------------------------------------------------------------------------
00224 //------------------------- protected: glResize() ----------------------------
00225 //----------------------------------------------------------------------------
00226 
00227 void vuSpecFVR::glResize()
00228 {
00229     glViewport(0, 0, (GLint)m_glCanvas->getWidth(),(GLint)m_glCanvas->getHeight());
00230     m_Data->resize(m_glCanvas->getWidth(),m_glCanvas->getHeight());
00231 }
00232 
00233 //----------------------------------------------------------------------------
00234 //------------------------- protected: glOnMouse() ---------------------------
00235 //----------------------------------------------------------------------------
00236 
00237 void vuSpecFVR::glOnMouse(wxMouseEvent &ev)
00238 {
00239     if(!m_Data) return;
00240     if (ev.LeftDown() || ev.RightDown())
00241     {
00242         //Store the click position.
00243         m_x = (int) ev.GetX();
00244         m_y = (int) ev.GetY();
00245     }
00246     else if (ev.LeftIsDown() && ev.Moving())
00247     {
00248         //Rotate the volume
00249         vuVector t = m_Data->getCamera().getPosition()-m_Data->getCenter();
00250         float d = t.norm();
00251         m_Data->getCamera().translateXYZ(0.0f, 0.0f, d);
00252         t = m_Data->getCamera().getPosition();
00253         //use the arc ball
00254         vuArcBall ball;
00255         ball.attachCamera(m_Data->getCamera());
00256         ball.setWinSize(m_glCanvas->getWidth(),m_glCanvas->getHeight());
00257         ball.turn(m_x, m_y, ev.GetX(), ev.GetY());
00258         //m_Data->getCamera().rotateAboutUp(ev.GetX() - m_x);
00259         //m_Data->getCamera().rotateAboutRight(ev.GetY() - m_y);
00260         m_Data->getCamera().translateXYZ(0.0f, 0.0f, -d);
00261         m_Data->doRefresh();
00262         m_glCanvas->redraw();
00263         
00264         //Store the click position.
00265         m_x = (int) ev.GetX();
00266         m_y = (int) ev.GetY();
00267     }
00268     else if (ev.LeftDClick())
00269     {
00270         m_TFuncDlg.Show(true);
00271     } else if (ev.RightDClick())
00272     {
00273         m_LightDial.Show(true);
00274     } 
00275 }
00276 
00277 vuCamera* vuSpecFVR::getCamera ()
00278 {
00279     return &m_Data->getCamera();
00280 }
00281 
00282 vuImage* vuSpecFVR::getCurrentImage ()
00283 
00284 {
00285         return m_Data->getImage ();
00286 //      return NULL;
00287 }
00288 
00289 void vuSpecFVR::DrawAgain()
00290 
00291 {
00292 //      cout << "vuRaycast::notifyDataChanged ()" << endl;
00293 
00294     m_Data->doRefresh();
00295     m_glCanvas->redraw();
00296     
00297 //      glRender ();
00298 }
00299 
00300 void vuSpecFVR::DrawFromImage ()
00301 
00302 {
00303 //      m_Data->displayFromImage ();
00304 //      m_Data->render ();
00305         m_glCanvas->redraw ();
00306 }
00307 
00308 void vuSpecFVR::handleGUIevent(wxCommandEvent& ev)
00309 {
00310     switch(ev.GetId()) {
00311         default:
00312             break;
00313     }
00314 }
00315 
00316 void vuSpecFVR::OnButtonLightPos(wxCommandEvent& ev) {
00317     vuVector v(m_Data->getCenter());
00318     v-=getCamera()->getPosition();
00319     v.makeUnit();
00320     v*=-1.0f;
00321     m_Data->setLightDir(v);
00322 }

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