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 //-------------------------------------------------------------------
31 #include <wx/tooltip.h>
32 #include <wx/config.h>
34 #include <iostream> // for std::cout
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"
45 wxVtkClipping3DViewVolCntrlPanel::wxVtkClipping3DViewVolCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
48 wxPanel *panel = this;
49 _wxvtkclipping3Dview = wxvtkclipping3Dview;
52 ckVolum = new wxCheckBox(panel,-1,_T("Volume"));
53 ckBoxVolume = new wxCheckBox(panel,-1,_T("Volume Box"));
55 ckBoxVolume->Disable();
57 rbRayCasting = new wxRadioButton(panel, -1, _T("Ray Casting"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
58 rbMIP = new wxRadioButton(panel, -1, _T("MIP"));
60 ckInterpolation = new wxCheckBox(panel, -1, _T("Interpolation"));
61 ckShade = new wxCheckBox(panel, -1, _T("Shade"));
63 rbRayCasting->Disable();
66 ckInterpolation->Disable();
70 wxButton *btnVolumeFunctions = new wxButton(panel,-1,_T("Read Volume Functions"));
72 Connect(btnVolumeFunctions->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions );
74 ckBoxVolume->SetValue(false);
76 Connect(ckVolum->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume );
77 Connect(ckBoxVolume->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume );
79 Connect(rbRayCasting->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive );
80 Connect(rbMIP->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnMIPActive );
82 Connect(ckInterpolation->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive );
83 Connect(ckShade->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnShadeActive );
87 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
88 wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
89 wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
90 wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(20);
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);
98 sizerH1->Add(rbRayCasting, 1, wxALL|wxEXPAND, 0 );
99 sizerH1->Add(rbMIP, 1, wxALL|wxEXPAND, 0 );
101 sizerH2->Add(ckInterpolation, 1, wxALL|wxEXPAND, 0 );
102 sizerH2->Add(ckShade, 1, wxALL|wxEXPAND, 0 );
104 sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
105 sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
106 sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
108 panel->SetSize(300,60);
109 panel->SetAutoLayout(true);
110 panel->SetSizer(sizer);
113 panel->SetEventHandler((wxEvtHandler*)this);
115 rbRayCasting->SetValue(true);
117 // _volumerendererdata = VolumeRendererData::New();
118 // _volumerendererdata->SetImageData(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData());
121 //-------------------------------------------------------------------
122 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
125 //-------------------------------------------------------------------
126 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
130 //-------------------------------------------------------------------
131 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
136 if(event.IsChecked())
138 ckBoxVolume->Enable();
141 ckBoxVolume->Disable();
144 // _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetRenderer()->RemoveAllViewProps();
148 _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked() );
149 if(event.IsChecked())
151 rbRayCasting->Enable();
153 ckInterpolation->Enable();
158 rbRayCasting->Disable();
160 ckInterpolation->Disable();
162 if(ckBoxVolume->IsChecked())
164 ckBoxVolume->SetValue(false);
168 _wxvtkclipping3Dview->Refresh();
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);
176 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
180 //-------------------------------------------------------------------
181 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
184 //cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
187 if(event.IsChecked())
189 // rbRayCasting->Disable();
191 ckInterpolation->Disable();
196 //rbRayCasting->Enable();
198 ckInterpolation->Enable();
203 _wxvtkclipping3Dview->VisibleVolumeBoxActor(event.IsChecked());
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);
211 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
216 //EED 22 Fevrier 2007
217 //-------------------------------------------------------------------
218 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
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();
232 //use for update in the refresh
234 vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
235 vtkVolume* newvol =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
240 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
241 if (dialog.ShowModal() == wxID_OK)
243 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
249 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
253 int tfSize=gtf->size();
257 hDlg->erasePointsTransferenceFunction();
262 hDlg->addPointToTransferenceFunction(g,in*100);
268 int ctfSize=rctf->size();
274 double gr=(*greyctf)[i];
278 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
282 //setting variables if the user wants to do refresh
285 //hDlg->setClipping3DView(_wxvtkclipping3Dview);
287 hDlg->setVolume(newvol);
288 hDlg->setVolumeMapper(volumeMapper);
291 // when the user had changed the transference Function
293 if(hDlg->ShowModal()== wxID_OK )
295 // -- vtkPiecewiseFunction --
296 tfun->RemoveAllPoints();
300 int nTFPoints=hDlg->getSizeTransferenceFunction();
304 hDlg->getTransferenceFunctionPoint(i,xi,yi);
305 tfun->AddPoint( xi , yi/100.0 );
307 itf->push_back(yi/100.0);
310 // -- vtkColorTransferFunction --
311 ctfun->RemoveAllPoints ();
318 int nCTFpoints=hDlg->getSizeBarColor();
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);
330 //---------------------------------
331 // Refreshing and sending the event
332 //---------------------------------
333 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
338 // _volumerendererdata->OpacityChanged(*gtf, *itf);
339 _wxvtkclipping3Dview->UpdateVolumeBox(*gtf, *itf, ctfun);
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);
349 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
352 volumeMapper->Update();
356 if(hDlg->getRefreshed())
359 //--Transference Function----
360 tfun->RemoveAllPoints();
365 double grey1=(*gtf)[i];
366 double in2=(*itf)[i];
367 tfun->AddPoint( grey1 , in2 );
370 // -- vtkColorTransferFunction --
371 ctfun->RemoveAllPoints ();
374 size=greyctf->size();
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);
384 //---------------------------------
385 // Refreshing and sending the event
386 //---------------------------------
387 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
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);
394 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
396 _wxvtkclipping3Dview->Refresh();
399 volumeMapper->Update();
410 void wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event)
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);
420 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
422 _wxvtkclipping3Dview->Refresh();
425 void wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event)
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);
435 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
437 _wxvtkclipping3Dview->Refresh();
441 void wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event)
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);
449 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
451 _wxvtkclipping3Dview->Refresh();
454 void wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event)
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);
462 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
464 _wxvtkclipping3Dview->Refresh();