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

vuBCCRaycaster.cpp

Go to the documentation of this file.
00001 #include "vuBCCRaycaster.h"
00002 #include <wx/wx.h>
00003 #include <wx/button.h>
00004 
00005 //----------------------------------------------------------------------------
00006 //------------------------- The vuBCCRaycasterBCC event table --------------------------
00007 //----------------------------------------------------------------------------
00008 
00009 enum
00010 {
00011   idCANVAS,
00012   idRENDER,
00013   idLGTINT,
00014   idLGTCOL
00015 };
00016 
00017 BEGIN_EVENT_TABLE(vuBCCRaycaster, vuBasicUtility)
00018   EVT_BUTTON  (idRENDER, vuBCCRaycaster::OnButtonRender)
00019 END_EVENT_TABLE();
00020 
00021 //----------------------------------------------------------------------------
00022 //------------------------- The constructor ----------------------------------
00023 //----------------------------------------------------------------------------
00024 
00025 vuBCCRaycaster::vuBCCRaycaster() : m_TFunc(4,256), m_TFuncDlg(this, m_TFunc)
00026 {
00027     m_Data = 0;
00028     m_ViewScale = 1.0f;
00029 }
00030 
00031 //----------------------------------------------------------------------------
00032 //------------------------- The destructor -----------------------------------
00033 //----------------------------------------------------------------------------
00034 
00035 vuBCCRaycaster::~vuBCCRaycaster()
00036 {
00037     if (m_Data != 0) delete m_Data;
00038 }
00039 
00040 //----------------------------------------------------------------------------
00041 //------------------------- public: getFileType() ----------------------------
00042 //----------------------------------------------------------------------------
00043 
00044 const char* vuBCCRaycaster::getFileType()
00045 {
00046     return "15121";
00047 }
00048 
00049 //----------------------------------------------------------------------------
00050 //------------------------- public: init() -----------------------------------
00051 //----------------------------------------------------------------------------
00052 
00053 bool vuBCCRaycaster::init(const char* DataFile)
00054 {
00055     SetEvtHandlerEnabled(true);
00056 
00057     //Set up the window
00058     SetTitle("Raycaster BCC Volume Rendering");
00059     CreateStatusBar();
00060 
00061     //Create a volume data instance.
00062     m_Data = new vu1512113;
00063     m_Data->setFileName(DataFile);
00064 
00065     //Read in the data.
00066     bool success = m_Data->read();
00067     if (success)
00068     {
00069         m_glCanvas->SetSize(512,512);
00070         Fit();
00071     }
00072     else
00073     {
00074         wxMessageDialog dlg(this,m_Data->getErrorMessage(),"vuBCCRaycasterBCCVR",wxOK);
00075         dlg.ShowModal();
00076     }
00077 
00078     return success;
00079 };
00080 
00081 void vuBCCRaycaster::DrawAgain ()
00082 {
00083     m_DrawPreview = false;
00084     m_Data->refresh = true;
00085     m_glCanvas->redraw();
00086 }
00087 
00088 void vuBCCRaycaster::DrawFromImage ()
00089 {
00090         m_glCanvas->redraw ();
00091 }
00092 
00093 vuImage* vuBCCRaycaster::getCurrentImage ()
00094 {
00095         return m_Data->getImage();
00096 }
00097 
00098 vuCamera* vuBCCRaycaster::getCamera ()
00099 {
00100     return m_Data->getCameraPtr();
00101 }
00102 
00103 //----------------------------------------------------------------------------
00104 //------------------------- public: addBottom() ------------------------------
00105 //----------------------------------------------------------------------------
00106 
00107 void vuBCCRaycaster::addBottom(wxSizer *sizer)
00108 {
00109 
00110   sizer->Add( new wxButton(this, idRENDER, "Render"),
00111                  0,           // make horizontally unstretchable
00112                  wxALL,       // make border all around (implicit top alignment)
00113                  10 );        // set border width to 10    
00114 }
00115 
00116 //----------------------------------------------------------------------------
00117 //------------------------- public: OnButtonRender() -------------------------
00118 //----------------------------------------------------------------------------
00119 
00120 void vuBCCRaycaster::OnButtonRender( wxCommandEvent& event)
00121 {
00122     m_Data->setIsReRendering(true);
00123     m_DrawPreview = false;
00124     m_Data->refresh = true;
00125     m_glCanvas->redraw();
00126 }
00127 
00128 //----------------------------------------------------------------------------
00129 //------------------------- protected: glInit() ------------------------------
00130 //----------------------------------------------------------------------------
00131 
00132 bool vuBCCRaycaster::glInit(void)
00133 {
00134   /*
00135     if (m_Data == 0) return false;
00136 
00137     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00138 
00139     glEnable(GL_LIGHTING);
00140     glEnable(GL_LIGHT0);
00141     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00142   */
00143   m_Data->initOpenGL();
00144 
00145   return true;
00146 }
00147 
00148 //----------------------------------------------------------------------------
00149 //------------------------- protected: glRender() ----------------------------
00150 //----------------------------------------------------------------------------
00151 
00152 void vuBCCRaycaster::onRender()
00153 {
00154   m_Data->setTransferFunc(m_TFunc);     // better once too often :-|
00155 
00156   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
00157   glMatrixMode(GL_PROJECTION);
00158   glLoadIdentity();
00159   glOrtho(0,m_Data->getCamera().getWidth(),
00160           0,m_Data->getCamera().getHeight(), -1, 1);
00161   glMatrixMode(GL_MODELVIEW);
00162   glLoadIdentity();
00163 
00164     wxStopWatch watch;
00165     watch.Start();
00166 
00167     m_Data->render();
00168 
00169     watch.Pause();
00170     SetStatusText(wxString("Render Time: ") + vuString(watch.Time()).c_str() + "ms");
00171 }
00172 
00173 //----------------------------------------------------------------------------
00174 //------------------------- protected: glResize() ----------------------------
00175 //----------------------------------------------------------------------------
00176 
00177 void vuBCCRaycaster::glResize()
00178 {
00179     //Set the viewport.
00180     glViewport(0, 0, (GLint)m_glCanvas->getWidth(),(GLint)m_glCanvas->getHeight());
00181     m_Data->setImageSize(m_glCanvas->getWidth(),m_glCanvas->getHeight());
00182     
00183   /*
00184     //Find the largest dimension of the data.
00185     dword max = m_Data->getDim1Size();
00186     if (m_Data->getDim2Size() > max)
00187         max = m_Data->getDim2Size();
00188     if (m_Data->getDim3Size() > max)
00189         max = m_Data->getDim3Size();
00190 
00191     //Set the opengl projection matrix.
00192     glMatrixMode(GL_PROJECTION);
00193     glLoadIdentity();
00194     glOrtho((float)max/(-1.0f*m_ViewScale), (float)max/m_ViewScale,
00195             (float)max/(-1.0f*m_ViewScale), (float)max/m_ViewScale,
00196             10000.0f, -10000.0f);
00197     glMatrixMode(GL_MODELVIEW);
00198     glLoadIdentity();
00199     
00200     //Set the opengl light info.
00201     float lpos[4] = {0.0, 0.0, 1024.0, 1.0};
00202     glLightfv(GL_LIGHT0, GL_POSITION, lpos);
00203   */
00204 }
00205 
00206 //----------------------------------------------------------------------------
00207 //------------------------- protected: glOnMouse() ---------------------------
00208 //----------------------------------------------------------------------------
00209 
00210 void vuBCCRaycaster::onMouse(wxMouseEvent &ev)
00211 {
00212   if(!m_Data) return;
00213 
00214   if (ev.LeftDClick()) {
00215     m_TFuncDlg.Show(true);
00216   }
00217 }
00218 

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