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