3 #include "vtkCylinderSource.h"
4 #include "vtkPolyDataMapper.h"
5 #include "vtkRenderer.h"
6 #include "vtkRenderWindow.h"
7 #include "vtkRenderWindowInteractor.h"
8 #include "vtkProperty.h"
10 #include "vtkPoints.h"
11 #include "vtkCellArray.h"
12 #include "vtkPolyData.h"
13 #include "vtkPolyDataMapper.h"
14 #include "vtkPolyDataWriter.h"
15 #include "vtkPolyDataReader.h"
16 #include "vtkImageReader.h"
17 #include "vtkImageViewer.h"
18 #include "vtkImageViewer2.h"
19 #include "vtkImageToStructuredPoints.h"
22 #include "vtkExtractVOI.h"
23 #include "vtkImageClip.h"
24 #include "vtkImageResample.h"
25 #include "vtkImageThreshold.h"
26 #include "vtkImageCast.h"
27 #include "vtkImageSeedConnectivity.h"
28 #include "vtkImageData.h"
29 #include "vtkMarchingCubes.h"
30 #include "vtkImageReslice.h"
31 #include "vtkTransform.h"
32 #include "vtkSphereSource.h"
33 #include "vtkDoubleArray.h"
34 #include "vtkPointData.h"
35 #include "vtkCommand.h"
36 #include "vtkCallbackCommand.h"
37 #include "vtkImageResample.h"
39 #include "vtkStripper.h"
42 #include "wxEmptyPanelWidget.h"
44 #include <wx/splitter.h>
46 //-------------------------------------------------------------------
47 //-------------------------------------------------------------------
48 //-------------------------------------------------------------------
49 wxEmptyPanelWidget::wxEmptyPanelWidget(wxWindow *parent)
50 : wxPanel( parent, -1)
52 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
53 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
54 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
55 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
57 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
58 pnlSplitter -> SetMinimumPaneSize( 150 );
59 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
60 this -> SetSizer(sizer);
67 // Result: Volume + Axis
75 //-------------------------------------------------------------------
76 wxEmptyPanelWidget::~wxEmptyPanelWidget(){
80 _surfMapper -> Delete();
81 _surfActor -> Delete();
83 // Result: Volume + Axis
85 _mapfinal -> Delete();
86 _stripfinal -> Delete();
87 _isoMapperMC6 -> Delete();
88 _isoActorMC6 -> Delete();
91 //-------------------------------------------------------------------
92 wxPanel* wxEmptyPanelWidget::CreateViewPanel(wxWindow *parent)
94 wxPanel *panel = new wxPanel(parent,-1);
95 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
97 _imageviewer3D = new wxVtk3DBaseView(panel);
98 wxVTKRenderWindowInteractor *iren = _imageviewer3D->GetWxVTKRenderWindowInteractor();
99 sizer->Add(iren , 1, wxEXPAND, 0);
101 panel->SetSizer(sizer);
102 panel->SetAutoLayout(true);
103 panel->SetSize(400,400);
107 //-------------------------------------------------------------------
108 wxPanel* wxEmptyPanelWidget::CreateControlPanel(wxWindow *parent)
110 wxPanel *panel = new wxPanel(parent,-1);
111 _opacity1 = new wxSlider( panel, -1, 50, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
112 _isoValue = new wxSlider( panel, -1, 0 , 0, 3000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
113 _opacity2 = new wxSlider( panel, -1, 50, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
114 _opacity1->SetSize(250,20); // Original Volume
115 _isoValue->SetSize(250,20);
116 _opacity2->SetSize(250,20); // Result Volume
117 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
118 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
119 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
120 sizer->Add(new wxStaticText(panel,-1,_T("Isovalue - Original Volume")));
121 sizer->Add(_isoValue);
122 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
123 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
124 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
125 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
126 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Original Volume")));
127 sizer->Add(_opacity1);
128 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
129 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
130 sizer->Add(_opacity2);
132 panel->SetSizer(sizer);
133 panel->SetAutoLayout(true);
134 panel->SetSize(400,400);
136 Connect(_opacity1->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget::OnOpacity1 );
137 Connect(_isoValue->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget::OnIsoValue );
138 Connect(_opacity2->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget::OnOpacity2 );
141 //------------------------------------------------------------------------
142 void wxEmptyPanelWidget::Refresh()
144 _imageviewer3D->Refresh();
146 //------------------------------------------------------------------------
148 void wxEmptyPanelWidget::ConfigureVTK(vtkImageData *imagedata, int x, int y, int z)
151 _imageviewer3D->Configure();
153 double puntoactualprov[3];
154 puntoactualprov[0]=x;
155 puntoactualprov[1]=y;
156 puntoactualprov[2]=z;
161 imagedata->GetSpacing(espprin);
162 imagedata->GetExtent(extprin);
164 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
165 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
166 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
169 // Juan Francisco Carrillo Filter
170 _prgov= axisExtractor::New();
171 _prgov->SetHumbral(0.45);
172 _prgov->SetInput(imagedata);
173 _prgov->SetPoint(puntoactualprov);
177 // Juan Francisco Carrillo Filter
178 _prgov= axisExtractor02::New();
180 _prgov->SetParam2(1);
181 _prgov->SetParam3(0.5);
182 _prgov->SetMaxant(20);
183 _prgov->SetMinant(5);
184 _prgov->SetInput(imagedata);
185 _prgov->SetPoint(puntoactualprov);
189 vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
190 writer->SetInput(_prgov->GetOutput());
191 writer->SetFileName("c:/temp/salida_JF.vtk");
192 writer->SetFileTypeToASCII();
196 // Visualisation - result vascular tree
197 _mapfinal = vtkPolyDataMapper::New();
198 _mapfinal->SetInput(_prgov->GetOutput());
200 _stripfinal = vtkActor::New();
201 _stripfinal->SetMapper(_mapfinal);
202 _stripfinal->GetProperty()->SetColor(1, 1, 1);
203 _stripfinal->GetProperty()->SetLineWidth(2);
205 _stripfinal->GetProperty()->BackfaceCullingOff();
207 // Visualisation - result volume
208 vtkImageData *imageOut = _prgov->GetVolumen();
211 _isoMC6 = vtkMarchingCubes::New();
212 _isoMC6->SetInput(imageOut);
213 _isoMC6->SetValue(0, 1);
216 _isoMapperMC6 = vtkPolyDataMapper::New();
217 _isoMapperMC6->SetInput(_isoMC6->GetOutput());
218 _isoMapperMC6->ScalarVisibilityOff();
219 _isoMapperMC6->ImmediateModeRenderingOn();
221 _isoActorMC6 = vtkActor::New();
222 _isoActorMC6->SetMapper(_isoMapperMC6);
223 _isoActorMC6->GetProperty()->SetColor( 0, 1, 0);
224 _isoActorMC6->GetProperty()->SetOpacity(0.25);
226 // Visualisation - original volume
228 imagedata->GetScalarRange( range );
230 _mCubes = vtkMarchingCubes::New( );
231 _mCubes->SetInput( imagedata );
232 _mCubes->SetValue( 0, range[1] / 4 );
234 vtkStripper *stripper = vtkStripper::New();
235 stripper->SetInput( _mCubes->GetOutput( ) );
237 _surfMapper = vtkPolyDataMapper::New( );
238 _surfMapper->SetInput( stripper->GetOutput() );
239 _surfMapper->ScalarVisibilityOff( );
242 _surfActor = vtkActor::New( );
243 _surfActor->SetMapper( _surfMapper );
244 _surfActor->PickableOff( );
245 _surfActor->GetProperty( )->SetColor( 0.9803, 0.9215, 0.8392 );
246 _surfActor->GetProperty( )->SetOpacity( 0.3 );
250 _isoValue->SetRange( (int)(range[0]), (int)(range[1]) );
251 _isoValue->SetValue( (int)(range[1]/4) );
252 _opacity1->SetValue( (int)(_surfActor->GetProperty( )->GetOpacity( )*100) );
253 _opacity2->SetValue( (int)(_isoActorMC6->GetProperty( )->GetOpacity( )*100));
256 vtkRenderer *ren = _imageviewer3D->GetRenderer();
257 ren->AddActor(_surfActor);
258 ren->AddActor(_isoActorMC6);
259 ren->AddActor(_stripfinal);
265 //------------------------------------------------------------------------
266 void wxEmptyPanelWidget::OnOpacity1(wxScrollEvent& event){
267 double value = ((double)_opacity1->GetValue())/100;
268 _surfActor->GetProperty( )->SetOpacity( value );
271 //------------------------------------------------------------------------
272 void wxEmptyPanelWidget::OnOpacity2(wxScrollEvent& event){
273 double value = ((double)_opacity2->GetValue())/100;
274 _isoActorMC6->GetProperty( )->SetOpacity( value );
277 //------------------------------------------------------------------------
278 void wxEmptyPanelWidget::OnIsoValue(wxScrollEvent& event){
280 _mCubes->SetValue(0, _isoValue->GetValue());