1 /*=========================================================================
4 Module: $RCSfile: wxMaracasIRMView.cxx,v $
6 Date: $Date: 2009/06/16 13:25:58 $
7 Version: $Revision: 1.11 $
9 Copyright: (c) 2002, 2003
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notice for more information.
16 =========================================================================*/
20 // EOF - wxMaracasMPR.cxx
22 #include "wxMaracasIRMView.h"
23 //#include "wxMaracasIRMViewPanel.h"
24 #include "wxMaracasIRMViewProp3DMHD.h"
25 #include "wxMaracasIRMViewProp3D.h"
27 #include <wx/colordlg.h>
28 #include <wx/bmpbuttn.h>
30 #include <OpenImage.xpm>
33 wxMaracasIRMView* wxMaracasIRMView::instance=NULL;
35 wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent,std::string path)
36 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
38 irmmanager = new wxMaracasIRMViewManager();
40 wxauimanager = new wxAuiManager(this);
44 std::string iconsdir = path;
45 iconsdir+="/data/Icons";
46 this->_toolb = new ToolBar(this,iconsdir);
47 wxAuiPaneInfo paneinfo;
48 wxauimanager->AddPane(_toolb,paneinfo.ToolbarPane().Top());
50 wxauimanager->Update();
55 wxMaracasIRMView::~wxMaracasIRMView( ){
61 std::string wxMaracasIRMView::getPath(){
67 void wxMaracasIRMView::createFileChooser(){
71 wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
73 instance = new wxMaracasIRMView(parent,path);
78 wxMaracasIRMView* wxMaracasIRMView::getInstance(){
82 void wxMaracasIRMView::setRenderer(vtkRenderer* renderer){
83 irmmanager->setRenderer(renderer);
86 void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
87 irmmanager->addRemoveActor(propid, addremove);
90 void wxMaracasIRMView::changeOpacity(int _propid, int value){
91 irmmanager->changeOpacity(_propid,value);
94 void wxMaracasIRMView::changeIsoValue(int propid, double value){
95 irmmanager->changeIsoValue(propid, value);
98 void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
100 irmmanager->changeColor(propid, red, green, blue);
104 wxString s( str,wxConvUTF8 );
105 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
112 void wxMaracasIRMView::onLoadImageFile(){
114 wxString mhd(_T("mhd"));
115 wxString stl(_T("stl"));
117 wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
118 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
120 if(fildial->ShowModal()==wxID_OK){
121 wxString filename = fildial->GetFilename();
122 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
125 if(filename.EndsWith(mhd)){
126 loadPropMHD(pathfile,filename);
127 }else if(filename.EndsWith(stl)){
128 loadProp3D(pathfile,filename);
134 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){
136 std::string s = std::string(filename.mb_str());
137 vtkImageData* img = irmmanager->getImageData(s);
139 s = std::string(dataname.mb_str());
147 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
149 int id = irmmanager->addPropMHD(imgdata,dataname);
152 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
153 int maxiso = irmmanager->getMaxIsoValue(id);
154 ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
155 addIRMViewPanel(controlpan, dataname);
160 std::cout << "Exception : " << str << '\n';
161 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
167 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){
168 std::string s = std::string(filename.mb_str());
169 vtkProp3D* prop3D = irmmanager->getProp3D(s);
171 s = std::string(dataname.mb_str() );
172 this->addProp3D(prop3D,s);
174 //TODO msj to the user indicating error in file
181 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
183 int id = irmmanager->addProp3D(prop3D,dataname);
185 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
186 addIRMViewPanel(controlpan, dataname);
189 std::cout << "Exception : " << str << '\n';
190 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
195 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
197 wxString s(dataname.c_str(),wxConvUTF8 );
198 wxAuiPaneInfo paneinfo;
199 wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
200 wxauimanager->Update();
205 void wxMaracasIRMView::deleteActor(int propid){
207 irmmanager->deleteActor(propid);
221 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
222 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
226 std::string iconfil = iconsdir;
228 //iconfil+= "/OpenImage.png";
229 //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
230 wxBitmap bitmap0(OpenImage_xpm);
231 this->AddTool(1, wxString(_T("test")),bitmap0);
233 /*iconfil+= "/Open.png";
234 wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
235 this->AddTool(2, wxString(_T("test")),*bitmap2); */
237 /*iconfil = iconsdir;
238 iconfil+= "/Open.png";
239 wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
240 this->AddTool(30, wxString(_T("test")),*bitmap30);*/
244 _evthand = new ToolBarEventHandler();
245 this->SetEventHandler(_evthand);
249 ToolBar::~ToolBar(void){
252 ToolBarEventHandler::ToolBarEventHandler()
255 ToolBarEventHandler::~ToolBarEventHandler(){
258 void ToolBarEventHandler::onLoadImageFile(wxCommandEvent& event){
259 wxMaracasIRMView::getInstance()->onLoadImageFile();
264 BEGIN_EVENT_TABLE(ToolBarEventHandler, wxEvtHandler)
265 EVT_MENU(1, ToolBarEventHandler::onLoadImageFile)