1 /*=========================================================================
4 Module: $RCSfile: wxMaracasIRMView.cxx,v $
6 Date: $Date: 2009/04/14 14:48:07 $
7 Version: $Revision: 1.4 $
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"
24 #include <wx/colordlg.h>
25 #include <wx/bmpbuttn.h>
27 wxMaracasIRMView* wxMaracasIRMView::instance=NULL;
29 wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent,std::string path)
30 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
32 irmmanager = new wxMaracasIRMViewManager();
34 wxauimanager = new wxAuiManager(this);
38 std::string iconsdir = path;
39 iconsdir+="/data/Icons";
40 wxToolBar* toolbar = new ToolBar(this,iconsdir);
41 wxAuiPaneInfo paneinfo;
42 wxauimanager->AddPane(toolbar,paneinfo.ToolbarPane().Top());
44 wxauimanager->Update();
49 wxMaracasIRMView::~wxMaracasIRMView( ){
54 std::string wxMaracasIRMView::getPath(){
60 void wxMaracasIRMView::createFileChooser(){
64 wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
66 instance = new wxMaracasIRMView(parent,path);
71 wxMaracasIRMView* wxMaracasIRMView::getInstance(){
75 void wxMaracasIRMView::setRenderer(vtkRenderer* renderer){
76 irmmanager->setRenderer(renderer);
79 void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
80 irmmanager->addRemoveActor(propid, addremove);
83 void wxMaracasIRMView::changeOpacity(int _propid, int value){
84 irmmanager->changeOpacity(_propid,value);
87 void wxMaracasIRMView::changeIsoValue(int propid, int value){
88 irmmanager->changeIsoValue(propid, value);
91 void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
93 irmmanager->changeColor(propid, red, green, blue);
97 wxString s( str,wxConvUTF8 );
98 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
105 void wxMaracasIRMView::onLoadImageFile(){
107 wxString mhd(_T("mhd"));
108 wxString stl(_T("stl"));
110 wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
111 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
113 if(fildial->ShowModal()==wxID_OK){
114 wxString filename = fildial->GetFilename();
115 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
118 if(filename.EndsWith(mhd)){
119 loadPropMHD(pathfile,filename);
120 }else if(filename.EndsWith(stl)){
121 loadProp3D(pathfile,filename);
127 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){
129 std::string s = std::string(filename.mb_str());
130 vtkImageData* img = irmmanager->getImageData(s);
132 s = std::string(dataname.mb_str());
140 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
142 int id = irmmanager->addPropMHD(imgdata,dataname);
145 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
146 int maxiso = irmmanager->getMaxIsoValue(id);
147 ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
148 addIRMViewPanel(controlpan, dataname);
153 std::cout << "Exception : " << str << '\n';
154 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
160 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){
161 std::string s = std::string(filename.mb_str());
162 vtkProp3D* prop3D = irmmanager->getProp3D(s);
164 s = std::string(dataname.mb_str() );
165 this->addProp3D(prop3D,s);
167 //TODO msj to the user indicating error in file
174 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
176 int id = irmmanager->addProp3D(prop3D,dataname);
178 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
179 addIRMViewPanel(controlpan, dataname);
182 std::cout << "Exception : " << str << '\n';
183 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
188 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
190 wxString s(dataname.c_str(),wxConvUTF8 );
191 wxAuiPaneInfo paneinfo;
192 wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
193 wxauimanager->Update();
198 ** Implementation of viewProp3D
201 wxMaracasIRMViewProp3D::wxMaracasIRMViewProp3D(wxWindow* parent,int propid)
202 :wxMaracasIRMViewPanel(parent, propid){
206 wxMaracasIRMViewProp3D::~wxMaracasIRMViewProp3D(){
207 wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false);
210 void wxMaracasIRMViewProp3D::createControls(){
213 choices[0] = wxString(_T("On"));
214 choices[1] = wxString(_T("Off"));
215 checkbox = new wxCheckBox(this,-1,wxString(_T("Show Actor")));
216 this->addControl(checkbox);
218 Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onCheckBoxChange);
219 checkbox->SetValue(true);
221 std::string iconfile = wxMaracasIRMView::getInstance()->getPath();
222 iconfile+= "/Data/Icons/Color.png";
223 wxBitmap* bitmap = new wxBitmap(wxString(iconfile.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
224 _colorchoose = new wxBitmapButton(this, -1, *bitmap,wxDefaultPosition,wxSize(30,30));
225 Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onColorChange);
227 wxBoxSizer* sizercolor = new wxBoxSizer(wxVERTICAL);
228 sizercolor->Add(checkbox,wxFIXED_MINSIZE);
229 sizercolor->Add(_colorchoose,wxFIXED_MINSIZE);
230 this->addControl(sizercolor);
233 wxStaticText* label = new wxStaticText(this, -1, wxString(_T("Opacity")));
234 opacity = new wxSlider(this, -1,100,0,100,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
235 Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onOpacityRelease);
236 wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);
237 sizeropacity->Add(label,wxFIXED_MINSIZE);
238 sizeropacity->Add(opacity,wxFIXED_MINSIZE);
239 this->addControl(sizeropacity);
242 void wxMaracasIRMViewProp3D::onCheckBoxChange(wxCommandEvent& event){
243 wxMaracasIRMView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue());
245 void wxMaracasIRMViewProp3D::onColorChange(wxCommandEvent& event){
246 wxColourDialog* colourdiag = new wxColourDialog(this);
247 if(colourdiag->ShowModal()==wxID_OK){
248 wxColour colour = colourdiag->GetColourData().GetColour();
249 _colorchoose->SetBackgroundColour(colour);
251 float r = colour.Red()/255;
252 float g = colour.Green()/255;
253 float b = colour.Blue()/255;
255 wxMaracasIRMView::getInstance()->changeColor(this->getPropId(),r,g,b);
259 /*void wxMaracasIRMViewProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){
263 void wxMaracasIRMViewProp3D::onOpacityRelease(wxScrollEvent& event ){
265 wxMaracasIRMView::getInstance()->changeOpacity(this->getPropId(),opacity->GetValue());
271 ** IRM viewProp3DMHD implementation
273 wxMaracasIRMViewProp3DMHD::wxMaracasIRMViewProp3DMHD(wxWindow* parent, int propid)
274 : wxMaracasIRMViewProp3D(parent, propid)
278 wxMaracasIRMViewProp3DMHD::~wxMaracasIRMViewProp3DMHD(){
281 void wxMaracasIRMViewProp3DMHD::createControls(int maxisovalue){
283 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
285 wxStaticText* label = new wxStaticText(this, -1, wxString(_T("IsoValue")));
286 sizer->Add(label, wxGROW);
287 //this->addControl(label);
288 isovalue = new wxSlider(this, -1,maxisovalue,0,maxisovalue,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
289 sizer->Add(isovalue, wxGROW);
290 //this->addControl(isovalue);
292 this->addControl(sizer);
293 Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3DMHD::onIsoValueRelease);
296 void wxMaracasIRMViewProp3DMHD::onIsoValueRelease(wxScrollEvent& event ){
298 wxMaracasIRMView::getInstance()->changeIsoValue(this->getPropId(), isovalue->GetValue());
305 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
306 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
310 std::string iconfil = iconsdir;
312 iconfil+= "/OpenImage.png";
313 wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
314 this->AddTool(0, wxString(_T("test")),*bitmap0);
316 /*iconfil+= "/Open.png";
317 wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
318 this->AddTool(2, wxString(_T("test")),*bitmap2); */
320 /*iconfil = iconsdir;
321 iconfil+= "/Open.png";
322 wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
323 this->AddTool(30, wxString(_T("test")),*bitmap30);*/
330 ToolBar::~ToolBar(void){
332 void ToolBar::onLoadImageFile(wxCommandEvent& event){
333 wxMaracasIRMView::getInstance()->onLoadImageFile();
338 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)
339 EVT_MENU(0, ToolBar::onLoadImageFile)