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

vuSplat.cpp

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

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