]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DViewVolCntrlPanel.cxx
f140661cb7aab57dbeacf71e42204165b583d6a9
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkClipping3DViewVolCntrlPanel.cxx
1 //-------------------------------------------------------------------
2 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
3 //-------------------------------------------------------------------
4
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"
13
14 wxVtkClipping3DViewVolCntrlPanel::wxVtkClipping3DViewVolCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
15 : wxPanel(parent, -1)
16 {
17         wxPanel *panel  = this;
18         _wxvtkclipping3Dview    = wxvtkclipping3Dview;
19
20
21         wxCheckBox              *ckVolum                = new wxCheckBox(panel,-1,_T("Volume"));
22         wxCheckBox              *ckBoxVolume    = new wxCheckBox(panel,-1,_T("Volume Box"));
23
24         ckBoxVolume->Disable();
25
26         rbRayCasting   = new wxRadioButton(panel, -1, _T("Ray Casting"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
27     rbMIP   = new wxRadioButton(panel, -1, _T("MIP"));
28
29     ckInterpolation = new wxCheckBox(panel, -1, _T("Interpolation"));
30     ckShade = new wxCheckBox(panel, -1, _T("Shade"));
31
32     rbRayCasting->Disable();
33     rbMIP->Disable();
34     ckInterpolation->Disable();
35     ckShade->Disable();
36
37
38         wxButton *btnVolumeFunctions    = new wxButton(panel,-1,_T("Read Volume Functions"));
39
40         Connect(btnVolumeFunctions->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions       );
41
42         ckBoxVolume->SetValue(false);
43
44         Connect(ckVolum->GetId()                , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume                          );
45         Connect(ckBoxVolume->GetId()    , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume                       );
46
47         Connect(rbRayCasting->GetId()   , wxEVT_COMMAND_RADIOBUTTON_SELECTED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive                       );
48         Connect(rbMIP->GetId()          , wxEVT_COMMAND_RADIOBUTTON_SELECTED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnMIPActive                              );
49
50     Connect(ckInterpolation->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive            );
51         Connect(ckShade->GetId()        , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnShadeActive                    );
52
53
54
55         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
56         wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
57         wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
58         wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(20);
59
60         sizerH0->Add( ckVolum                                                                   , 1, wxALL|wxEXPAND, 0);
61         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
62         sizerH0->Add( ckBoxVolume                                                               , 1, wxALL|wxEXPAND, 0);
63         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
64         sizerH0->Add( btnVolumeFunctions                                                , 1, wxALL|wxEXPAND, 0);
65
66     sizerH1->Add(rbRayCasting, 1, wxALL|wxEXPAND, 0 );
67     sizerH1->Add(rbMIP, 1, wxALL|wxEXPAND, 0 );
68
69     sizerH2->Add(ckInterpolation, 1, wxALL|wxEXPAND, 0 );
70     sizerH2->Add(ckShade, 1, wxALL|wxEXPAND, 0 );
71
72
73         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
74     sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
75     sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
76
77         panel->SetSize(300,60);
78         panel->SetAutoLayout(true);
79         panel->SetSizer(sizer);
80         panel->Layout();
81
82         panel->SetEventHandler((wxEvtHandler*)this);
83
84 }
85 //-------------------------------------------------------------------
86 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
87 {
88 }
89 //-------------------------------------------------------------------
90 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
91 {
92 }
93
94 //-------------------------------------------------------------------
95 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
96 {
97     cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
98         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
99         if(event.IsChecked())
100         {
101             rbRayCasting->Enable();
102         rbMIP->Enable();
103         ckInterpolation->Enable();
104         ckShade->Enable();
105         }
106         else
107         {
108         rbRayCasting->Disable();
109         rbMIP->Disable();
110         ckInterpolation->Disable();
111         ckShade->Disable();
112         }
113         _wxvtkclipping3Dview->Refresh();
114
115         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
116         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
117 }
118
119 //-------------------------------------------------------------------
120 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
121 {
122         _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
123         _wxvtkclipping3Dview->Refresh();
124 }
125
126 //EED 22 Fevrier 2007
127 //-------------------------------------------------------------------
128 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
129 {
130
131         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
132         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
133         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
134         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
135         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
136         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
137         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
138         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
139         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
140         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
141
142         //use for update in the refresh
143         /*
144         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
145         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
146         */
147
148         /*
149         MMLR BORRAME
150         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
151         if (dialog.ShowModal() == wxID_OK)
152         {
153                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
154
155
156         }
157         */
158
159         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
160         //
161         // put in a method
162         //
163         int tfSize=gtf->size();
164                 if(tfSize>0)
165                 {
166                         int i=0;
167                         hDlg->erasePointsTransferenceFunction();
168                         while(i<tfSize)
169                         {
170                                 double g=(*gtf)[i];
171                                 double in=(*itf)[i];
172                                 hDlg->addPointToTransferenceFunction(g,in*100);
173                                 i++;
174                         }
175
176                 }
177
178         int ctfSize=rctf->size();
179         if(ctfSize>0)
180         {
181                 int i=0;
182                         while(i<ctfSize)
183                         {
184                                 double gr=(*greyctf)[i];
185                                 double r=(*rctf)[i];
186                                 double g=(*gctf)[i];
187                                 double b=(*bctf)[i];
188                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
189                                 i++;
190                         }
191         }
192         //setting variables if the user wants to do refresh
193         hDlg->setCTF(ctfun);
194         hDlg->setTF(tfun);
195         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
196         /*
197         hDlg->setVolume(newvol);
198         hDlg->setVolumeMapper(volumeMapper);
199         */
200         //
201         // when the user had changed the transference Function
202         //
203         if(hDlg->ShowModal()== wxID_OK )
204         {
205                         // -- vtkPiecewiseFunction --
206                         tfun->RemoveAllPoints();
207                         gtf->clear();
208                         itf->clear();
209
210                         int nTFPoints=hDlg->getSizeTransferenceFunction();
211                         int i=0;
212                         while(i<nTFPoints)
213                         {
214                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
215                                 tfun->AddPoint( xi , yi/100.0 );
216                                 gtf->push_back(xi);
217                                 itf->push_back(yi/100.0);
218                                 i++;
219                         }
220                         // -- vtkColorTransferFunction  --
221                         ctfun->RemoveAllPoints ();
222                         //clean colors
223                         rctf->clear();
224                         gctf->clear();
225                         bctf->clear();
226                         greyctf->clear();
227
228                         int nCTFpoints=hDlg->getSizeBarColor();
229                         i=0;
230                         while(i<nCTFpoints)
231                         {
232                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
233                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
234                                 rctf->push_back(r/255.0);
235                                 gctf->push_back(g/255.0);
236                                 bctf->push_back(b/255.0);
237                                 greyctf->push_back(xi);
238                                 i++;
239                         }
240                         //---------------------------------
241                         // Refreshing and sending the event
242                         //---------------------------------
243                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
244                         _wxvtkclipping3Dview->Refresh();
245                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
246                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
247
248                         /*
249                         volumeMapper->Update();
250                         newvol->Update();
251                         */
252         } else  {
253                 if(hDlg->getRefreshed())
254                 {
255                         int i=0,size;
256                         //--Transference Function----
257                         tfun->RemoveAllPoints();
258                         i=0;
259                         size=gtf->size();
260                         for(i=0;i<size;i++)
261                         {
262                                 double grey1=(*gtf)[i];
263                                 double  in2=(*itf)[i];
264                                 tfun->AddPoint( grey1 , in2 );
265                         }
266
267                         // -- vtkColorTransferFunction  --
268                         ctfun->RemoveAllPoints ();
269
270                         i=0;
271                         size=greyctf->size();
272                         for(i=0;i<size;i++)
273                         {
274                                 double grey2=(*greyctf)[i];
275                                 double red =(*rctf)[i];
276                                 double green =(*gctf)[i];
277                                 double blue = (*bctf)[i];
278                                 ctfun->AddRGBPoint(grey2,red,green,blue);
279                         }
280
281                         //---------------------------------
282                         // Refreshing and sending the event
283                         //---------------------------------
284                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
285                         _wxvtkclipping3Dview->Refresh();
286                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
287                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
288
289                         /*
290                         volumeMapper->Update();
291                         newvol->Update();
292                         */
293                  }
294
295         }
296         //destroy the dialog
297         hDlg->Destroy();
298 }
299
300 void    wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event){
301     //If Ray Casting is active, others options are disabled. Only RayCasting is true
302     _wxvtkclipping3Dview->SetRayCasting(true);
303     _wxvtkclipping3Dview->SetMIPActive(false);
304     _wxvtkclipping3Dview->Refresh();
305 }
306
307 void    wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event){
308     //If MIP is active, others options are disabled. Only MIP is true
309     _wxvtkclipping3Dview->SetMIPActive(true);
310     _wxvtkclipping3Dview->SetRayCasting(false);
311
312     _wxvtkclipping3Dview->Refresh();
313 }
314
315
316
317 void    wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event){
318     _wxvtkclipping3Dview->SetInterpolation(event.IsChecked());
319     _wxvtkclipping3Dview->Refresh();
320 }
321
322 void    wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event){
323     _wxvtkclipping3Dview->SetShade(event.IsChecked());
324     _wxvtkclipping3Dview->Refresh();
325 }
326