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("Vol"));
22 wxCheckBox *ckBoxVolume = new wxCheckBox(panel,-1,_T("Volume Box"));
24 wxButton *btnVolumeFunctions = new wxButton(panel,-1,_T("Read Volume Functions"));
26 Connect(btnVolumeFunctions->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions );
28 ckBoxVolume->SetValue(false);
30 Connect(ckVolum->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume );
31 Connect(ckBoxVolume->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume );
33 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
34 wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
36 sizerH0->Add( ckVolum , 1, wxALL|wxEXPAND, 0);
37 sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
38 sizerH0->Add( ckBoxVolume , 1, wxALL|wxEXPAND, 0);
39 sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
40 sizerH0->Add( btnVolumeFunctions , 1, wxALL|wxEXPAND, 0);
43 sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
45 panel->SetSize(300,60);
46 panel->SetAutoLayout(true);
47 panel->SetSizer(sizer);
50 panel->SetEventHandler((wxEvtHandler*)this);
53 //-------------------------------------------------------------------
54 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
57 //-------------------------------------------------------------------
58 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
62 //-------------------------------------------------------------------
63 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
65 _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked() );
66 _wxvtkclipping3Dview->Refresh();
68 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
69 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
72 //-------------------------------------------------------------------
73 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
75 _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
76 _wxvtkclipping3Dview->Refresh();
80 //-------------------------------------------------------------------
81 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
84 int /*i=0,*/ xi,yi,r,g,b; // JPRx
85 vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
86 vtkPiecewiseFunction* tfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
87 std::vector<double>* gtf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
88 std::vector<double>* itf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
89 std::vector<double>* greyctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
90 std::vector<double>* rctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
91 std::vector<double>* gctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
92 std::vector<double>* bctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
93 vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
95 //use for update in the refresh
97 vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
98 vtkVolume* newvol =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
103 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
104 if (dialog.ShowModal() == wxID_OK)
106 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
112 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
116 int tfSize=gtf->size();
120 hDlg->erasePointsTransferenceFunction();
125 hDlg->addPointToTransferenceFunction(g,in*100);
131 int ctfSize=rctf->size();
137 double gr=(*greyctf)[i];
141 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
145 //setting variables if the user wants to do refresh
148 //hDlg->setClipping3DView(_wxvtkclipping3Dview);
150 hDlg->setVolume(newvol);
151 hDlg->setVolumeMapper(volumeMapper);
154 // when the user had changed the transference Function
156 if(hDlg->ShowModal()== wxID_OK )
158 // -- vtkPiecewiseFunction --
159 tfun->RemoveAllPoints();
163 int nTFPoints=hDlg->getSizeTransferenceFunction();
167 hDlg->getTransferenceFunctionPoint(i,xi,yi);
168 tfun->AddPoint( xi , yi/100.0 );
170 itf->push_back(yi/100.0);
173 // -- vtkColorTransferFunction --
174 ctfun->RemoveAllPoints ();
181 int nCTFpoints=hDlg->getSizeBarColor();
185 hDlg->getDataBarColorPoint(i,xi,r,g,b);
186 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
187 rctf->push_back(r/255.0);
188 gctf->push_back(g/255.0);
189 bctf->push_back(b/255.0);
190 greyctf->push_back(xi);
193 //---------------------------------
194 // Refreshing and sending the event
195 //---------------------------------
196 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
197 _wxvtkclipping3Dview->Refresh();
198 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
199 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
202 volumeMapper->Update();
206 if(hDlg->getRefreshed())
209 //--Transference Function----
210 tfun->RemoveAllPoints();
215 double grey1=(*gtf)[i];
216 double in2=(*itf)[i];
217 tfun->AddPoint( grey1 , in2 );
220 // -- vtkColorTransferFunction --
221 ctfun->RemoveAllPoints ();
224 size=greyctf->size();
227 double grey2=(*greyctf)[i];
228 double red =(*rctf)[i];
229 double green =(*gctf)[i];
230 double blue = (*bctf)[i];
231 ctfun->AddRGBPoint(grey2,red,green,blue);
234 //---------------------------------
235 // Refreshing and sending the event
236 //---------------------------------
237 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
238 _wxvtkclipping3Dview->Refresh();
239 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
240 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
243 volumeMapper->Update();