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

vuBCCMarchingTetrahedra.cpp

Go to the documentation of this file.
00001 #include "../../wxUIElements/vuGLCanvas.h"
00002 #include <wx/wx.h>
00003 
00004 #include "vuBCCMarchingTetrahedra.h"
00005 #include "../../wxUIElements/vuTransferDialog.h"
00006 
00007 //----------------------------------------------------------------------------
00008 //------------------------- The vuBCCMarchingTetrahedra event table --------------------------
00009 //----------------------------------------------------------------------------
00010 
00011 enum
00012   {
00013     idCANVAS
00014   };
00015 
00016 BEGIN_EVENT_TABLE(vuBCCMarchingTetrahedra, vuBasicUtility)
00017   END_EVENT_TABLE()
00018 
00019   //----------------------------------------------------------------------------
00020   //------------------------- The constructor ----------------------------------
00021   //----------------------------------------------------------------------------
00022 
00023   vuBCCMarchingTetrahedra::vuBCCMarchingTetrahedra(void)
00024 {
00025   m_Data = 0;
00026   m_ViewScale = 1.0f;
00027 }
00028 
00029 //----------------------------------------------------------------------------
00030 //------------------------- The destructor -----------------------------------
00031 //----------------------------------------------------------------------------
00032 
00033 vuBCCMarchingTetrahedra::~vuBCCMarchingTetrahedra(void)
00034 {
00035   if (m_Data != 0) delete m_Data;
00036 }
00037 
00038 //----------------------------------------------------------------------------
00039 //------------------------- public: getFileType() ----------------------------
00040 //----------------------------------------------------------------------------
00041 
00042 const char* vuBCCMarchingTetrahedra::getFileType(void)
00043 {
00044   return "15121";
00045 }
00046 
00047 //----------------------------------------------------------------------------
00048 //------------------------- public: init() -----------------------------------
00049 //----------------------------------------------------------------------------
00050 
00051 bool vuBCCMarchingTetrahedra::init(const char* DataFile)
00052 {
00053   //Set up the window for the splatter.
00054   SetTitle("MarchingTetrahedra");
00055   CreateStatusBar();
00056 
00057   //Create a volume data instance.
00058   m_Data = new vu1512121;
00059   m_Data->setFileName(DataFile);
00060 
00061   //Read in the data.
00062   bool success = m_Data->read();
00063   if (success)
00064     {
00065       m_glCanvas->SetSize(512,512);
00066       Fit();
00067     }
00068   else
00069     {
00070       wxMessageDialog dlg(this,m_Data->getErrorMessage(),"vuBCCMarchingTetrahedra",wxOK);
00071       dlg.ShowModal();
00072     }
00073 
00074   return success;
00075 }
00076 
00077 void vuBCCMarchingTetrahedra::DrawAgain ()
00078 
00079 {
00080 }
00081 
00082 void vuBCCMarchingTetrahedra::DrawFromImage ()
00083 
00084 {
00085 }
00086 
00087 vuImage* vuBCCMarchingTetrahedra::getCurrentImage ()
00088 
00089 {
00090         return NULL;
00091 }
00092 
00093 vuCamera* vuBCCMarchingTetrahedra::getCamera ()
00094 
00095 {
00096         return &m_Camera;
00097 }
00098 
00099 //----------------------------------------------------------------------------
00100 //------------------------- protected: glInit() ------------------------------
00101 //----------------------------------------------------------------------------
00102 
00103 bool vuBCCMarchingTetrahedra::glInit(void)
00104 {
00105   if (m_Data == 0) return false;
00106 
00107   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00108 
00109   glEnable(GL_LIGHTING);
00110   glEnable(GL_LIGHT0);
00111   glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00112 
00113   //m_Data->initOpenGL();
00114   return true;
00115 }
00116 
00117 //----------------------------------------------------------------------------
00118 //------------------------- protected: glRender() ----------------------------
00119 //----------------------------------------------------------------------------
00120 
00121 void vuBCCMarchingTetrahedra::glRender()
00122 {
00123   wxStopWatch watch;
00124   watch.Start();
00125 
00126   glClear(GL_COLOR_BUFFER_BIT);
00127 
00128   glLoadIdentity();
00129   m_Camera.gluLookAt();
00130   glTranslatef((float)m_Data->getDim1Size()/(-2.0f),
00131                (float)m_Data->getDim2Size()/(-2.0f),
00132                (float)m_Data->getDim3Size()/(-2.0f));
00133 
00134   m_Data->setViewVectors(m_Camera.getLookAtVector(),
00135                          m_Camera.getUpVector(),
00136                          m_Camera.getRightVector());
00137 
00138   m_Data->resetNTriangles();
00139   m_Data->render();
00140 
00141   watch.Pause();
00142   SetStatusText(wxString("Render Time: ") + vuString(watch.Time()).c_str() + "ms" + " (" + vuString(m_Data->getNTriangles()).c_str() + " triangles)");
00143 }
00144 
00145 //----------------------------------------------------------------------------
00146 //------------------------- protected: glResize() ----------------------------
00147 //----------------------------------------------------------------------------
00148 
00149 void vuBCCMarchingTetrahedra::glResize()
00150 {
00151   //Set the viewport.
00152   glViewport(0, 0, (GLint)m_glCanvas->getWidth(),(GLint)m_glCanvas->getHeight());
00153     
00154   //Find the largest dimension of the data.
00155   dword max = m_Data->getDim1Size();
00156   if (m_Data->getDim2Size() > max)
00157     max = m_Data->getDim2Size();
00158   if (m_Data->getDim3Size() > max)
00159     max = m_Data->getDim3Size();
00160 
00161   //Set the opengl projection matrix.
00162   glMatrixMode(GL_PROJECTION);
00163   glLoadIdentity();
00164   glOrtho((float)max/(-1.0f*m_ViewScale), (float)max/m_ViewScale,
00165           (float)max/(-1.0f*m_ViewScale), (float)max/m_ViewScale,
00166           10000.0f, -10000.0f);
00167   glMatrixMode(GL_MODELVIEW);
00168   glLoadIdentity();
00169     
00170   //Set the opengl light info.
00171   float lpos[4] = {0.0, 0.0, 1024.0, 1.0};
00172   glLightfv(GL_LIGHT0, GL_POSITION, lpos);
00173 }
00174 
00175 //----------------------------------------------------------------------------
00176 //------------------------- protected: glOnMouse() ---------------------------
00177 //----------------------------------------------------------------------------
00178 
00179 void vuBCCMarchingTetrahedra::glOnMouse(wxMouseEvent &ev)
00180 {
00181   if (ev.LeftDown() || ev.RightDown() || ev.MiddleDown())
00182     {
00183       //Store the click position.
00184       m_x = (int) ev.GetX();
00185       m_y = (int) ev.GetY();
00186     }
00187   else if (ev.LeftIsDown() && ev.Moving())
00188     {
00189       //Rotate the volume
00190       vuVector t = m_Camera.getPosition();
00191       float d = t.norm();
00192 
00193       m_Camera.translateXYZ(0.0f, 0.0f, d);
00194       m_Camera.rotateAboutUp(ev.GetX() - m_x);
00195       m_Camera.rotateAboutRight(ev.GetY() - m_y);
00196       m_Camera.translateXYZ(0.0f, 0.0f, -d);
00197       m_glCanvas->redraw();
00198 
00199       //Store the click position.
00200       m_x = (int) ev.GetX();
00201       m_y = (int) ev.GetY();
00202     }
00203   else if (ev.RightIsDown() && ev.Moving())
00204     {
00205       //Zoom the volume.
00206       m_ViewScale -= ((float)ev.GetY() - m_y)/500.0f;
00207       glResize();
00208       m_glCanvas->redraw();
00209 
00210       //Store the click position.
00211       m_x = (int) ev.GetX();
00212       m_y = (int) ev.GetY();
00213     }
00214   else if (ev.MiddleIsDown() && ev.Moving())
00215     {
00216       //TODO:change th
00217 
00218       if (ev.GetY() < m_y)
00219         {
00220           // increment theshold
00221           m_Data->incThreshold();
00222         }
00223       else
00224         {
00225           // decrement threshold
00226           m_Data->decThreshold();
00227         }
00228 
00229       m_Data->render();
00230       m_glCanvas->redraw();
00231 
00232       m_x = (int) ev.GetX();
00233       m_y = (int) ev.GetY();
00234     }
00235   //    else if (ev.LeftDClick())
00236   //    {
00237   //      //Pop up the transfer function editor
00238   //      vuTransferDialog dlg(this,m_TFunc);
00239   //
00240   //      if (dlg.ShowModal() == wxID_OK)
00241   //      {
00242   //          m_TFunc = dlg.getTransferFunc();
00243   //          m_Data->setTransferFunc(m_TFunc);
00244   //          m_glCanvas->redraw();
00245   //      }
00246   //    }
00247 }

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