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