1 /*=========================================================================
4 Module: $RCSfile: wxMaracasIRMView.cxx,v $
6 Date: $Date: 2009/04/15 12:35:01 $
7 Version: $Revision: 1.5 $
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 #include "OpenImage.xpm"
30 wxMaracasIRMView* wxMaracasIRMView::instance=NULL;
32 wxMaracasIRMView::wxMaracasIRMView( wxWindow* parent,std::string path)
33 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
35 irmmanager = new wxMaracasIRMViewManager();
37 wxauimanager = new wxAuiManager(this);
41 std::string iconsdir = path;
42 iconsdir+="/data/Icons";
43 wxToolBar* toolbar = new ToolBar(this,iconsdir);
44 wxAuiPaneInfo paneinfo;
45 wxauimanager->AddPane(toolbar,paneinfo.ToolbarPane().Top());
47 wxauimanager->Update();
52 wxMaracasIRMView::~wxMaracasIRMView( ){
57 std::string wxMaracasIRMView::getPath(){
63 void wxMaracasIRMView::createFileChooser(){
67 wxMaracasIRMView* wxMaracasIRMView::getInstance(wxWindow* parent,std::string path){
69 instance = new wxMaracasIRMView(parent,path);
74 wxMaracasIRMView* wxMaracasIRMView::getInstance(){
78 void wxMaracasIRMView::setRenderer(vtkRenderer* renderer){
79 irmmanager->setRenderer(renderer);
82 void wxMaracasIRMView::addRemoveActor(int propid, bool addremove){
83 irmmanager->addRemoveActor(propid, addremove);
86 void wxMaracasIRMView::changeOpacity(int _propid, int value){
87 irmmanager->changeOpacity(_propid,value);
90 void wxMaracasIRMView::changeIsoValue(int propid, int value){
91 irmmanager->changeIsoValue(propid, value);
94 void wxMaracasIRMView::changeColor(int propid, double red, double green, double blue){
96 irmmanager->changeColor(propid, red, green, blue);
100 wxString s( str,wxConvUTF8 );
101 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
108 void wxMaracasIRMView::onLoadImageFile(){
110 wxString mhd(_T("mhd"));
111 wxString stl(_T("stl"));
113 wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
114 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
116 if(fildial->ShowModal()==wxID_OK){
117 wxString filename = fildial->GetFilename();
118 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
121 if(filename.EndsWith(mhd)){
122 loadPropMHD(pathfile,filename);
123 }else if(filename.EndsWith(stl)){
124 loadProp3D(pathfile,filename);
130 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){
132 std::string s = std::string(filename.mb_str());
133 vtkImageData* img = irmmanager->getImageData(s);
135 s = std::string(dataname.mb_str());
143 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
145 int id = irmmanager->addPropMHD(imgdata,dataname);
148 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
149 int maxiso = irmmanager->getMaxIsoValue(id);
150 ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
151 addIRMViewPanel(controlpan, dataname);
156 std::cout << "Exception : " << str << '\n';
157 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
163 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){
164 std::string s = std::string(filename.mb_str());
165 vtkProp3D* prop3D = irmmanager->getProp3D(s);
167 s = std::string(dataname.mb_str() );
168 this->addProp3D(prop3D,s);
170 //TODO msj to the user indicating error in file
177 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
179 int id = irmmanager->addProp3D(prop3D,dataname);
181 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
182 addIRMViewPanel(controlpan, dataname);
185 std::cout << "Exception : " << str << '\n';
186 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
191 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
193 wxString s(dataname.c_str(),wxConvUTF8 );
194 wxAuiPaneInfo paneinfo;
195 wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
196 wxauimanager->Update();
201 ** Implementation of viewProp3D
204 wxMaracasIRMViewProp3D::wxMaracasIRMViewProp3D(wxWindow* parent,int propid)
205 :wxMaracasIRMViewPanel(parent, propid){
209 wxMaracasIRMViewProp3D::~wxMaracasIRMViewProp3D(){
212 wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false);
215 void wxMaracasIRMViewProp3D::createControls(){
218 choices[0] = wxString(_T("On"));
219 choices[1] = wxString(_T("Off"));
220 checkbox = new wxCheckBox(this,-1,wxString(_T("Show Actor")));
221 this->addControl(checkbox);
223 Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onCheckBoxChange);
224 checkbox->SetValue(true);
226 //std::string iconfile = wxMaracasIRMView::getInstance()->getPath();
227 //iconfile+= "/Data/Icons/Color.png";
228 //wxBitmap* bitmap = new wxBitmap(wxString(iconfile.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
229 wxBitmap bitmap(Color_xpm);
230 _colorchoose = new wxBitmapButton(this, -1, bitmap,wxDefaultPosition,wxSize(30,30));
231 Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onColorChange);
233 wxBoxSizer* sizercolor = new wxBoxSizer(wxVERTICAL);
234 sizercolor->Add(checkbox,wxFIXED_MINSIZE);
235 sizercolor->Add(_colorchoose,wxFIXED_MINSIZE);
236 this->addControl(sizercolor);
239 wxStaticText* label = new wxStaticText(this, -1, wxString(_T("Opacity")));
240 opacity = new wxSlider(this, -1,100,0,100,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
241 Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onOpacityRelease);
242 wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);
243 sizeropacity->Add(label,wxFIXED_MINSIZE);
244 sizeropacity->Add(opacity,wxFIXED_MINSIZE);
245 this->addControl(sizeropacity);
248 void wxMaracasIRMViewProp3D::onCheckBoxChange(wxCommandEvent& event){
249 wxMaracasIRMView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue());
251 void wxMaracasIRMViewProp3D::onColorChange(wxCommandEvent& event){
252 wxColourDialog* colourdiag = new wxColourDialog(this);
253 if(colourdiag->ShowModal()==wxID_OK){
254 wxColour colour = colourdiag->GetColourData().GetColour();
255 _colorchoose->SetBackgroundColour(colour);
257 float r = colour.Red()/255;
258 float g = colour.Green()/255;
259 float b = colour.Blue()/255;
261 wxMaracasIRMView::getInstance()->changeColor(this->getPropId(),r,g,b);
265 /*void wxMaracasIRMViewProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){
269 void wxMaracasIRMViewProp3D::onOpacityRelease(wxScrollEvent& event ){
271 wxMaracasIRMView::getInstance()->changeOpacity(this->getPropId(),opacity->GetValue());
277 ** IRM viewProp3DMHD implementation
279 wxMaracasIRMViewProp3DMHD::wxMaracasIRMViewProp3DMHD(wxWindow* parent, int propid)
280 : wxMaracasIRMViewProp3D(parent, propid)
284 wxMaracasIRMViewProp3DMHD::~wxMaracasIRMViewProp3DMHD(){
286 //wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false);
288 void wxMaracasIRMViewProp3DMHD::createControls(int maxisovalue){
290 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
292 wxStaticText* label = new wxStaticText(this, -1, wxString(_T("IsoValue")));
293 sizer->Add(label, wxGROW);
294 //this->addControl(label);
295 isovalue = new wxSlider(this, -1,maxisovalue,0,maxisovalue,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
296 sizer->Add(isovalue, wxGROW);
297 //this->addControl(isovalue);
299 this->addControl(sizer);
300 Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3DMHD::onIsoValueRelease);
303 void wxMaracasIRMViewProp3DMHD::onIsoValueRelease(wxScrollEvent& event ){
305 wxMaracasIRMView::getInstance()->changeIsoValue(this->getPropId(), isovalue->GetValue());
312 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
313 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
317 std::string iconfil = iconsdir;
319 //iconfil+= "/OpenImage.png";
320 //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
321 wxBitmap bitmap0(OpenImage_xpm);
322 this->AddTool(0, wxString(_T("test")),bitmap0);
324 /*iconfil+= "/Open.png";
325 wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
326 this->AddTool(2, wxString(_T("test")),*bitmap2); */
328 /*iconfil = iconsdir;
329 iconfil+= "/Open.png";
330 wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
331 this->AddTool(30, wxString(_T("test")),*bitmap30);*/
338 ToolBar::~ToolBar(void){
340 void ToolBar::onLoadImageFile(wxCommandEvent& event){
341 wxMaracasIRMView::getInstance()->onLoadImageFile();
346 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)
347 EVT_MENU(0, ToolBar::onLoadImageFile)