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 sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
100 sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
101 sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
103 panel->SetSize(300,60);
104 panel->SetAutoLayout(true);
105 panel->SetSizer(sizer);
108 panel->SetEventHandler((wxEvtHandler*)this);
110 rbRayCasting->SetValue(true);
112 // _volumerendererdata = VolumeRendererData::New();
113 // _volumerendererdata->SetImageData(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData());
116 //-------------------------------------------------------------------
117 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
120 //-------------------------------------------------------------------
121 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
125 //-------------------------------------------------------------------
126 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
131 if(event.IsChecked())
133 ckBoxVolume->Enable();
136 ckBoxVolume->Disable();
139 // _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetRenderer()->RemoveAllViewProps();
143 _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked() );
144 if(event.IsChecked())
146 rbRayCasting->Enable();
148 ckInterpolation->Enable();
153 rbRayCasting->Disable();
155 ckInterpolation->Disable();
157 if(ckBoxVolume->IsChecked())
159 ckBoxVolume->SetValue(false);
163 _wxvtkclipping3Dview->Refresh();
166 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
167 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
170 //-------------------------------------------------------------------
171 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
174 //cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
177 if(event.IsChecked())
179 // rbRayCasting->Disable();
181 ckInterpolation->Disable();
186 //rbRayCasting->Enable();
188 ckInterpolation->Enable();
193 _wxvtkclipping3Dview->VisibleVolumeBoxActor(event.IsChecked());
195 _wxvtkclipping3Dview->Refresh();
196 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
197 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
201 //EED 22 Fevrier 2007
202 //-------------------------------------------------------------------
203 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
206 int /*i=0,*/ xi,yi,r,g,b; // JPRx
207 vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
208 vtkPiecewiseFunction* tfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
209 std::vector<double>* gtf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
210 std::vector<double>* itf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
211 std::vector<double>* greyctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
212 std::vector<double>* rctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
213 std::vector<double>* gctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
214 std::vector<double>* bctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
215 vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
217 //use for update in the refresh
219 vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
220 vtkVolume* newvol =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
225 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
226 if (dialog.ShowModal() == wxID_OK)
228 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
234 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
238 int tfSize=gtf->size();
242 hDlg->erasePointsTransferenceFunction();
247 hDlg->addPointToTransferenceFunction(g,in*100);
253 int ctfSize=rctf->size();
259 double gr=(*greyctf)[i];
263 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
267 //setting variables if the user wants to do refresh
270 //hDlg->setClipping3DView(_wxvtkclipping3Dview);
272 hDlg->setVolume(newvol);
273 hDlg->setVolumeMapper(volumeMapper);
276 // when the user had changed the transference Function
278 if(hDlg->ShowModal()== wxID_OK )
280 // -- vtkPiecewiseFunction --
281 tfun->RemoveAllPoints();
285 int nTFPoints=hDlg->getSizeTransferenceFunction();
289 hDlg->getTransferenceFunctionPoint(i,xi,yi);
290 tfun->AddPoint( xi , yi/100.0 );
292 itf->push_back(yi/100.0);
295 // -- vtkColorTransferFunction --
296 ctfun->RemoveAllPoints ();
303 int nCTFpoints=hDlg->getSizeBarColor();
307 hDlg->getDataBarColorPoint(i,xi,r,g,b);
308 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
309 rctf->push_back(r/255.0);
310 gctf->push_back(g/255.0);
311 bctf->push_back(b/255.0);
312 greyctf->push_back(xi);
315 //---------------------------------
316 // Refreshing and sending the event
317 //---------------------------------
318 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
323 // _volumerendererdata->OpacityChanged(*gtf, *itf);
324 _wxvtkclipping3Dview->UpdateVolumeBox(*gtf, *itf, ctfun);
328 _wxvtkclipping3Dview->Refresh();
329 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
330 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
333 volumeMapper->Update();
337 if(hDlg->getRefreshed())
340 //--Transference Function----
341 tfun->RemoveAllPoints();
346 double grey1=(*gtf)[i];
347 double in2=(*itf)[i];
348 tfun->AddPoint( grey1 , in2 );
351 // -- vtkColorTransferFunction --
352 ctfun->RemoveAllPoints ();
355 size=greyctf->size();
358 double grey2=(*greyctf)[i];
359 double red =(*rctf)[i];
360 double green =(*gctf)[i];
361 double blue = (*bctf)[i];
362 ctfun->AddRGBPoint(grey2,red,green,blue);
365 //---------------------------------
366 // Refreshing and sending the event
367 //---------------------------------
368 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
370 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
371 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
373 _wxvtkclipping3Dview->Refresh();
376 volumeMapper->Update();
387 void wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event){
388 //If Ray Casting is active, others options are disabled. Only RayCasting is true
389 _wxvtkclipping3Dview->SetRayCasting(true);
390 _wxvtkclipping3Dview->SetMIPActive(false);
392 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
394 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
395 _wxvtkclipping3Dview->Refresh();
398 void wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event){
399 //If MIP is active, others options are disabled. Only MIP is true
400 _wxvtkclipping3Dview->SetMIPActive(true);
401 _wxvtkclipping3Dview->SetRayCasting(false);
403 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
404 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
406 _wxvtkclipping3Dview->Refresh();
411 void wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event){
412 _wxvtkclipping3Dview->SetInterpolation(event.IsChecked());
414 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
415 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
416 _wxvtkclipping3Dview->Refresh();
419 void wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event){
420 _wxvtkclipping3Dview->SetShade(event.IsChecked());
422 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
423 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
424 _wxvtkclipping3Dview->Refresh();