]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DViewVolCntrlPanel.cxx
feafc6e30131d95d4419a6d398d3103fd69d0bb6
[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
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 }
88 //-------------------------------------------------------------------
89 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
90 {
91 }
92 //-------------------------------------------------------------------
93 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
94 {
95 }
96
97 //-------------------------------------------------------------------
98 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
99 {
100     cout<<"JPRG::wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume::event_value::"<<event.IsChecked()<<endl;
101         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
102         if(event.IsChecked())
103         {
104             rbRayCasting->Enable();
105         rbMIP->Enable();
106         ckInterpolation->Enable();
107         ckShade->Enable();
108         }
109         else
110         {
111         rbRayCasting->Disable();
112         rbMIP->Disable();
113         ckInterpolation->Disable();
114         ckShade->Disable();
115         }
116         _wxvtkclipping3Dview->Refresh();
117
118         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
119         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
120 }
121
122 //-------------------------------------------------------------------
123 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
124 {
125         _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
126         _wxvtkclipping3Dview->Refresh();
127 }
128
129 //EED 22 Fevrier 2007
130 //-------------------------------------------------------------------
131 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
132 {
133
134         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
135         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
136         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
137         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
138         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
139         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
140         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
141         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
142         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
143         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
144
145         //use for update in the refresh
146         /*
147         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
148         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
149         */
150
151         /*
152         MMLR BORRAME
153         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
154         if (dialog.ShowModal() == wxID_OK)
155         {
156                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
157
158
159         }
160         */
161
162         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
163         //
164         // put in a method
165         //
166         int tfSize=gtf->size();
167                 if(tfSize>0)
168                 {
169                         int i=0;
170                         hDlg->erasePointsTransferenceFunction();
171                         while(i<tfSize)
172                         {
173                                 double g=(*gtf)[i];
174                                 double in=(*itf)[i];
175                                 hDlg->addPointToTransferenceFunction(g,in*100);
176                                 i++;
177                         }
178
179                 }
180
181         int ctfSize=rctf->size();
182         if(ctfSize>0)
183         {
184                 int i=0;
185                         while(i<ctfSize)
186                         {
187                                 double gr=(*greyctf)[i];
188                                 double r=(*rctf)[i];
189                                 double g=(*gctf)[i];
190                                 double b=(*bctf)[i];
191                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
192                                 i++;
193                         }
194         }
195         //setting variables if the user wants to do refresh
196         hDlg->setCTF(ctfun);
197         hDlg->setTF(tfun);
198         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
199         /*
200         hDlg->setVolume(newvol);
201         hDlg->setVolumeMapper(volumeMapper);
202         */
203         //
204         // when the user had changed the transference Function
205         //
206         if(hDlg->ShowModal()== wxID_OK )
207         {
208                         // -- vtkPiecewiseFunction --
209                         tfun->RemoveAllPoints();
210                         gtf->clear();
211                         itf->clear();
212
213                         int nTFPoints=hDlg->getSizeTransferenceFunction();
214                         int i=0;
215                         while(i<nTFPoints)
216                         {
217                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
218                                 tfun->AddPoint( xi , yi/100.0 );
219                                 gtf->push_back(xi);
220                                 itf->push_back(yi/100.0);
221                                 i++;
222                         }
223                         // -- vtkColorTransferFunction  --
224                         ctfun->RemoveAllPoints ();
225                         //clean colors
226                         rctf->clear();
227                         gctf->clear();
228                         bctf->clear();
229                         greyctf->clear();
230
231                         int nCTFpoints=hDlg->getSizeBarColor();
232                         i=0;
233                         while(i<nCTFpoints)
234                         {
235                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
236                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
237                                 rctf->push_back(r/255.0);
238                                 gctf->push_back(g/255.0);
239                                 bctf->push_back(b/255.0);
240                                 greyctf->push_back(xi);
241                                 i++;
242                         }
243                         //---------------------------------
244                         // Refreshing and sending the event
245                         //---------------------------------
246                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
247                         _wxvtkclipping3Dview->Refresh();
248                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
249                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
250
251                         /*
252                         volumeMapper->Update();
253                         newvol->Update();
254                         */
255         } else  {
256                 if(hDlg->getRefreshed())
257                 {
258                         int i=0,size;
259                         //--Transference Function----
260                         tfun->RemoveAllPoints();
261                         i=0;
262                         size=gtf->size();
263                         for(i=0;i<size;i++)
264                         {
265                                 double grey1=(*gtf)[i];
266                                 double  in2=(*itf)[i];
267                                 tfun->AddPoint( grey1 , in2 );
268                         }
269
270                         // -- vtkColorTransferFunction  --
271                         ctfun->RemoveAllPoints ();
272
273                         i=0;
274                         size=greyctf->size();
275                         for(i=0;i<size;i++)
276                         {
277                                 double grey2=(*greyctf)[i];
278                                 double red =(*rctf)[i];
279                                 double green =(*gctf)[i];
280                                 double blue = (*bctf)[i];
281                                 ctfun->AddRGBPoint(grey2,red,green,blue);
282                         }
283
284                         //---------------------------------
285                         // Refreshing and sending the event
286                         //---------------------------------
287                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
288                         _wxvtkclipping3Dview->Refresh();
289                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
290                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
291
292                         /*
293                         volumeMapper->Update();
294                         newvol->Update();
295                         */
296                  }
297
298         }
299         //destroy the dialog
300         hDlg->Destroy();
301 }
302
303 void    wxVtkClipping3DViewVolCntrlPanel::OnRayCastingActive(wxCommandEvent& event){
304     //If Ray Casting is active, others options are disabled. Only RayCasting is true
305     _wxvtkclipping3Dview->SetRayCasting(true);
306     _wxvtkclipping3Dview->SetMIPActive(false);
307     _wxvtkclipping3Dview->Refresh();
308 }
309
310 void    wxVtkClipping3DViewVolCntrlPanel::OnMIPActive(wxCommandEvent& event){
311     //If MIP is active, others options are disabled. Only MIP is true
312     _wxvtkclipping3Dview->SetMIPActive(true);
313     _wxvtkclipping3Dview->SetRayCasting(false);
314
315     _wxvtkclipping3Dview->Refresh();
316 }
317
318
319
320 void    wxVtkClipping3DViewVolCntrlPanel::OnInterpolationActive(wxCommandEvent& event){
321     _wxvtkclipping3Dview->SetInterpolation(event.IsChecked());
322     _wxvtkclipping3Dview->Refresh();
323 }
324
325 void    wxVtkClipping3DViewVolCntrlPanel::OnShadeActive(wxCommandEvent& event){
326     _wxvtkclipping3Dview->SetShade(event.IsChecked());
327     _wxvtkclipping3Dview->Refresh();
328 }
329