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