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 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
352 //-------------------------------------------------------------------
353 void wxVtkClipping3DViewCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
355 _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked() );
356 _wxvtkclipping3Dview->Refresh();
358 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
359 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
361 //-------------------------------------------------------------------
362 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface(wxCommandEvent& event)
364 _wxvtkclipping3Dview->SetVisibleBoxSurface(event.IsChecked() );
365 _wxvtkclipping3Dview->Refresh();
367 //-------------------------------------------------------------------
368 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
370 printf("EED ERROR JPReyes wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume calling _wxvtkclipping3Dview->SetVisibleBoxVolume that not exists ...");
371 //EED01July2011 _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
372 //this->BoundingBoxChanged(event.IsChecked());
373 _wxvtkclipping3Dview->Refresh();
375 //-------------------------------------------------------------------
376 void wxVtkClipping3DViewCntrlPanel::OnColor(wxCommandEvent& event)
378 int idTissue=GetIdTissue();
381 // EED 17 Janvier 2007
382 wxColourDialog dlgColour(this);
383 // dlgColour.ShowModal();
384 if( dlgColour.ShowModal( ) == wxID_OK )
387 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
388 float r=dlgColour.GetColourData().GetColour().Red()/255;
389 float g=dlgColour.GetColourData().GetColour().Green()/255;
390 float b=dlgColour.GetColourData().GetColour().Blue()/255;
391 tmpActor->GetProperty()->SetColor( r , g , b );
392 _color->SetBackgroundColour(dlgColour.GetColourData().GetColour());
394 _wxvtkclipping3Dview->Refresh();
396 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
397 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
401 //-------------------------------------------------------------------
402 void wxVtkClipping3DViewCntrlPanel::OnVisibleSurface(wxCommandEvent& event)
404 int idTissue=GetIdTissue();
407 _wxvtkclipping3Dview->VisibleActor(idTissue, _visible->GetValue());
409 _wxvtkclipping3Dview->Refresh();
411 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
412 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
415 //-------------------------------------------------------------------
416 void wxVtkClipping3DViewCntrlPanel::OnOpacity(wxScrollEvent& event)
418 int idTissue=GetIdTissue();
422 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
423 float opacity=_opacity->GetValue();
424 tmpActor->GetProperty()->SetOpacity( opacity/100 );
426 _wxvtkclipping3Dview->Refresh();
428 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
429 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
433 //----------------------------------------------------------------------------
434 void wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin(wxScrollEvent& event)
436 int value = _isoValue->GetValue();
437 int delta= (int)pow( (double)4 ,(double) _isoValueSpin->GetValue() );
438 int min=value - delta/2;
439 int max=value + delta/2;
445 _isoValue->SetRange(min,max);
449 //------------------------------------------------------------------------
450 void wxVtkClipping3DViewCntrlPanel::OnIsoValue(wxScrollEvent& event)
454 int idTissue=GetIdTissue();
457 int isoValue=_isoValue->GetValue();
458 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->SetIsovalue(idTissue,isoValue);
460 // tmpStr.Printf("%d",isoValue);
462 _wxvtkclipping3Dview->Refresh();
464 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
465 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
469 //-------------------------------------------------------------------
470 void wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL(wxCommandEvent& event)
473 int idTissue=GetIdTissue();
480 wxString dirSTL = wxGetHomeDir( ) ;
481 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
483 if( dialog.ShowModal( ) == wxID_OK )
487 // ------------------------------------------------------------------------
488 // 1. GENERATE STL FILES
489 // ------------------------------------------------------------------------
490 // const char* fileprefix = "c:\\Creatis\\";
491 std::string prefix = (const char*) (dialog.GetPath().mb_str() );
492 std::string filename;
494 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
496 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
499 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
500 vtkClosePolyData *cpd = vtkClosePolyData::New();
503 //EED 2017-01-01 Migration VTK7
504 #if VTK_MAJOR_VERSION <= 5
505 filtro->SetInput( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
506 pdcf->SetInput( filtro->GetOutput() );
507 cpd->SetInput( pdcf->GetOutput() );
509 filtro->SetInputData( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
510 pdcf->SetInputData( filtro->GetOutput() );
511 cpd->SetInputData( pdcf->GetOutput() );
514 // 1.2 se escribe a disco el archivo stl de la superficie interna
516 vtkSTLWriter *writer = vtkSTLWriter::New();
518 //EED 2017-01-01 Migration VTK7
519 #if VTK_MAJOR_VERSION <= 5
520 writer->SetInput( cpd->GetOutput() );
522 writer->SetInputData( cpd->GetOutput() );
526 writer->SetFileName(filename.c_str());
527 writer->SetFileTypeToASCII();
539 //EED 30 Janvier 2007
540 //-------------------------------------------------------------------
541 void wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(wxCommandEvent& event)
543 wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
544 if (dialog.ShowModal() == wxID_OK)
546 std::string directory = (const char*) (dialog.GetDirectory().mb_str() );
547 std::string filename = (const char*) (dialog.GetFilename().mb_str() );
548 float rescalaSlope = 1;
549 float rescalaIntercept = 0;
550 vtkMPRBaseData *vtkmprbasedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData();
551 vtkImageData *vtkimagedata = vtkmprbasedata->GetImageData();
553 vtkimagedata->GetDimensions(dim);
561 //EED 10 oct 2007 MaracasVisu pour bbMaracasvisu
562 marRAW2Files marraw2;
563 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
567 //EED 22 Fevrier 2007
568 //-------------------------------------------------------------------
569 void wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
572 int /*i=0,*/ xi,yi,r,g,b; // JPRx
573 vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
574 vtkPiecewiseFunction* tfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
575 std::vector<double>* gtf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
576 std::vector<double>* itf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
577 std::vector<double>* greyctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
578 std::vector<double>* rctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
579 std::vector<double>* gctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
580 std::vector<double>* bctf = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
581 vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
583 //use for update in the refresh
585 vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
586 vtkVolume* newvol =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
591 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
592 if (dialog.ShowModal() == wxID_OK)
594 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
600 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
604 int tfSize=gtf->size();
608 hDlg->erasePointsTransferenceFunction();
613 hDlg->addPointToTransferenceFunction(g,in*100);
619 int ctfSize=rctf->size();
625 double gr=(*greyctf)[i];
629 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
633 //setting variables if the user wants to do refresh
636 //hDlg->setClipping3DView(_wxvtkclipping3Dview);
638 hDlg->setVolume(newvol);
639 hDlg->setVolumeMapper(volumeMapper);
642 // when the user had changed the transference Function
644 if(hDlg->ShowModal()== wxID_OK )
646 // -- vtkPiecewiseFunction --
647 tfun->RemoveAllPoints();
651 int nTFPoints=hDlg->getSizeTransferenceFunction();
655 hDlg->getTransferenceFunctionPoint(i,xi,yi);
656 tfun->AddPoint( xi , yi/100.0 );
658 itf->push_back(yi/100.0);
661 // -- vtkColorTransferFunction --
662 ctfun->RemoveAllPoints ();
669 int nCTFpoints=hDlg->getSizeBarColor();
673 hDlg->getDataBarColorPoint(i,xi,r,g,b);
674 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
675 rctf->push_back(r/255.0);
676 gctf->push_back(g/255.0);
677 bctf->push_back(b/255.0);
678 greyctf->push_back(xi);
681 //---------------------------------
682 // Refreshing and sending the event
683 //---------------------------------
684 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
685 _wxvtkclipping3Dview->Refresh();
686 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
687 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
690 volumeMapper->Update();
694 if(hDlg->getRefreshed())
697 //--Transference Function----
698 tfun->RemoveAllPoints();
703 double grey1=(*gtf)[i];
704 double in2=(*itf)[i];
705 tfun->AddPoint( grey1 , in2 );
708 // -- vtkColorTransferFunction --
709 ctfun->RemoveAllPoints ();
712 size=greyctf->size();
715 double grey2=(*greyctf)[i];
716 double red =(*rctf)[i];
717 double green =(*gctf)[i];
718 double blue = (*bctf)[i];
719 ctfun->AddRGBPoint(grey2,red,green,blue);
722 //---------------------------------
723 // Refreshing and sending the event
724 //---------------------------------
725 //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
726 _wxvtkclipping3Dview->Refresh();
727 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
728 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
731 volumeMapper->Update();
742 //-------------------------------------------------------------------
743 void wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad(wxCommandEvent& event)
745 wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxOPEN);
746 if (dialog.ShowModal() == wxID_OK)
748 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( (char *)dialog.GetPath().c_str() );
749 _wxvtkclipping3Dview->Refresh();
750 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121); // Refresh
751 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);