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