]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxEmptyPanelWidget.cxx
7814c78d4268f18a1231013a9447e447b45cd62d
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxEmptyPanelWidget.cxx
1
2 #include "vtkActor.h"
3 #include "vtkCylinderSource.h"
4 #include "vtkPolyDataMapper.h"
5 #include "vtkRenderer.h"
6 #include "vtkRenderWindow.h"
7 #include "vtkRenderWindowInteractor.h"
8 #include "vtkProperty.h"
9 #include "vtkCamera.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"
20
21
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"
38 #include "vtkMath.h"
39 #include "vtkStripper.h"
40
41
42 #include "wxEmptyPanelWidget.h"
43
44 #include <wx/splitter.h>
45
46 //-------------------------------------------------------------------
47 //-------------------------------------------------------------------
48 //-------------------------------------------------------------------
49 wxEmptyPanelWidget::wxEmptyPanelWidget(wxWindow *parent)
50 : wxPanel( parent, -1) 
51 {
52         wxBoxSizer                      *sizer                  = new wxBoxSizer(wxVERTICAL  );
53     wxSplitterWindow    *pnlSplitter    = new wxSplitterWindow( this , -1);
54         wxPanel                         *viewPanel              = CreateViewPanel(pnlSplitter);
55         wxPanel                         *controlPanel   = CreateControlPanel(pnlSplitter);
56
57         sizer           -> Add( pnlSplitter ,1,wxGROW  ,0);
58         pnlSplitter     -> SetMinimumPaneSize( 150 );
59     pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
60         this            -> SetSizer(sizer);
61
62         // Original Volule
63         _mCubes                 = NULL;
64         _surfMapper             = NULL;
65         _surfActor              = NULL;
66
67         // Result: Volume + Axis
68         _prgov                  = NULL;
69         _mapfinal               = NULL;
70         _stripfinal             = NULL;
71         _isoMapperMC6   = NULL;
72         _isoActorMC6    = NULL;
73         _isoMC6                 = NULL;
74 }
75 //-------------------------------------------------------------------
76 wxEmptyPanelWidget::~wxEmptyPanelWidget(){
77
78         // Original Volule
79         _mCubes                 -> Delete();
80         _surfMapper             -> Delete();
81         _surfActor              -> Delete();
82
83         // Result: Volume + Axis
84         _prgov                  -> Delete();
85         _mapfinal               -> Delete();
86         _stripfinal             -> Delete();
87         _isoMapperMC6   -> Delete();
88         _isoActorMC6    -> Delete();
89         _isoMC6                 -> Delete();
90 }
91 //-------------------------------------------------------------------
92 wxPanel* wxEmptyPanelWidget::CreateViewPanel(wxWindow *parent)
93 {
94         wxPanel *panel          =       new wxPanel(parent,-1);
95     wxBoxSizer *sizer   =       new wxBoxSizer(wxVERTICAL);
96
97         _imageviewer3D = new wxVtk3DBaseView(panel);
98         wxVTKRenderWindowInteractor *iren = _imageviewer3D->GetWxVTKRenderWindowInteractor();   
99         sizer->Add(iren , 1, wxEXPAND, 0);
100
101         panel->SetSizer(sizer);
102         panel->SetAutoLayout(true);
103         panel->SetSize(400,400);
104         panel->Layout();
105         return panel;
106 }
107 //-------------------------------------------------------------------
108 wxPanel* wxEmptyPanelWidget::CreateControlPanel(wxWindow *parent)
109 {
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);
131
132         panel->SetSizer(sizer);
133         panel->SetAutoLayout(true);
134         panel->SetSize(400,400);
135         panel->Layout();
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 ); 
139         return panel;
140 }
141 //------------------------------------------------------------------------
142 void wxEmptyPanelWidget::Refresh()
143 {
144         _imageviewer3D->Refresh();
145 }
146 //------------------------------------------------------------------------
147
148 void wxEmptyPanelWidget::ConfigureVTK(vtkImageData *imagedata, int x, int y, int z)
149 {
150     wxBusyCursor wait;
151         _imageviewer3D->Configure();
152         
153         double puntoactualprov[3];
154         puntoactualprov[0]=x;
155         puntoactualprov[1]=y;
156         puntoactualprov[2]=z;
157
158         double espprin[3];
159         int extprin[6];                         
160         
161         imagedata->GetSpacing(espprin);
162         imagedata->GetExtent(extprin);
163
164         puntoactualprov[0]=puntoactualprov[0]*espprin[0];
165         puntoactualprov[1]=puntoactualprov[1]*espprin[1];
166         puntoactualprov[2]=puntoactualprov[2]*espprin[2];
167         
168         /* Old
169         // Juan Francisco Carrillo Filter 
170         _prgov= axisExtractor::New();
171         _prgov->SetHumbral(0.45);
172         _prgov->SetInput(imagedata);
173         _prgov->SetPoint(puntoactualprov);
174         _prgov->Update();
175         */
176
177         // Juan Francisco Carrillo Filter 
178         _prgov= axisExtractor02::New();
179         _prgov->SetParam(1);
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);
186         _prgov->Update();
187
188
189         vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
190         writer->SetInput(_prgov->GetOutput());
191     writer->SetFileName("c:/temp/salida_JF.vtk");
192     writer->SetFileTypeToASCII();
193     writer->Write();
194
195
196         // Visualisation - result vascular tree
197         _mapfinal = vtkPolyDataMapper::New();
198         _mapfinal->SetInput(_prgov->GetOutput());
199
200         _stripfinal = vtkActor::New();
201         _stripfinal->SetMapper(_mapfinal);
202         _stripfinal->GetProperty()->SetColor(1, 1, 1);
203         _stripfinal->GetProperty()->SetLineWidth(2);
204
205         _stripfinal->GetProperty()->BackfaceCullingOff();
206
207         // Visualisation - result volume
208         vtkImageData *imageOut = _prgov->GetVolumen();
209         imageOut->Update();
210
211     _isoMC6 = vtkMarchingCubes::New();
212     _isoMC6->SetInput(imageOut);
213     _isoMC6->SetValue(0, 1);
214         _isoMC6->Update();
215
216         _isoMapperMC6 = vtkPolyDataMapper::New();
217     _isoMapperMC6->SetInput(_isoMC6->GetOutput());
218     _isoMapperMC6->ScalarVisibilityOff();
219     _isoMapperMC6->ImmediateModeRenderingOn();
220
221         _isoActorMC6 = vtkActor::New();
222     _isoActorMC6->SetMapper(_isoMapperMC6);
223     _isoActorMC6->GetProperty()->SetColor( 0, 1, 0);
224     _isoActorMC6->GetProperty()->SetOpacity(0.25);
225  
226         // Visualisation - original volume
227     double range[2];
228     imagedata->GetScalarRange( range );
229
230     _mCubes = vtkMarchingCubes::New( );
231     _mCubes->SetInput( imagedata );
232     _mCubes->SetValue( 0, range[1] / 4 );
233
234     vtkStripper *stripper = vtkStripper::New();
235     stripper->SetInput( _mCubes->GetOutput( ) );
236
237     _surfMapper = vtkPolyDataMapper::New( );
238         _surfMapper->SetInput( stripper->GetOutput() );
239     _surfMapper->ScalarVisibilityOff( );
240     stripper->Delete();
241
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 );
247                 
248
249         // Update Controls
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));
254     
255         // Interface Update
256         vtkRenderer *ren = _imageviewer3D->GetRenderer();
257         ren->AddActor(_surfActor);
258         ren->AddActor(_isoActorMC6);
259         ren->AddActor(_stripfinal);
260
261 }
262
263
264
265 //------------------------------------------------------------------------
266 void wxEmptyPanelWidget::OnOpacity1(wxScrollEvent& event){
267         double value = ((double)_opacity1->GetValue())/100;
268     _surfActor->GetProperty( )->SetOpacity( value );
269         Refresh();
270 }
271 //------------------------------------------------------------------------
272 void wxEmptyPanelWidget::OnOpacity2(wxScrollEvent& event){
273         double value = ((double)_opacity2->GetValue())/100;
274     _isoActorMC6->GetProperty( )->SetOpacity( value );
275         Refresh();
276 }
277 //------------------------------------------------------------------------
278 void wxEmptyPanelWidget::OnIsoValue(wxScrollEvent& event){
279     wxBusyCursor wait;
280         _mCubes->SetValue(0, _isoValue->GetValue());
281         Refresh();
282 }