]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkClipping3DViewVolCntrlPanel.cxx
Divides in two panels the Surface/Volume tab. It was changed only the class "maracasV...
[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("Vol"));
22         wxCheckBox              *ckBoxVolume    = new wxCheckBox(panel,-1,_T("Volume Box"));
23
24         wxButton *btnVolumeFunctions    = new wxButton(panel,-1,_T("Read Volume Functions"));
25
26         Connect(btnVolumeFunctions->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions       ); 
27
28         ckBoxVolume->SetValue(false);
29
30         Connect(ckVolum->GetId()                , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume                          );
31         Connect(ckBoxVolume->GetId()    , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume                       );
32
33         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
34         wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
35
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);
41
42
43         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
44
45         panel->SetSize(300,60);
46         panel->SetAutoLayout(true);
47         panel->SetSizer(sizer);
48         panel->Layout();
49
50         panel->SetEventHandler((wxEvtHandler*)this);
51
52 }
53 //-------------------------------------------------------------------
54 wxVtkClipping3DViewVolCntrlPanel::~wxVtkClipping3DViewVolCntrlPanel()
55 {
56 }
57 //-------------------------------------------------------------------
58 void wxVtkClipping3DViewVolCntrlPanel::Refresh()
59 {
60 }
61
62 //-------------------------------------------------------------------
63 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
64 {
65         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
66         _wxvtkclipping3Dview->Refresh();
67
68         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
69         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
70 }
71
72 //-------------------------------------------------------------------
73 void wxVtkClipping3DViewVolCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
74 {
75         _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
76         _wxvtkclipping3Dview->Refresh();
77 }
78
79 //EED 22 Fevrier 2007
80 //-------------------------------------------------------------------
81 void wxVtkClipping3DViewVolCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
82 {
83         
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();
94
95         //use for update in the refresh
96         /*
97         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
98         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
99         */
100
101         /*
102         MMLR BORRAME 
103         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
104         if (dialog.ShowModal() == wxID_OK)
105         {
106                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
107                 
108         
109         }
110         */
111
112         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
113         // 
114         // put in a method
115         //
116         int tfSize=gtf->size();
117                 if(tfSize>0)
118                 {
119                         int i=0;
120                         hDlg->erasePointsTransferenceFunction();
121                         while(i<tfSize)
122                         {
123                                 double g=(*gtf)[i];
124                                 double in=(*itf)[i];
125                                 hDlg->addPointToTransferenceFunction(g,in*100);
126                                 i++;
127                         }
128                         
129                 }
130
131         int ctfSize=rctf->size();
132         if(ctfSize>0)
133         {
134                 int i=0;
135                         while(i<ctfSize)
136                         {
137                                 double gr=(*greyctf)[i];
138                                 double r=(*rctf)[i];
139                                 double g=(*gctf)[i];
140                                 double b=(*bctf)[i];
141                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
142                                 i++;
143                         }
144         }
145         //setting variables if the user wants to do refresh
146         hDlg->setCTF(ctfun);
147         hDlg->setTF(tfun);
148         //hDlg->setClipping3DView(_wxvtkclipping3Dview);
149         /*
150         hDlg->setVolume(newvol);
151         hDlg->setVolumeMapper(volumeMapper);
152         */
153         //
154         // when the user had changed the transference Function
155         //
156         if(hDlg->ShowModal()== wxID_OK )
157         {       
158                         // -- vtkPiecewiseFunction --
159                         tfun->RemoveAllPoints();
160                         gtf->clear();
161                         itf->clear();
162                 
163                         int nTFPoints=hDlg->getSizeTransferenceFunction();
164                         int i=0;
165                         while(i<nTFPoints)
166                         {
167                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
168                                 tfun->AddPoint( xi , yi/100.0 );
169                                 gtf->push_back(xi);
170                                 itf->push_back(yi/100.0);
171                                 i++;
172                         }       
173                         // -- vtkColorTransferFunction  --
174                         ctfun->RemoveAllPoints ();
175                         //clean colors
176                         rctf->clear();
177                         gctf->clear();
178                         bctf->clear();
179                         greyctf->clear();
180
181                         int nCTFpoints=hDlg->getSizeBarColor();
182                         i=0;    
183                         while(i<nCTFpoints)
184                         {
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);
191                                 i++;
192                         }
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);
200                         
201                         /*
202                         volumeMapper->Update();
203                         newvol->Update();
204                         */
205         } else  {
206                 if(hDlg->getRefreshed())
207                 {
208                         int i=0,size;
209                         //--Transference Function----
210                         tfun->RemoveAllPoints();
211                         i=0;
212                         size=gtf->size();
213                         for(i=0;i<size;i++)
214                         {
215                                 double grey1=(*gtf)[i];
216                                 double  in2=(*itf)[i];
217                                 tfun->AddPoint( grey1 , in2 );
218                         }
219                         
220                         // -- vtkColorTransferFunction  --
221                         ctfun->RemoveAllPoints ();
222                         
223                         i=0;
224                         size=greyctf->size();           
225                         for(i=0;i<size;i++)
226                         {
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);
232                         }
233                 
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);
241                         
242                         /*
243                         volumeMapper->Update();
244                         newvol->Update();
245                         */
246                  }
247                  
248         }
249         //destroy the dialog
250         hDlg->Destroy();
251 }