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/05/29 13:39:56 $
00007   Version:   $Revision: 1.9 $
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         wxToolBar* toolbar = new ToolBar(this,iconsdir);
00047         wxAuiPaneInfo paneinfo; 
00048         wxauimanager->AddPane(toolbar,paneinfo.ToolbarPane().Top());                    
00049 
00050         wxauimanager->Update();
00051         createFileChooser();
00052 
00053 
00054 }
00055 wxMaracasIRMView::~wxMaracasIRMView( ){
00056 
00057 
00058 }
00059 
00060 std::string wxMaracasIRMView::getPath(){
00061         return _path;
00062 }
00063 
00064 
00065 
00066 void wxMaracasIRMView::createFileChooser(){
00067     
00068 }
00069 
00070 wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
00071         if(instance==NULL){
00072                 instance = new wxMaracasIRMView(parent,path);
00073         }
00074         return instance;
00075 }
00076 
00077 wxMaracasIRMView* wxMaracasIRMView::getInstance(){
00078         return instance;
00079 }
00080 
00081 void wxMaracasIRMView::setRenderer(vtkRenderer*  renderer){
00082         irmmanager->setRenderer(renderer);
00083 }
00084 
00085 void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
00086         irmmanager->addRemoveActor(propid, addremove);
00087 }
00088 
00089 void wxMaracasIRMView::changeOpacity(int _propid, int value){
00090         irmmanager->changeOpacity(_propid,value);
00091 }
00092 
00093 void wxMaracasIRMView::changeIsoValue(int propid, double value){        
00094         irmmanager->changeIsoValue(propid, value);
00095 }
00096 
00097 void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
00098         try{
00099                 irmmanager->changeColor(propid, red, green, blue);
00100 
00101         }catch(char* str){
00102 
00103                 wxString s( str,wxConvUTF8 );
00104                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
00105                 diag->ShowModal();
00106                 delete diag;
00107 
00108         }
00109 }
00110 
00111 void wxMaracasIRMView::onLoadImageFile(){
00112 
00113         wxString mhd(_T("mhd"));
00114         wxString stl(_T("stl"));
00115 
00116         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
00117                 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
00118 
00119         if(fildial->ShowModal()==wxID_OK){
00120         wxString filename = fildial->GetFilename();
00121                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);        
00122                 
00123 
00124                 if(filename.EndsWith(mhd)){                     
00125                         loadPropMHD(pathfile,filename);
00126                 }else if(filename.EndsWith(stl)){
00127             loadProp3D(pathfile,filename);
00128                 }
00129         }
00130         delete fildial;
00131 
00132 }
00133 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){               
00134                 
00135         std::string s = std::string(filename.mb_str());
00136         vtkImageData* img = irmmanager->getImageData(s);
00137         if(img!=NULL){
00138                 s = std::string(dataname.mb_str());
00139                 addPropMHD(img, s);
00140         }
00141         
00142         
00143 
00144 }
00145 
00146 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
00147         try{
00148                 int id = irmmanager->addPropMHD(imgdata,dataname);              
00149                 if(id!=-1){
00150                         
00151                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
00152                         int maxiso = irmmanager->getMaxIsoValue(id);
00153                         ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
00154                         addIRMViewPanel(controlpan, dataname);
00155                 }
00156 
00157         }catch(char* str){
00158 
00159                 std::cout << "Exception : " << str << '\n';
00160                 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
00161                 diag->ShowModal();
00162 
00163         }
00164 }
00165 
00166 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){                        
00167         std::string s = std::string(filename.mb_str());
00168         vtkProp3D* prop3D = irmmanager->getProp3D(s);
00169         if(prop3D != NULL){
00170                 s = std::string(dataname.mb_str() );
00171                 this->addProp3D(prop3D,s);
00172         }else{
00173                 //TODO msj to the user indicating error in file
00174         }
00175                 
00176         
00177         
00178 }
00179 
00180 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
00181         try{
00182                 int id = irmmanager->addProp3D(prop3D,dataname);
00183                 if(id!=-1){
00184                         wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
00185                         addIRMViewPanel(controlpan, dataname);
00186                 }
00187         }catch(char* str){
00188                 std::cout << "Exception : " << str << '\n';
00189                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
00190                 diag->ShowModal();              
00191         }
00192         
00193 }
00194 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
00195 
00196         wxString s(dataname.c_str(),wxConvUTF8 );
00197         wxAuiPaneInfo paneinfo; 
00198         wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
00199         wxauimanager->Update();
00200         
00201         
00202 }
00203 
00204 void wxMaracasIRMView::deleteActor(int propid){
00205         try{
00206                 irmmanager->deleteActor(propid);
00207         }catch(char* e){
00208                 
00209         }
00210 }
00211 
00212 
00213 
00214 
00215 
00220 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
00221 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
00222 {    
00223 
00224 
00225         std::string iconfil = iconsdir;
00226 
00227         //iconfil+= "/OpenImage.png";
00228         //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
00229         wxBitmap bitmap0(OpenImage_xpm);
00230         this->AddTool(0, wxString(_T("test")),bitmap0);
00231 
00232         /*iconfil+= "/Open.png";
00233         wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
00234         this->AddTool(2, wxString(_T("test")),*bitmap2);        */      
00235 
00236         /*iconfil = iconsdir;
00237         iconfil+= "/Open.png";
00238         wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
00239         this->AddTool(30, wxString(_T("test")),*bitmap30);*/
00240         
00241         this->Realize();
00242         
00243         
00244 }
00245 
00246 ToolBar::~ToolBar(void){
00247 }
00248 void ToolBar::onLoadImageFile(wxCommandEvent& event){
00249         wxMaracasIRMView::getInstance()->onLoadImageFile();
00250 }
00251 
00252 
00253 
00254 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)   
00255         EVT_MENU(0, ToolBar::onLoadImageFile)    
00256            
00257 END_EVENT_TABLE()
00258 
00259 

Generated on Fri Jun 12 00:08:34 2009 for creaMaracasVisu by  doxygen 1.5.7.1