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