]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR3DViewCntrlPanel.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkMPR3DViewCntrlPanel.cxx
1 #include "wxVtkMPR3DViewCntrlPanel.h"
2
3 #include "HistogramDialog.h"
4
5 wxVtkMPR3DViewCntrlPanel::wxVtkMPR3DViewCntrlPanel(wxWindow *parent, wxVtkMPR3DView *wxvtkmpr3Dview )
6 : wxPanel(parent, -1)
7 {
8
9         wxPanel *panel  = this;
10         _wxvtkmpr3Dview = wxvtkmpr3Dview;
11
12         /*int maxX = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
13         int maxY = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
14         int maxZ = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();*/
15
16         int maxX = 1;
17         int maxY = 1;
18         int maxZ = 1;
19
20         wxCheckBox              *ckBoxX                 = new wxCheckBox(panel,-1,_T("X           "));
21                                         _positionX              = new wxSlider(panel,-1,maxX/2,0,maxX, wxDefaultPosition, wxSize(150,40), wxSL_HORIZONTAL | wxSL_LABELS);
22         wxCheckBox              *ckBoxY                 = new wxCheckBox(panel,-1,_T("Y           "));
23                                         _positionY              = new wxSlider(panel,-1,maxY/2,0,maxY, wxDefaultPosition, wxSize(150,40), wxSL_HORIZONTAL | wxSL_LABELS);
24         wxCheckBox              *ckBoxZ                 = new wxCheckBox(panel,-1,_T("Z           "));
25                                         _positionZ              = new wxSlider(panel,-1,maxZ/2,0,maxZ, wxDefaultPosition, wxSize(150,40), wxSL_HORIZONTAL | wxSL_LABELS);
26         wxButton                *btnColorTable  = new wxButton (panel, -1, _T("Edit Color Table") );
27
28         _ckBoxXYZ                       = new wxCheckBox(panel,-1,_T("XYZ                  "));
29         _ckBoxPlane                     = new wxCheckBox(panel,-1,_T("Plane"));
30
31         ckBoxX->SetValue(false);
32         ckBoxY->SetValue(false);
33         ckBoxZ->SetValue(false);
34         _ckBoxXYZ->SetValue(false);
35         _ckBoxPlane->SetValue(false);
36
37         _positionX->SetSize(400,20);
38         _positionY->SetSize(400,20);
39         _positionZ->SetSize(400,20);
40
41         Connect(ckBoxX->GetId()                 , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX   );
42         Connect(_positionX->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionX              );
43         Connect(ckBoxY->GetId()                 , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY   );
44         Connect(_positionY->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionY              );
45         Connect(ckBoxZ->GetId()                 , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ   );
46         Connect(_positionZ->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionZ              );
47         Connect(btnColorTable->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnEditColorTable );
48
49         Connect(_ckBoxXYZ->GetId()  , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisXYZ );
50         Connect(_ckBoxPlane->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisiblePlane   );
51
52
53         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
54 //      wxBoxSizer *sizer        = new wxBoxSizer(wxVERTICAL);
55
56 //      wxBoxSizer *sizerH4 = new wxBoxSizer(wxHORIZONTAL);
57         wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10);
58         wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10);
59
60
61
62 //EED 28 sep 2006
63 //      wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10);
64 //      wxFlexGridSizer *sizerH7 = new wxFlexGridSizer(10);
65
66 //      sizerH4->Add( ckBoxX            , 1, wxALL|wxEXPAND, 0);
67 //      sizerH4->Add( new wxStaticText(panel, -1,"  ")                  , 1, wxALL|wxEXPAND, 0);
68 //      sizerH4->Add( _positionX        , 1, wxALL|wxEXPAND, 0);
69
70 //      sizerH5->Add( ckBoxY            , 1, wxALL|wxEXPAND, 0);
71 //      sizerH5->Add( new wxStaticText(panel, -1,"  ")                  , 1, wxALL|wxEXPAND, 0);
72 //      sizerH5->Add( _positionY        , 1, wxALL|wxEXPAND, 0);
73
74 //      sizerH6->Add( ckBoxZ            , 1, wxALL|wxEXPAND, 0);
75 //      sizerH6->Add( new wxStaticText(panel, -1,"  ")                  , 1, wxALL|wxEXPAND, 0);
76 //      sizerH6->Add( _positionZ        , 1, wxALL|wxEXPAND, 0);
77
78 //      sizerH7->Add( _ckBoxXYZ         , 1, wxALL|wxEXPAND, 0);
79 //      sizerH7->Add( _ckBoxPlane       , 1, wxALL|wxEXPAND, 0);
80
81 //      sizer->Add( sizerH4                     , 1, wxALL|wxEXPAND, 2);
82 //      sizer->Add( sizerH5                     , 1, wxALL|wxEXPAND, 2);
83 //      sizer->Add( sizerH6                     , 1, wxALL|wxEXPAND, 2);
84 //      sizer->Add( sizerH7                     , 1, wxALL|wxEXPAND, 2);
85
86         sizerH4->Add( _positionX                                                                ,1,wxGROW                                       , 0 );
87         sizerH4->Add( ckBoxX                                                                    ,0,wxALIGN_CENTER_VERTICAL|wxSHAPED     , 0 );
88         sizerH4->Add( _positionY                                                                ,1,wxGROW                                       , 0 );
89         sizerH4->Add( ckBoxY                                                                    ,0,wxALIGN_CENTER_VERTICAL|wxSHAPED     , 0 );
90         sizerH4->Add( _positionZ                                                                ,1,wxGROW                                       , 0 );
91         sizerH4->Add( ckBoxZ                                                                    ,0,wxALIGN_CENTER_VERTICAL|wxSHAPED     , 0 );
92         sizerH4->Add( btnColorTable                                                             ,0,wxALIGN_CENTER_VERTICAL|wxSHAPED     , 0 );
93
94         sizerH5->Add( _ckBoxXYZ                         ,  1, wxALL|wxEXPAND, 0);
95         sizerH5->Add( _ckBoxPlane                       ,  1, wxALL|wxEXPAND, 0);
96         sizerH5->Add( new wxStaticText(panel, -1,_T("      "))                  , 1, wxALL|wxEXPAND, 0);
97 //      sizerH5->Add( ckBoxX                            ,  1, wxALL|wxEXPAND, 0);
98 //      sizerH5->Add( ckBoxY                            ,  1, wxALL|wxEXPAND, 0);
99 //      sizerH5->Add( ckBoxZ                            ,  1, wxALL|wxEXPAND, 0);
100
101         sizer->Add( sizerH4                                     ,  1, wxALL|wxGROW, 2);
102         sizer->Add( sizerH5                                     ,  1, wxALL|wxEXPAND, 2);
103
104
105         panel->SetSize(400,50);
106         panel->SetAutoLayout(true);
107         panel->SetSizer(sizer);
108         panel->Layout();
109
110         panel->SetEventHandler((wxEvtHandler*)this);
111
112         //this->UpdateControlPanel();
113
114 }
115 void wxVtkMPR3DViewCntrlPanel::UpdateControlPanel()
116 {
117
118         vtkMPRBaseData* basedata = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData();
119         if(basedata != NULL){
120
121                 /*int maxX = basedata->GetMaxPositionX();
122                 int maxY = basedata->GetMaxPositionY();
123                 int maxZ = basedata->GetMaxPositionZ();*/
124                 int x0,x1,y0,y1,z0,z1;
125
126                 basedata->GetDimensionExtention(&x0,&x1,&y0,&y1,&z0,&z1);
127                 /*int maxX = x1-x0;//basedata->GetMaxPositionX();
128                 int maxY = y1-y0;//basedata->GetMaxPositionY();
129                 int maxZ = z1-z0;//basedata->GetMaxPositionZ();*/
130
131                 
132
133                 //std::cout<<"wxVtkMPR3DViewCntrlPanel::UpdateControlPanel() maxX="<<maxX<<" maxY="<<maxY<<" maxZ="<<maxZ<<std::endl;
134                 /*_positionX->SetRange(0,maxX);
135                 _positionY->SetRange(0,maxY);
136                 _positionZ->SetRange(0,maxZ);*/
137                 _positionX->SetRange(x0,x1);
138                 _positionY->SetRange(y0,y1);
139                 _positionZ->SetRange(z0,z1);
140
141                 _positionX->SetValue((x0+x1)/2);
142                 _positionY->SetValue((y0+y1)/2);
143                 _positionZ->SetValue((z0+z1)/2);
144
145                 _positionX->Update();
146                 _positionY->Update();
147                 _positionZ->Update();
148                 this->Update();
149         }
150         
151 }
152 //-------------------------------------------------------------------
153 wxVtkMPR3DViewCntrlPanel::~wxVtkMPR3DViewCntrlPanel()
154 {
155 }
156 //-------------------------------------------------------------------
157 void wxVtkMPR3DViewCntrlPanel::Refresh()
158 {
159 //      wxPanel::Refresh();
160         _positionX->SetValue( (int)(_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX( )) );
161         _positionY->SetValue( (int)(_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY( )) );
162         _positionZ->SetValue( (int)(_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ( )) );
163 }
164 /*
165 //-------------------------------------------------------------------
166 int wxVtkMPR3DViewCntrlPanel::GetIdTissue()
167 {
168         int idTissue=-1;
169         if (_surfA->GetValue()==true)
170         {
171                 idTissue=0;
172         }
173         if (_surfB->GetValue()==true)
174         {
175                 idTissue=1;
176         }
177         if (_surfC->GetValue()==true)
178         {
179                 idTissue=2;
180         }
181         if (_surfD->GetValue()==true)
182         {
183                 idTissue=3;
184         }
185
186         return idTissue;
187 }
188 */
189
190 //-------------------------------------------------------------------
191 void wxVtkMPR3DViewCntrlPanel::OnEditColorTable(wxCommandEvent& event)
192 {
193
194         vtkColorTransferFunction *ctfun                 = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetvtkColorTransferFunction(); 
195         std::vector<double> *ctfunVectorPoint   = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetctFunVectorPoint();
196         std::vector<double> *ctfunVectorRed             = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetctFunVectorRed();
197         std::vector<double> *ctfunVectorGreen   = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetctFunVectorGreen();
198         std::vector<double> *ctfunVectorBlue    =   this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetctFunVectorBlue();
199
200         //void *p=this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer(); // JPRx
201
202
203         int i=0,xi,r,g,b;
204         
205         vtkImageData *imagedata = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
206
207         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Color table"),imagedata,2);
208         
209                 
210         hDlg->erasePointsTransferenceFunction();        
211         int ctfSize=ctfunVectorRed->size();
212         if(ctfSize>0)
213         {
214 // MACHETE  OJO Eduardo
215                 int i=0;
216                         while(i<ctfSize)
217                         {
218                                 double gr       = (*ctfunVectorPoint)[i];
219                                 double r        = (*ctfunVectorRed)[i];
220                                 double g        = (*ctfunVectorGreen)[i];
221                                 double b        = (*ctfunVectorBlue)[i];
222                         
223 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
224                                 i++;
225                         }
226         }
227
228         //
229         // when the user had changed the transference Function
230         //
231         
232         //setting variables if the user wants to do refresh
233         
234         hDlg->setCTF(ctfun);
235         //hDlg->setMPR3Dview(_wxvtkmpr3Dview);
236         
237         if(hDlg->ShowModal()== wxID_OK )
238         {       
239                 
240                 // -- vtkColorTransferFunction  --
241                         ctfun->RemoveAllPoints ();
242                         //clean colors
243                         ctfunVectorPoint->clear();
244                         ctfunVectorRed->clear();
245                         ctfunVectorGreen->clear();
246                         ctfunVectorBlue->clear();
247
248                         int nCTFpoints=hDlg->getSizeBarColor();
249 // Machete .. Ojo Eduardo
250                         i=0;    
251                         while(i<nCTFpoints)
252                         {
253                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
254                                 /*
255                                 if (i==0)
256                                 {
257                                         hDlg->getDataBarColorPoint(1,xi,r,g,b);
258                                 } 
259                                 if (i==nCTFpoints)
260                                 {
261                                         hDlg->getDataBarColorPoint(i-1,xi,r,g,b);
262                                 } 
263                                 */
264                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
265                                 ctfunVectorPoint->push_back(xi);
266                                 ctfunVectorRed->push_back(r/255.0);
267                                 ctfunVectorGreen->push_back(g/255.0);
268                                 ctfunVectorBlue->push_back(b/255.0);
269                                 i++;
270                                 
271                         }
272                         
273         }
274         
275         else
276         {
277                 
278                 if(hDlg->getRefreshed())
279                 {
280                         // -- vtkColorTransferFunction  --
281                         ctfun->RemoveAllPoints ();
282                         
283                         int i=0;
284                         int size=ctfunVectorPoint->size();
285                         
286                         for(i=0;i<size;i++)
287                         {
288                                 double grey2=(*ctfunVectorPoint)[i];
289                                 double red =(*ctfunVectorRed)[i];
290                                 double green =(*ctfunVectorGreen)[i];
291                                 double blue = (*ctfunVectorBlue)[i];
292                                 ctfun->AddRGBPoint(grey2,red,green,blue);
293                         }
294                  }      
295                  
296         }
297
298  hDlg->Destroy();
299 }
300
301
302 //-------------------------------------------------------------------
303 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
304 {
305         _wxvtkmpr3Dview->VisibleImageActor(0, event.IsChecked() );
306         _wxvtkmpr3Dview->Refresh();
307
308         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
309
310         try{
311                 _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
312         }catch(char* e){
313                 std::cout<<e<<std::endl;
314         }
315
316 }
317 //-------------------------------------------------------------------
318 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
319 {
320         _wxvtkmpr3Dview->VisibleImageActor(1, event.IsChecked() );
321         _wxvtkmpr3Dview->Refresh();
322
323         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
324         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
325
326 }
327 //-------------------------------------------------------------------
328 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
329 {
330         _wxvtkmpr3Dview->VisibleImageActor(2, event.IsChecked() );
331         _wxvtkmpr3Dview->Refresh();
332
333         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
334         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
335 }
336
337 //-------------------------------------------------------------------
338 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisXYZ(wxCommandEvent& event)
339 {
340         _wxvtkmpr3Dview->VisiblePointWidget(event.IsChecked());
341 }
342
343 //-------------------------------------------------------------------
344 void wxVtkMPR3DViewCntrlPanel::OnVisiblePlane(wxCommandEvent& event)
345 {
346         _wxvtkmpr3Dview->VisiblePlaneWidget(event.IsChecked());
347 }
348
349
350 //-------------------------------------------------------------------
351 void wxVtkMPR3DViewCntrlPanel::OnPositionX(wxScrollEvent& event)
352 {
353         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( _positionX->GetValue() );
354         _wxvtkmpr3Dview->RefreshView();
355         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
356         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
357 }
358 //-------------------------------------------------------------------
359 void wxVtkMPR3DViewCntrlPanel::OnPositionY(wxScrollEvent& event)
360 {
361         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( _positionY->GetValue() );
362         _wxvtkmpr3Dview->RefreshView();
363         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
364         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
365 }
366 //-------------------------------------------------------------------
367 void wxVtkMPR3DViewCntrlPanel::OnPositionZ(wxScrollEvent& event)
368 {
369         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( _positionZ->GetValue() );
370         _wxvtkmpr3Dview->RefreshView();
371         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
372         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
373 }