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 # ------------------------------------------------------------------------ */
28 #include <wx/tooltip.h>
29 #include <wx/config.h>
31 #include <iostream> // for std::cout
34 #include "wxVtkClipping3DViewCntrlPanel.h"
35 #include "wx/colordlg.h"
36 #include "vtkTriangleFilter.h"
37 #include "vtkPolyDataConnectivityFilter.h"
38 #include "vtkClosePolyData.h"
39 #include "vtkSTLWriter.h"
40 #include "HistogramDialog.h"
41 #include "marDicomBase.h"
43 wxVtkClipping3DViewCntrlPanel::wxVtkClipping3DViewCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
46 wxPanel *panel = this;
47 _wxvtkclipping3Dview = wxvtkclipping3Dview;
50 // wxStaticText *text1 = new wxStaticText(panel, -1,_T(" "));
51 // wxStaticText *text2 = new wxStaticText(panel, -1,_T(" "));
53 _surfA = new wxRadioButton(panel,-1,_T("A"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
54 _surfB = new wxRadioButton(panel,-1,_T("B"));
55 _surfC = new wxRadioButton(panel,-1,_T("C"));
56 _surfD = new wxRadioButton(panel,-1,_T("D"));
58 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
59 //wxCheckBox *ckVolum = new wxCheckBox(panel,-1,_T("Vol"));
60 wxCheckBox *ckBoxSurface = new wxCheckBox(panel,-1,_T("Surface Box"));
62 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
63 //wxCheckBox *ckBoxVolume = new wxCheckBox(panel,-1,_T("Volume Box"));
65 _color = new wxButton(panel,-1,_T(""));
66 _visible = new wxCheckBox(panel,-1,_T("Vis"));
67 //EED _opacity = new wxSlider(panel,-1,50,0,100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
68 _opacity = new wxSlider(panel,-1,50,0,100, wxDefaultPosition, wxSize(300,110), wxSL_HORIZONTAL | wxSL_LABELS);
70 wxStaticText *isoValueTitle = new wxStaticText(panel,-1,_T("isoValue"));
71 //EED _isoValue = new wxSlider(panel,-1,2000,110,2000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS);
72 _isoValue = new wxSlider(panel,-1,2000,110,2000, wxDefaultPosition, wxSize(300,110), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS);
74 _wireFrameRep = new wxRadioButton(panel,-1,_T("WireFrame"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
75 _surfaceRep = new wxRadioButton(panel,-1,_T("Surface"));
78 vtkImageData *vtkimagedata = wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
79 vtkimagedata->GetScalarRange( range );
80 //EED 2020-11-25 _isoValue->SetRange( (int)(range[1]*0.1) , (int)(range[1]) );
81 _isoValue->SetRange( (int)(range[0]) , (int)(range[1]) );
82 _isoValue->SetValue( (int)(wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(0)) );
84 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
85 #if wxMAJOR_VERSION <= 2
86 _isoValue->SetTickFreq(25,0);
91 _isoValueSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxDefaultSize, wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
92 _isoValueSpin->SetRange(1,8);
93 _isoValueSpin->SetValue(5);
94 Connect(_isoValueSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin );
96 wxButton *btnSTL = new wxButton(panel,-1,_T("Create STL File"));
97 wxButton *btnSaveRaw = new wxButton(panel,-1,_T("Save Raw Volume"));
99 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
100 //wxButton *btnVolumeFunctions = new wxButton(panel,-1,_T("Read Volume Functions"));
103 Connect(btnSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL );
104 Connect(btnSaveRaw->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume );
106 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
107 //Connect(btnVolumeFunctions->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions );
110 wxButton *btnMeshVTKLoad = new wxButton(panel,-1,_T("Load Mesh"));
111 Connect(btnMeshVTKLoad->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad );
115 int maxX = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
116 int maxY = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
117 int maxZ = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();
118 wxCheckBox *ckBoxX = new wxCheckBox(panel,-1,"X");
119 _positionX = new wxSlider(panel,-1,maxX/2,0,maxX, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
120 wxCheckBox *ckBoxY = new wxCheckBox(panel,-1,"Y");
121 _positionY = new wxSlider(panel,-1,maxY/2,0,maxY, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
122 wxCheckBox *ckBoxZ = new wxCheckBox(panel,-1,"Z");
123 _positionZ = new wxSlider(panel,-1,maxZ/2,0,maxZ, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
126 // ckVolum->Enable(false);
127 ckBoxSurface->SetValue(false);
130 //ckBoxVolume->SetValue(false);
133 _color->SetSize(40,20);
134 _opacity->SetSize(370,20);
135 // ckBoxX->SetValue(true);
136 // ckBoxY->SetValue(true);
137 // ckBoxZ->SetValue(true);
138 _surfA->SetValue(true);
139 _wireFrameRep->SetValue(false);
140 _surfaceRep->SetValue(true);
141 _visible->SetValue(false);
142 // _positionX->SetSize(400,20);
143 // _positionY->SetSize(400,20);
144 // _positionZ->SetSize(400,20);
146 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
147 //Connect(ckVolum->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleVolume );
148 //Connect(ckBoxVolume->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume );
150 Connect(_surfA->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface );
151 Connect(_surfB->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface );
152 Connect(_surfC->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface );
153 Connect(_surfD->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface );
154 Connect(ckBoxSurface->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface );
156 Connect(_wireFrameRep->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame );
157 Connect(_surfaceRep->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame );
159 Connect(_color->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnColor );
160 Connect(_visible->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleSurface );
161 Connect(_opacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnOpacity );
164 // Connect(_isoValue->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue );
165 Connect(_isoValue->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue );
168 Connect(ckBoxX->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX );
169 Connect(_positionX->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionX );
170 Connect(ckBoxY->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY );
171 Connect(_positionY->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionY );
172 Connect(ckBoxZ->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ );
173 Connect(_positionZ->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionZ );
176 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
177 wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
178 wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
179 wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(10);
180 wxFlexGridSizer *sizerH3 = new wxFlexGridSizer(10);
181 //wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10); // JPRx
182 //wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10); // JPRx
183 //wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10); // JPRx
185 //RaC 03-2010 Divides in two panels thje last tab Surface/Volume
186 //sizerH0->Add( ckVolum , 1, wxALL|wxEXPAND, 0);
187 //sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
188 //sizerH0->Add( ckBoxVolume , 1, wxALL|wxEXPAND, 0);
189 //sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
190 //sizerH0->Add( btnVolumeFunctions , 1, wxALL|wxEXPAND, 0);
191 //sizerH0->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
192 sizerH0->Add( btnMeshVTKLoad , 1, wxALL|wxEXPAND, 0);
195 sizerH1->Add( _surfA , 1, wxALL|wxEXPAND, 0);
196 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
197 sizerH1->Add( _surfB , 1, wxALL|wxEXPAND, 0);
198 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
199 sizerH1->Add( _surfC , 1, wxALL|wxEXPAND, 0);
200 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
201 sizerH1->Add( _surfD , 1, wxALL|wxEXPAND, 0);
202 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
203 sizerH1->Add( ckBoxSurface , 1, wxALL|wxEXPAND, 0);
204 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
205 sizerH1->Add( btnSTL , 1, wxALL|wxEXPAND, 0);
206 sizerH1->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
207 sizerH1->Add( btnSaveRaw , 1, wxALL|wxEXPAND, 0);
210 // sizerH2->Add( new wxStaticText(panel, -1,_T(" ") , 1, wxALL|wxEXPAND, 0);
211 sizerH2->Add( _color , 1, wxALL|wxEXPAND, 0);
212 sizerH2->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
213 sizerH2->Add( _visible , 1, wxALL|wxEXPAND, 0);
214 sizerH2->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
217 sizerH2->Add( _wireFrameRep , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
218 sizerH2->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
219 sizerH2->Add( _surfaceRep , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
220 sizerH2->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
224 sizerH3->Add( isoValueTitle , 1, wxALL|wxEXPAND, 0);
225 sizerH3->Add( _isoValueSpin , 1, wxALL|wxEXPAND, 0);
226 sizerH3->Add( _isoValue , 1, wxALL|wxEXPAND, 0);
228 sizerH3->Add( new wxStaticText(panel, -1,_T(" ")) , 1, wxALL|wxEXPAND, 0);
229 sizerH3->Add( new wxStaticText(panel, -1,_T("Opacity:")) , 1, wxALL|wxEXPAND, 0);
230 sizerH3->Add( _opacity , 1, wxALL|wxEXPAND, 0);
234 sizerH4->Add( ckBoxX , 1, wxALL|wxEXPAND, 0);
235 sizerH4->Add( text2 , 1, wxALL|wxEXPAND, 0);
236 sizerH4->Add( _positionX , 1, wxALL|wxEXPAND, 0);
238 sizerH5->Add( ckBoxY , 1, wxALL|wxEXPAND, 0);
239 sizerH5->Add( text2 , 1, wxALL|wxEXPAND, 0);
240 sizerH5->Add( _positionY , 1, wxALL|wxEXPAND, 0);
242 sizerH6->Add( ckBoxZ , 1, wxALL|wxEXPAND, 0);
243 sizerH6->Add( text2 , 1, wxALL|wxEXPAND, 0);
244 sizerH6->Add( _positionZ , 1, wxALL|wxEXPAND, 0);
246 sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
247 sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
248 sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
249 sizer->Add( sizerH3 , 1, wxALL|wxEXPAND, 2);
250 // sizer->Add( sizerH4 , 1, wxALL|wxEXPAND, 2);
251 // sizer->Add( sizerH5 , 1, wxALL|wxEXPAND, 2);
252 // sizer->Add( sizerH6 , 1, wxALL|wxEXPAND, 2);
254 panel->SetSize(300,60);
255 panel->SetAutoLayout(true);
256 panel->SetSizer(sizer);
259 panel->SetEventHandler((wxEvtHandler*)this);
262 //-------------------------------------------------------------------
263 wxVtkClipping3DViewCntrlPanel::~wxVtkClipping3DViewCntrlPanel()
266 //-------------------------------------------------------------------
267 void wxVtkClipping3DViewCntrlPanel::Refresh()
269 // wxPanel::Refresh();
271 _positionX->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetX( ) );
272 _positionY->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetY( ) );
273 _positionZ->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetZ( ) );
276 //-------------------------------------------------------------------
277 int wxVtkClipping3DViewCntrlPanel::GetIdTissue()
280 if (_surfA->GetValue()==true)
284 if (_surfB->GetValue()==true)
288 if (_surfC->GetValue()==true)
292 if (_surfD->GetValue()==true)
300 //-------------------------------------------------------------------
301 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
303 _wxvtkclipping3Dview->VisibleImageActor(0, event.IsChecked() );
304 _wxvtkclipping3Dview->Refresh();
306 //-------------------------------------------------------------------
307 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
309 _wxvtkclipping3Dview->VisibleImageActor(1, event.IsChecked() );
310 _wxvtkclipping3Dview->Refresh();
312 //-------------------------------------------------------------------
313 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
315 _wxvtkclipping3Dview->VisibleImageActor(2, event.IsChecked() );
316 _wxvtkclipping3Dview->Refresh();
320 //-------------------------------------------------------------------
321 void wxVtkClipping3DViewCntrlPanel::OnSurface(wxCommandEvent& event)
323 int idTissue=GetIdTissue();
328 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
330 tmpActor->GetProperty()->GetColor( rgb );
331 wxColour colour( (int)(rgb[0]*255) , (int)(rgb[1]*255) , (int)(rgb[2]*255) );
332 _color->SetBackgroundColour(colour);
335 _visible->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVisibleTissue(idTissue));
338 _opacity->SetValue( (int)(tmpActor->GetProperty()->GetOpacity()*100) );
340 // Representation Type WireFrame / Surface
341 _surfaceRep->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue));
342 _wireFrameRep->SetValue(!_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue));
345 int isoValue= (int)(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(idTissue));
346 _isoValue->SetValue(isoValue);
351 //-------------------------------------------------------------------
352 void wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame(wxCommandEvent& event)
354 int idTissue=GetIdTissue();
357 _wxvtkclipping3Dview->SetRepSurfaceWireFrame(idTissue , _surfaceRep->GetValue() );
359 _wxvtkclipping3Dview->Refresh();
361 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
362 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
363 #if wxMAJOR_VERSION <= 2
364 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
366 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
372 //-------------------------------------------------------------------
373 void wxVtkClipping3DViewCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
375 _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked() );
376 _wxvtkclipping3Dview->Refresh();
378 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
380 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
381 #if wxMAJOR_VERSION <= 2
382 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
384 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
388 //-------------------------------------------------------------------
389 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface(wxCommandEvent& event)
391 _wxvtkclipping3Dview->SetVisibleBoxSurface(event.IsChecked() );
392 _wxvtkclipping3Dview->Refresh();
394 //-------------------------------------------------------------------
395 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
397 printf("EED ERROR JPReyes wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume calling _wxvtkclipping3Dview->SetVisibleBoxVolume that not exists ...");
398 //EED01July2011 _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
399 //this->BoundingBoxChanged(event.IsChecked());
400 _wxvtkclipping3Dview->Refresh();
402 //-------------------------------------------------------------------
403 void wxVtkClipping3DViewCntrlPanel::OnColor(wxCommandEvent& event)
405 int idTissue=GetIdTissue();
408 // EED 17 Janvier 2007
409 wxColourDialog dlgColour(this);
410 // dlgColour.ShowModal();
411 if( dlgColour.ShowModal( ) == wxID_OK )
414 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
415 float r=dlgColour.GetColourData().GetColour().Red()/255;
416 float g=dlgColour.GetColourData().GetColour().Green()/255;
417 float b=dlgColour.GetColourData().GetColour().Blue()/255;
418 tmpActor->GetProperty()->SetColor( r , g , b );
419 _color->SetBackgroundColour(dlgColour.GetColourData().GetColour());
420 _wxvtkclipping3Dview->Refresh();
421 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
422 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
423 #if wxMAJOR_VERSION <= 2
424 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
426 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
432 //-------------------------------------------------------------------
433 void wxVtkClipping3DViewCntrlPanel::OnVisibleSurface(wxCommandEvent& event)
435 int idTissue=GetIdTissue();
438 _wxvtkclipping3Dview->VisibleActor(idTissue, _visible->GetValue());
439 _wxvtkclipping3Dview->Refresh();
440 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
441 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
442 #if wxMAJOR_VERSION <= 2
443 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
445 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
449 //-------------------------------------------------------------------
450 void wxVtkClipping3DViewCntrlPanel::OnOpacity(wxScrollEvent& event)
452 int idTissue=GetIdTissue();
456 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
457 float opacity=_opacity->GetValue();
458 tmpActor->GetProperty()->SetOpacity( opacity/100 );
459 _wxvtkclipping3Dview->Refresh();
460 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
461 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
462 #if wxMAJOR_VERSION <= 2
463 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
465 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
470 //----------------------------------------------------------------------------
471 void wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin(wxScrollEvent& event)
473 int value = _isoValue->GetValue();
474 int delta= (int)pow( (double)4 ,(double) _isoValueSpin->GetValue() );
475 int min=value - delta/2;
476 int max=value + delta/2;
482 _isoValue->SetRange(min,max);
486 //------------------------------------------------------------------------
487 void wxVtkClipping3DViewCntrlPanel::OnIsoValue(wxScrollEvent& event)
491 int idTissue=GetIdTissue();
494 int isoValue=_isoValue->GetValue();
495 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->SetIsovalue(idTissue,isoValue);
497 // tmpStr.Printf("%d",isoValue);
499 _wxvtkclipping3Dview->Refresh();
501 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
503 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
504 #if wxMAJOR_VERSION <= 2
505 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
507 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
513 //-------------------------------------------------------------------
514 void wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL(wxCommandEvent& event)
517 int idTissue=GetIdTissue();
524 wxString dirSTL = wxGetHomeDir( ) ;
525 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
526 #if wxMAJOR_VERSION <= 2
527 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
529 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxFD_SAVE );
532 if( dialog.ShowModal( ) == wxID_OK )
536 // ------------------------------------------------------------------------
537 // 1. GENERATE STL FILES
538 // ------------------------------------------------------------------------
539 // const char* fileprefix = "c:\\Creatis\\";
540 std::string prefix = (const char*) (dialog.GetPath().mb_str() );
541 std::string filename;
543 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
545 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
548 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
549 vtkClosePolyData *cpd = vtkClosePolyData::New();
552 //EED 2017-01-01 Migration VTK7
553 #if VTK_MAJOR_VERSION <= 5
554 filtro->SetInput( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
555 pdcf->SetInput( filtro->GetOutput() );
556 cpd->SetInput( pdcf->GetOutput() );
558 filtro->SetInputConnection( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutputPort() );
559 pdcf->SetInputConnection( filtro->GetOutputPort() );
560 cpd->SetInputConnection( pdcf->GetOutputPort() );
563 // 1.2 Write the stl file
565 vtkSTLWriter *writer = vtkSTLWriter::New();
567 //EED 2017-01-01 Migration VTK7
568 #if VTK_MAJOR_VERSION <= 5
569 writer->SetInput( cpd->GetOutput() );
571 writer->SetInputConnection( cpd->GetOutputPort() );
574 writer->SetFileName(filename.c_str());
575 writer->SetFileTypeToASCII();
586 //EED 30 Janvier 2007
587 //-------------------------------------------------------------------
588 void wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(wxCommandEvent& event)
590 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
591 #if wxMAJOR_VERSION <= 2
592 wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
594 wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxFD_SAVE );
596 if (dialog.ShowModal() == wxID_OK)
598 std::string directory = (const char*) (dialog.GetDirectory().mb_str() );
599 std::string filename = (const char*) (dialog.GetFilename().mb_str() );
600 float rescalaSlope = 1;
601 float rescalaIntercept = 0;
602 vtkMPRBaseData *vtkmprbasedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData();
603 vtkImageData *vtkimagedata = vtkmprbasedata->GetImageData();
605 vtkimagedata->GetDimensions(dim);
613 //EED 10 oct 2007 MaracasVisu pour bbMaracasvisu
614 marRAW2Files marraw2;
615 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
619 //EED 22 Fevrier 2007
620 //-------------------------------------------------------------------
621 void wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
624 int /*i=0,*/ xi,yi,r,g,b; // JPRx
625 vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
626 vtkPiecewiseFunction* tfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
627 std::vector<double>* gtf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
628 std::vector<double>* itf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
629 std::vector<double>* greyctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
630 std::vector<double>* rctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
631 std::vector<double>* gctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
632 std::vector<double>* bctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
633 vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
635 //use for update in the refresh
637 vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
638 vtkVolume* newvol =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
643 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
644 if (dialog.ShowModal() == wxID_OK)
646 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
652 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
656 int tfSize=gtf->size();
660 hDlg->erasePointsTransferenceFunction();
665 hDlg->addPointToTransferenceFunction(g,in*100);
671 int ctfSize=rctf->size();
677 double gr=(*greyctf)[i];
681 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
685 //setting variables if the user wants to do refresh
688 //hDlg->setClipping3DView(_wxvtkclipping3Dview);
690 hDlg->setVolume(newvol);
691 hDlg->setVolumeMapper(volumeMapper);
694 // when the user had changed the transference Function
696 if(hDlg->ShowModal()== wxID_OK )
698 // -- vtkPiecewiseFunction --
699 tfun->RemoveAllPoints();
703 int nTFPoints=hDlg->getSizeTransferenceFunction();
707 hDlg->getTransferenceFunctionPoint(i,xi,yi);
708 tfun->AddPoint( xi , yi/100.0 );
710 itf->push_back(yi/100.0);
713 // -- vtkColorTransferFunction --
714 ctfun->RemoveAllPoints ();
721 int nCTFpoints=hDlg->getSizeBarColor();
725 hDlg->getDataBarColorPoint(i,xi,r,g,b);
726 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
727 rctf->push_back(r/255.0);
728 gctf->push_back(g/255.0);
729 bctf->push_back(b/255.0);
730 greyctf->push_back(xi);
733 //---------------------------------
734 // Refreshing and sending the event
735 //---------------------------------
736 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
737 _wxvtkclipping3Dview->Refresh();
738 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
740 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
741 #if wxMAJOR_VERSION <= 2
742 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
744 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
750 volumeMapper->Update();
754 if(hDlg->getRefreshed())
757 //--Transference Function----
758 tfun->RemoveAllPoints();
763 double grey1=(*gtf)[i];
764 double in2=(*itf)[i];
765 tfun->AddPoint( grey1 , in2 );
768 // -- vtkColorTransferFunction --
769 ctfun->RemoveAllPoints ();
772 size=greyctf->size();
775 double grey2 = (*greyctf)[i];
776 double red = (*rctf)[i];
777 double green = (*gctf)[i];
778 double blue = (*bctf)[i];
779 ctfun->AddRGBPoint(grey2,red,green,blue);
782 //---------------------------------
783 // Refreshing and sending the event
784 //---------------------------------
785 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
786 _wxvtkclipping3Dview->Refresh();
787 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
788 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
789 #if wxMAJOR_VERSION <= 2
790 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
792 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
796 volumeMapper->Update();
807 //-------------------------------------------------------------------
808 void wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad(wxCommandEvent& event)
810 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
811 #if wxMAJOR_VERSION <= 2
812 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxOPEN);
813 if (dialog.ShowModal() == wxID_OK)
815 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( (char *)dialog.GetPath().c_str() );
816 _wxvtkclipping3Dview->Refresh();
817 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
818 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
821 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxFD_OPEN);
822 if (dialog.ShowModal() == wxID_OK)
824 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( dialog.GetPath().char_str() );
825 _wxvtkclipping3Dview->Refresh();
826 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
827 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);