1 //-------------------------------------------------------------------
2 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
3 //-------------------------------------------------------------------
5 #include "wxVtkClipping3DViewVolCntrlPanel.h"
6 #include "wx/colordlg.h"
7 #include "vtkTriangleFilter.h"
8 #include "vtkPolyDataConnectivityFilter.h"
9 #include "vtkClosePolyData.h"
10 #include "vtkSTLWriter.h"
11 #include "HistogramDialog.h"
12 #include "marDicomBase.h"
14 wxVtkClipping3DViewVolCntrlPanel::wxVtkClipping3DViewVolCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
17 wxPanel *panel = this;
18 _wxvtkclipping3Dview = wxvtkclipping3Dview;
21 wxCheckBox *ckVolum = new wxCheckBox(panel,-1,_T("Volume"));
22 wxCheckBox *ckBoxVolume = new wxCheckBox(panel,-1,_T("Volume Box"));
24 ckBoxVolume->Disable();
26 rbRayCasting = new wxRadioButton(panel, -1, _T("Ray Casting"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
27 rbMIP = new wxRadioButton(panel, -1, _T("MIP"));
29 ckInterpolation = new wxCheckBox(panel, -1, _T("Interpolation"));
30 ckShade = new wxCheckBox(panel, -1, _T("Shade"));
32 rbRayCasting->Disable();
33 rbRayCasting->SetValue(true);
35 ckInterpolation->Disable();
39 wxButton *btnVolumeFunctions = new wxButton(panel,-1,_T("Read Volume Functions"));
41 Connect(btnVolumeFunctions->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions );
43 ckBoxVolume->SetValue(false);
45 Connect(ckVolum->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume );
46 Connect(ckBoxVolume->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume );
48 Connect(rbRayCasting->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive );
49 Connect(rbMIP->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnMIPActive );
51 Connect(ckInterpolation->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive );
52 Connect(ckShade->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnShadeActive );
56 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
57 wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
58 wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
59 wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(20);
61 sizerH0->Add( ckVolum , 1, wxALL|wxEXPAND, 0);
62 sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
63 sizerH0->Add( ckBoxVolume , 1, wxALL|wxEXPAND, 0);
64 sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
65 sizerH0->Add( btnVolumeFunctions , 1, wxALL|wxEXPAND, 0);
67 sizerH1->Add(rbRayCasting, 1, wxALL|wxEXPAND, 0 );
68 sizerH1->Add(rbMIP, 1, wxALL|wxEXPAND, 0 );
70 sizerH2->Add(ckInterpolation, 1, wxALL|wxEXPAND, 0 );
71 sizerH2->Add(ckShade, 1, wxALL|wxEXPAND, 0 );
74 sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
75 sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
76 sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
78 panel->SetSize(300,60);
79 panel->SetAutoLayout(true);
80 panel->SetSizer(sizer);
83 panel->SetEventHandler((wxEvtHandler*)this);
86 //-------------------------------------------------------------------
87 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
90 //-------------------------------------------------------------------
91 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
95 //-------------------------------------------------------------------
96 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
98 cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
99 _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked() );
100 if(event.IsChecked())
102 rbRayCasting->Enable();
104 ckInterpolation->Enable();
109 rbRayCasting->Disable();
111 ckInterpolation->Disable();
114 _wxvtkclipping3Dview->Refresh();
116 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
117 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
120 //-------------------------------------------------------------------
121 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
123 _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
124 _wxvtkclipping3Dview->Refresh();
127 //EED 22 Fevrier 2007
128 //-------------------------------------------------------------------
129 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
132 int /*i=0,*/ xi,yi,r,g,b; // JPRx
133 vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
134 vtkPiecewiseFunction* tfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
135 std::vector<double>* gtf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
136 std::vector<double>* itf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
137 std::vector<double>* greyctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
138 std::vector<double>* rctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
139 std::vector<double>* gctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
140 std::vector<double>* bctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
141 vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
143 //use for update in the refresh
145 vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
146 vtkVolume* newvol =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
151 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
152 if (dialog.ShowModal() == wxID_OK)
154 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
160 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
164 int tfSize=gtf->size();
168 hDlg->erasePointsTransferenceFunction();
173 hDlg->addPointToTransferenceFunction(g,in*100);
179 int ctfSize=rctf->size();
185 double gr=(*greyctf)[i];
189 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
193 //setting variables if the user wants to do refresh
196 //hDlg->setClipping3DView(_wxvtkclipping3Dview);
198 hDlg->setVolume(newvol);
199 hDlg->setVolumeMapper(volumeMapper);
202 // when the user had changed the transference Function
204 if(hDlg->ShowModal()== wxID_OK )
206 // -- vtkPiecewiseFunction --
207 tfun->RemoveAllPoints();
211 int nTFPoints=hDlg->getSizeTransferenceFunction();
215 hDlg->getTransferenceFunctionPoint(i,xi,yi);
216 tfun->AddPoint( xi , yi/100.0 );
218 itf->push_back(yi/100.0);
221 // -- vtkColorTransferFunction --
222 ctfun->RemoveAllPoints ();
229 int nCTFpoints=hDlg->getSizeBarColor();
233 hDlg->getDataBarColorPoint(i,xi,r,g,b);
234 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
235 rctf->push_back(r/255.0);
236 gctf->push_back(g/255.0);
237 bctf->push_back(b/255.0);
238 greyctf->push_back(xi);
241 //---------------------------------
242 // Refreshing and sending the event
243 //---------------------------------
244 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
245 _wxvtkclipping3Dview->Refresh();
246 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
247 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
250 volumeMapper->Update();
254 if(hDlg->getRefreshed())
257 //--Transference Function----
258 tfun->RemoveAllPoints();
263 double grey1=(*gtf)[i];
264 double in2=(*itf)[i];
265 tfun->AddPoint( grey1 , in2 );
268 // -- vtkColorTransferFunction --
269 ctfun->RemoveAllPoints ();
272 size=greyctf->size();
275 double grey2=(*greyctf)[i];
276 double red =(*rctf)[i];
277 double green =(*gctf)[i];
278 double blue = (*bctf)[i];
279 ctfun->AddRGBPoint(grey2,red,green,blue);
282 //---------------------------------
283 // Refreshing and sending the event
284 //---------------------------------
285 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
286 _wxvtkclipping3Dview->Refresh();
287 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
288 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
291 volumeMapper->Update();
301 void wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event){
302 //If Ray Casting is active, others options are disabled. Only RayCasting is true
303 _wxvtkclipping3Dview->SetRayCasting(true);
304 _wxvtkclipping3Dview->SetMIPActive(false);
305 _wxvtkclipping3Dview->Refresh();
308 void wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event){
309 //If MIP is active, others options are disabled. Only MIP is true
310 _wxvtkclipping3Dview->SetMIPActive(true);
311 _wxvtkclipping3Dview->SetRayCasting(false);
313 _wxvtkclipping3Dview->Refresh();
318 void wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event){
319 _wxvtkclipping3Dview->SetInterpolation(event.IsChecked());
320 _wxvtkclipping3Dview->Refresh();
323 void wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event){
324 _wxvtkclipping3Dview->SetShade(event.IsChecked());
325 _wxvtkclipping3Dview->Refresh();