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