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