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

vuSlicer.cpp

Go to the documentation of this file.
00001 #include "vuSlicer.h"
00002 
00003 #include "vuPreviewWin.h"
00004 #include "vuCamera.h"
00005 
00006 #include "../../wxUIElements/vuTransferDialog.h"
00007 
00008 #define SLIDER_MAX 10000
00009 //----------------------------------------------------------------------------
00010 //------------------------- The vuSlicer event table --------------------------
00011 //----------------------------------------------------------------------------
00012 
00013 enum
00014 {
00015   idCANVAS,
00016   idSLIDESLICE
00017 };
00018 
00019 BEGIN_EVENT_TABLE(vuSlicer, vuBasicUtility)
00020    EVT_COMMAND_SCROLL(idSLIDESLICE, vuSlicer::OnSlideSlice)
00021 END_EVENT_TABLE();
00022 
00023 //----------------------------------------------------------------------------
00024 //------------------------- The constructor ----------------------------------
00025 //----------------------------------------------------------------------------
00026 
00027 vuSlicer::vuSlicer()
00028 {
00029     m_Data = NULL;
00030 }
00031 
00032 //----------------------------------------------------------------------------
00033 //------------------------- The destructor -----------------------------------
00034 //----------------------------------------------------------------------------
00035 
00036 vuSlicer::~vuSlicer()
00037 {
00038     if (m_Data != 0) delete m_Data;
00039 }
00040 
00041 //----------------------------------------------------------------------------
00042 //------------------------- public: getFileType() ----------------------------
00043 //----------------------------------------------------------------------------
00044 
00045 const char* vuSlicer::getFileType()
00046 {
00047     return "11121";
00048 }
00049 
00050 //----------------------------------------------------------------------------
00051 //------------------------- public: init() -----------------------------------
00052 //----------------------------------------------------------------------------
00053 
00054 bool vuSlicer::init(const char* DataFile)
00055 {
00056     SetEvtHandlerEnabled(true);
00057 
00058     //Set up the window
00059     SetTitle("Slicer");
00060     CreateStatusBar();
00061 
00062     //Create a volume data instance.
00063     m_Data = new vu1112116;
00064     m_Data->setFileName(DataFile);
00065 
00066 
00067     //make a colourful transfer function
00068     m_TFunc.addOpacity(1,0.0);
00069     m_TFunc.addOpacity(255,1.0);
00070     m_TFunc.addColour(0,vuColourRGBa(0.0f));
00071     m_TFunc.addColour(64,vuColourRGBa(0,0,1));
00072     m_TFunc.addColour(128,vuColourRGBa(0,1,1));
00073     m_TFunc.addColour(196,vuColourRGBa(1,1,0));
00074     m_TFunc.addColour(255,vuColourRGBa(1,0,0));
00075     m_TFunc.setOpacitySmoothing(0);
00076     m_TFunc.setColourSmoothing(0.25);
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(),"vuSlicer",wxOK);
00090         dlg.ShowModal();
00091     }
00092 
00093     return success;
00094 }
00095 
00096 //----------------------------------------------------------------------------
00097 //------------------------- public: addRight() -------------------------------
00098 //----------------------------------------------------------------------------
00099 
00100 void vuSlicer::addRight(wxSizer *sizer)
00101 {
00102   //Add some control elements
00103   sizer->Add( new wxStaticText( this, -1, "Slice", wxDefaultPosition, wxSize(50,20)),
00104               0,            // make vertically stretchable
00105               wxEXPAND,     // make horizontally stretchable
00106               5 );         // set border width to
00107   
00108   sizer->Add( m_SliceSlider = new wxSlider(this, idSLIDESLICE, 0, 0, SLIDER_MAX, 
00109                                            wxDefaultPosition, wxSize(30,300), wxSL_VERTICAL, 
00110                                            wxDefaultValidator, "slider"),1,wxALL,10 );
00111 }
00112 
00113 //----------------------------------------------------------------------------
00114 //------------------------- protected: glInit() ------------------------------
00115 //----------------------------------------------------------------------------
00116 
00117 bool vuSlicer::glInit(void)
00118 {
00119     if (m_Data == 0) return false;
00120     m_Data->initOpenGL();
00121     return true;
00122 };
00123 
00124 //----------------------------------------------------------------------------
00125 //------------------------- protected: glRender() ----------------------------
00126 //----------------------------------------------------------------------------
00127 
00128 void vuSlicer::glRender()
00129 {
00130     
00131     m_Data->render();
00132     
00133 };
00134 
00135 //----------------------------------------------------------------------------
00136 //------------------------- protected: glResize() ----------------------------
00137 //----------------------------------------------------------------------------
00138 
00139 void vuSlicer::glResize()
00140 {
00141     m_Data->setImageSize(m_glCanvas->getWidth(),m_glCanvas->getHeight());
00142     m_glCanvas->redraw();
00143 }
00144 
00145 //----------------------------------------------------------------------------
00146 //------------------------- protected: glOnMouse() ---------------------------
00147 //----------------------------------------------------------------------------
00148 
00149 void vuSlicer::glOnMouse(wxMouseEvent &ev)
00150 {
00151     if(!m_Data) return;
00152     if (ev.LeftDown() || ev.RightDown())
00153     {
00154         //Store the click position.
00155         m_x = (int) ev.GetX();
00156         m_y = (int) ev.GetY();
00157         vuVector pos;
00158         m_Data->getPosition(pos);
00159         pos[0] = m_x;
00160         pos[1] = m_glCanvas->getHeight()-m_y;
00161         m_Data->setPosition(pos);
00162     }
00163     else if (ev.LeftIsDown() && ev.Moving())
00164     {
00165         //Store the click position.
00166         m_x = (int) ev.GetX();
00167         m_y = (int) ev.GetY();
00168     }
00169     else if (ev.LeftDClick())
00170     {
00171         //Pop up the transfer function editor
00172         vuTransferDialog dlg(this,m_TFunc);
00173 
00174         if (dlg.ShowModal() == wxID_OK)
00175         {
00176             m_TFunc = dlg.getTransferFunc();
00177             m_Data->setTransferFunc(m_TFunc);
00178             m_glCanvas->redraw();
00179         }
00180     } else 
00181       {
00182         vuVector pos;
00183         m_Data->getPosition(pos);
00184         m_x = (int) ev.GetX();
00185         m_y = (int) ev.GetY();
00186         pos[0] = m_x;
00187         pos[1] = m_glCanvas->getHeight()-m_y;
00188         if(m_Data->isInside(pos))
00189         {
00190             char msg[1024];
00191             sprintf(msg,"pos %0.0fx %0.0fy %0.0fz  value %d",pos[0],pos[1],pos[2],
00192                     (int)m_Data->getValue(pos));
00193             SetStatusText(wxString(msg));
00194         }
00195       }
00196 }
00197 
00198 //------------------------------------------------------------------------------
00199 // event handler for the slice slider
00200 void vuSlicer::OnSlideSlice( wxScrollEvent& event)
00201 {
00202     vuVector pos;
00203     m_Data->getPosition(pos);
00204     pos[2] = m_SliceSlider->GetValue()*m_Data->getDim3Size()/SLIDER_MAX;
00205     m_Data->setPosition(pos);
00206     m_glCanvas->redraw();           
00207     
00208     if(m_Data->isInside(pos))
00209     {
00210         char msg[1024];
00211         sprintf(msg,"pos %0.0fx %0.0fy %0.0fz  value %d",pos[0],pos[1],pos[2],
00212                 (int)m_Data->getValue(pos));
00213         SetStatusText(wxString(msg));
00214     }
00215 }
00216 
00217 //--------------------------------------------------------------------------------------
00219 void vuSlicer::OnChar(wxKeyEvent& event)
00220 {
00221     vuVector pos;
00222     switch(event.GetKeyCode()) {
00223         case '+' :
00224             m_Data->getPosition(pos);
00225             pos += vuVector(0,0,1);
00226             m_Data->setPosition(pos);
00227             m_glCanvas->redraw();           
00228             break;
00229         case '-' :
00230             m_Data->getPosition(pos);
00231             pos -= vuVector(0,0,1);
00232             m_Data->setPosition(pos);
00233             m_glCanvas->redraw();           
00234             break;
00235     }
00236 
00237     if(m_Data->isInside(pos))
00238     {
00239         char msg[1024];
00240         sprintf(msg,"pos %0.0fx %0.0fy %0.0fz  value %d",pos[0],pos[1],pos[2],
00241                 (int)m_Data->getValue(pos));
00242         SetStatusText(wxString(msg));
00243         m_SliceSlider->SetValue(int(pos[2]*SLIDER_MAX/m_Data->getDim3Size()));
00244     }
00245 }
00246 
00247 vuCamera* vuSlicer::getCamera ()
00248 {
00249     return NULL;
00250 }
00251 
00252 vuImage* vuSlicer::getCurrentImage ()
00253 
00254 {
00255 //      return m_Data->getImage ();
00256         return NULL;
00257 }
00258 
00259 void vuSlicer::DrawAgain()
00260 
00261 {
00262 //      cout << "vuRaycast::notifyDataChanged ()" << endl;
00263 
00264 //      m_Data->doRefresh();
00265 //      m_glCanvas->redraw();
00266 
00267 //      glRender ();
00268 }
00269 
00270 void vuSlicer::DrawFromImage ()
00271 
00272 {
00273 //      m_Data->displayFromImage ();
00274 //      m_Data->render ();
00275 //      m_glCanvas->redraw ();
00276 }

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