1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 //-------------------------------------------------------------------
27 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
28 //-------------------------------------------------------------------
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"
39 wxVtkClipping3DViewVolCntrlPanel::wxVtkClipping3DViewVolCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
42 wxPanel *panel = this;
43 _wxvtkclipping3Dview = wxvtkclipping3Dview;
46 ckVolum = new wxCheckBox(panel,-1,_T("Volume"));
47 ckBoxVolume = new wxCheckBox(panel,-1,_T("Volume Box"));
49 ckBoxVolume->Disable();
51 rbRayCasting = new wxRadioButton(panel, -1, _T("Ray Casting"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
52 rbMIP = new wxRadioButton(panel, -1, _T("MIP"));
54 ckInterpolation = new wxCheckBox(panel, -1, _T("Interpolation"));
55 ckShade = new wxCheckBox(panel, -1, _T("Shade"));
57 rbRayCasting->Disable();
60 ckInterpolation->Disable();
64 wxButton *btnVolumeFunctions = new wxButton(panel,-1,_T("Read Volume Functions"));
66 Connect(btnVolumeFunctions->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions );
68 ckBoxVolume->SetValue(false);
70 Connect(ckVolum->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume );
71 Connect(ckBoxVolume->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume );
73 Connect(rbRayCasting->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive );
74 Connect(rbMIP->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnMIPActive );
76 Connect(ckInterpolation->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive );
77 Connect(ckShade->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnShadeActive );
81 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
82 wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
83 wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
84 wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(20);
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);
92 sizerH1->Add(rbRayCasting, 1, wxALL|wxEXPAND, 0 );
93 sizerH1->Add(rbMIP, 1, wxALL|wxEXPAND, 0 );
95 sizerH2->Add(ckInterpolation, 1, wxALL|wxEXPAND, 0 );
96 sizerH2->Add(ckShade, 1, wxALL|wxEXPAND, 0 );
99 #if wxMAJOR_VERSION <= 2
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);
108 sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
109 sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
110 sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
112 panel->SetSize(300,60);
113 panel->SetAutoLayout(true);
114 panel->SetSizer(sizer);
117 panel->SetEventHandler((wxEvtHandler*)this);
119 rbRayCasting->SetValue(true);
121 // _volumerendererdata = VolumeRendererData::New();
122 // _volumerendererdata->SetImageData(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData());
125 //-------------------------------------------------------------------
126 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
129 //-------------------------------------------------------------------
130 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
134 //-------------------------------------------------------------------
135 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
140 if(event.IsChecked())
142 ckBoxVolume->Enable();
145 ckBoxVolume->Disable();
148 // _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetRenderer()->RemoveAllViewProps();
152 _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked() );
153 if(event.IsChecked())
155 rbRayCasting->Enable();
157 ckInterpolation->Enable();
162 rbRayCasting->Disable();
164 ckInterpolation->Disable();
166 if(ckBoxVolume->IsChecked())
168 ckBoxVolume->SetValue(false);
172 _wxvtkclipping3Dview->Refresh();
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);
180 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
184 //-------------------------------------------------------------------
185 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
188 //cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
191 if(event.IsChecked())
193 // rbRayCasting->Disable();
195 ckInterpolation->Disable();
200 //rbRayCasting->Enable();
202 ckInterpolation->Enable();
207 _wxvtkclipping3Dview->VisibleVolumeBoxActor(event.IsChecked());
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);
215 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
220 //EED 22 Fevrier 2007
221 //-------------------------------------------------------------------
222 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
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();
236 //use for update in the refresh
238 vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
239 vtkVolume* newvol =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
244 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
245 if (dialog.ShowModal() == wxID_OK)
247 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
253 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
257 int tfSize=gtf->size();
261 hDlg->erasePointsTransferenceFunction();
266 hDlg->addPointToTransferenceFunction(g,in*100);
272 int ctfSize=rctf->size();
278 double gr=(*greyctf)[i];
282 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
286 //setting variables if the user wants to do refresh
289 //hDlg->setClipping3DView(_wxvtkclipping3Dview);
291 hDlg->setVolume(newvol);
292 hDlg->setVolumeMapper(volumeMapper);
295 // when the user had changed the transference Function
297 if(hDlg->ShowModal()== wxID_OK )
299 // -- vtkPiecewiseFunction --
300 tfun->RemoveAllPoints();
304 int nTFPoints=hDlg->getSizeTransferenceFunction();
308 hDlg->getTransferenceFunctionPoint(i,xi,yi);
309 tfun->AddPoint( xi , yi/100.0 );
311 itf->push_back(yi/100.0);
314 // -- vtkColorTransferFunction --
315 ctfun->RemoveAllPoints ();
322 int nCTFpoints=hDlg->getSizeBarColor();
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);
334 //---------------------------------
335 // Refreshing and sending the event
336 //---------------------------------
337 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
342 // _volumerendererdata->OpacityChanged(*gtf, *itf);
343 _wxvtkclipping3Dview->UpdateVolumeBox(*gtf, *itf, ctfun);
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);
353 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
356 volumeMapper->Update();
360 if(hDlg->getRefreshed())
363 //--Transference Function----
364 tfun->RemoveAllPoints();
369 double grey1=(*gtf)[i];
370 double in2=(*itf)[i];
371 tfun->AddPoint( grey1 , in2 );
374 // -- vtkColorTransferFunction --
375 ctfun->RemoveAllPoints ();
378 size=greyctf->size();
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);
388 //---------------------------------
389 // Refreshing and sending the event
390 //---------------------------------
391 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
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);
398 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
400 _wxvtkclipping3Dview->Refresh();
403 volumeMapper->Update();
414 void wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event)
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);
424 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
426 _wxvtkclipping3Dview->Refresh();
429 void wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event)
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);
439 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
441 _wxvtkclipping3Dview->Refresh();
445 void wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event)
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);
453 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
455 _wxvtkclipping3Dview->Refresh();
458 void wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event)
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);
466 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
468 _wxvtkclipping3Dview->Refresh();