1 /*=========================================================================
4 Module: $RCSfile: wxMaracasIRMView.cxx,v $
6 Date: $Date: 2009/04/09 13:58:38 $
7 Version: $Revision: 1.2 $
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 std::cout << "Exception : " << str << '\n';
98 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str), wxString(str), wxICON_ERROR);
104 void wxMaracasIRMView::onLoadImageFile(){
106 wxString mhd(_T("mhd"));
107 wxString stl(_T("stl"));
109 wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
110 wxString(_T("")),"STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd" );
112 if(fildial->ShowModal()==wxID_OK){
113 wxString filename = fildial->GetFilename();
114 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
117 if(filename.EndsWith(mhd)){
118 loadPropMHD(pathfile,filename);
119 }else if(filename.EndsWith(stl)){
120 loadProp3D(pathfile,filename);
126 void wxMaracasIRMView::loadPropMHD(wxString filename, wxString dataname){
129 vtkImageData* img = irmmanager->getImageData(filename.c_str());
131 addPropMHD(img, dataname.c_str());
138 void wxMaracasIRMView::addPropMHD(vtkImageData* imgdata, std::string dataname){
140 int id = irmmanager->addPropMHD(imgdata,dataname);
143 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3DMHD(this, id);
144 int maxiso = irmmanager->getMaxIsoValue(id);
145 ((wxMaracasIRMViewProp3DMHD*)controlpan)->createControls(maxiso);
146 addIRMViewPanel(controlpan, dataname);
151 std::cout << "Exception : " << str << '\n';
152 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str), wxString(str), wxICON_ERROR);
158 void wxMaracasIRMView::loadProp3D(wxString filename, wxString dataname){
160 vtkProp3D* prop3D = irmmanager->getProp3D(filename.c_str());
162 this->addProp3D(prop3D,dataname.c_str());
164 //TODO msj to the user indicating error in file
171 void wxMaracasIRMView::addProp3D(vtkProp3D* prop3D, std::string dataname){
173 int id = irmmanager->addProp3D(prop3D,dataname);
175 wxMaracasIRMViewPanel* controlpan = new wxMaracasIRMViewProp3D(this, id);
176 addIRMViewPanel(controlpan, dataname);
179 std::cout << "Exception : " << str << '\n';
180 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str), wxString(str), wxICON_ERROR);
185 void wxMaracasIRMView::addIRMViewPanel(wxMaracasIRMViewPanel* irmview, std::string dataname){
187 wxString s(dataname.c_str());
188 wxAuiPaneInfo paneinfo;
189 wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
190 wxauimanager->Update();
195 ** Implementation of viewProp3D
198 wxMaracasIRMViewProp3D::wxMaracasIRMViewProp3D(wxWindow* parent,int propid)
199 :wxMaracasIRMViewPanel(parent, propid){
203 wxMaracasIRMViewProp3D::~wxMaracasIRMViewProp3D(){
204 wxMaracasIRMView::getInstance()->addRemoveActor(_propid, false);
207 void wxMaracasIRMViewProp3D::createControls(){
212 checkbox = new wxCheckBox(this,-1,wxString(_T("Show Actor")));
213 this->addControl(checkbox);
214 Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onCheckBoxChange);
215 checkbox->SetValue(true);
218 wxBoxSizer* sizercolor = new wxBoxSizer(wxVERTICAL);
219 std::string iconfile = wxMaracasIRMView::getInstance()->getPath();
220 iconfile+= "/Data/Icons/Color.png";
221 wxBitmap* bitmap = new wxBitmap(wxString(iconfile.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
222 _colorchoose = new wxBitmapButton(this, -1, *bitmap);
223 sizercolor->Add(_colorchoose,wxFIXED_MINSIZE);
224 Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onColorChange);
226 this->addControl(sizercolor);
229 wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);
230 wxStaticText* label = new wxStaticText(this, -1, wxString(_T("Opacity")));
231 sizeropacity->Add(label,wxFIXED_MINSIZE);
232 opacity = new wxSlider(this, -1,100,0,100,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
233 sizeropacity->Add(opacity,wxFIXED_MINSIZE);
234 Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onOpacityRelease);
236 this->addControl(sizeropacity);
239 /*isovalue = new wxSlider(this, -1,0,0,100);
240 this->addControl(isovalue);
241 Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3D::onIsoValueRelease); */
243 void wxMaracasIRMViewProp3D::onCheckBoxChange(wxCommandEvent& event){
244 wxMaracasIRMView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue());
246 void wxMaracasIRMViewProp3D::onColorChange(wxCommandEvent& event){
247 wxColourDialog* colourdiag = new wxColourDialog(this);
248 if(colourdiag->ShowModal()==wxID_OK){
249 wxColour colour = colourdiag->GetColourData().GetColour();
250 _colorchoose->SetBackgroundColour(colour);
252 float r = colour.Red()/255;
253 float g = colour.Green()/255;
254 float b = colour.Blue()/255;
256 wxMaracasIRMView::getInstance()->changeColor(this->getPropId(),r,g,b);
260 /*void wxMaracasIRMViewProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){
264 void wxMaracasIRMViewProp3D::onOpacityRelease(wxScrollEvent& event ){
266 wxMaracasIRMView::getInstance()->changeOpacity(this->getPropId(),opacity->GetValue());
272 ** IRM viewProp3DMHD implementation
274 wxMaracasIRMViewProp3DMHD::wxMaracasIRMViewProp3DMHD(wxWindow* parent, int propid)
275 : wxMaracasIRMViewProp3D(parent, propid)
279 wxMaracasIRMViewProp3DMHD::~wxMaracasIRMViewProp3DMHD(){
282 void wxMaracasIRMViewProp3DMHD::createControls(int maxisovalue){
284 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
286 wxStaticText* label = new wxStaticText(this, -1, wxString(_T("IsoValue")));
287 sizer->Add(label, wxGROW);
288 //this->addControl(label);
289 isovalue = new wxSlider(this, -1,maxisovalue,0,maxisovalue,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS);
290 sizer->Add(isovalue, wxGROW);
291 //this->addControl(isovalue);
293 this->addControl(sizer);
294 Connect(isovalue->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasIRMViewProp3DMHD::onIsoValueRelease);
297 void wxMaracasIRMViewProp3DMHD::onIsoValueRelease(wxScrollEvent& event ){
299 wxMaracasIRMView::getInstance()->changeIsoValue(this->getPropId(), isovalue->GetValue());
306 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
307 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
311 std::string iconfil = iconsdir;
313 iconfil+= "/OpenImage.png";
314 wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
315 this->AddTool(0, wxString(_T("test")),*bitmap0);
317 /*iconfil+= "/Open.png";
318 wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
319 this->AddTool(2, wxString(_T("test")),*bitmap2); */
321 /*iconfil = iconsdir;
322 iconfil+= "/Open.png";
323 wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
324 this->AddTool(30, wxString(_T("test")),*bitmap30);*/
331 ToolBar::~ToolBar(void){
333 void ToolBar::onLoadImageFile(wxCommandEvent& event){
334 wxMaracasIRMView::getInstance()->onLoadImageFile();
339 BEGIN_EVENT_TABLE(ToolBar, wxToolBar)
340 EVT_MENU(0, ToolBar::onLoadImageFile)