]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DViewVolCntrlPanel.cxx
#3128 creaMaracasVisu Feature New Normal - branch changeWx28to30 compilation with...
[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
99         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
100     sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
101     sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
102
103         panel->SetSize(300,60);
104         panel->SetAutoLayout(true);
105         panel->SetSizer(sizer);
106         panel->Layout();
107
108         panel->SetEventHandler((wxEvtHandler*)this);
109
110         rbRayCasting->SetValue(true);
111
112 //      _volumerendererdata = VolumeRendererData::New();
113 //      _volumerendererdata->SetImageData(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData());
114
115 }
116 //-------------------------------------------------------------------
117 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
118 {
119 }
120 //-------------------------------------------------------------------
121 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
122 {
123 }
124
125 //-------------------------------------------------------------------
126 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
127 {
128
129
130
131     if(event.IsChecked())
132     {
133         ckBoxVolume->Enable();
134     }
135     else{
136         ckBoxVolume->Disable();
137     }
138
139   //  _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetRenderer()->RemoveAllViewProps();
140
141
142
143         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
144         if(event.IsChecked())
145         {
146             rbRayCasting->Enable();
147             rbMIP->Enable();
148             ckInterpolation->Enable();
149             ckShade->Enable();
150         }
151         else
152         {
153             rbRayCasting->Disable();
154             rbMIP->Disable();
155             ckInterpolation->Disable();
156             ckShade->Disable();
157             if(ckBoxVolume->IsChecked())
158             {
159                ckBoxVolume->SetValue(false);
160             }
161         }
162
163         _wxvtkclipping3Dview->Refresh();
164
165
166         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
167 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
168 #if wxMAJOR_VERSION <= 2
169         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
170 #else
171         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
172 #endif
173 }
174
175 //-------------------------------------------------------------------
176 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
177 {
178
179   //cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
180
181
182     if(event.IsChecked())
183     {
184            // rbRayCasting->Disable();
185            // rbMIP->Disable();
186             ckInterpolation->Disable();
187             ckShade->Disable();
188     }
189     else
190     {
191             //rbRayCasting->Enable();
192             //rbMIP->Enable();
193             ckInterpolation->Enable();
194             ckShade->Enable();
195
196     }
197
198     _wxvtkclipping3Dview->VisibleVolumeBoxActor(event.IsChecked());
199
200     _wxvtkclipping3Dview->Refresh();
201     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
202 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
203 #if wxMAJOR_VERSION <= 2
204     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
205 #else
206     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
207 #endif
208
209 }
210
211 //EED 22 Fevrier 2007
212 //-------------------------------------------------------------------
213 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
214 {
215
216         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
217         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
218         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
219         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
220         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
221         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
222         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
223         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
224         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
225         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
226
227         //use for update in the refresh
228         /*
229         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
230         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
231         */
232
233         /*
234         MMLR BORRAME
235         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
236         if (dialog.ShowModal() == wxID_OK)
237         {
238                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
239
240
241         }
242         */
243
244         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
245         //
246         // put in a method
247         //
248         int tfSize=gtf->size();
249                 if(tfSize>0)
250                 {
251                         int i=0;
252                         hDlg->erasePointsTransferenceFunction();
253                         while(i<tfSize)
254                         {
255                                 double g=(*gtf)[i];
256                                 double in=(*itf)[i];
257                                 hDlg->addPointToTransferenceFunction(g,in*100);
258                                 i++;
259                         }
260
261                 }
262
263         int ctfSize=rctf->size();
264         if(ctfSize>0)
265         {
266                 int i=0;
267                         while(i<ctfSize)
268                         {
269                                 double gr=(*greyctf)[i];
270                                 double r=(*rctf)[i];
271                                 double g=(*gctf)[i];
272                                 double b=(*bctf)[i];
273                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
274                                 i++;
275                         }
276         }
277         //setting variables if the user wants to do refresh
278         hDlg->setCTF(ctfun);
279         hDlg->setTF(tfun);
280         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
281         /*
282         hDlg->setVolume(newvol);
283         hDlg->setVolumeMapper(volumeMapper);
284         */
285         //
286         // when the user had changed the transference Function
287         //
288         if(hDlg->ShowModal()== wxID_OK )
289         {
290                         // -- vtkPiecewiseFunction --
291                         tfun->RemoveAllPoints();
292                         gtf->clear();
293                         itf->clear();
294
295                         int nTFPoints=hDlg->getSizeTransferenceFunction();
296                         int i=0;
297                         while(i<nTFPoints)
298                         {
299                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
300                                 tfun->AddPoint( xi , yi/100.0 );
301                                 gtf->push_back(xi);
302                                 itf->push_back(yi/100.0);
303                                 i++;
304                         }
305                         // -- vtkColorTransferFunction  --
306                         ctfun->RemoveAllPoints ();
307                         //clean colors
308                         rctf->clear();
309                         gctf->clear();
310                         bctf->clear();
311                         greyctf->clear();
312
313                         int nCTFpoints=hDlg->getSizeBarColor();
314                         i=0;
315                         while(i<nCTFpoints)
316                         {
317                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
318                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
319                                 rctf->push_back(r/255.0);
320                                 gctf->push_back(g/255.0);
321                                 bctf->push_back(b/255.0);
322                                 greyctf->push_back(xi);
323                                 i++;
324                         }
325                         //---------------------------------
326                         // Refreshing and sending the event
327                         //---------------------------------
328                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
329
330                         //test
331
332
333          //   _volumerendererdata->OpacityChanged(*gtf, *itf);
334             _wxvtkclipping3Dview->UpdateVolumeBox(*gtf, *itf, ctfun);
335
336 //test end
337
338                         _wxvtkclipping3Dview->Refresh();
339                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
340 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
341 #if wxMAJOR_VERSION <= 2
342                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
343 #else
344                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
345 #endif
346                         /*
347                         volumeMapper->Update();
348                         newvol->Update();
349                         */
350         } else  {
351                 if(hDlg->getRefreshed())
352                 {
353                         int i=0,size;
354                         //--Transference Function----
355                         tfun->RemoveAllPoints();
356                         i=0;
357                         size=gtf->size();
358                         for(i=0;i<size;i++)
359                         {
360                                 double grey1=(*gtf)[i];
361                                 double  in2=(*itf)[i];
362                                 tfun->AddPoint( grey1 , in2 );
363                         }
364
365                         // -- vtkColorTransferFunction  --
366                         ctfun->RemoveAllPoints ();
367
368                         i=0;
369                         size=greyctf->size();
370                         for(i=0;i<size;i++)
371                         {
372                                 double grey2=(*greyctf)[i];
373                                 double red =(*rctf)[i];
374                                 double green =(*gctf)[i];
375                                 double blue = (*bctf)[i];
376                                 ctfun->AddRGBPoint(grey2,red,green,blue);
377                         }
378
379                         //---------------------------------
380                         // Refreshing and sending the event
381                         //---------------------------------
382                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
383
384                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
385 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
386 #if wxMAJOR_VERSION <= 2
387                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
388 #else
389                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
390 #endif
391                 _wxvtkclipping3Dview->Refresh();
392
393                         /*
394                         volumeMapper->Update();
395                         newvol->Update();
396                         */
397                  }
398
399         }
400         //destroy the dialog
401
402         hDlg->Destroy();
403 }
404
405 void wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event)
406 {
407     //If Ray Casting is active, others options are disabled. Only RayCasting is true
408     _wxvtkclipping3Dview->SetRayCasting(true);
409     _wxvtkclipping3Dview->SetMIPActive(false);
410     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
411 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
412 #if wxMAJOR_VERSION <= 2
413     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
414 #else
415     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
416 #endif
417     _wxvtkclipping3Dview->Refresh();
418 }
419
420 void wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event)
421 {
422     //If MIP is active, others options are disabled. Only MIP is true
423     _wxvtkclipping3Dview->SetMIPActive(true);
424     _wxvtkclipping3Dview->SetRayCasting(false);
425     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
426 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
427 #if wxMAJOR_VERSION <= 2
428     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
429 #else
430     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
431 #endif
432     _wxvtkclipping3Dview->Refresh();
433 }
434
435
436 void wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event)
437 {
438     _wxvtkclipping3Dview->SetInterpolation(event.IsChecked());
439     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
440 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
441 #if wxMAJOR_VERSION <= 2
442     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
443 #else
444     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
445 #endif
446     _wxvtkclipping3Dview->Refresh();
447 }
448
449 void wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event)
450 {
451     _wxvtkclipping3Dview->SetShade(event.IsChecked());
452     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
453 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
454 #if wxMAJOR_VERSION <= 2
455     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
456 #else
457     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
458 #endif
459     _wxvtkclipping3Dview->Refresh();
460 }
461