/*========================================================================= Program: wxMaracas Module: $RCSfile: wxMaracasIRMView.cxx,v $ Language: C++ Date: $Date: 2009/05/04 15:06:42 $ Version: $Revision: 1.7 $ Copyright: (c) 2002, 2003 License: This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // EOF - wxMaracasMPR.cxx #include "wxMaracasIRMView.h" #include #include #include #include wxMaracasIRMView* wxMaracasIRMView::instance=NULL; wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent,std::string path) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){ irmmanager = new wxMaracasIRMViewManager(); wxauimanager = new wxAuiManager(this); _path = path; std::string iconsdir = path; iconsdir+="/data/Icons"; wxToolBar* toolbar = new ToolBar(this,iconsdir); wxAuiPaneInfo paneinfo; wxauimanager->AddPane(toolbar,paneinfo.ToolbarPane().Top()); wxauimanager->Update(); createFileChooser(); } wxMaracasIRMView::~wxMaracasIRMView( ){ } std::string wxMaracasIRMView::getPath(){ return _path; } void wxMaracasIRMView::createFileChooser(){ } wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){ if(instance==NULL){ instance = new wxMaracasIRMView(parent,path); } return instance; } wxMaracasIRMView* wxMaracasIRMView::getInstance(){ return instance; } void wxMaracasIRMView::setRenderer(vtkRenderer* renderer){ irmmanager->setRenderer(renderer); } void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){ irmmanager->addRemoveActor(propid, addremove); } void wxMaracasIRMView::changeOpacity(int _propid, int value){ irmmanager->changeOpacity(_propid,value); } void wxMaracasIRMView::changeIsoValue(int propid, double value){ irmmanager->changeIsoValue(propid, value); } void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){ try{ irmmanager->changeColor(propid, red, green, blue); }catch(char* str){ wxString s( str,wxConvUTF8 ); wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR); diag->ShowModal(); delete diag; } } void wxMaracasIRMView::onLoadImageFile(){ wxString mhd(_T("mhd")); wxString stl(_T("stl")); wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")), wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) ); if(fildial->ShowModal()==wxID_OK){ wxString filename = fildial->GetFilename(); wxString pathfile(fildial->GetDirectory() + _T("/") + filename); if(filename.EndsWith(mhd)){ loadPropMHD(pathfile,filename); }else if(filename.EndsWith(stl)){ loadProp3D(pathfile,filename); } } delete fildial; } void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){ std::string s = std::string(filename.mb_str()); vtkImageData* img = irmmanager->getImageData(s); if(img!=NULL){ s = std::string(dataname.mb_str()); addPropMHD(img, s); } } void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){ try{ int id = irmmanager->addPropMHD(imgdata,dataname); if(id!=-1){ wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id); int maxiso = irmmanager->getMaxIsoValue(id); ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso); addIRMViewPanel(controlpan, dataname); } }catch(char* str){ std::cout << "Exception : " << str << '\n'; wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR); diag->ShowModal(); } } void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){ std::string s = std::string(filename.mb_str()); vtkProp3D* prop3D = irmmanager->getProp3D(s); if(prop3D != NULL){ s = std::string(dataname.mb_str() ); this->addProp3D(prop3D,s); }else{ //TODO msj to the user indicating error in file } } void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){ try{ int id = irmmanager->addProp3D(prop3D,dataname); if(id!=-1){ wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id); addIRMViewPanel(controlpan, dataname); } }catch(char* str){ std::cout << "Exception : " << str << '\n'; wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR); diag->ShowModal(); } } void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){ wxString s(dataname.c_str(),wxConvUTF8 ); wxAuiPaneInfo paneinfo; wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s)); wxauimanager->Update(); } void wxMaracasIRMView::deleteActor(int propid){ try{ irmmanager->deleteActor(propid); }catch(char* e){ } } /** ** Implementation of viewProp3D **/ wxMaracasIRMViewProp3D::wxMaracasIRMViewProp3D(wxWindow* parent,int propid) :wxMaracasIRMViewPanel(parent, propid){ createControls(); } wxMaracasIRMViewProp3D::~wxMaracasIRMViewProp3D(){ //wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false); wxMaracasIRMView::getInstance()->deleteActor(_propid); } void wxMaracasIRMViewProp3D::createControls(){ wxFlexGridSizer* sizerirmprop = new wxFlexGridSizer(1,1,1); wxString choices[2]; choices[0] = wxString(_T("On")); choices[1] = wxString(_T("Off")); checkbox = new wxCheckBox(this,-1,wxString(_T("Show Actor"))); Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onCheckBoxChange); checkbox->SetValue(true); sizerirmprop->Add(checkbox,wxFIXED_MINSIZE); //this->addControl(checkbox); wxBitmap bitmap(Color_xpm); _colorchoose = new wxBitmapButton(this, -1, bitmap,wxDefaultPosition,wxSize(30,30)); Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onColorChange); sizerirmprop->Add(_colorchoose,wxFIXED_MINSIZE); //sizercolor->Add(checkbox,wxFIXED_MINSIZE); //sizercolor->Add(_colorchoose,wxFIXED_MINSIZE); //this->addControl(sizercolor); wxStaticText* label = new wxStaticText(this, -1, wxString(_T("Opacity"))); opacity = new wxSlider(this, -1,100,0,100,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS); Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onOpacityRelease); wxFlexGridSizer* sizeropacity = new wxFlexGridSizer(1,1,1); sizeropacity->Add(label,wxFIXED_MINSIZE); sizeropacity->Add(opacity,wxFIXED_MINSIZE); sizerirmprop->Add(sizeropacity,wxFIXED_MINSIZE); //this->addControl(sizeropacity); this->addControl(sizerirmprop); } void wxMaracasIRMViewProp3D::onCheckBoxChange(wxCommandEvent& event){ wxMaracasIRMView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue()); } void wxMaracasIRMViewProp3D::onColorChange(wxCommandEvent& event){ wxColourDialog* colourdiag = new wxColourDialog(this); if(colourdiag->ShowModal()==wxID_OK){ wxColour colour = colourdiag->GetColourData().GetColour(); _colorchoose->SetBackgroundColour(colour); double r = (double)(colour.Red())/255.0; double g = (double)(colour.Green())/255.0; double b = (double)(colour.Blue())/255.0; wxMaracasIRMView::getInstance()->changeColor(this->getPropId(),r,g,b); } delete colourdiag; } /*void wxMaracasIRMViewProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){ }*/ void wxMaracasIRMViewProp3D::onOpacityRelease(wxScrollEvent& event ){ wxMaracasIRMView::getInstance()->changeOpacity(this->getPropId(),opacity->GetValue()); } /** ** IRM viewProp3DMHD implementation **/ wxMaracasIRMViewProp3DMHD::wxMaracasIRMViewProp3DMHD(wxWindow* parent, int propid) : wxMaracasIRMViewProp3D(parent, propid) { } wxMaracasIRMViewProp3DMHD::~wxMaracasIRMViewProp3DMHD(){ //this->Show(false); //wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false); } void wxMaracasIRMViewProp3DMHD::createControls(int maxisovalue){ wxFlexGridSizer* sizer = new wxFlexGridSizer(1,1,1); wxStaticText* label = new wxStaticText(this, -1, wxString(_T("IsoValue"))); sizer->Add(label, wxGROW); //this->addControl(label); isovalue = new wxSlider(this, -1,maxisovalue,0,maxisovalue,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS); sizer->Add(isovalue, wxGROW); //this->addControl(isovalue); this->addControl(sizer); Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3DMHD::onIsoValueRelease); } void wxMaracasIRMViewProp3DMHD::onIsoValueRelease(wxScrollEvent& event ){ wxMaracasIRMView::getInstance()->changeIsoValue(this->getPropId(), isovalue->GetValue()/1.0); } /** ** **/ ToolBar::ToolBar(wxWindow * parent,std::string iconsdir) : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize) { std::string iconfil = iconsdir; //iconfil+= "/OpenImage.png"; //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG); wxBitmap bitmap0(OpenImage_xpm); this->AddTool(0, wxString(_T("test")),bitmap0); /*iconfil+= "/Open.png"; wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG); this->AddTool(2, wxString(_T("test")),*bitmap2); */ /*iconfil = iconsdir; iconfil+= "/Open.png"; wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG); this->AddTool(30, wxString(_T("test")),*bitmap30);*/ this->Realize(); } ToolBar::~ToolBar(void){ } void ToolBar::onLoadImageFile(wxCommandEvent& event){ wxMaracasIRMView::getInstance()->onLoadImageFile(); } BEGIN_EVENT_TABLE(ToolBar, wxToolBar) EVT_MENU(0, ToolBar::onLoadImageFile) END_EVENT_TABLE()