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 "vtkCylinderSource.h"
28 #include "vtkPolyDataMapper.h"
29 #include "vtkRenderer.h"
30 #include "vtkRenderWindow.h"
31 #include "vtkRenderWindowInteractor.h"
32 #include "vtkProperty.h"
33 #include "vtkCamera.h"
34 #include "vtkPoints.h"
35 #include "vtkCellArray.h"
36 #include "vtkPolyData.h"
37 #include "vtkPolyDataMapper.h"
38 #include "vtkPolyDataWriter.h"
39 #include "vtkPolyDataReader.h"
40 #include "vtkImageReader.h"
41 #include "vtkImageViewer.h"
42 #include "vtkImageViewer2.h"
43 #include "vtkImageToStructuredPoints.h"
46 #include "vtkExtractVOI.h"
47 #include "vtkImageClip.h"
48 #include "vtkImageResample.h"
49 #include "vtkImageThreshold.h"
50 #include "vtkImageCast.h"
51 #include "vtkImageSeedConnectivity.h"
52 #include "vtkImageData.h"
53 #include "vtkMarchingCubes.h"
54 #include "vtkImageReslice.h"
55 #include "vtkTransform.h"
56 #include "vtkSphereSource.h"
57 #include "vtkDoubleArray.h"
58 #include "vtkPointData.h"
59 #include "vtkCommand.h"
60 #include "vtkCallbackCommand.h"
61 #include "vtkImageResample.h"
63 #include "vtkStripper.h"
66 #include "wxEmptyPanelWidget.h"
68 #include <wx/splitter.h>
70 //-------------------------------------------------------------------
71 //-------------------------------------------------------------------
72 //-------------------------------------------------------------------
73 wxEmptyPanelWidget::wxEmptyPanelWidget(wxWindow *parent)
74 : wxPanel( parent, -1)
76 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
77 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
78 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
79 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
81 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
82 pnlSplitter -> SetMinimumPaneSize( 150 );
83 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
84 this -> SetSizer(sizer);
91 // Result: Volume + Axis
99 //-------------------------------------------------------------------
100 wxEmptyPanelWidget::~wxEmptyPanelWidget(){
104 _surfMapper -> Delete();
105 _surfActor -> Delete();
107 // Result: Volume + Axis
109 _mapfinal -> Delete();
110 _stripfinal -> Delete();
111 _isoMapperMC6 -> Delete();
112 _isoActorMC6 -> Delete();
115 //-------------------------------------------------------------------
116 wxPanel* wxEmptyPanelWidget::CreateViewPanel(wxWindow *parent)
118 wxPanel *panel = new wxPanel(parent,-1);
119 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
121 _imageviewer3D = new wxVtk3DBaseView(panel);
122 wxVTKRenderWindowInteractor *iren = _imageviewer3D->GetWxVTKRenderWindowInteractor();
123 sizer->Add(iren , 1, wxEXPAND, 0);
125 panel->SetSizer(sizer);
126 panel->SetAutoLayout(true);
127 panel->SetSize(400,400);
131 //-------------------------------------------------------------------
132 wxPanel* wxEmptyPanelWidget::CreateControlPanel(wxWindow *parent)
134 wxPanel *panel = new wxPanel(parent,-1);
135 _opacity1 = new wxSlider( panel, -1, 50, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
136 _isoValue = new wxSlider( panel, -1, 0 , 0, 3000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
137 _opacity2 = new wxSlider( panel, -1, 50, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
138 _opacity1->SetSize(250,20); // Original Volume
139 _isoValue->SetSize(250,20);
140 _opacity2->SetSize(250,20); // Result Volume
141 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
142 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
143 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
144 sizer->Add(new wxStaticText(panel,-1,_T("Isovalue - Original Volume")));
145 sizer->Add(_isoValue);
146 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
147 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
148 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
149 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
150 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Original Volume")));
151 sizer->Add(_opacity1);
152 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
153 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
154 sizer->Add(_opacity2);
156 panel->SetSizer(sizer);
157 panel->SetAutoLayout(true);
158 panel->SetSize(400,400);
160 Connect(_opacity1->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget::OnOpacity1 );
161 Connect(_isoValue->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget::OnIsoValue );
162 Connect(_opacity2->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget::OnOpacity2 );
165 //------------------------------------------------------------------------
166 void wxEmptyPanelWidget::Refresh()
168 _imageviewer3D->Refresh();
170 //------------------------------------------------------------------------
172 void wxEmptyPanelWidget::ConfigureVTK(vtkImageData *imagedata, int x, int y, int z)
175 _imageviewer3D->Configure();
177 double puntoactualprov[3];
178 puntoactualprov[0]=x;
179 puntoactualprov[1]=y;
180 puntoactualprov[2]=z;
185 imagedata->GetSpacing(espprin);
186 imagedata->GetExtent(extprin);
188 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
189 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
190 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
193 // Juan Francisco Carrillo Filter
194 _prgov= axisExtractor::New();
195 _prgov->SetHumbral(0.45);
196 _prgov->SetInput(imagedata);
197 _prgov->SetPoint(puntoactualprov);
201 // Juan Francisco Carrillo Filter
202 _prgov= axisExtractor02::New();
204 _prgov->SetParam2(1);
205 _prgov->SetParam3(0.5);
206 _prgov->SetMaxant(20);
207 _prgov->SetMinant(5);
208 _prgov->SetInput(imagedata);
209 _prgov->SetPoint(puntoactualprov);
213 vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
214 writer->SetInput(_prgov->GetOutput());
215 writer->SetFileName("c:/temp/salida_JF.vtk");
216 writer->SetFileTypeToASCII();
220 // Visualisation - result vascular tree
221 _mapfinal = vtkPolyDataMapper::New();
222 _mapfinal->SetInput(_prgov->GetOutput());
224 _stripfinal = vtkActor::New();
225 _stripfinal->SetMapper(_mapfinal);
226 _stripfinal->GetProperty()->SetColor(1, 1, 1);
227 _stripfinal->GetProperty()->SetLineWidth(2);
229 _stripfinal->GetProperty()->BackfaceCullingOff();
231 // Visualisation - result volume
232 vtkImageData *imageOut = _prgov->GetVolumen();
235 _isoMC6 = vtkMarchingCubes::New();
236 _isoMC6->SetInput(imageOut);
237 _isoMC6->SetValue(0, 1);
240 _isoMapperMC6 = vtkPolyDataMapper::New();
241 _isoMapperMC6->SetInput(_isoMC6->GetOutput());
242 _isoMapperMC6->ScalarVisibilityOff();
243 _isoMapperMC6->ImmediateModeRenderingOn();
245 _isoActorMC6 = vtkActor::New();
246 _isoActorMC6->SetMapper(_isoMapperMC6);
247 _isoActorMC6->GetProperty()->SetColor( 0, 1, 0);
248 _isoActorMC6->GetProperty()->SetOpacity(0.25);
250 // Visualisation - original volume
252 imagedata->GetScalarRange( range );
254 _mCubes = vtkMarchingCubes::New( );
255 _mCubes->SetInput( imagedata );
256 _mCubes->SetValue( 0, range[1] / 4 );
258 vtkStripper *stripper = vtkStripper::New();
259 stripper->SetInput( _mCubes->GetOutput( ) );
261 _surfMapper = vtkPolyDataMapper::New( );
262 _surfMapper->SetInput( stripper->GetOutput() );
263 _surfMapper->ScalarVisibilityOff( );
266 _surfActor = vtkActor::New( );
267 _surfActor->SetMapper( _surfMapper );
268 _surfActor->PickableOff( );
269 _surfActor->GetProperty( )->SetColor( 0.9803, 0.9215, 0.8392 );
270 _surfActor->GetProperty( )->SetOpacity( 0.3 );
274 _isoValue->SetRange( (int)(range[0]), (int)(range[1]) );
275 _isoValue->SetValue( (int)(range[1]/4) );
276 _opacity1->SetValue( (int)(_surfActor->GetProperty( )->GetOpacity( )*100) );
277 _opacity2->SetValue( (int)(_isoActorMC6->GetProperty( )->GetOpacity( )*100));
280 vtkRenderer *ren = _imageviewer3D->GetRenderer();
281 ren->AddActor(_surfActor);
282 ren->AddActor(_isoActorMC6);
283 ren->AddActor(_stripfinal);
289 //------------------------------------------------------------------------
290 void wxEmptyPanelWidget::OnOpacity1(wxScrollEvent& event){
291 double value = ((double)_opacity1->GetValue())/100;
292 _surfActor->GetProperty( )->SetOpacity( value );
295 //------------------------------------------------------------------------
296 void wxEmptyPanelWidget::OnOpacity2(wxScrollEvent& event){
297 double value = ((double)_opacity2->GetValue())/100;
298 _isoActorMC6->GetProperty( )->SetOpacity( value );
301 //------------------------------------------------------------------------
302 void wxEmptyPanelWidget::OnIsoValue(wxScrollEvent& event){
304 _mCubes->SetValue(0, _isoValue->GetValue());