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