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 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: wxSegmentationFM3DWidget.cxx,v $
31 Date: $Date: 2012/11/15 14:15:18 $
32 Version: $Revision: 1.2 $
34 Copyright: (c) 2002, 2003
37 This software is distributed WITHOUT ANY WARRANTY; without even
38 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39 PURPOSE. See the above copyright notice for more information.
41 =========================================================================*/
46 #include <wx/splitter.h>
47 #include <wx/notebook.h>
48 #include <wx/colordlg.h>
50 #include "vtkMarchingCubes.h"
51 #include "vtkPolyDataMapper.h"
55 #include "wxSegmentationFM3DWidget.h"
58 //-------------------------------------------------------------------
59 //-------------------------------------------------------------------
60 //-------------------------------------------------------------------
62 BEGIN_EVENT_TABLE( wxSegmentationFM3DWidget, wxPanel )
63 EVT_MENU( 12121, wxSegmentationFM3DWidget::OnRefreshView )
64 // EVT_MENU( 12122, wxSegmentationFM3DWidget::OnDClickLeft )
68 wxSegmentationFM3DWidget::wxSegmentationFM3DWidget( wxWindow* parent,
69 marImageData *marimageData ,double voxelSize)
70 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
73 _voxelSize = voxelSize;
74 _marimageData = marimageData;
76 _wxvtk3Dbaseview_Clipping3D_C = NULL;
77 _wxvtkmpr3Dview_C = NULL;
78 _wxvtkclipping3Dview_C = NULL;
80 wxSplitterWindow* mainSplitter = new wxSplitterWindow(this,-1);
81 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( mainSplitter , -1);
84 _MPRWidget2 = new wxMPRWidget2(pnlSplitter,_marimageData,voxelSize);
85 wxPanel * contour3DView = Create3DViewContour( pnlSplitter , _MPRWidget2->GetVtkMPRBaseData());
86 this->GetSize(&ww,&hh);
88 pnlSplitter -> SplitVertically( _MPRWidget2, contour3DView , 600);
94 //PANEL DE OPERACIONES
95 //------------------------------------------------------------------
97 wxPanel* panelOperaciones = new wxPanel(mainSplitter, -1);
99 wxFlexGridSizer *fgs = new wxFlexGridSizer(2);
101 fgs->Add( new wxStaticText(panelOperaciones, -1, _T("Fast Marching Controls")));
102 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("")));
103 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("")));
104 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("")));
106 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("Alpha")));
107 slAlpha = new wxSlider(panelOperaciones, -1, 50, 1, 400, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
110 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("Beta")));
111 slBeta = new wxSlider(panelOperaciones, -1, 128, 0, 800, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
114 btnSegment = new wxButton(panelOperaciones, -1, _T("Segment"));
115 fgs->Add(btnSegment);
116 btnUndo = new wxButton(panelOperaciones, -1, _T("Undo"));
122 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("")));
123 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("")));
127 fgs->Add( new wxStaticText(panelOperaciones, -1, _T("Mesh Controls")));
128 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("")));
129 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("")));
130 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("")));
132 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("Opacity")));
133 slVolumeOpacity = new wxSlider(panelOperaciones, -1,50,1,100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
134 fgs->Add(slVolumeOpacity);
136 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("Sigma")));
137 slSigmaLevel = new wxSlider(panelOperaciones, -1,100,1,300, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
138 fgs->Add(slSigmaLevel);
140 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("Convergence")));
141 slLaplacianConvergence = new wxSlider(panelOperaciones, -1,3000,1,3000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
142 fgs->Add(slLaplacianConvergence);
144 fgs->Add(new wxStaticText(panelOperaciones, -1, _T("Iterations")));
145 slLaplacianIterations = new wxSlider(panelOperaciones, -1,100,1,2000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
146 fgs->Add(slLaplacianIterations);
148 panelOperaciones->SetSizer(fgs);
151 slSigmaLevel->Disable();
152 slVolumeOpacity->Disable();
153 slLaplacianConvergence->Disable();
154 slLaplacianIterations->Disable();
156 Connect(slAlpha->GetId(), wxEVT_SCROLL_THUMBRELEASE, (wxObjectEventFunction) &wxSegmentationFM3DWidget::OnChangeAlpha);
157 Connect(slBeta->GetId(), wxEVT_SCROLL_THUMBRELEASE, (wxObjectEventFunction) &wxSegmentationFM3DWidget::OnChangeBeta);
158 Connect(btnSegment->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) &wxSegmentationFM3DWidget::OnBtnSegment);
159 Connect(btnUndo->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) &wxSegmentationFM3DWidget::OnBtnUndo);
160 Connect(slVolumeOpacity->GetId(), wxEVT_SCROLL_THUMBRELEASE, (wxObjectEventFunction) &wxSegmentationFM3DWidget::OnChangeOpacity);
161 Connect(slSigmaLevel->GetId(), wxEVT_SCROLL_THUMBRELEASE, (wxObjectEventFunction) &wxSegmentationFM3DWidget::OnChangeSigmaLevel);
162 Connect(slLaplacianConvergence->GetId(),wxEVT_SCROLL_THUMBRELEASE, (wxObjectEventFunction) &wxSegmentationFM3DWidget::OnChangeLaplacianConvergence);
163 Connect(slLaplacianIterations->GetId(), wxEVT_SCROLL_THUMBRELEASE, (wxObjectEventFunction) &wxSegmentationFM3DWidget::OnChangeLaplacianIteration);
164 //-------------------------------------------------------------------
166 mainSplitter->SplitVertically(pnlSplitter, panelOperaciones, 600);
168 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
169 sizer->Add(mainSplitter,1, wxGROW,0);
170 pnlSplitter -> SetMinimumPaneSize( 50 );
171 this -> SetSizer(sizer);
175 //------------------------------------------------------------------
179 convergenceValue = 1;
180 iterationsValue = 100;
181 filtroSegmentacion = new itkFM3D();
182 //------------------------------------------------------------------
186 //------------------------------------------------------------------
187 f_gauss = vtkImageGaussianSmooth::New();
188 f_laplace = vtkSmoothPolyDataFilter::New();
189 f_cubes = vtkMarchingCubes::New();
190 f_mapper = vtkPolyDataMapper::New();
191 f_cubes->SetInput(f_gauss->GetOutput());
192 f_cubes->SetValue(0,128);
193 f_laplace->SetInput(f_cubes->GetOutput());
194 f_mapper->SetInput(f_laplace->GetOutput());
195 f_mapper->ScalarVisibilityOff();
196 f_actor = vtkActor::New();
197 f_actor->SetMapper(f_mapper);
198 f_actor->GetProperty()->SetColor(0.9,0.5,0.5);
199 //------------------------------------------------------------------
204 //----------------------------------------------------------------------------
206 wxSegmentationFM3DWidget::~wxSegmentationFM3DWidget( )
208 if (_wxvtk3Dbaseview_Clipping3D_C != NULL) { delete _wxvtk3Dbaseview_Clipping3D_C; }
209 if (_wxvtkmpr3Dview_C != NULL) { delete _wxvtkmpr3Dview_C; }
210 if (_wxvtkclipping3Dview_C != NULL) { delete _wxvtkclipping3Dview_C; }
214 //----------------------------------------------------------------------------
215 wxPanel* wxSegmentationFM3DWidget::Create3DViewContour( wxWindow *parent, vtkMPRBaseData *vtkmprbasedata)
218 wxPanel *panel=new wxPanel(parent,-1);
220 wxSplitterWindow *panelClipping3D = new wxSplitterWindow( panel , -1);
221 _wxvtk3Dbaseview_Clipping3D_C = new wxVtk3DBaseView( panelClipping3D );
223 _wxvtkclipping3Dview_C = new wxVtkClipping3DView(_wxvtk3Dbaseview_Clipping3D_C);
224 vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer();
225 vtkclipping3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
226 vtkclipping3Ddataviewer->Configure();
227 _wxvtkclipping3Dview_C->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
229 _wxvtkmpr3Dview_C = new wxVtkMPR3DView( _wxvtk3Dbaseview_Clipping3D_C );
230 vtkMPR3DDataViewer *vtkmpr3Ddataviewer = new vtkMPR3DDataViewer();
231 vtkmpr3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
232 vtkmpr3Ddataviewer->Configure();
233 _wxvtkmpr3Dview_C->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
235 wxWindow *window3D = _wxvtk3Dbaseview_Clipping3D_C->GetWxVTKRenderWindowInteractor();
237 wxPanel *panelControl = new wxPanel(panelClipping3D,-1);
238 wxPanel *controlPanelMPR3D = _wxvtkmpr3Dview_C->CreateControlPanel(panelControl);
239 wxPanel *controlPanelClipping3D = _wxvtkclipping3Dview_C->CreateControlPanel(panelControl);
241 // wxBoxSizer *sizerCtrol = new wxBoxSizer(wxVERTICAL);
242 wxFlexGridSizer *sizerCtrol = new wxFlexGridSizer(1);
244 sizerCtrol->Add(controlPanelMPR3D , 1, wxALL|wxEXPAND, 2);
245 sizerCtrol->Add(controlPanelClipping3D , 1, wxALL|wxEXPAND, 2);
246 panelControl->SetAutoLayout(true);
247 panelControl->SetSizer(sizerCtrol);
248 panelControl->SetSize(400,350);
249 panelControl->Layout();
253 while (pp->GetParent()!=NULL) pp=pp->GetParent();
254 pp->GetSize(&ww,&hh);
257 // panelClipping3D -> SetMinimumPaneSize( -50 );
258 panelClipping3D -> SplitHorizontally( panelControl,window3D, (int)(hh*0.20) );
259 wxwindow=panelClipping3D;
261 wxBoxSizer *sizerH1 = new wxBoxSizer(wxHORIZONTAL);
262 sizerH1->Add(wxwindow , 1, wxALL|wxEXPAND, 0);
263 panel->SetAutoLayout(true);
264 panel->SetSizer(sizerH1);
265 panel->SetSize(400,400);
269 // panel->FitInside();
276 //----------------------------------------------------------------------------
277 void wxSegmentationFM3DWidget::ConfigureVTK(){
278 _MPRWidget2->ConfigureVTK();
279 _wxvtk3Dbaseview_Clipping3D_C -> Configure();
280 _wxvtkmpr3Dview_C -> Configure();
281 _wxvtkclipping3Dview_C -> Configure();
283 vtkInteractorStyle3DView *vtkinteractorstyle3Dview = new vtkInteractorStyle3DView();
284 vtkinteractorstyle3Dview->SetWxVtkMPR3DView(_wxvtkmpr3Dview_C);
285 vtkinteractorstyle3Dview->SetWxVtkClipping3DView(_wxvtkclipping3Dview_C);
286 _wxvtk3Dbaseview_Clipping3D_C->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( vtkinteractorstyle3Dview );
290 //----------------------------------------------------------------------------
291 vtkMPRBaseData *wxSegmentationFM3DWidget::GetVtkMPRBaseData(){
292 return _MPRWidget2->GetVtkMPRBaseData();
294 //----------------------------------------------------------------------------
295 vtkPlane2DView *wxSegmentationFM3DWidget::GetVtkPlane2DView()
297 return _MPRWidget2->GetVtkPlane2DView();
299 //----------------------------------------------------------------------------
300 void wxSegmentationFM3DWidget::OnRefreshView(wxCommandEvent & event)
304 //----------------------------------------------------------------------------
305 void wxSegmentationFM3DWidget::RefreshView()
307 this->_MPRWidget2->RefreshView();
308 _wxvtkmpr3Dview_C -> RefreshView();
309 _wxvtkclipping3Dview_C -> Refresh();
310 _wxvtk3Dbaseview_Clipping3D_C -> Refresh();
318 * This method is invoked when the segmentation button is pressed
321 void wxSegmentationFM3DWidget::OnBtnSegment(wxCommandEvent& event){
326 double x =_MPRWidget2->GetVtkMPRBaseData()->GetX();
327 double y =_MPRWidget2->GetVtkMPRBaseData()->GetY();
328 double z = _MPRWidget2->GetVtkMPRBaseData()->GetZ();
330 filtroSegmentacion->AddSeed(x,y,z);
331 filtroSegmentacion->SetAlpha(this->alphaValue);
332 filtroSegmentacion->SetBeta(this->betaValue);
334 vtkImageData* resultado = filtroSegmentacion->segment(_MPRWidget2->GetVtkMPRBaseData()->GetImageData() );
337 f_gauss->SetInput(resultado);
338 f_gauss->SetStandardDeviation(this->sigmaValue);
340 f_laplace->SetNumberOfIterations(this->iterationsValue);
341 f_laplace->SetConvergence(this->convergenceValue);
344 f_actor->GetProperty()->SetOpacity(this->opacityValue);
346 vtkRenderer *ren = _wxvtkmpr3Dview_C->GetWxvtk3Dbaseview()->GetRenderer();
348 ren->AddActor(f_actor);
352 slVolumeOpacity->Enable();
353 slSigmaLevel->Enable();
354 slLaplacianConvergence->Enable();
355 slLaplacianIterations->Enable();
360 * This method is invoked when the slAlpha scroll change its value
363 void wxSegmentationFM3DWidget::OnChangeAlpha(wxScrollEvent& event){
364 alphaValue = ((double)slAlpha->GetValue());
365 alphaValue = alphaValue / 100;
369 * This method is invoked when the slBeta scroll change its value
372 void wxSegmentationFM3DWidget::OnChangeBeta(wxScrollEvent& event){
373 betaValue = ((double)slBeta->GetValue());
377 * Carga la imagen resultado de la segmentacion FM ITK
380 void wxSegmentationFM3DWidget::OnBtnUndo(wxCommandEvent& event){
382 if (f_actor != NULL){
383 vtkRenderer *ren = _wxvtkmpr3Dview_C->GetWxvtk3Dbaseview()->GetRenderer();
384 ren->RemoveActor(f_actor);
387 slSigmaLevel->Disable();
388 slVolumeOpacity->Disable();
389 slLaplacianConvergence->Disable();
390 slLaplacianIterations->Disable();
397 * Este metodo cambia la opacidad del actor que representa la segmentacion realizada
400 void wxSegmentationFM3DWidget::OnChangeOpacity(wxScrollEvent& event){
401 if (f_actor != NULL){
402 opacityValue = ((double)slVolumeOpacity->GetValue())/100.0;
403 f_actor->GetProperty()->SetOpacity(opacityValue);
409 * Cambia el valor de la desviacion estandar del filtro gaussiano aplicado al
410 * volumen resultado de la segmentacion
412 void wxSegmentationFM3DWidget::OnChangeSigmaLevel(wxScrollEvent& event){
414 this->sigmaValue = ((double)slSigmaLevel->GetValue())/300.0;
415 f_gauss->SetStandardDeviation(this->sigmaValue);
422 * Cambia el valor de la convergencia del filtro de suavizado laplaciano aplicado
423 * a la superficie que representa el volumen resultado de la segmentacion
425 void wxSegmentationFM3DWidget::OnChangeLaplacianConvergence(wxScrollEvent& event){
427 this->convergenceValue = ((double)slLaplacianConvergence->GetValue())/3000.0;
428 f_laplace->SetConvergence(this->convergenceValue);
435 * Cambia el numero de iteraciones del filtro de suavizado laplaciano aplicado a la superficie
436 * que representa el volumen resultado de la segmentacion
438 void wxSegmentationFM3DWidget::OnChangeLaplacianIteration(wxScrollEvent& event){
440 this->iterationsValue = slLaplacianIterations->GetValue();
441 f_laplace->SetNumberOfIterations(this->iterationsValue);
447 // EOF - wxSegmentationFM3DWidget.cxx