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

vuBCCFirstHitRaycaster.cpp

Go to the documentation of this file.
00001 #include "vuBCCFirstHitRaycaster.h"
00002 #include "../../wxUIElements/vuTransferDialog.h"
00003 #include <wx/wx.h>
00004 #include <wx/button.h>
00005 
00006 //----------------------------------------------------------------------------
00007 //------------------------- The vuBCCFirstHitRaycasterBCC event table --------------------------
00008 //----------------------------------------------------------------------------
00009 
00010 enum
00011 {
00012   idCANVAS,
00013   idRENDER,
00014   idLGTINT,
00015   idLGTCOL
00016 };
00017 
00018 BEGIN_EVENT_TABLE(vuBCCFirstHitRaycaster, vuBasicUtility)
00019   EVT_COMMAND_SCROLL(idLGTINT, vuBCCFirstHitRaycaster::OnLightChangeIntensity)
00020   EVT_COMMAND_SCROLL(idLGTCOL, vuBCCFirstHitRaycaster::OnLightChangeColour)
00021   EVT_BUTTON  (idRENDER, vuBCCFirstHitRaycaster::OnButtonRender)
00022 END_EVENT_TABLE()
00023 
00024 //----------------------------------------------------------------------------
00025 //------------------------- The constructor ----------------------------------
00026 //----------------------------------------------------------------------------
00027 
00028 vuBCCFirstHitRaycaster::vuBCCFirstHitRaycaster() : m_TFunc(4,256)
00029 {
00030     m_Data = 0;
00031     m_ViewScale = 1.0f;
00032 }
00033 
00034 //----------------------------------------------------------------------------
00035 //------------------------- The destructor -----------------------------------
00036 //----------------------------------------------------------------------------
00037 
00038 vuBCCFirstHitRaycaster::~vuBCCFirstHitRaycaster()
00039 {
00040     if (m_Data != 0) delete m_Data;
00041 }
00042 
00043 //----------------------------------------------------------------------------
00044 //------------------------- public: getFileType() ----------------------------
00045 //----------------------------------------------------------------------------
00046 
00047 const char* vuBCCFirstHitRaycaster::getFileType()
00048 {
00049     return "15121";
00050 }
00051 
00052 //----------------------------------------------------------------------------
00053 //------------------------- public: init() -----------------------------------
00054 //----------------------------------------------------------------------------
00055 
00056 bool vuBCCFirstHitRaycaster::init(const char* DataFile)
00057 {
00058     SetEvtHandlerEnabled(true);
00059 
00060     //Set up the window
00061     SetTitle("FirstHitRaycasterBCC Volume Rendering");
00062     CreateStatusBar();
00063 
00064     //Create a volume data instance.
00065     m_Data = new vu1512122;
00066     m_Data->setFileName(DataFile);
00067 
00068     //Read in the data.
00069     bool success = m_Data->read();
00070     if (success)
00071     {
00072         m_glCanvas->SetSize(512,512);
00073         Fit();
00074     }
00075     else
00076     {
00077         wxMessageDialog dlg(this,m_Data->getErrorMessage(),"vuBCCFirstHitRaycasterBCCVR",wxOK);
00078         dlg.ShowModal();
00079     }
00080 
00081     return success;
00082 };
00083 
00084 void vuBCCFirstHitRaycaster::DrawAgain ()
00085 {
00086     m_DrawPreview = false;
00087     m_Data->refresh = true;
00088     m_glCanvas->redraw();
00089 }
00090 
00091 void vuBCCFirstHitRaycaster::DrawFromImage ()
00092 {
00093         m_glCanvas->redraw ();
00094 }
00095 
00096 vuImage* vuBCCFirstHitRaycaster::getCurrentImage ()
00097 {
00098         return m_Data->getImage();
00099 }
00100 
00101 vuCamera* vuBCCFirstHitRaycaster::getCamera ()
00102 {
00103     return m_Data->getCameraPtr();
00104 }
00105 
00106 //----------------------------------------------------------------------------
00107 //------------------------- public: addBottom() ------------------------------
00108 //----------------------------------------------------------------------------
00109 
00110 void vuBCCFirstHitRaycaster::addBottom(wxSizer *sizer)
00111 {
00112   //Add some control elements
00113   sizer->Add( new wxStaticText( this, -1, "Colour", wxDefaultPosition, wxSize(50,30)),
00114               1,            // make vertically stretchable
00115               wxEXPAND,     // make horizontally stretchable
00116               10 );         // set border width to 10
00117   
00118   sizer->Add( m_LightColour = new wxSlider(this, idLGTCOL, 50, 0, 100, 
00119                                            wxDefaultPosition, wxSize(300,30), wxSL_HORIZONTAL, 
00120                                            wxDefaultValidator, "slider"),
00121               1,
00122               wxALL,
00123               10 );
00124   sizer->Add( new wxStaticText( this, -1, "Intensity", wxDefaultPosition, wxSize(50,30)),
00125               1,            // make vertically stretchable
00126               wxEXPAND,     // make horizontally stretchable
00127               10 );         // set border width to 10
00128   
00129   sizer->Add( m_LightIntensity = new wxSlider(this, idLGTINT, 50, 0, 100, 
00130                                               wxDefaultPosition, wxSize(300,30), wxSL_HORIZONTAL, 
00131                                               wxDefaultValidator, "slider"),
00132               1,
00133               wxALL,
00134               10 );
00135 
00136   sizer->Add( new wxButton(this, idRENDER, "Render"),
00137                  0,           // make horizontally unstretchable
00138                  wxALL,       // make border all around (implicit top alignment)
00139                  10 );        // set border width to 10    
00140 }
00141 
00142 //----------------------------------------------------------------------------
00143 //------------------------- public: OnLightChangeIntensity() -----------------
00144 //----------------------------------------------------------------------------
00145 
00146 void vuBCCFirstHitRaycaster::OnLightChangeIntensity( wxScrollEvent& event)
00147 {
00148   cout<<"intensity "<<event.GetPosition()<<endl;
00149 }
00150 
00151 //----------------------------------------------------------------------------
00152 //------------------------- public: OnLightChangeColour() --------------------
00153 //----------------------------------------------------------------------------
00154 
00155 void vuBCCFirstHitRaycaster::OnLightChangeColour( wxScrollEvent& event)
00156 {
00157   cout<<"colour "<<event.GetPosition()<<endl;
00158 }
00159 
00160 //----------------------------------------------------------------------------
00161 //------------------------- public: OnButtonRender() -------------------------
00162 //----------------------------------------------------------------------------
00163 
00164 void vuBCCFirstHitRaycaster::OnButtonRender( wxCommandEvent& event)
00165 {
00166     m_Data->setIsReRendering(true);
00167     m_DrawPreview = false;
00168     m_Data->refresh = true;
00169     m_glCanvas->redraw();
00170 }
00171 
00172 //----------------------------------------------------------------------------
00173 //------------------------- protected: glInit() ------------------------------
00174 //----------------------------------------------------------------------------
00175 
00176 bool vuBCCFirstHitRaycaster::glInit(void)
00177 {
00178   /*
00179     if (m_Data == 0) return false;
00180 
00181     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00182 
00183     glEnable(GL_LIGHTING);
00184     glEnable(GL_LIGHT0);
00185     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00186   */
00187   m_Data->initOpenGL();
00188 
00189   return true;
00190 }
00191 
00192 //----------------------------------------------------------------------------
00193 //------------------------- protected: glRender() ----------------------------
00194 //----------------------------------------------------------------------------
00195 
00196 void vuBCCFirstHitRaycaster::onRender()
00197 {
00198   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
00199   glMatrixMode(GL_PROJECTION);
00200   glLoadIdentity();
00201   glOrtho(0,m_Data->getCamera().getWidth(),
00202           0,m_Data->getCamera().getHeight(), -1, 1);
00203   glMatrixMode(GL_MODELVIEW);
00204   glLoadIdentity();
00205 
00206     wxStopWatch watch;
00207     watch.Start();
00208 
00209     m_Data->render();
00210 
00211     watch.Pause();
00212     SetStatusText(wxString("Render Time: ") + vuString(watch.Time()).c_str() + "ms");
00213 }
00214 
00215 //----------------------------------------------------------------------------
00216 //------------------------- protected: glResize() ----------------------------
00217 //----------------------------------------------------------------------------
00218 
00219 void vuBCCFirstHitRaycaster::glResize()
00220 {
00221     //Set the viewport.
00222     glViewport(0, 0, (GLint)m_glCanvas->getWidth(),(GLint)m_glCanvas->getHeight());
00223     m_Data->setImageSize(m_glCanvas->getWidth(),m_glCanvas->getHeight());
00224     
00225   /*
00226     //Find the largest dimension of the data.
00227     dword max = m_Data->getDim1Size();
00228     if (m_Data->getDim2Size() > max)
00229         max = m_Data->getDim2Size();
00230     if (m_Data->getDim3Size() > max)
00231         max = m_Data->getDim3Size();
00232 
00233     //Set the opengl projection matrix.
00234     glMatrixMode(GL_PROJECTION);
00235     glLoadIdentity();
00236     glOrtho((float)max/(-1.0f*m_ViewScale), (float)max/m_ViewScale,
00237             (float)max/(-1.0f*m_ViewScale), (float)max/m_ViewScale,
00238             10000.0f, -10000.0f);
00239     glMatrixMode(GL_MODELVIEW);
00240     glLoadIdentity();
00241     
00242     //Set the opengl light info.
00243     float lpos[4] = {0.0, 0.0, 1024.0, 1.0};
00244     glLightfv(GL_LIGHT0, GL_POSITION, lpos);
00245   */
00246 }
00247 
00248 //----------------------------------------------------------------------------
00249 //------------------------- protected: glOnMouse() ---------------------------
00250 //----------------------------------------------------------------------------
00251 
00252 void vuBCCFirstHitRaycaster::onMouse(wxMouseEvent &ev)
00253 {
00254 /* -- this is aready done in vuBasicUtility
00255     vuCamera *cam = getCamera();
00256     if (ev.LeftDown() || ev.RightDown())
00257     {
00258         //Store the click position.
00259         m_x = (int) ev.GetX();
00260         m_y = (int) ev.GetY();
00261     }
00262     else if (ev.LeftIsDown() && ev.Moving())
00263     {
00264         //Rotate the volume
00265         vuVector t = cam->getPosition();
00266         float d = t.norm();
00267 
00268         cam->translateXYZ(0.0f, 0.0f, d);
00269         cam->rotateAboutUp(ev.GetX() - m_x);
00270         cam->rotateAboutRight(ev.GetY() - m_y);
00271         cam->translateXYZ(0.0f, 0.0f, -d);
00272         //m_glCanvas->redraw();
00273 
00274         //Store the click position.
00275         m_x = (int) ev.GetX();
00276         m_y = (int) ev.GetY();
00277     }
00278     else if (ev.RightIsDown() && ev.Moving())
00279     {
00280         //Zoom the volume.
00281         m_ViewScale -= ((float)ev.GetY() - m_y)/500.0f;
00282         glResize();
00283         //m_glCanvas->redraw();
00284 
00285         //Store the click position.
00286         m_x = (int) ev.GetX();
00287         m_y = (int) ev.GetY();
00288     }
00289 */
00290 }
00291 

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