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