1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 #include "wxVtkClipping3DViewCntrlPanel.h"
28 #include "wx/colordlg.h"
29 #include "vtkTriangleFilter.h"
30 #include "vtkPolyDataConnectivityFilter.h"
31 #include "vtkClosePolyData.h"
32 #include "vtkSTLWriter.h"
33 #include "HistogramDialog.h"
34 #include "marDicomBase.h"
36 wxVtkClipping3DViewCntrlPanel::wxVtkClipping3DViewCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
39 wxPanel *panel = this;
40 _wxvtkclipping3Dview = wxvtkclipping3Dview;
43 // wxStaticText *text1 = new wxStaticText(panel, -1,_T(" "));
44 // wxStaticText *text2 = new wxStaticText(panel, -1,_T(" "));
46 _surfA = new wxRadioButton(panel,-1,_T("A"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
47 _surfB = new wxRadioButton(panel,-1,_T("B"));
48 _surfC = new wxRadioButton(panel,-1,_T("C"));
49 _surfD = new wxRadioButton(panel,-1,_T("D"));
51 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
52 //wxCheckBox *ckVolum = new wxCheckBox(panel,-1,_T("Vol"));
53 wxCheckBox *ckBoxSurface = new wxCheckBox(panel,-1,_T("Surface Box"));
55 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
56 //wxCheckBox *ckBoxVolume = new wxCheckBox(panel,-1,_T("Volume Box"));
58 _color = new wxButton(panel,-1,_T(""));
59 _visible = new wxCheckBox(panel,-1,_T("Vis"));
60 _opacity = new wxSlider(panel,-1,50,0,100, wxDefaultPosition, wxSize(100,40), wxSL_HORIZONTAL | wxSL_LABELS);
62 wxStaticText *isoValueTitle = new wxStaticText(panel,-1,_T("isoValue"));
63 _isoValue = new wxSlider(panel,-1,2000,110,2000, wxDefaultPosition, wxSize(300,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS);
65 _wireFrameRep = new wxRadioButton(panel,-1,_T("WireFrame"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
66 _surfaceRep = new wxRadioButton(panel,-1,_T("Surface"));
69 vtkImageData *vtkimagedata = wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
70 vtkimagedata->GetScalarRange( range );
71 _isoValue->SetRange( (int)(range[1]*0.1) , (int)(range[1]) );
72 _isoValue->SetValue( (int)(wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(0)) );
74 _isoValue->SetTickFreq(25,0);
76 _isoValueSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
77 _isoValueSpin->SetRange(1,8);
78 _isoValueSpin->SetValue(5);
79 Connect(_isoValueSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin );
81 wxButton *btnSTL = new wxButton(panel,-1,_T("Create STL File"));
82 wxButton *btnSaveRaw = new wxButton(panel,-1,_T("Save Raw Volume"));
84 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
85 //wxButton *btnVolumeFunctions = new wxButton(panel,-1,_T("Read Volume Functions"));
88 Connect(btnSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL );
89 Connect(btnSaveRaw->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume );
91 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
92 //Connect(btnVolumeFunctions->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions );
95 wxButton *btnMeshVTKLoad = new wxButton(panel,-1,_T("Load Mesh"));
96 Connect(btnMeshVTKLoad->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad );
100 int maxX = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
101 int maxY = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
102 int maxZ = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();
103 wxCheckBox *ckBoxX = new wxCheckBox(panel,-1,"X");
104 _positionX = new wxSlider(panel,-1,maxX/2,0,maxX, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
105 wxCheckBox *ckBoxY = new wxCheckBox(panel,-1,"Y");
106 _positionY = new wxSlider(panel,-1,maxY/2,0,maxY, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
107 wxCheckBox *ckBoxZ = new wxCheckBox(panel,-1,"Z");
108 _positionZ = new wxSlider(panel,-1,maxZ/2,0,maxZ, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
111 // ckVolum->Enable(false);
112 ckBoxSurface->SetValue(false);
115 //ckBoxVolume->SetValue(false);
118 _color->SetSize(40,20);
119 _opacity->SetSize(370,20);
120 // ckBoxX->SetValue(true);
121 // ckBoxY->SetValue(true);
122 // ckBoxZ->SetValue(true);
123 _surfA->SetValue(true);
124 _wireFrameRep->SetValue(false);
125 _surfaceRep->SetValue(true);
126 _visible->SetValue(false);
127 // _positionX->SetSize(400,20);
128 // _positionY->SetSize(400,20);
129 // _positionZ->SetSize(400,20);
131 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
132 //Connect(ckVolum->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleVolume );
133 //Connect(ckBoxVolume->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume );
135 Connect(_surfA->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface );
136 Connect(_surfB->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface );
137 Connect(_surfC->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface );
138 Connect(_surfD->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface );
139 Connect(ckBoxSurface->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface );
141 Connect(_wireFrameRep->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame );
142 Connect(_surfaceRep->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame );
144 Connect(_color->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnColor );
145 Connect(_visible->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleSurface );
146 Connect(_opacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnOpacity );
149 // Connect(_isoValue->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue );
150 Connect(_isoValue->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue );
153 Connect(ckBoxX->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX );
154 Connect(_positionX->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionX );
155 Connect(ckBoxY->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY );
156 Connect(_positionY->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionY );
157 Connect(ckBoxZ->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ );
158 Connect(_positionZ->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionZ );
161 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
162 wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
163 wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
164 wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(10);
165 wxFlexGridSizer *sizerH3 = new wxFlexGridSizer(10);
166 //wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10); // JPRx
167 //wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10); // JPRx
168 //wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10); // JPRx
170 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
171 //sizerH0->Add( ckVolum , 1, wxALL|wxEXPAND, 0);
172 //sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
173 //sizerH0->Add( ckBoxVolume , 1, wxALL|wxEXPAND, 0);
174 //sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
175 //sizerH0->Add( btnVolumeFunctions , 1, wxALL|wxEXPAND, 0);
176 //sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
177 sizerH0->Add( btnMeshVTKLoad , 1, wxALL|wxEXPAND, 0);
180 sizerH1->Add( _surfA , 1, wxALL|wxEXPAND, 0);
181 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
182 sizerH1->Add( _surfB , 1, wxALL|wxEXPAND, 0);
183 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
184 sizerH1->Add( _surfC , 1, wxALL|wxEXPAND, 0);
185 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
186 sizerH1->Add( _surfD , 1, wxALL|wxEXPAND, 0);
187 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
188 sizerH1->Add( ckBoxSurface , 1, wxALL|wxEXPAND, 0);
189 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
190 sizerH1->Add( btnSTL , 1, wxALL|wxEXPAND, 0);
191 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
192 sizerH1->Add( btnSaveRaw , 1, wxALL|wxEXPAND, 0);
195 // sizerH2->Add( new wxStaticText(panel, -1,_T(" ") , 1, wxALL|wxEXPAND, 0);
196 sizerH2->Add( _color , 1, wxALL|wxEXPAND, 0);
197 sizerH2->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
198 sizerH2->Add( _visible , 1, wxALL|wxEXPAND, 0);
199 sizerH2->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
202 sizerH2->Add( _wireFrameRep , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
203 sizerH2->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
204 sizerH2->Add( _surfaceRep , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
205 sizerH2->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
209 sizerH3->Add( isoValueTitle , 1, wxALL|wxEXPAND, 0);
210 sizerH3->Add( _isoValueSpin , 1, wxALL|wxEXPAND, 0);
211 sizerH3->Add( _isoValue , 1, wxALL|wxEXPAND, 0);
213 sizerH3->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
214 sizerH3->Add( new wxStaticText(panel, -1,_T("Opacity:")) , 1, wxALL|wxEXPAND, 0);
215 sizerH3->Add( _opacity , 1, wxALL|wxEXPAND, 0);
219 sizerH4->Add( ckBoxX , 1, wxALL|wxEXPAND, 0);
220 sizerH4->Add( text2 , 1, wxALL|wxEXPAND, 0);
221 sizerH4->Add( _positionX , 1, wxALL|wxEXPAND, 0);
223 sizerH5->Add( ckBoxY , 1, wxALL|wxEXPAND, 0);
224 sizerH5->Add( text2 , 1, wxALL|wxEXPAND, 0);
225 sizerH5->Add( _positionY , 1, wxALL|wxEXPAND, 0);
227 sizerH6->Add( ckBoxZ , 1, wxALL|wxEXPAND, 0);
228 sizerH6->Add( text2 , 1, wxALL|wxEXPAND, 0);
229 sizerH6->Add( _positionZ , 1, wxALL|wxEXPAND, 0);
231 sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
232 sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
233 sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
234 sizer->Add( sizerH3 , 1, wxALL|wxEXPAND, 2);
235 // sizer->Add( sizerH4 , 1, wxALL|wxEXPAND, 2);
236 // sizer->Add( sizerH5 , 1, wxALL|wxEXPAND, 2);
237 // sizer->Add( sizerH6 , 1, wxALL|wxEXPAND, 2);
239 panel->SetSize(300,60);
240 panel->SetAutoLayout(true);
241 panel->SetSizer(sizer);
244 panel->SetEventHandler((wxEvtHandler*)this);
247 //-------------------------------------------------------------------
248 wxVtkClipping3DViewCntrlPanel::~wxVtkClipping3DViewCntrlPanel()
251 //-------------------------------------------------------------------
252 void wxVtkClipping3DViewCntrlPanel::Refresh()
254 // wxPanel::Refresh();
256 _positionX->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetX( ) );
257 _positionY->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetY( ) );
258 _positionZ->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetZ( ) );
261 //-------------------------------------------------------------------
262 int wxVtkClipping3DViewCntrlPanel::GetIdTissue()
265 if (_surfA->GetValue()==true)
269 if (_surfB->GetValue()==true)
273 if (_surfC->GetValue()==true)
277 if (_surfD->GetValue()==true)
285 //-------------------------------------------------------------------
286 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
288 _wxvtkclipping3Dview->VisibleImageActor(0, event.IsChecked() );
289 _wxvtkclipping3Dview->Refresh();
291 //-------------------------------------------------------------------
292 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
294 _wxvtkclipping3Dview->VisibleImageActor(1, event.IsChecked() );
295 _wxvtkclipping3Dview->Refresh();
297 //-------------------------------------------------------------------
298 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
300 _wxvtkclipping3Dview->VisibleImageActor(2, event.IsChecked() );
301 _wxvtkclipping3Dview->Refresh();
305 //-------------------------------------------------------------------
306 void wxVtkClipping3DViewCntrlPanel::OnSurface(wxCommandEvent& event)
308 int idTissue=GetIdTissue();
313 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
315 tmpActor->GetProperty()->GetColor( rgb );
316 wxColour colour( (int)(rgb[0]*255) , (int)(rgb[1]*255) , (int)(rgb[2]*255) );
317 _color->SetBackgroundColour(colour);
320 _visible->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVisibleTissue(idTissue));
323 _opacity->SetValue( (int)(tmpActor->GetProperty()->GetOpacity()*100) );
325 // Representation Type WireFrame / Surface
326 _surfaceRep->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue));
327 _wireFrameRep->SetValue(!_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue));
330 int isoValue= (int)(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(idTissue));
331 _isoValue->SetValue(isoValue);
336 //-------------------------------------------------------------------
337 void wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame(wxCommandEvent& event)
339 int idTissue=GetIdTissue();
342 _wxvtkclipping3Dview->SetRepSurfaceWireFrame(idTissue , _surfaceRep->GetValue() );
344 _wxvtkclipping3Dview->Refresh();
346 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
347 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
348 #if wxMAJOR_VERSION <= 2
349 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
351 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
357 //-------------------------------------------------------------------
358 void wxVtkClipping3DViewCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
360 _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked() );
361 _wxvtkclipping3Dview->Refresh();
363 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
365 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
366 #if wxMAJOR_VERSION <= 2
367 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
369 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
373 //-------------------------------------------------------------------
374 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface(wxCommandEvent& event)
376 _wxvtkclipping3Dview->SetVisibleBoxSurface(event.IsChecked() );
377 _wxvtkclipping3Dview->Refresh();
379 //-------------------------------------------------------------------
380 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
382 printf("EED ERROR JPReyes wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume calling _wxvtkclipping3Dview->SetVisibleBoxVolume that not exists ...");
383 //EED01July2011 _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
384 //this->BoundingBoxChanged(event.IsChecked());
385 _wxvtkclipping3Dview->Refresh();
387 //-------------------------------------------------------------------
388 void wxVtkClipping3DViewCntrlPanel::OnColor(wxCommandEvent& event)
390 int idTissue=GetIdTissue();
393 // EED 17 Janvier 2007
394 wxColourDialog dlgColour(this);
395 // dlgColour.ShowModal();
396 if( dlgColour.ShowModal( ) == wxID_OK )
399 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
400 float r=dlgColour.GetColourData().GetColour().Red()/255;
401 float g=dlgColour.GetColourData().GetColour().Green()/255;
402 float b=dlgColour.GetColourData().GetColour().Blue()/255;
403 tmpActor->GetProperty()->SetColor( r , g , b );
404 _color->SetBackgroundColour(dlgColour.GetColourData().GetColour());
405 _wxvtkclipping3Dview->Refresh();
406 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
407 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
408 #if wxMAJOR_VERSION <= 2
409 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
411 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
417 //-------------------------------------------------------------------
418 void wxVtkClipping3DViewCntrlPanel::OnVisibleSurface(wxCommandEvent& event)
420 int idTissue=GetIdTissue();
423 _wxvtkclipping3Dview->VisibleActor(idTissue, _visible->GetValue());
424 _wxvtkclipping3Dview->Refresh();
425 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
426 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
427 #if wxMAJOR_VERSION <= 2
428 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
430 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
434 //-------------------------------------------------------------------
435 void wxVtkClipping3DViewCntrlPanel::OnOpacity(wxScrollEvent& event)
437 int idTissue=GetIdTissue();
441 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
442 float opacity=_opacity->GetValue();
443 tmpActor->GetProperty()->SetOpacity( opacity/100 );
444 _wxvtkclipping3Dview->Refresh();
445 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
446 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
447 #if wxMAJOR_VERSION <= 2
448 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
450 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
455 //----------------------------------------------------------------------------
456 void wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin(wxScrollEvent& event)
458 int value = _isoValue->GetValue();
459 int delta= (int)pow( (double)4 ,(double) _isoValueSpin->GetValue() );
460 int min=value - delta/2;
461 int max=value + delta/2;
467 _isoValue->SetRange(min,max);
471 //------------------------------------------------------------------------
472 void wxVtkClipping3DViewCntrlPanel::OnIsoValue(wxScrollEvent& event)
476 int idTissue=GetIdTissue();
479 int isoValue=_isoValue->GetValue();
480 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->SetIsovalue(idTissue,isoValue);
482 // tmpStr.Printf("%d",isoValue);
484 _wxvtkclipping3Dview->Refresh();
486 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
488 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
489 #if wxMAJOR_VERSION <= 2
490 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
492 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
498 //-------------------------------------------------------------------
499 void wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL(wxCommandEvent& event)
502 int idTissue=GetIdTissue();
509 wxString dirSTL = wxGetHomeDir( ) ;
510 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
511 #if wxMAJOR_VERSION <= 2
512 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
514 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxFD_SAVE );
517 if( dialog.ShowModal( ) == wxID_OK )
521 // ------------------------------------------------------------------------
522 // 1. GENERATE STL FILES
523 // ------------------------------------------------------------------------
524 // const char* fileprefix = "c:\\Creatis\\";
525 std::string prefix = (const char*) (dialog.GetPath().mb_str() );
526 std::string filename;
528 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
530 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
533 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
534 vtkClosePolyData *cpd = vtkClosePolyData::New();
537 //EED 2017-01-01 Migration VTK7
538 #if VTK_MAJOR_VERSION <= 5
539 filtro->SetInput( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
540 pdcf->SetInput( filtro->GetOutput() );
541 cpd->SetInput( pdcf->GetOutput() );
543 filtro->SetInputData( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
544 pdcf->SetInputData( filtro->GetOutput() );
545 cpd->SetInputData( pdcf->GetOutput() );
548 // 1.2 se escribe a disco el archivo stl de la superficie interna
550 vtkSTLWriter *writer = vtkSTLWriter::New();
552 //EED 2017-01-01 Migration VTK7
553 #if VTK_MAJOR_VERSION <= 5
554 writer->SetInput( cpd->GetOutput() );
556 writer->SetInputData( cpd->GetOutput() );
560 writer->SetFileName(filename.c_str());
561 writer->SetFileTypeToASCII();
573 //EED 30 Janvier 2007
574 //-------------------------------------------------------------------
575 void wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(wxCommandEvent& event)
577 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
578 #if wxMAJOR_VERSION <= 2
579 wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
581 wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxFD_SAVE );
583 if (dialog.ShowModal() == wxID_OK)
585 std::string directory = (const char*) (dialog.GetDirectory().mb_str() );
586 std::string filename = (const char*) (dialog.GetFilename().mb_str() );
587 float rescalaSlope = 1;
588 float rescalaIntercept = 0;
589 vtkMPRBaseData *vtkmprbasedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData();
590 vtkImageData *vtkimagedata = vtkmprbasedata->GetImageData();
592 vtkimagedata->GetDimensions(dim);
600 //EED 10 oct 2007 MaracasVisu pour bbMaracasvisu
601 marRAW2Files marraw2;
602 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
606 //EED 22 Fevrier 2007
607 //-------------------------------------------------------------------
608 void wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
611 int /*i=0,*/ xi,yi,r,g,b; // JPRx
612 vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
613 vtkPiecewiseFunction* tfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
614 std::vector<double>* gtf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
615 std::vector<double>* itf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
616 std::vector<double>* greyctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
617 std::vector<double>* rctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
618 std::vector<double>* gctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
619 std::vector<double>* bctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
620 vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
622 //use for update in the refresh
624 vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
625 vtkVolume* newvol =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
630 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
631 if (dialog.ShowModal() == wxID_OK)
633 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
639 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
643 int tfSize=gtf->size();
647 hDlg->erasePointsTransferenceFunction();
652 hDlg->addPointToTransferenceFunction(g,in*100);
658 int ctfSize=rctf->size();
664 double gr=(*greyctf)[i];
668 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
672 //setting variables if the user wants to do refresh
675 //hDlg->setClipping3DView(_wxvtkclipping3Dview);
677 hDlg->setVolume(newvol);
678 hDlg->setVolumeMapper(volumeMapper);
681 // when the user had changed the transference Function
683 if(hDlg->ShowModal()== wxID_OK )
685 // -- vtkPiecewiseFunction --
686 tfun->RemoveAllPoints();
690 int nTFPoints=hDlg->getSizeTransferenceFunction();
694 hDlg->getTransferenceFunctionPoint(i,xi,yi);
695 tfun->AddPoint( xi , yi/100.0 );
697 itf->push_back(yi/100.0);
700 // -- vtkColorTransferFunction --
701 ctfun->RemoveAllPoints ();
708 int nCTFpoints=hDlg->getSizeBarColor();
712 hDlg->getDataBarColorPoint(i,xi,r,g,b);
713 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
714 rctf->push_back(r/255.0);
715 gctf->push_back(g/255.0);
716 bctf->push_back(b/255.0);
717 greyctf->push_back(xi);
720 //---------------------------------
721 // Refreshing and sending the event
722 //---------------------------------
723 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
724 _wxvtkclipping3Dview->Refresh();
725 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
727 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
728 #if wxMAJOR_VERSION <= 2
729 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
731 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
737 volumeMapper->Update();
741 if(hDlg->getRefreshed())
744 //--Transference Function----
745 tfun->RemoveAllPoints();
750 double grey1=(*gtf)[i];
751 double in2=(*itf)[i];
752 tfun->AddPoint( grey1 , in2 );
755 // -- vtkColorTransferFunction --
756 ctfun->RemoveAllPoints ();
759 size=greyctf->size();
762 double grey2 = (*greyctf)[i];
763 double red = (*rctf)[i];
764 double green = (*gctf)[i];
765 double blue = (*bctf)[i];
766 ctfun->AddRGBPoint(grey2,red,green,blue);
769 //---------------------------------
770 // Refreshing and sending the event
771 //---------------------------------
772 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
773 _wxvtkclipping3Dview->Refresh();
774 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
775 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
776 #if wxMAJOR_VERSION <= 2
777 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
779 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
783 volumeMapper->Update();
794 //-------------------------------------------------------------------
795 void wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad(wxCommandEvent& event)
797 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
798 #if wxMAJOR_VERSION <= 2
799 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxOPEN);
800 if (dialog.ShowModal() == wxID_OK)
802 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( (char *)dialog.GetPath().c_str() );
803 _wxvtkclipping3Dview->Refresh();
804 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
805 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
808 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxFD_OPEN);
809 if (dialog.ShowModal() == wxID_OK)
811 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( dialog.GetPath().char_str() );
812 _wxvtkclipping3Dview->Refresh();
813 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
814 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);