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