]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DViewCntrlPanel.cxx
#3020 creaMaracasVisu Bug New Normal - ViewerNV opacity, isovalue slice (size)
[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                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
348
349         }
350 }
351
352 //-------------------------------------------------------------------
353 void wxVtkClipping3DViewCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
354 {
355         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
356         _wxvtkclipping3Dview->Refresh();
357
358         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
359         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
360 }
361 //-------------------------------------------------------------------
362 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface(wxCommandEvent& event)
363 {
364         _wxvtkclipping3Dview->SetVisibleBoxSurface(event.IsChecked() );
365         _wxvtkclipping3Dview->Refresh();
366 }
367 //-------------------------------------------------------------------
368 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
369 {
370 printf("EED ERROR JPReyes wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume  calling    _wxvtkclipping3Dview->SetVisibleBoxVolume that not exists ...");
371 //EED01July2011 _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
372         //this->BoundingBoxChanged(event.IsChecked());
373         _wxvtkclipping3Dview->Refresh();
374 }
375 //-------------------------------------------------------------------
376 void wxVtkClipping3DViewCntrlPanel::OnColor(wxCommandEvent& event)
377 {
378         int idTissue=GetIdTissue();
379         if (idTissue!=-1)
380         {
381 // EED 17 Janvier 2007
382                 wxColourDialog dlgColour(this);
383 //              dlgColour.ShowModal();
384                 if( dlgColour.ShowModal( ) == wxID_OK )
385                 {
386                         vtkActor *tmpActor;
387                         tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
388                         float r=dlgColour.GetColourData().GetColour().Red()/255;
389                         float g=dlgColour.GetColourData().GetColour().Green()/255;
390                         float b=dlgColour.GetColourData().GetColour().Blue()/255;
391                         tmpActor->GetProperty()->SetColor( r , g , b );
392                         _color->SetBackgroundColour(dlgColour.GetColourData().GetColour());
393
394                         _wxvtkclipping3Dview->Refresh();
395
396                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
397                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
398                 }
399         }
400 }
401 //-------------------------------------------------------------------
402 void wxVtkClipping3DViewCntrlPanel::OnVisibleSurface(wxCommandEvent& event)
403 {
404         int idTissue=GetIdTissue();
405         if (idTissue!=-1)
406         {
407                 _wxvtkclipping3Dview->VisibleActor(idTissue, _visible->GetValue());
408
409                 _wxvtkclipping3Dview->Refresh();
410
411                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
412                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
413         }
414 }
415 //-------------------------------------------------------------------
416 void wxVtkClipping3DViewCntrlPanel::OnOpacity(wxScrollEvent& event)
417 {
418         int idTissue=GetIdTissue();
419         if (idTissue!=-1)
420         {
421                 vtkActor *tmpActor;
422                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
423                 float opacity=_opacity->GetValue();
424                 tmpActor->GetProperty()->SetOpacity( opacity/100 );
425
426                 _wxvtkclipping3Dview->Refresh();
427
428                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
429                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
430         }
431 }
432
433 //----------------------------------------------------------------------------
434 void wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin(wxScrollEvent& event)
435 {
436         int value = _isoValue->GetValue();
437         int delta= (int)pow( (double)4 ,(double) _isoValueSpin->GetValue() );
438         int min=value - delta/2;
439         int max=value + delta/2;
440         if (min<0)
441         {
442                 min=0;
443                 max=delta;
444         }
445         _isoValue->SetRange(min,max);
446 }
447
448
449 //------------------------------------------------------------------------
450 void wxVtkClipping3DViewCntrlPanel::OnIsoValue(wxScrollEvent& event)
451 {
452         wxBusyCursor wait;
453
454         int idTissue=GetIdTissue();
455         if (idTissue!=-1)
456         {
457                 int isoValue=_isoValue->GetValue();
458                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->SetIsovalue(idTissue,isoValue);
459 //              wxString tmpStr;
460 //              tmpStr.Printf("%d",isoValue);
461
462                 _wxvtkclipping3Dview->Refresh();
463
464                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
465                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
466         }
467
468 }
469 //-------------------------------------------------------------------
470 void wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL(wxCommandEvent& event)
471 {
472
473         int idTissue=GetIdTissue();
474         if (idTissue==-1)
475         {
476                 idTissue=0;
477         }
478
479
480         wxString dirSTL = wxGetHomeDir( ) ;
481         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
482
483         if( dialog.ShowModal( ) == wxID_OK )
484         {
485
486
487                 // ------------------------------------------------------------------------
488                 //  1.  GENERATE STL FILES
489                 // ------------------------------------------------------------------------
490 //              const char* fileprefix = "c:\\Creatis\\";
491                 std::string prefix = (const char*) (dialog.GetPath().mb_str() );
492                 std::string filename;
493
494                 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
495
496         vtkTriangleFilter *filtro = vtkTriangleFilter::New();
497
498
499                 filtro->SetInput( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
500                 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
501         pdcf->SetInput( filtro->GetOutput() );
502         vtkClosePolyData *cpd = vtkClosePolyData::New();
503         cpd->SetInput( pdcf->GetOutput() );
504
505                 // 1.2 se escribe a disco el archivo stl de la superficie interna
506         cpd->Update();
507         vtkSTLWriter *writer = vtkSTLWriter::New();
508         writer->SetInput( cpd->GetOutput() );
509                 filename =prefix;
510         writer->SetFileName(filename.c_str());
511         writer->SetFileTypeToASCII();
512         writer->Write();
513         writer->Delete();
514
515
516         filtro->Delete();
517         cpd->Delete();
518         pdcf->Delete();
519         }
520
521 }
522
523 //EED 30 Janvier 2007
524 //-------------------------------------------------------------------
525 void wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(wxCommandEvent& event)
526 {
527         wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
528         if (dialog.ShowModal() == wxID_OK)
529         {
530                 std::string directory = (const char*) (dialog.GetDirectory().mb_str() );
531                 std::string filename  = (const char*) (dialog.GetFilename().mb_str() );
532                 float rescalaSlope           =  1;
533                 float rescalaIntercept       =  0;
534                 vtkMPRBaseData *vtkmprbasedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData();
535                 vtkImageData *vtkimagedata       = vtkmprbasedata->GetImageData();
536                 int dim[3];
537                 vtkimagedata->GetDimensions(dim);
538                 int voi[6];
539                 voi[0]=0;
540                 voi[1]=dim[0];
541                 voi[2]=0;
542                 voi[3]=dim[1];
543                 voi[4]=0;
544                 voi[5]=dim[2];
545 //EED 10 oct 2007 MaracasVisu pour bbMaracasvisu
546                 marRAW2Files marraw2;
547                 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
548         }
549 }
550
551 //EED 22 Fevrier 2007
552 //-------------------------------------------------------------------
553 void wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
554 {
555
556         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
557         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
558         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
559         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
560         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
561         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
562         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
563         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
564         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
565         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
566
567         //use for update in the refresh
568         /*
569         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
570         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
571         */
572
573         /*
574         MMLR BORRAME
575         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
576         if (dialog.ShowModal() == wxID_OK)
577         {
578                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
579
580
581         }
582         */
583
584         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
585         //
586         // put in a method
587         //
588         int tfSize=gtf->size();
589                 if(tfSize>0)
590                 {
591                         int i=0;
592                         hDlg->erasePointsTransferenceFunction();
593                         while(i<tfSize)
594                         {
595                                 double g=(*gtf)[i];
596                                 double in=(*itf)[i];
597                                 hDlg->addPointToTransferenceFunction(g,in*100);
598                                 i++;
599                         }
600
601                 }
602
603         int ctfSize=rctf->size();
604         if(ctfSize>0)
605         {
606                 int i=0;
607                         while(i<ctfSize)
608                         {
609                                 double gr=(*greyctf)[i];
610                                 double r=(*rctf)[i];
611                                 double g=(*gctf)[i];
612                                 double b=(*bctf)[i];
613                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
614                                 i++;
615                         }
616         }
617         //setting variables if the user wants to do refresh
618         hDlg->setCTF(ctfun);
619         hDlg->setTF(tfun);
620         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
621         /*
622         hDlg->setVolume(newvol);
623         hDlg->setVolumeMapper(volumeMapper);
624         */
625         //
626         // when the user had changed the transference Function
627         //
628         if(hDlg->ShowModal()== wxID_OK )
629         {
630                         // -- vtkPiecewiseFunction --
631                         tfun->RemoveAllPoints();
632                         gtf->clear();
633                         itf->clear();
634
635                         int nTFPoints=hDlg->getSizeTransferenceFunction();
636                         int i=0;
637                         while(i<nTFPoints)
638                         {
639                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
640                                 tfun->AddPoint( xi , yi/100.0 );
641                                 gtf->push_back(xi);
642                                 itf->push_back(yi/100.0);
643                                 i++;
644                         }
645                         // -- vtkColorTransferFunction  --
646                         ctfun->RemoveAllPoints ();
647                         //clean colors
648                         rctf->clear();
649                         gctf->clear();
650                         bctf->clear();
651                         greyctf->clear();
652
653                         int nCTFpoints=hDlg->getSizeBarColor();
654                         i=0;
655                         while(i<nCTFpoints)
656                         {
657                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
658                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
659                                 rctf->push_back(r/255.0);
660                                 gctf->push_back(g/255.0);
661                                 bctf->push_back(b/255.0);
662                                 greyctf->push_back(xi);
663                                 i++;
664                         }
665                         //---------------------------------
666                         // Refreshing and sending the event
667                         //---------------------------------
668                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
669                         _wxvtkclipping3Dview->Refresh();
670                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
671                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
672
673                         /*
674                         volumeMapper->Update();
675                         newvol->Update();
676                         */
677         } else  {
678                 if(hDlg->getRefreshed())
679                 {
680                         int i=0,size;
681                         //--Transference Function----
682                         tfun->RemoveAllPoints();
683                         i=0;
684                         size=gtf->size();
685                         for(i=0;i<size;i++)
686                         {
687                                 double grey1=(*gtf)[i];
688                                 double  in2=(*itf)[i];
689                                 tfun->AddPoint( grey1 , in2 );
690                         }
691
692                         // -- vtkColorTransferFunction  --
693                         ctfun->RemoveAllPoints ();
694
695                         i=0;
696                         size=greyctf->size();
697                         for(i=0;i<size;i++)
698                         {
699                                 double grey2=(*greyctf)[i];
700                                 double red =(*rctf)[i];
701                                 double green =(*gctf)[i];
702                                 double blue = (*bctf)[i];
703                                 ctfun->AddRGBPoint(grey2,red,green,blue);
704                         }
705
706                         //---------------------------------
707                         // Refreshing and sending the event
708                         //---------------------------------
709                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
710                         _wxvtkclipping3Dview->Refresh();
711                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
712                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
713
714                         /*
715                         volumeMapper->Update();
716                         newvol->Update();
717                         */
718                  }
719
720         }
721         //destroy the dialog
722         hDlg->Destroy();
723 }
724
725 //EED 23 Mai 2007
726 //-------------------------------------------------------------------
727 void wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad(wxCommandEvent& event)
728 {
729         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxOPEN);
730         if (dialog.ShowModal() == wxID_OK)
731         {
732                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( (char *)dialog.GetPath().c_str() );
733                 _wxvtkclipping3Dview->Refresh();
734                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
735                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
736         }
737 }
738