1 /*=========================================================================
4 Module: $RCSfile: wxMaracasIRMView.cxx,v $
6 Date: $Date: 2009/05/14 13:54:35 $
7 Version: $Revision: 1.8 $
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 wxToolBar* toolbar = new ToolBar(this,iconsdir);
47 wxAuiPaneInfo paneinfo;
48 wxauimanager->AddPane(toolbar,paneinfo.ToolbarPane().Top());
50 wxauimanager->Update();
55 wxMaracasIRMView::~wxMaracasIRMView( ){
60 std::string wxMaracasIRMView::getPath(){
66 void wxMaracasIRMView::createFileChooser(){
70 wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
72 instance = new wxMaracasIRMView(parent,path);
77 wxMaracasIRMView* wxMaracasIRMView::getInstance(){
81 void wxMaracasIRMView::setRenderer(vtkRenderer* renderer){
82 irmmanager->setRenderer(renderer);
85 void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
86 irmmanager->addRemoveActor(propid, addremove);
89 void wxMaracasIRMView::changeOpacity(int _propid, int value){
90 irmmanager->changeOpacity(_propid,value);
93 void wxMaracasIRMView::changeIsoValue(int propid, double value){
94 irmmanager->changeIsoValue(propid, value);
97 void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
99 irmmanager->changeColor(propid, red, green, blue);
103 wxString s( str,wxConvUTF8 );
104 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
111 void wxMaracasIRMView::onLoadImageFile(){
113 wxString mhd(_T("mhd"));
114 wxString stl(_T("stl"));
116 wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
117 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
119 if(fildial->ShowModal()==wxID_OK){
120 wxString filename = fildial->GetFilename();
121 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
124 if(filename.EndsWith(mhd)){
125 loadPropMHD(pathfile,filename);
126 }else if(filename.EndsWith(stl)){
127 loadProp3D(pathfile,filename);
133 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){
135 std::string s = std::string(filename.mb_str());
136 vtkImageData* img = irmmanager->getImageData(s);
138 s = std::string(dataname.mb_str());
146 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
148 int id = irmmanager->addPropMHD(imgdata,dataname);
151 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
152 int maxiso = irmmanager->getMaxIsoValue(id);
153 ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
154 addIRMViewPanel(controlpan, dataname);
159 std::cout << "Exception : " << str << '\n';
160 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
166 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){
167 std::string s = std::string(filename.mb_str());
168 vtkProp3D* prop3D = irmmanager->getProp3D(s);
170 s = std::string(dataname.mb_str() );
171 this->addProp3D(prop3D,s);
173 //TODO msj to the user indicating error in file
180 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
182 int id = irmmanager->addProp3D(prop3D,dataname);
184 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
185 addIRMViewPanel(controlpan, dataname);
188 std::cout << "Exception : " << str << '\n';
189 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
194 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
196 wxString s(dataname.c_str(),wxConvUTF8 );
197 wxAuiPaneInfo paneinfo;
198 wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
199 wxauimanager->Update();
204 void wxMaracasIRMView::deleteActor(int propid){
206 irmmanager->deleteActor(propid);
220 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
221 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
225 std::string iconfil = iconsdir;
227 //iconfil+= "/OpenImage.png";
228 //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
229 wxBitmap bitmap0(OpenImage_xpm);
230 this->AddTool(0, wxString(_T("test")),bitmap0);
232 /*iconfil+= "/Open.png";
233 wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
234 this->AddTool(2, wxString(_T("test")),*bitmap2); */
236 /*iconfil = iconsdir;
237 iconfil+= "/Open.png";
238 wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
239 this->AddTool(30, wxString(_T("test")),*bitmap30);*/
246 ToolBar::~ToolBar(void){
248 void ToolBar::onLoadImageFile(wxCommandEvent& event){
249 wxMaracasIRMView::getInstance()->onLoadImageFile();
254 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)
255 EVT_MENU(0, ToolBar::onLoadImageFile)