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