]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DViewVolCntrlPanel.cxx
*** empty log message ***
[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         ckVolum         = new wxCheckBox(panel,-1,_T("Volume"));
22         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
34     rbMIP->Disable();
35     ckInterpolation->Disable();
36     ckShade->Disable();
37
38
39         wxButton *btnVolumeFunctions    = new wxButton(panel,-1,_T("Read Volume Functions"));
40
41         Connect(btnVolumeFunctions->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions       );
42
43         ckBoxVolume->SetValue(false);
44
45         Connect(ckVolum->GetId()                , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume                          );
46         Connect(ckBoxVolume->GetId()    , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume                       );
47
48         Connect(rbRayCasting->GetId()   , wxEVT_COMMAND_RADIOBUTTON_SELECTED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive                       );
49         Connect(rbMIP->GetId()          , wxEVT_COMMAND_RADIOBUTTON_SELECTED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnMIPActive                              );
50
51     Connect(ckInterpolation->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive            );
52         Connect(ckShade->GetId()        , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnShadeActive                    );
53
54
55
56         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
57         wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
58         wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
59         wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(20);
60
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);
66
67     sizerH1->Add(rbRayCasting, 1, wxALL|wxEXPAND, 0 );
68     sizerH1->Add(rbMIP, 1, wxALL|wxEXPAND, 0 );
69
70     sizerH2->Add(ckInterpolation, 1, wxALL|wxEXPAND, 0 );
71     sizerH2->Add(ckShade, 1, wxALL|wxEXPAND, 0 );
72
73
74         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
75     sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
76     sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
77
78         panel->SetSize(300,60);
79         panel->SetAutoLayout(true);
80         panel->SetSizer(sizer);
81         panel->Layout();
82
83         panel->SetEventHandler((wxEvtHandler*)this);
84
85         rbRayCasting->SetValue(true);
86
87 //      _volumerendererdata = VolumeRendererData::New();
88 //      _volumerendererdata->SetImageData(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData());
89
90 }
91 //-------------------------------------------------------------------
92 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
93 {
94 }
95 //-------------------------------------------------------------------
96 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
97 {
98 }
99
100 //-------------------------------------------------------------------
101 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
102 {
103
104
105
106     if(event.IsChecked())
107     {
108         ckBoxVolume->Enable();
109     }
110     else{
111         ckBoxVolume->Disable();
112     }
113
114   //  _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetRenderer()->RemoveAllViewProps();
115
116
117
118         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
119         if(event.IsChecked())
120         {
121             rbRayCasting->Enable();
122             rbMIP->Enable();
123             ckInterpolation->Enable();
124             ckShade->Enable();
125         }
126         else
127         {
128             rbRayCasting->Disable();
129             rbMIP->Disable();
130             ckInterpolation->Disable();
131             ckShade->Disable();
132             if(ckBoxVolume->IsChecked())
133             {
134                ckBoxVolume->SetValue(false);
135             }
136         }
137
138         _wxvtkclipping3Dview->Refresh();
139
140
141         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
142         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
143 }
144
145 //-------------------------------------------------------------------
146 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
147 {
148
149   //cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
150
151
152     if(event.IsChecked())
153     {
154            // rbRayCasting->Disable();
155            // rbMIP->Disable();
156             ckInterpolation->Disable();
157             ckShade->Disable();
158     }
159     else
160     {
161             //rbRayCasting->Enable();
162             //rbMIP->Enable();
163             ckInterpolation->Enable();
164             ckShade->Enable();
165
166     }
167
168     _wxvtkclipping3Dview->VisibleVolumeBoxActor(event.IsChecked());
169
170     _wxvtkclipping3Dview->Refresh();
171     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
172     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
173
174 }
175
176 //EED 22 Fevrier 2007
177 //-------------------------------------------------------------------
178 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
179 {
180
181         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
182         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
183         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
184         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
185         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
186         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
187         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
188         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
189         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
190         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
191
192         //use for update in the refresh
193         /*
194         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
195         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
196         */
197
198         /*
199         MMLR BORRAME
200         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
201         if (dialog.ShowModal() == wxID_OK)
202         {
203                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
204
205
206         }
207         */
208
209         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
210         //
211         // put in a method
212         //
213         int tfSize=gtf->size();
214                 if(tfSize>0)
215                 {
216                         int i=0;
217                         hDlg->erasePointsTransferenceFunction();
218                         while(i<tfSize)
219                         {
220                                 double g=(*gtf)[i];
221                                 double in=(*itf)[i];
222                                 hDlg->addPointToTransferenceFunction(g,in*100);
223                                 i++;
224                         }
225
226                 }
227
228         int ctfSize=rctf->size();
229         if(ctfSize>0)
230         {
231                 int i=0;
232                         while(i<ctfSize)
233                         {
234                                 double gr=(*greyctf)[i];
235                                 double r=(*rctf)[i];
236                                 double g=(*gctf)[i];
237                                 double b=(*bctf)[i];
238                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
239                                 i++;
240                         }
241         }
242         //setting variables if the user wants to do refresh
243         hDlg->setCTF(ctfun);
244         hDlg->setTF(tfun);
245         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
246         /*
247         hDlg->setVolume(newvol);
248         hDlg->setVolumeMapper(volumeMapper);
249         */
250         //
251         // when the user had changed the transference Function
252         //
253         if(hDlg->ShowModal()== wxID_OK )
254         {
255                         // -- vtkPiecewiseFunction --
256                         tfun->RemoveAllPoints();
257                         gtf->clear();
258                         itf->clear();
259
260                         int nTFPoints=hDlg->getSizeTransferenceFunction();
261                         int i=0;
262                         while(i<nTFPoints)
263                         {
264                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
265                                 tfun->AddPoint( xi , yi/100.0 );
266                                 gtf->push_back(xi);
267                                 itf->push_back(yi/100.0);
268                                 i++;
269                         }
270                         // -- vtkColorTransferFunction  --
271                         ctfun->RemoveAllPoints ();
272                         //clean colors
273                         rctf->clear();
274                         gctf->clear();
275                         bctf->clear();
276                         greyctf->clear();
277
278                         int nCTFpoints=hDlg->getSizeBarColor();
279                         i=0;
280                         while(i<nCTFpoints)
281                         {
282                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
283                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
284                                 rctf->push_back(r/255.0);
285                                 gctf->push_back(g/255.0);
286                                 bctf->push_back(b/255.0);
287                                 greyctf->push_back(xi);
288                                 i++;
289                         }
290                         //---------------------------------
291                         // Refreshing and sending the event
292                         //---------------------------------
293                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
294
295
296                         //test
297
298
299          //   _volumerendererdata->OpacityChanged(*gtf, *itf);
300             _wxvtkclipping3Dview->UpdateVolumeBox(*gtf, *itf, ctfun);
301
302 //test end
303
304                         _wxvtkclipping3Dview->Refresh();
305                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
306                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
307
308                         /*
309                         volumeMapper->Update();
310                         newvol->Update();
311
312
313                         */
314         } else  {
315                 if(hDlg->getRefreshed())
316                 {
317                         int i=0,size;
318                         //--Transference Function----
319                         tfun->RemoveAllPoints();
320                         i=0;
321                         size=gtf->size();
322                         for(i=0;i<size;i++)
323                         {
324                                 double grey1=(*gtf)[i];
325                                 double  in2=(*itf)[i];
326                                 tfun->AddPoint( grey1 , in2 );
327                         }
328
329                         // -- vtkColorTransferFunction  --
330                         ctfun->RemoveAllPoints ();
331
332                         i=0;
333                         size=greyctf->size();
334                         for(i=0;i<size;i++)
335                         {
336                                 double grey2=(*greyctf)[i];
337                                 double red =(*rctf)[i];
338                                 double green =(*gctf)[i];
339                                 double blue = (*bctf)[i];
340                                 ctfun->AddRGBPoint(grey2,red,green,blue);
341                         }
342
343                         //---------------------------------
344                         // Refreshing and sending the event
345                         //---------------------------------
346                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
347
348
349                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
350                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
351
352
353                 _wxvtkclipping3Dview->Refresh();
354
355                         /*
356                         volumeMapper->Update();
357                         newvol->Update();
358                         */
359                  }
360
361         }
362         //destroy the dialog
363
364
365         hDlg->Destroy();
366 }
367
368 void    wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event){
369     //If Ray Casting is active, others options are disabled. Only RayCasting is true
370     _wxvtkclipping3Dview->SetRayCasting(true);
371     _wxvtkclipping3Dview->SetMIPActive(false);
372
373     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
374
375     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
376     _wxvtkclipping3Dview->Refresh();
377 }
378
379 void    wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event){
380     //If MIP is active, others options are disabled. Only MIP is true
381     _wxvtkclipping3Dview->SetMIPActive(true);
382     _wxvtkclipping3Dview->SetRayCasting(false);
383
384     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
385     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
386
387     _wxvtkclipping3Dview->Refresh();
388 }
389
390
391
392 void    wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event){
393
394
395     _wxvtkclipping3Dview->SetInterpolation(event.IsChecked());
396
397     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
398     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
399     _wxvtkclipping3Dview->Refresh();
400 }
401
402 void    wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event){
403
404
405     _wxvtkclipping3Dview->SetShade(event.IsChecked());
406
407     wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
408     _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
409     _wxvtkclipping3Dview->Refresh();
410 }
411