]> Creatis software - creaMaracasVisu.git/blob - lib/GUI/Wx/SurfaceRenderer/wxMaracasSurfaceRendering.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / GUI / Wx / SurfaceRenderer / wxMaracasSurfaceRendering.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /*=========================================================================
27
28   Program:   wxMaracas
29   Module:    $RCSfile: wxMaracasSurfaceRendering.cxx,v $
30   Language:  C++
31   Date:      $Date: 2012/11/15 14:15:37 $
32   Version:   $Revision: 1.3 $
33
34   Copyright: (c) 2002, 2003
35   License:
36
37      This software is distributed WITHOUT ANY WARRANTY; without even
38      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39      PURPOSE.  See the above copyright notice for more information.
40
41 =========================================================================*/
42
43 // EOF - wxMaracasMPR.cxx
44
45 #include "wxMaracasSurfaceRendering.h"
46 #include "wxMaracasSurfaceRenderingProp3DMHD.h"
47 #include "wxMaracasSurfaceRenderingProp3D.h"
48
49 #include <wx/colordlg.h>
50 #include <wx/bmpbuttn.h>
51
52 #include <OpenImage.xpm>
53 #include <Color.xpm>
54
55 wxMaracasSurfaceRendering* wxMaracasSurfaceRendering::instance=NULL;
56
57 wxMaracasSurfaceRendering::wxMaracasSurfaceRendering( wxWindow* parent,std::string path)
58 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
59
60         surrendmanager = new wxMaracasSurfaceRenderingManager();
61
62         wxauimanager = new wxAuiManager(this);
63
64         _path = path;
65
66         std::string iconsdir = path;
67         iconsdir+="/data/Icons";
68         this->_toolb = new ToolBar(this,iconsdir);
69         
70         wxStaticText* txt = new wxStaticText(this, -1, wxString(_T("  Surface Rendering  ")));
71         wxAuiPaneInfo paneinfo;
72         wxauimanager->AddPane(txt,paneinfo.ToolbarPane().Top());
73         wxauimanager->AddPane(_toolb,paneinfo.ToolbarPane().Top());
74
75         wxauimanager->Update();
76         createFileChooser();
77 }
78 wxMaracasSurfaceRendering::~wxMaracasSurfaceRendering( ){
79         delete _toolb;
80 }
81
82 std::string wxMaracasSurfaceRendering::getPath(){
83         return _path;
84 }
85
86 void wxMaracasSurfaceRendering::createFileChooser(){
87
88 }
89
90 wxMaracasSurfaceRendering* wxMaracasSurfaceRendering::getInstance(wxWindow* parent,std::string path){
91         if(instance==NULL){
92                 instance = new wxMaracasSurfaceRendering(parent,path);
93         }
94         return instance;
95 }
96
97 wxMaracasSurfaceRendering* wxMaracasSurfaceRendering::getInstance(){
98         return instance;
99 }
100
101 void wxMaracasSurfaceRendering::setRenderer(vtkRenderer*  renderer){
102         surrendmanager->setRenderer(renderer);
103 }
104
105 void wxMaracasSurfaceRendering::setInteractor(vtkRenderWindowInteractor*  interactor){
106         surrendmanager->setInteractor(interactor);
107 }
108
109 void wxMaracasSurfaceRendering::addRemoveActor(int propid, bool addremove){
110         try{
111                 surrendmanager->addRemoveActor(propid, addremove);
112         }
113         catch(char* str){
114                 std::cout << "Exception : " << str << '\n';
115                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
116                 diag->ShowModal();
117                 delete diag;
118         }
119 }
120 void wxMaracasSurfaceRendering::addRemoveSurfaceBox(int propid, bool addremove){
121         try{
122                 surrendmanager->addRemoveSurfaceBox(propid, addremove);
123         }
124         catch(char* str){
125                 std::cout << "Exception : " << str << '\n';
126                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
127                 diag->ShowModal();
128                 delete diag;
129         }
130 }
131
132
133 void wxMaracasSurfaceRendering::changeOpacity(int _propid, int value){
134         try{
135                 surrendmanager->changeOpacity(_propid,value);
136         }
137         catch(char* str){
138                 std::cout << "Exception : " << str << '\n';
139                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
140                 diag->ShowModal();
141                 delete diag;
142         }
143 }
144
145 void wxMaracasSurfaceRendering::changeIsoValue(int propid, double value){
146         try{
147                 surrendmanager->changeIsoValue(propid, value);
148         }
149         catch(char* str){
150                 std::cout << "Exception : " << str << '\n';
151                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
152                 diag->ShowModal();
153                 delete diag;
154         }
155 }
156
157 void wxMaracasSurfaceRendering::changeColor(int propid, double red, double green, double blue){
158         try{
159                 surrendmanager->changeColor(propid, red, green, blue);
160
161         }catch(char* str){
162
163                 wxString s( str,wxConvUTF8 );
164                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
165                 diag->ShowModal();
166                 delete diag;
167         }
168 }
169
170 void wxMaracasSurfaceRendering::onLoadImageFile(){
171
172         wxString mhd(_T("mhd"));
173         wxString stl(_T("stl"));
174
175         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a STL file")),wxString(_T("")),
176                 wxString(_T("")),wxString(_T("STL files (*.stl)|*.stl|MHD files (*.mhd)|*.mhd")) );
177
178         if(fildial->ShowModal()==wxID_OK){
179         wxString filename = fildial->GetFilename();
180                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
181
182                 if(filename.EndsWith(mhd))
183                 {
184                         loadPropMHD(pathfile,filename);
185                 }
186                 else if(filename.EndsWith(stl)){
187             loadProp3D(pathfile,filename);
188                 }
189         }
190         delete fildial;
191 }
192
193 void wxMaracasSurfaceRendering::loadPropMHD(wxString filename, wxString dataname){
194
195         std::string s = std::string(filename.mb_str());
196         vtkImageData* img = surrendmanager->getImageData(s);
197         if(img!=NULL){
198                 s = std::string(dataname.mb_str());
199                 addPropMHD(img, s);
200         }
201 }
202
203 void wxMaracasSurfaceRendering::addPropMHD(vtkImageData* imgdata, std::string dataname){
204         try{
205                 int id = surrendmanager->addPropMHD(-1, imgdata,dataname);
206                 if(id!=-1){
207
208                         wxMaracasSurfaceRenderingPanel* controlpan = new wxMaracasSurfaceRenderingProp3DMHD(this, id, false, -1);
209                         int maxiso = surrendmanager->getMaxIsoValue(id);
210                         ((wxMaracasSurfaceRenderingProp3DMHD*)controlpan)->createControls(maxiso);
211                         addSurfaceRenderingPanel(controlpan, dataname);
212                 }
213
214         }catch(char* str){
215
216                 std::cout << "Exception : " << str << '\n';
217                 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
218                 diag->ShowModal();
219                 delete diag;
220         }
221 }
222
223 void wxMaracasSurfaceRendering::loadProp3D(wxString filename, wxString dataname){
224         std::string fn = std::string(filename.mb_str());
225         std::string dn = std::string(dataname.mb_str());
226
227         int id = surrendmanager->addProp3D(-1, fn, dn);
228
229         if(id!=-1){
230                 wxMaracasSurfaceRenderingPanel* controlpan = new wxMaracasSurfaceRenderingProp3D(this, id, false, -1);
231                 addSurfaceRenderingPanel(controlpan, dn);
232         }
233         /*vtkProp3D* prop3D = surrendmanager->getProp3D(s);
234         if(prop3D != NULL){
235                 s = std::string(dataname.mb_str() );
236                 this->addProp3D(prop3D,s);
237         }else{
238                 //TODO msj to the user indicating error in file
239         }*/
240 }
241
242 void wxMaracasSurfaceRendering::addProp3D(vtkProp3D* prop3D, std::string dataname){
243         try{
244                 int id = surrendmanager->addProp3D(-1, prop3D,dataname);
245                 if(id!=-1){
246                         wxMaracasSurfaceRenderingPanel* controlpan = new wxMaracasSurfaceRenderingProp3D(this, id, false, -1);
247                         addSurfaceRenderingPanel(controlpan, dataname);
248                 }
249         }catch(char* str){
250                 std::cout << "Exception : " << str << '\n';
251                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
252                 diag->ShowModal();
253                 delete diag;
254         }
255 }
256 void wxMaracasSurfaceRendering::addSurfaceRenderingPanel(wxMaracasSurfaceRenderingPanel* surrend, std::string dataname){
257
258         wxString s(dataname.c_str(),wxConvUTF8 );
259         wxAuiPaneInfo paneinfo;
260         wxauimanager->AddPane(surrend, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
261         wxauimanager->Update();
262 }
263
264 void wxMaracasSurfaceRendering::deleteActor(int propid){
265         try{
266                 surrendmanager->deleteActor(propid);
267         }catch(char* str){
268                 //CPR
269                 std::cout << "Exception : " << str << '\n';
270                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
271                 diag->ShowModal();
272                 delete diag;
273         }
274 }
275
276 bool wxMaracasSurfaceRendering::interactorSet(){
277         return surrendmanager->interactorSet();
278 }
279
280 /**
281 **
282 **/
283
284 ToolBar::ToolBar(wxWindow * parent,std::string iconsdir)
285 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
286 {
287         std::string iconfil = iconsdir;
288
289         //iconfil+= "/OpenImage.png";
290         //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
291         wxBitmap bitmap0(OpenImage_xpm);
292         this->AddTool(1, wxString(_T("test")),bitmap0, NULL, wxITEM_NORMAL, wxString(_T("Open File")));
293         
294         /*iconfil+= "/Open.png";
295         wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
296         this->AddTool(2, wxString(_T("test")),*bitmap2);        */
297
298         /*iconfil = iconsdir;
299         iconfil+= "/Open.png";
300         wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
301         this->AddTool(30, wxString(_T("test")),*bitmap30);*/
302
303         this->Realize();
304
305         _evthand = new ToolBarEventHandler();
306         this->SetEventHandler(_evthand);
307 }
308
309 ToolBar::~ToolBar(void){
310 }
311
312 ToolBarEventHandler::ToolBarEventHandler()
313 : wxEvtHandler(){
314 }
315
316 ToolBarEventHandler::~ToolBarEventHandler(){
317 }
318
319 void ToolBarEventHandler::onLoadImageFile(wxCommandEvent& event){
320         wxMaracasSurfaceRendering::getInstance()->onLoadImageFile();
321 }
322
323
324 BEGIN_EVENT_TABLE(ToolBarEventHandler, wxEvtHandler)
325         EVT_MENU(1, ToolBarEventHandler::onLoadImageFile)
326 END_EVENT_TABLE()
327
328