1 #include "wxVtkMPR3DViewCntrlPanel.h"
3 #include "HistogramDialog.h"
5 wxVtkMPR3DViewCntrlPanel::wxVtkMPR3DViewCntrlPanel(wxWindow *parent, wxVtkMPR3DView *wxvtkmpr3Dview )
10 _wxvtkmpr3Dview = wxvtkmpr3Dview;
12 /*int maxX = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
13 int maxY = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
14 int maxZ = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();*/
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") );
28 _ckBoxXYZ = new wxCheckBox(panel,-1,_T("XYZ "));
29 _ckBoxPlane = new wxCheckBox(panel,-1,_T("Plane"));
31 ckBoxX->SetValue(false);
32 ckBoxY->SetValue(false);
33 ckBoxZ->SetValue(false);
34 _ckBoxXYZ->SetValue(false);
35 _ckBoxPlane->SetValue(false);
37 _positionX->SetSize(400,20);
38 _positionY->SetSize(400,20);
39 _positionZ->SetSize(400,20);
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 );
49 Connect(_ckBoxXYZ->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisXYZ );
50 Connect(_ckBoxPlane->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisiblePlane );
53 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
54 // wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
56 // wxBoxSizer *sizerH4 = new wxBoxSizer(wxHORIZONTAL);
57 wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10);
58 wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10);
63 // wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10);
64 // wxFlexGridSizer *sizerH7 = new wxFlexGridSizer(10);
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);
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);
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);
78 // sizerH7->Add( _ckBoxXYZ , 1, wxALL|wxEXPAND, 0);
79 // sizerH7->Add( _ckBoxPlane , 1, wxALL|wxEXPAND, 0);
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);
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 );
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);
101 sizer->Add( sizerH4 , 1, wxALL|wxGROW, 2);
102 sizer->Add( sizerH5 , 1, wxALL|wxEXPAND, 2);
105 panel->SetSize(400,50);
106 panel->SetAutoLayout(true);
107 panel->SetSizer(sizer);
110 panel->SetEventHandler((wxEvtHandler*)this);
112 //this->UpdateControlPanel();
115 void wxVtkMPR3DViewCntrlPanel::UpdateControlPanel()
118 vtkMPRBaseData* basedata = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData();
119 if(basedata != NULL){
121 /*int maxX = basedata->GetMaxPositionX();
122 int maxY = basedata->GetMaxPositionY();
123 int maxZ = basedata->GetMaxPositionZ();*/
124 int x0,x1,y0,y1,z0,z1;
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();*/
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);
141 _positionX->SetValue((x0+x1)/2);
142 _positionY->SetValue((y0+y1)/2);
143 _positionZ->SetValue((z0+z1)/2);
145 _positionX->Update();
146 _positionY->Update();
147 _positionZ->Update();
152 //-------------------------------------------------------------------
153 wxVtkMPR3DViewCntrlPanel::~wxVtkMPR3DViewCntrlPanel()
156 //-------------------------------------------------------------------
157 void wxVtkMPR3DViewCntrlPanel::Refresh()
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( )) );
165 //-------------------------------------------------------------------
166 int wxVtkMPR3DViewCntrlPanel::GetIdTissue()
169 if (_surfA->GetValue()==true)
173 if (_surfB->GetValue()==true)
177 if (_surfC->GetValue()==true)
181 if (_surfD->GetValue()==true)
190 //-------------------------------------------------------------------
191 void wxVtkMPR3DViewCntrlPanel::OnEditColorTable(wxCommandEvent& event)
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();
200 //void *p=this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer(); // JPRx
205 vtkImageData *imagedata = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
207 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Color table"),imagedata,2);
210 hDlg->erasePointsTransferenceFunction();
211 int ctfSize=ctfunVectorRed->size();
214 // MACHETE OJO Eduardo
218 double gr = (*ctfunVectorPoint)[i];
219 double r = (*ctfunVectorRed)[i];
220 double g = (*ctfunVectorGreen)[i];
221 double b = (*ctfunVectorBlue)[i];
223 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
229 // when the user had changed the transference Function
232 //setting variables if the user wants to do refresh
235 //hDlg->setMPR3Dview(_wxvtkmpr3Dview);
237 if(hDlg->ShowModal()== wxID_OK )
240 // -- vtkColorTransferFunction --
241 ctfun->RemoveAllPoints ();
243 ctfunVectorPoint->clear();
244 ctfunVectorRed->clear();
245 ctfunVectorGreen->clear();
246 ctfunVectorBlue->clear();
248 int nCTFpoints=hDlg->getSizeBarColor();
249 // Machete .. Ojo Eduardo
253 hDlg->getDataBarColorPoint(i,xi,r,g,b);
257 hDlg->getDataBarColorPoint(1,xi,r,g,b);
261 hDlg->getDataBarColorPoint(i-1,xi,r,g,b);
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);
278 if(hDlg->getRefreshed())
280 // -- vtkColorTransferFunction --
281 ctfun->RemoveAllPoints ();
284 int size=ctfunVectorPoint->size();
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);
302 //-------------------------------------------------------------------
303 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
305 _wxvtkmpr3Dview->VisibleImageActor(0, event.IsChecked() );
306 _wxvtkmpr3Dview->Refresh();
308 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
311 _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
313 std::cout<<e<<std::endl;
317 //-------------------------------------------------------------------
318 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
320 _wxvtkmpr3Dview->VisibleImageActor(1, event.IsChecked() );
321 _wxvtkmpr3Dview->Refresh();
323 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
324 _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
327 //-------------------------------------------------------------------
328 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
330 _wxvtkmpr3Dview->VisibleImageActor(2, event.IsChecked() );
331 _wxvtkmpr3Dview->Refresh();
333 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
334 _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
337 //-------------------------------------------------------------------
338 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisXYZ(wxCommandEvent& event)
340 _wxvtkmpr3Dview->VisiblePointWidget(event.IsChecked());
343 //-------------------------------------------------------------------
344 void wxVtkMPR3DViewCntrlPanel::OnVisiblePlane(wxCommandEvent& event)
346 _wxvtkmpr3Dview->VisiblePlaneWidget(event.IsChecked());
350 //-------------------------------------------------------------------
351 void wxVtkMPR3DViewCntrlPanel::OnPositionX(wxScrollEvent& event)
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);
358 //-------------------------------------------------------------------
359 void wxVtkMPR3DViewCntrlPanel::OnPositionY(wxScrollEvent& event)
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);
366 //-------------------------------------------------------------------
367 void wxVtkMPR3DViewCntrlPanel::OnPositionZ(wxScrollEvent& event)
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);