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

vuBccSplat.cpp

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

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