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

vuSpecSplat.cpp

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

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