wxMaracasIRMView.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   wxMaracas
00004   Module:    $RCSfile: wxMaracasIRMView.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2009/06/16 13:25:58 $
00007   Version:   $Revision: 1.11 $
00008 
00009   Copyright: (c) 2002, 2003
00010   License:
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notice for more information.
00015 
00016 =========================================================================*/
00017 
00018 
00019 
00020 // EOF - wxMaracasMPR.cxx
00021 
00022 #include "wxMaracasIRMView.h"
00023 //#include "wxMaracasIRMViewPanel.h"
00024 #include "wxMaracasIRMViewProp3DMHD.h"
00025 #include "wxMaracasIRMViewProp3D.h"
00026 
00027 #include <wx/colordlg.h>
00028 #include <wx/bmpbuttn.h>
00029 
00030 #include <OpenImage.xpm>
00031 #include <Color.xpm>
00032 
00033 wxMaracasIRMView* wxMaracasIRMView::instance=NULL;
00034 
00035 wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent,std::string path)
00036 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
00037 
00038         irmmanager = new wxMaracasIRMViewManager();
00039 
00040         wxauimanager = new wxAuiManager(this);
00041 
00042         _path = path;
00043 
00044         std::string iconsdir = path;
00045         iconsdir+="/data/Icons";
00046         this->_toolb = new ToolBar(this,iconsdir);
00047         wxAuiPaneInfo paneinfo;
00048         wxauimanager->AddPane(_toolb,paneinfo.ToolbarPane().Top());
00049 
00050         wxauimanager->Update();
00051         createFileChooser();
00052 
00053 
00054 }
00055 wxMaracasIRMView::~wxMaracasIRMView( ){
00056 
00057         delete _toolb;
00058 
00059 }
00060 
00061 std::string wxMaracasIRMView::getPath(){
00062         return _path;
00063 }
00064 
00065 
00066 
00067 void wxMaracasIRMView::createFileChooser(){
00068 
00069 }
00070 
00071 wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
00072         if(instance==NULL){
00073                 instance = new wxMaracasIRMView(parent,path);
00074         }
00075         return instance;
00076 }
00077 
00078 wxMaracasIRMView* wxMaracasIRMView::getInstance(){
00079         return instance;
00080 }
00081 
00082 void wxMaracasIRMView::setRenderer(vtkRenderer*  renderer){
00083         irmmanager->setRenderer(renderer);
00084 }
00085 
00086 void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
00087         irmmanager->addRemoveActor(propid, addremove);
00088 }
00089 
00090 void wxMaracasIRMView::changeOpacity(int _propid, int value){
00091         irmmanager->changeOpacity(_propid,value);
00092 }
00093 
00094 void wxMaracasIRMView::changeIsoValue(int propid, double value){
00095         irmmanager->changeIsoValue(propid, value);
00096 }
00097 
00098 void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
00099         try{
00100                 irmmanager->changeColor(propid, red, green, blue);
00101 
00102         }catch(char* str){
00103 
00104                 wxString s( str,wxConvUTF8 );
00105                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
00106                 diag->ShowModal();
00107                 delete diag;
00108 
00109         }
00110 }
00111 
00112 void wxMaracasIRMView::onLoadImageFile(){
00113 
00114         wxString mhd(_T("mhd"));
00115         wxString stl(_T("stl"));
00116 
00117         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
00118                 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
00119 
00120         if(fildial->ShowModal()==wxID_OK){
00121         wxString filename = fildial->GetFilename();
00122                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
00123 
00124 
00125                 if(filename.EndsWith(mhd)){
00126                         loadPropMHD(pathfile,filename);
00127                 }else if(filename.EndsWith(stl)){
00128             loadProp3D(pathfile,filename);
00129                 }
00130         }
00131         delete fildial;
00132 
00133 }
00134 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){
00135 
00136         std::string s = std::string(filename.mb_str());
00137         vtkImageData* img = irmmanager->getImageData(s);
00138         if(img!=NULL){
00139                 s = std::string(dataname.mb_str());
00140                 addPropMHD(img, s);
00141         }
00142 
00143 
00144 
00145 }
00146 
00147 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
00148         try{
00149                 int id = irmmanager->addPropMHD(imgdata,dataname);
00150                 if(id!=-1){
00151 
00152                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
00153                         int maxiso = irmmanager->getMaxIsoValue(id);
00154                         ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
00155                         addIRMViewPanel(controlpan, dataname);
00156                 }
00157 
00158         }catch(char* str){
00159 
00160                 std::cout << "Exception : " << str << '\n';
00161                 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
00162                 diag->ShowModal();
00163 
00164         }
00165 }
00166 
00167 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){
00168         std::string s = std::string(filename.mb_str());
00169         vtkProp3D* prop3D = irmmanager->getProp3D(s);
00170         if(prop3D != NULL){
00171                 s = std::string(dataname.mb_str() );
00172                 this->addProp3D(prop3D,s);
00173         }else{
00174                 //TODO msj to the user indicating error in file
00175         }
00176 
00177 
00178 
00179 }
00180 
00181 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
00182         try{
00183                 int id = irmmanager->addProp3D(prop3D,dataname);
00184                 if(id!=-1){
00185                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
00186                         addIRMViewPanel(controlpan, dataname);
00187                 }
00188         }catch(char* str){
00189                 std::cout << "Exception : " << str << '\n';
00190                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
00191                 diag->ShowModal();
00192         }
00193 
00194 }
00195 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
00196 
00197         wxString s(dataname.c_str(),wxConvUTF8 );
00198         wxAuiPaneInfo paneinfo;
00199         wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
00200         wxauimanager->Update();
00201 
00202 
00203 }
00204 
00205 void wxMaracasIRMView::deleteActor(int propid){
00206         try{
00207                 irmmanager->deleteActor(propid);
00208         }catch(char* e){
00209 
00210         }
00211 }
00212 
00213 
00214 
00215 
00216 
00221 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
00222 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
00223 {
00224 
00225 
00226         std::string iconfil = iconsdir;
00227 
00228         //iconfil+= "/OpenImage.png";
00229         //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
00230         wxBitmap bitmap0(OpenImage_xpm);
00231         this->AddTool(1, wxString(_T("test")),bitmap0);
00232 
00233         /*iconfil+= "/Open.png";
00234         wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
00235         this->AddTool(2, wxString(_T("test")),*bitmap2);        */
00236 
00237         /*iconfil = iconsdir;
00238         iconfil+= "/Open.png";
00239         wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
00240         this->AddTool(30, wxString(_T("test")),*bitmap30);*/
00241 
00242         this->Realize();
00243 
00244         _evthand = new ToolBarEventHandler();
00245         this->SetEventHandler(_evthand);
00246 
00247 }
00248 
00249 ToolBar::~ToolBar(void){
00250 }
00251 
00252 ToolBarEventHandler::ToolBarEventHandler()
00253 : wxEvtHandler(){
00254 }
00255 ToolBarEventHandler::~ToolBarEventHandler(){
00256 }
00257 
00258 void ToolBarEventHandler::onLoadImageFile(wxCommandEvent& event){
00259         wxMaracasIRMView::getInstance()->onLoadImageFile();
00260 }
00261 
00262 
00263 
00264 BEGIN_EVENT_TABLE(ToolBarEventHandler, wxEvtHandler)
00265         EVT_MENU(1, ToolBarEventHandler::onLoadImageFile)
00266 END_EVENT_TABLE()
00267 
00268 

Generated on Wed Jul 29 16:35:30 2009 for creaMaracasVisu_lib by  doxygen 1.5.3