]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DViewVolCntrlPanel.cxx
#3207
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkClipping3DViewVolCntrlPanel.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 //-------------------------------------------------------------------
27 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
28 //-------------------------------------------------------------------
29
30 #include "wxVtkClipping3DViewVolCntrlPanel.h"
31 #include "wx/colordlg.h"
32 #include "vtkTriangleFilter.h"
33 #include "vtkPolyDataConnectivityFilter.h"
34 #include "vtkClosePolyData.h"
35 #include "vtkSTLWriter.h"
36 #include "HistogramDialog.h"
37 #include "marDicomBase.h"
38
39 wxVtkClipping3DViewVolCntrlPanel::wxVtkClipping3DViewVolCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
40 : wxPanel(parent, -1)
41 {
42         wxPanel *panel  = this;
43         _wxvtkclipping3Dview    = wxvtkclipping3Dview;
44
45
46         ckVolum         = new wxCheckBox(panel,-1,_T("Volume"));
47         ckBoxVolume     = new wxCheckBox(panel,-1,_T("Volume Box"));
48
49         ckBoxVolume->Disable();
50
51         rbRayCasting   = new wxRadioButton(panel, -1, _T("Ray Casting"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
52     rbMIP   = new wxRadioButton(panel, -1, _T("MIP"));
53
54     ckInterpolation = new wxCheckBox(panel, -1, _T("Interpolation"));
55     ckShade = new wxCheckBox(panel, -1, _T("Shade"));
56
57     rbRayCasting->Disable();
58
59     rbMIP->Disable();
60     ckInterpolation->Disable();
61     ckShade->Disable();
62
63
64         wxButton *btnVolumeFunctions    = new wxButton(panel,-1,_T("Read Volume Functions"));
65
66         Connect(btnVolumeFunctions->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions       );
67
68         ckBoxVolume->SetValue(false);
69
70         Connect(ckVolum->GetId()                , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume                          );
71         Connect(ckBoxVolume->GetId()    , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume                       );
72
73         Connect(rbRayCasting->GetId()   , wxEVT_COMMAND_RADIOBUTTON_SELECTED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive                       );
74         Connect(rbMIP->GetId()          , wxEVT_COMMAND_RADIOBUTTON_SELECTED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnMIPActive                              );
75
76     Connect(ckInterpolation->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive            );
77         Connect(ckShade->GetId()        , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnShadeActive                    );
78
79
80
81         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
82         wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
83         wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
84         wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(20);
85
86         sizerH0->Add( ckVolum                                                                   , 1, wxALL|wxEXPAND, 0);
87         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
88         sizerH0->Add( ckBoxVolume                                                               , 1, wxALL|wxEXPAND, 0);
89         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
90         sizerH0->Add( btnVolumeFunctions                                                , 1, wxALL|wxEXPAND, 0);
91
92     sizerH1->Add(rbRayCasting, 1, wxALL|wxEXPAND, 0 );
93     sizerH1->Add(rbMIP, 1, wxALL|wxEXPAND, 0 );
94
95     sizerH2->Add(ckInterpolation, 1, wxALL|wxEXPAND, 0 );
96     sizerH2->Add(ckShade, 1, wxALL|wxEXPAND, 0 );
97
98         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
99     sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
100     sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
101
102         panel->SetSize(300,60);
103         panel->SetAutoLayout(true);
104         panel->SetSizer(sizer);
105         panel->Layout();
106
107         panel->SetEventHandler((wxEvtHandler*)this);
108
109         rbRayCasting->SetValue(true);
110
111 //      _volumerendererdata = VolumeRendererData::New();
112 //      _volumerendererdata->SetImageData(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData());
113
114 }
115 //-------------------------------------------------------------------
116 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
117 {
118 }
119 //-------------------------------------------------------------------
120 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
121 {
122 }
123
124 //-------------------------------------------------------------------
125 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
126 {
127
128
129
130     if(event.IsChecked())
131     {
132         ckBoxVolume->Enable();
133     }
134     else{
135         ckBoxVolume->Disable();
136     }
137
138   //  _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetRenderer()->RemoveAllViewProps();
139
140
141
142         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
143         if(event.IsChecked())
144         {
145             rbRayCasting->Enable();
146             rbMIP->Enable();
147             ckInterpolation->Enable();
148             ckShade->Enable();
149         }
150         else
151         {
152             rbRayCasting->Disable();
153             rbMIP->Disable();
154             ckInterpolation->Disable();
155             ckShade->Disable();
156             if(ckBoxVolume->IsChecked())
157             {
158                ckBoxVolume->SetValue(false);
159             }
160         }
161
162         _wxvtkclipping3Dview->Refresh();
163
164
165         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
166 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
167 #if wxMAJOR_VERSION <= 2
168         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
169 #else
170         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
171 #endif
172 }
173
174 //-------------------------------------------------------------------
175 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
176 {
177
178   //cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
179
180
181     if(event.IsChecked())
182     {
183            // rbRayCasting->Disable();
184            // rbMIP->Disable();
185             ckInterpolation->Disable();
186             ckShade->Disable();
187     }
188     else
189     {
190             //rbRayCasting->Enable();
191             //rbMIP->Enable();
192             ckInterpolation->Enable();
193             ckShade->Enable();
194
195     }
196
197     _wxvtkclipping3Dview->VisibleVolumeBoxActor(event.IsChecked());
198
199     _wxvtkclipping3Dview->Refresh();
200     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
201 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
202 #if wxMAJOR_VERSION <= 2
203     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
204 #else
205     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
206 #endif
207
208 }
209
210 //EED 22 Fevrier 2007
211 //-------------------------------------------------------------------
212 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
213 {
214
215         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
216         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
217         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
218         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
219         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
220         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
221         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
222         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
223         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
224         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
225
226         //use for update in the refresh
227         /*
228         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
229         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
230         */
231
232         /*
233         MMLR BORRAME
234         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
235         if (dialog.ShowModal() == wxID_OK)
236         {
237                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
238
239
240         }
241         */
242
243         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
244         //
245         // put in a method
246         //
247         int tfSize=gtf->size();
248                 if(tfSize>0)
249                 {
250                         int i=0;
251                         hDlg->erasePointsTransferenceFunction();
252                         while(i<tfSize)
253                         {
254                                 double g=(*gtf)[i];
255                                 double in=(*itf)[i];
256                                 hDlg->addPointToTransferenceFunction(g,in*100);
257                                 i++;
258                         }
259
260                 }
261
262         int ctfSize=rctf->size();
263         if(ctfSize>0)
264         {
265                 int i=0;
266                         while(i<ctfSize)
267                         {
268                                 double gr=(*greyctf)[i];
269                                 double r=(*rctf)[i];
270                                 double g=(*gctf)[i];
271                                 double b=(*bctf)[i];
272                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
273                                 i++;
274                         }
275         }
276         //setting variables if the user wants to do refresh
277         hDlg->setCTF(ctfun);
278         hDlg->setTF(tfun);
279         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
280         /*
281         hDlg->setVolume(newvol);
282         hDlg->setVolumeMapper(volumeMapper);
283         */
284         //
285         // when the user had changed the transference Function
286         //
287         if(hDlg->ShowModal()== wxID_OK )
288         {
289                         // -- vtkPiecewiseFunction --
290                         tfun->RemoveAllPoints();
291                         gtf->clear();
292                         itf->clear();
293
294                         int nTFPoints=hDlg->getSizeTransferenceFunction();
295                         int i=0;
296                         while(i<nTFPoints)
297                         {
298                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
299                                 tfun->AddPoint( xi , yi/100.0 );
300                                 gtf->push_back(xi);
301                                 itf->push_back(yi/100.0);
302                                 i++;
303                         }
304                         // -- vtkColorTransferFunction  --
305                         ctfun->RemoveAllPoints ();
306                         //clean colors
307                         rctf->clear();
308                         gctf->clear();
309                         bctf->clear();
310                         greyctf->clear();
311
312                         int nCTFpoints=hDlg->getSizeBarColor();
313                         i=0;
314                         while(i<nCTFpoints)
315                         {
316                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
317                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
318                                 rctf->push_back(r/255.0);
319                                 gctf->push_back(g/255.0);
320                                 bctf->push_back(b/255.0);
321                                 greyctf->push_back(xi);
322                                 i++;
323                         }
324                         //---------------------------------
325                         // Refreshing and sending the event
326                         //---------------------------------
327                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
328
329                         //test
330
331
332          //   _volumerendererdata->OpacityChanged(*gtf, *itf);
333             _wxvtkclipping3Dview->UpdateVolumeBox(*gtf, *itf, ctfun);
334
335 //test end
336
337                         _wxvtkclipping3Dview->Refresh();
338                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
339 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
340 #if wxMAJOR_VERSION <= 2
341                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
342 #else
343                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
344 #endif
345                         /*
346                         volumeMapper->Update();
347                         newvol->Update();
348                         */
349         } else  {
350                 if(hDlg->getRefreshed())
351                 {
352                         int i=0,size;
353                         //--Transference Function----
354                         tfun->RemoveAllPoints();
355                         i=0;
356                         size=gtf->size();
357                         for(i=0;i<size;i++)
358                         {
359                                 double grey1=(*gtf)[i];
360                                 double  in2=(*itf)[i];
361                                 tfun->AddPoint( grey1 , in2 );
362                         }
363
364                         // -- vtkColorTransferFunction  --
365                         ctfun->RemoveAllPoints ();
366
367                         i=0;
368                         size=greyctf->size();
369                         for(i=0;i<size;i++)
370                         {
371                                 double grey2=(*greyctf)[i];
372                                 double red =(*rctf)[i];
373                                 double green =(*gctf)[i];
374                                 double blue = (*bctf)[i];
375                                 ctfun->AddRGBPoint(grey2,red,green,blue);
376                         }
377
378                         //---------------------------------
379                         // Refreshing and sending the event
380                         //---------------------------------
381                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
382
383                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
384 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
385 #if wxMAJOR_VERSION <= 2
386                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
387 #else
388                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
389 #endif
390                 _wxvtkclipping3Dview->Refresh();
391
392                         /*
393                         volumeMapper->Update();
394                         newvol->Update();
395                         */
396                  }
397
398         }
399         //destroy the dialog
400
401         hDlg->Destroy();
402 }
403
404 void wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event)
405 {
406     //If Ray Casting is active, others options are disabled. Only RayCasting is true
407     _wxvtkclipping3Dview->SetRayCasting(true);
408     _wxvtkclipping3Dview->SetMIPActive(false);
409     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
410 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
411 #if wxMAJOR_VERSION <= 2
412     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
413 #else
414     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
415 #endif
416     _wxvtkclipping3Dview->Refresh();
417 }
418
419 void wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event)
420 {
421     //If MIP is active, others options are disabled. Only MIP is true
422     _wxvtkclipping3Dview->SetMIPActive(true);
423     _wxvtkclipping3Dview->SetRayCasting(false);
424     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
425 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
426 #if wxMAJOR_VERSION <= 2
427     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
428 #else
429     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
430 #endif
431     _wxvtkclipping3Dview->Refresh();
432 }
433
434
435 void wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event)
436 {
437     _wxvtkclipping3Dview->SetInterpolation(event.IsChecked());
438     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
439 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
440 #if wxMAJOR_VERSION <= 2
441     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
442 #else
443     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
444 #endif
445     _wxvtkclipping3Dview->Refresh();
446 }
447
448 void wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event)
449 {
450     _wxvtkclipping3Dview->SetShade(event.IsChecked());
451     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
452 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
453 #if wxMAJOR_VERSION <= 2
454     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
455 #else
456     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
457 #endif
458     _wxvtkclipping3Dview->Refresh();
459 }
460