]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DViewCntrlPanel.cxx
#3128 creaMaracasVisu Feature New Normal - branch changeWx28to30 compilation with...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkClipping3DViewCntrlPanel.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 #include "wxVtkClipping3DViewCntrlPanel.h"
28 #include "wx/colordlg.h"
29 #include "vtkTriangleFilter.h"
30 #include "vtkPolyDataConnectivityFilter.h"
31 #include "vtkClosePolyData.h"
32 #include "vtkSTLWriter.h"
33 #include "HistogramDialog.h"
34 #include "marDicomBase.h"
35
36 wxVtkClipping3DViewCntrlPanel::wxVtkClipping3DViewCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
37 : wxPanel(parent, -1)
38 {
39         wxPanel *panel  = this;
40         _wxvtkclipping3Dview    = wxvtkclipping3Dview;
41
42 //EEDx2.6
43 //      wxStaticText    *text1                  = new wxStaticText(panel, -1,_T("          "));
44 //      wxStaticText    *text2                  = new wxStaticText(panel, -1,_T("  "));
45
46                                         _surfA                  = new wxRadioButton(panel,-1,_T("A"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
47                                         _surfB                  = new wxRadioButton(panel,-1,_T("B"));
48                                         _surfC                  = new wxRadioButton(panel,-1,_T("C"));
49                                         _surfD                  = new wxRadioButton(panel,-1,_T("D"));
50
51         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
52         //wxCheckBox            *ckVolum                = new wxCheckBox(panel,-1,_T("Vol"));
53         wxCheckBox              *ckBoxSurface   = new wxCheckBox(panel,-1,_T("Surface Box"));
54
55         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
56         //wxCheckBox            *ckBoxVolume    = new wxCheckBox(panel,-1,_T("Volume Box"));
57
58                                         _color                  = new wxButton(panel,-1,_T(""));
59                                         _visible                = new wxCheckBox(panel,-1,_T("Vis"));
60                                         _opacity                = new wxSlider(panel,-1,50,0,100, wxDefaultPosition, wxSize(100,40), wxSL_HORIZONTAL | wxSL_LABELS);
61
62         wxStaticText    *isoValueTitle  = new wxStaticText(panel,-1,_T("isoValue"));
63                                         _isoValue               = new wxSlider(panel,-1,2000,110,2000, wxDefaultPosition, wxSize(300,40), wxSL_HORIZONTAL  |  wxSL_AUTOTICKS | wxSL_LABELS);
64
65                                         _wireFrameRep   = new wxRadioButton(panel,-1,_T("WireFrame"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
66                                         _surfaceRep             = new wxRadioButton(panel,-1,_T("Surface"));
67
68         double range[2];
69         vtkImageData *vtkimagedata = wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
70         vtkimagedata->GetScalarRange( range );
71         _isoValue->SetRange( (int)(range[1]*0.1) , (int)(range[1]) );
72         _isoValue->SetValue( (int)(wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(0)) );
73
74         _isoValue->SetTickFreq(25,0);
75
76         _isoValueSpin   = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
77         _isoValueSpin->SetRange(1,8);
78         _isoValueSpin->SetValue(5);
79         Connect(_isoValueSpin->GetId()  , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin );
80
81         wxButton *btnSTL                                = new wxButton(panel,-1,_T("Create STL File"));
82         wxButton *btnSaveRaw                    = new wxButton(panel,-1,_T("Save Raw Volume"));
83
84         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
85         //wxButton *btnVolumeFunctions  = new wxButton(panel,-1,_T("Read Volume Functions"));
86
87
88         Connect(btnSTL->GetId()                         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL    );
89         Connect(btnSaveRaw->GetId()                     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume    );
90
91         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
92         //Connect(btnVolumeFunctions->GetId()   , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions  );
93
94
95         wxButton *btnMeshVTKLoad        = new wxButton(panel,-1,_T("Load Mesh"));
96         Connect(btnMeshVTKLoad->GetId() , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad      );
97
98
99 /*
100         int maxX = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
101         int maxY = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
102         int maxZ = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();
103         wxCheckBox              *ckBoxX                 = new wxCheckBox(panel,-1,"X");
104                                         _positionX              = new wxSlider(panel,-1,maxX/2,0,maxX, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
105         wxCheckBox              *ckBoxY                 = new wxCheckBox(panel,-1,"Y");
106                                         _positionY              = new wxSlider(panel,-1,maxY/2,0,maxY, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
107         wxCheckBox              *ckBoxZ                 = new wxCheckBox(panel,-1,"Z");
108                                         _positionZ              = new wxSlider(panel,-1,maxZ/2,0,maxZ, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
109 */
110
111 //      ckVolum->Enable(false);
112         ckBoxSurface->SetValue(false);
113
114
115         //ckBoxVolume->SetValue(false);
116
117
118         _color->SetSize(40,20);
119         _opacity->SetSize(370,20);
120 //      ckBoxX->SetValue(true);
121 //      ckBoxY->SetValue(true);
122 //      ckBoxZ->SetValue(true);
123         _surfA->SetValue(true);
124         _wireFrameRep->SetValue(false);
125         _surfaceRep->SetValue(true);
126         _visible->SetValue(false);
127 //      _positionX->SetSize(400,20);
128 //      _positionY->SetSize(400,20);
129 //      _positionZ->SetSize(400,20);
130
131         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
132         //Connect(ckVolum->GetId()              , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleVolume                             );
133         //Connect(ckBoxVolume->GetId()  , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume                  );
134
135         Connect(_surfA->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
136         Connect(_surfB->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
137         Connect(_surfC->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
138         Connect(_surfD->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
139         Connect(ckBoxSurface->GetId()   , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface                 );
140
141         Connect(_wireFrameRep->GetId()  , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame        );
142         Connect(_surfaceRep->GetId()    , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame        );
143
144         Connect(_color->GetId()                 , wxEVT_COMMAND_BUTTON_CLICKED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnColor                                             );
145         Connect(_visible->GetId()               , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleSurface                    );
146         Connect(_opacity->GetId()               , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnOpacity                                   );
147
148 //EED 27Dic2007
149 //      Connect(_isoValue->GetId()              , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue                                  );
150         Connect(_isoValue->GetId()              , wxEVT_SCROLL_THUMBRELEASE               , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue                                          );
151
152 /*
153         Connect(ckBoxX->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX   );
154         Connect(_positionX->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionX              );
155         Connect(ckBoxY->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY   );
156         Connect(_positionY->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionY              );
157         Connect(ckBoxZ->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ   );
158         Connect(_positionZ->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionZ              );
159 */
160
161         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
162         wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
163         wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
164         wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(10);
165         wxFlexGridSizer *sizerH3 = new wxFlexGridSizer(10);
166         //wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10); // JPRx
167         //wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10); // JPRx
168         //wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10); // JPRx
169
170         //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
171         //sizerH0->Add( ckVolum                                                                 , 1, wxALL|wxEXPAND, 0);
172         //sizerH0->Add( new wxStaticText(panel, -1,_T("          "))    , 1, wxALL|wxEXPAND, 0);
173         //sizerH0->Add( ckBoxVolume                                                             , 1, wxALL|wxEXPAND, 0);
174         //sizerH0->Add( new wxStaticText(panel, -1,_T("          "))    , 1, wxALL|wxEXPAND, 0);
175         //sizerH0->Add( btnVolumeFunctions                                              , 1, wxALL|wxEXPAND, 0);
176         //sizerH0->Add( new wxStaticText(panel, -1,_T("          "))    , 1, wxALL|wxEXPAND, 0);
177         sizerH0->Add( btnMeshVTKLoad                                                    , 1, wxALL|wxEXPAND, 0);
178
179
180         sizerH1->Add( _surfA                                                                    , 1, wxALL|wxEXPAND, 0);
181         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))              , 1, wxALL|wxEXPAND, 0);
182         sizerH1->Add( _surfB                                                                    , 1, wxALL|wxEXPAND, 0);
183         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))              , 1, wxALL|wxEXPAND, 0);
184         sizerH1->Add( _surfC                                                                    , 1, wxALL|wxEXPAND, 0);
185         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))              , 1, wxALL|wxEXPAND, 0);
186         sizerH1->Add( _surfD                                                                    , 1, wxALL|wxEXPAND, 0);
187         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
188         sizerH1->Add( ckBoxSurface                                                              , 1, wxALL|wxEXPAND, 0);
189         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
190         sizerH1->Add( btnSTL                                                                    , 1, wxALL|wxEXPAND, 0);
191         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
192         sizerH1->Add( btnSaveRaw                                                                , 1, wxALL|wxEXPAND, 0);
193
194
195 //      sizerH2->Add( new wxStaticText(panel, -1,_T("          ")                       , 1, wxALL|wxEXPAND, 0);
196         sizerH2->Add( _color                            , 1, wxALL|wxEXPAND, 0);
197         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
198         sizerH2->Add( _visible                          , 1, wxALL|wxEXPAND, 0);
199         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
200
201
202         sizerH2->Add( _wireFrameRep                             , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
203         sizerH2->Add( new wxStaticText(panel, -1,_T("   "))                                     , 1, wxALL|wxEXPAND, 0);
204         sizerH2->Add( _surfaceRep                               , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
205         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
206
207
208
209         sizerH3->Add( isoValueTitle                     , 1, wxALL|wxEXPAND, 0);
210         sizerH3->Add( _isoValueSpin                     , 1, wxALL|wxEXPAND, 0);
211         sizerH3->Add( _isoValue                         , 1, wxALL|wxEXPAND, 0);
212
213         sizerH3->Add( new wxStaticText(panel, -1,_T("      "))                  , 1, wxALL|wxEXPAND, 0);
214         sizerH3->Add( new wxStaticText(panel, -1,_T("Opacity:"))                        , 1, wxALL|wxEXPAND, 0);
215         sizerH3->Add( _opacity                          , 1, wxALL|wxEXPAND, 0);
216
217
218 /*
219         sizerH4->Add( ckBoxX            , 1, wxALL|wxEXPAND, 0);
220         sizerH4->Add( text2                     , 1, wxALL|wxEXPAND, 0);
221         sizerH4->Add( _positionX                , 1, wxALL|wxEXPAND, 0);
222
223         sizerH5->Add( ckBoxY            , 1, wxALL|wxEXPAND, 0);
224         sizerH5->Add( text2                     , 1, wxALL|wxEXPAND, 0);
225         sizerH5->Add( _positionY                , 1, wxALL|wxEXPAND, 0);
226
227         sizerH6->Add( ckBoxZ            , 1, wxALL|wxEXPAND, 0);
228         sizerH6->Add( text2                     , 1, wxALL|wxEXPAND, 0);
229         sizerH6->Add( _positionZ                , 1, wxALL|wxEXPAND, 0);
230 */
231         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
232         sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
233         sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
234         sizer->Add( sizerH3 , 1, wxALL|wxEXPAND, 2);
235 //      sizer->Add( sizerH4 , 1, wxALL|wxEXPAND, 2);
236 //      sizer->Add( sizerH5 , 1, wxALL|wxEXPAND, 2);
237 //      sizer->Add( sizerH6 , 1, wxALL|wxEXPAND, 2);
238
239         panel->SetSize(300,60);
240         panel->SetAutoLayout(true);
241         panel->SetSizer(sizer);
242         panel->Layout();
243
244         panel->SetEventHandler((wxEvtHandler*)this);
245
246 }
247 //-------------------------------------------------------------------
248 wxVtkClipping3DViewCntrlPanel::~wxVtkClipping3DViewCntrlPanel()
249 {
250 }
251 //-------------------------------------------------------------------
252 void wxVtkClipping3DViewCntrlPanel::Refresh()
253 {
254 //      wxPanel::Refresh();
255 /*
256         _positionX->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetX( ) );
257         _positionY->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetY( ) );
258         _positionZ->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetZ( ) );
259 */
260 }
261 //-------------------------------------------------------------------
262 int wxVtkClipping3DViewCntrlPanel::GetIdTissue()
263 {
264         int idTissue=-1;
265         if (_surfA->GetValue()==true)
266         {
267                 idTissue=0;
268         }
269         if (_surfB->GetValue()==true)
270         {
271                 idTissue=1;
272         }
273         if (_surfC->GetValue()==true)
274         {
275                 idTissue=2;
276         }
277         if (_surfD->GetValue()==true)
278         {
279                 idTissue=3;
280         }
281
282         return idTissue;
283 }
284 /*
285 //-------------------------------------------------------------------
286 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
287 {
288         _wxvtkclipping3Dview->VisibleImageActor(0, event.IsChecked() );
289         _wxvtkclipping3Dview->Refresh();
290 }
291 //-------------------------------------------------------------------
292 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
293 {
294         _wxvtkclipping3Dview->VisibleImageActor(1, event.IsChecked() );
295         _wxvtkclipping3Dview->Refresh();
296 }
297 //-------------------------------------------------------------------
298 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
299 {
300         _wxvtkclipping3Dview->VisibleImageActor(2, event.IsChecked() );
301         _wxvtkclipping3Dview->Refresh();
302 }
303 */
304
305 //-------------------------------------------------------------------
306 void wxVtkClipping3DViewCntrlPanel::OnSurface(wxCommandEvent& event)
307 {
308         int idTissue=GetIdTissue();
309         if (idTissue!=-1)
310         {
311                 // Color
312                 vtkActor *tmpActor;
313                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
314                 double rgb[3];
315                 tmpActor->GetProperty()->GetColor( rgb );
316                 wxColour colour( (int)(rgb[0]*255) , (int)(rgb[1]*255) , (int)(rgb[2]*255) );
317                 _color->SetBackgroundColour(colour);
318
319                 // Visible
320                 _visible->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVisibleTissue(idTissue));
321
322                 // Opacity
323                 _opacity->SetValue( (int)(tmpActor->GetProperty()->GetOpacity()*100) );
324
325                 // Representation Type  WireFrame / Surface
326                 _surfaceRep->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue));
327                 _wireFrameRep->SetValue(!_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue));
328
329                 // isoValue
330                 int isoValue= (int)(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(idTissue));
331                 _isoValue->SetValue(isoValue);
332         }
333 }
334
335
336 //-------------------------------------------------------------------
337 void wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame(wxCommandEvent& event)
338 {
339         int idTissue=GetIdTissue();
340         if (idTissue!=-1)
341         {
342                 _wxvtkclipping3Dview->SetRepSurfaceWireFrame(idTissue , _surfaceRep->GetValue() );
343
344                 _wxvtkclipping3Dview->Refresh();
345
346                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
347 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
348 #if wxMAJOR_VERSION <= 2
349                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
350 #else
351                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
352 #endif
353
354         } // if idTissue
355 }
356
357 //-------------------------------------------------------------------
358 void wxVtkClipping3DViewCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
359 {
360         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
361         _wxvtkclipping3Dview->Refresh();
362
363         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
364
365 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
366 #if wxMAJOR_VERSION <= 2
367         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
368 #else
369         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
370 #endif
371
372 }
373 //-------------------------------------------------------------------
374 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface(wxCommandEvent& event)
375 {
376         _wxvtkclipping3Dview->SetVisibleBoxSurface(event.IsChecked() );
377         _wxvtkclipping3Dview->Refresh();
378 }
379 //-------------------------------------------------------------------
380 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
381 {
382 printf("EED ERROR JPReyes wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume  calling    _wxvtkclipping3Dview->SetVisibleBoxVolume that not exists ...");
383 //EED01July2011 _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
384         //this->BoundingBoxChanged(event.IsChecked());
385         _wxvtkclipping3Dview->Refresh();
386 }
387 //-------------------------------------------------------------------
388 void wxVtkClipping3DViewCntrlPanel::OnColor(wxCommandEvent& event)
389 {
390         int idTissue=GetIdTissue();
391         if (idTissue!=-1)
392         {
393 // EED 17 Janvier 2007
394                 wxColourDialog dlgColour(this);
395 //              dlgColour.ShowModal();
396                 if( dlgColour.ShowModal( ) == wxID_OK )
397                 {
398                         vtkActor *tmpActor;
399                         tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
400                         float r=dlgColour.GetColourData().GetColour().Red()/255;
401                         float g=dlgColour.GetColourData().GetColour().Green()/255;
402                         float b=dlgColour.GetColourData().GetColour().Blue()/255;
403                         tmpActor->GetProperty()->SetColor( r , g , b );
404                         _color->SetBackgroundColour(dlgColour.GetColourData().GetColour());
405                         _wxvtkclipping3Dview->Refresh();
406                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
407 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
408 #if wxMAJOR_VERSION <= 2
409                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
410 #else
411                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
412 #endif
413                 } // if ShowModal
414         } // if idTissue
415 }
416
417 //-------------------------------------------------------------------
418 void wxVtkClipping3DViewCntrlPanel::OnVisibleSurface(wxCommandEvent& event)
419 {
420         int idTissue=GetIdTissue();
421         if (idTissue!=-1)
422         {
423                 _wxvtkclipping3Dview->VisibleActor(idTissue, _visible->GetValue());
424                 _wxvtkclipping3Dview->Refresh();
425                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
426 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
427 #if wxMAJOR_VERSION <= 2
428                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
429 #else
430                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
431 #endif
432         } // if idTissue
433 }
434 //-------------------------------------------------------------------
435 void wxVtkClipping3DViewCntrlPanel::OnOpacity(wxScrollEvent& event)
436 {
437         int idTissue=GetIdTissue();
438         if (idTissue!=-1)
439         {
440                 vtkActor *tmpActor;
441                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
442                 float opacity=_opacity->GetValue();
443                 tmpActor->GetProperty()->SetOpacity( opacity/100 );
444                 _wxvtkclipping3Dview->Refresh();
445                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
446 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
447 #if wxMAJOR_VERSION <= 2
448                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
449 #else
450                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
451 #endif
452         } // if idTissue
453 }
454
455 //----------------------------------------------------------------------------
456 void wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin(wxScrollEvent& event)
457 {
458         int value = _isoValue->GetValue();
459         int delta= (int)pow( (double)4 ,(double) _isoValueSpin->GetValue() );
460         int min=value - delta/2;
461         int max=value + delta/2;
462         if (min<0)
463         {
464                 min=0;
465                 max=delta;
466         }
467         _isoValue->SetRange(min,max);
468 }
469
470
471 //------------------------------------------------------------------------
472 void wxVtkClipping3DViewCntrlPanel::OnIsoValue(wxScrollEvent& event)
473 {
474         wxBusyCursor wait;
475
476         int idTissue=GetIdTissue();
477         if (idTissue!=-1)
478         {
479                 int isoValue=_isoValue->GetValue();
480                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->SetIsovalue(idTissue,isoValue);
481 //              wxString tmpStr;
482 //              tmpStr.Printf("%d",isoValue);
483
484                 _wxvtkclipping3Dview->Refresh();
485
486                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
487
488 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
489 #if wxMAJOR_VERSION <= 2
490                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
491 #else
492                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
493 #endif
494
495         } // if idTissue
496
497 }
498 //-------------------------------------------------------------------
499 void wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL(wxCommandEvent& event)
500 {
501
502         int idTissue=GetIdTissue();
503         if (idTissue==-1)
504         {
505                 idTissue=0;
506         }
507
508
509         wxString dirSTL = wxGetHomeDir( ) ;
510 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
511 #if wxMAJOR_VERSION <= 2
512         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
513 #else
514         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxFD_SAVE );
515 #endif
516
517         if( dialog.ShowModal( ) == wxID_OK )
518         {
519
520
521                 // ------------------------------------------------------------------------
522                 //  1.  GENERATE STL FILES
523                 // ------------------------------------------------------------------------
524 //              const char* fileprefix = "c:\\Creatis\\";
525                 std::string prefix = (const char*) (dialog.GetPath().mb_str() );
526                 std::string filename;
527
528                 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
529
530         vtkTriangleFilter *filtro = vtkTriangleFilter::New();
531
532
533                 filtro->SetInput( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
534                 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
535         pdcf->SetInput( filtro->GetOutput() );
536         vtkClosePolyData *cpd = vtkClosePolyData::New();
537         cpd->SetInput( pdcf->GetOutput() );
538
539                 // 1.2 se escribe a disco el archivo stl de la superficie interna
540         cpd->Update();
541         vtkSTLWriter *writer = vtkSTLWriter::New();
542         writer->SetInput( cpd->GetOutput() );
543                 filename =prefix;
544         writer->SetFileName(filename.c_str());
545         writer->SetFileTypeToASCII();
546         writer->Write();
547         writer->Delete();
548
549
550         filtro->Delete();
551         cpd->Delete();
552         pdcf->Delete();
553         }
554
555 }
556
557 //EED 30 Janvier 2007
558 //-------------------------------------------------------------------
559 void wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(wxCommandEvent& event)
560 {
561 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
562 #if wxMAJOR_VERSION <= 2
563         wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
564 #else
565         wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxFD_SAVE );
566 #endif
567         if (dialog.ShowModal() == wxID_OK)
568         {
569                 std::string directory = (const char*) (dialog.GetDirectory().mb_str() );
570                 std::string filename  = (const char*) (dialog.GetFilename().mb_str() );
571                 float rescalaSlope           =  1;
572                 float rescalaIntercept       =  0;
573                 vtkMPRBaseData *vtkmprbasedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData();
574                 vtkImageData *vtkimagedata       = vtkmprbasedata->GetImageData();
575                 int dim[3];
576                 vtkimagedata->GetDimensions(dim);
577                 int voi[6];
578                 voi[0]=0;
579                 voi[1]=dim[0];
580                 voi[2]=0;
581                 voi[3]=dim[1];
582                 voi[4]=0;
583                 voi[5]=dim[2];
584 //EED 10 oct 2007 MaracasVisu pour bbMaracasvisu
585                 marRAW2Files marraw2;
586                 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
587         }
588 }
589
590 //EED 22 Fevrier 2007
591 //-------------------------------------------------------------------
592 void wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
593 {
594
595         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
596         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
597         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
598         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
599         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
600         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
601         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
602         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
603         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
604         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
605
606         //use for update in the refresh
607         /*
608         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
609         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
610         */
611
612         /*
613         MMLR BORRAME
614         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
615         if (dialog.ShowModal() == wxID_OK)
616         {
617                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
618
619
620         }
621         */
622
623         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
624         //
625         // put in a method
626         //
627         int tfSize=gtf->size();
628                 if(tfSize>0)
629                 {
630                         int i=0;
631                         hDlg->erasePointsTransferenceFunction();
632                         while(i<tfSize)
633                         {
634                                 double g=(*gtf)[i];
635                                 double in=(*itf)[i];
636                                 hDlg->addPointToTransferenceFunction(g,in*100);
637                                 i++;
638                         }
639
640                 }
641
642         int ctfSize=rctf->size();
643         if(ctfSize>0)
644         {
645                 int i=0;
646                         while(i<ctfSize)
647                         {
648                                 double gr=(*greyctf)[i];
649                                 double r=(*rctf)[i];
650                                 double g=(*gctf)[i];
651                                 double b=(*bctf)[i];
652                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
653                                 i++;
654                         }
655         }
656         //setting variables if the user wants to do refresh
657         hDlg->setCTF(ctfun);
658         hDlg->setTF(tfun);
659         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
660         /*
661         hDlg->setVolume(newvol);
662         hDlg->setVolumeMapper(volumeMapper);
663         */
664         //
665         // when the user had changed the transference Function
666         //
667         if(hDlg->ShowModal()== wxID_OK )
668         {
669                         // -- vtkPiecewiseFunction --
670                         tfun->RemoveAllPoints();
671                         gtf->clear();
672                         itf->clear();
673
674                         int nTFPoints=hDlg->getSizeTransferenceFunction();
675                         int i=0;
676                         while(i<nTFPoints)
677                         {
678                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
679                                 tfun->AddPoint( xi , yi/100.0 );
680                                 gtf->push_back(xi);
681                                 itf->push_back(yi/100.0);
682                                 i++;
683                         }
684                         // -- vtkColorTransferFunction  --
685                         ctfun->RemoveAllPoints ();
686                         //clean colors
687                         rctf->clear();
688                         gctf->clear();
689                         bctf->clear();
690                         greyctf->clear();
691
692                         int nCTFpoints=hDlg->getSizeBarColor();
693                         i=0;
694                         while(i<nCTFpoints)
695                         {
696                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
697                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
698                                 rctf->push_back(r/255.0);
699                                 gctf->push_back(g/255.0);
700                                 bctf->push_back(b/255.0);
701                                 greyctf->push_back(xi);
702                                 i++;
703                         }
704                         //---------------------------------
705                         // Refreshing and sending the event
706                         //---------------------------------
707                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
708                         _wxvtkclipping3Dview->Refresh();
709                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
710
711 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
712 #if wxMAJOR_VERSION <= 2
713                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
714 #else
715                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
716 #endif
717
718
719
720                         /*
721                         volumeMapper->Update();
722                         newvol->Update();
723                         */
724         } else  {
725                 if(hDlg->getRefreshed())
726                 {
727                         int i=0,size;
728                         //--Transference Function----
729                         tfun->RemoveAllPoints();
730                         i=0;
731                         size=gtf->size();
732                         for(i=0;i<size;i++)
733                         {
734                                 double grey1=(*gtf)[i];
735                                 double  in2=(*itf)[i];
736                                 tfun->AddPoint( grey1 , in2 );
737                         }
738
739                         // -- vtkColorTransferFunction  --
740                         ctfun->RemoveAllPoints ();
741
742                         i=0;
743                         size=greyctf->size();
744                         for(i=0;i<size;i++)
745                         {
746                                 double grey2    = (*greyctf)[i];
747                                 double red      = (*rctf)[i];
748                                 double green    = (*gctf)[i];
749                                 double blue     = (*bctf)[i];
750                                 ctfun->AddRGBPoint(grey2,red,green,blue);
751                         }
752
753                         //---------------------------------
754                         // Refreshing and sending the event
755                         //---------------------------------
756                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
757                         _wxvtkclipping3Dview->Refresh();
758                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
759 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
760 #if wxMAJOR_VERSION <= 2
761                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
762 #else
763                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
764 #endif
765
766                         /*
767                         volumeMapper->Update();
768                         newvol->Update();
769                         */
770                  }
771
772         }
773         //destroy the dialog
774         hDlg->Destroy();
775 }
776
777 //EED 23 Mai 2007
778 //-------------------------------------------------------------------
779 void wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad(wxCommandEvent& event)
780 {
781 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
782 #if wxMAJOR_VERSION <= 2
783         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxOPEN);
784 #else
785         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxFD_OPEN);
786 #endif
787
788         if (dialog.ShowModal() == wxID_OK)
789         {
790                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( (char *)dialog.GetPath().c_str() );
791                 _wxvtkclipping3Dview->Refresh();
792                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
793
794 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
795 #if wxMAJOR_VERSION <= 2
796                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
797 #else
798                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
799 #endif
800
801         } // if
802 }
803