]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/include/wxEmptyPanelWidget.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / include / wxEmptyPanelWidget.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "vtkActor.h"
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"
44
45
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"
62 #include "vtkMath.h"
63 #include "vtkStripper.h"
64
65
66 #include "wxEmptyPanelWidget.h"
67
68 #include <wx/splitter.h>
69
70 //-------------------------------------------------------------------
71 //-------------------------------------------------------------------
72 //-------------------------------------------------------------------
73 wxEmptyPanelWidget::wxEmptyPanelWidget(wxWindow *parent)
74 : wxPanel( parent, -1) 
75 {
76         wxBoxSizer                      *sizer                  = new wxBoxSizer(wxVERTICAL  );
77     wxSplitterWindow    *pnlSplitter    = new wxSplitterWindow( this , -1);
78         wxPanel                         *viewPanel              = CreateViewPanel(pnlSplitter);
79         wxPanel                         *controlPanel   = CreateControlPanel(pnlSplitter);
80
81         sizer           -> Add( pnlSplitter ,1,wxGROW  ,0);
82         pnlSplitter     -> SetMinimumPaneSize( 150 );
83     pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
84         this            -> SetSizer(sizer);
85
86         // Original Volule
87         _mCubes                 = NULL;
88         _surfMapper             = NULL;
89         _surfActor              = NULL;
90
91         // Result: Volume + Axis
92         _prgov                  = NULL;
93         _mapfinal               = NULL;
94         _stripfinal             = NULL;
95         _isoMapperMC6   = NULL;
96         _isoActorMC6    = NULL;
97         _isoMC6                 = NULL;
98 }
99 //-------------------------------------------------------------------
100 wxEmptyPanelWidget::~wxEmptyPanelWidget(){
101
102         // Original Volule
103         _mCubes                 -> Delete();
104         _surfMapper             -> Delete();
105         _surfActor              -> Delete();
106
107         // Result: Volume + Axis
108         _prgov                  -> Delete();
109         _mapfinal               -> Delete();
110         _stripfinal             -> Delete();
111         _isoMapperMC6   -> Delete();
112         _isoActorMC6    -> Delete();
113         _isoMC6                 -> Delete();
114 }
115 //-------------------------------------------------------------------
116 wxPanel* wxEmptyPanelWidget::CreateViewPanel(wxWindow *parent)
117 {
118         wxPanel *panel          =       new wxPanel(parent,-1);
119     wxBoxSizer *sizer   =       new wxBoxSizer(wxVERTICAL);
120
121         _imageviewer3D = new wxVtk3DBaseView(panel);
122         wxVTKRenderWindowInteractor *iren = _imageviewer3D->GetWxVTKRenderWindowInteractor();   
123         sizer->Add(iren , 1, wxEXPAND, 0);
124
125         panel->SetSizer(sizer);
126         panel->SetAutoLayout(true);
127         panel->SetSize(400,400);
128         panel->Layout();
129         return panel;
130 }
131 //-------------------------------------------------------------------
132 wxPanel* wxEmptyPanelWidget::CreateControlPanel(wxWindow *parent)
133 {
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);
155
156         panel->SetSizer(sizer);
157         panel->SetAutoLayout(true);
158         panel->SetSize(400,400);
159         panel->Layout();
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 ); 
163         return panel;
164 }
165 //------------------------------------------------------------------------
166 void wxEmptyPanelWidget::Refresh()
167 {
168         _imageviewer3D->Refresh();
169 }
170 //------------------------------------------------------------------------
171
172 void wxEmptyPanelWidget::ConfigureVTK(vtkImageData *imagedata, int x, int y, int z)
173 {
174     wxBusyCursor wait;
175         _imageviewer3D->Configure();
176         
177         double puntoactualprov[3];
178         puntoactualprov[0]=x;
179         puntoactualprov[1]=y;
180         puntoactualprov[2]=z;
181
182         double espprin[3];
183         int extprin[6];                         
184         
185         imagedata->GetSpacing(espprin);
186         imagedata->GetExtent(extprin);
187
188         puntoactualprov[0]=puntoactualprov[0]*espprin[0];
189         puntoactualprov[1]=puntoactualprov[1]*espprin[1];
190         puntoactualprov[2]=puntoactualprov[2]*espprin[2];
191         
192         /* Old
193         // Juan Francisco Carrillo Filter 
194         _prgov= axisExtractor::New();
195         _prgov->SetHumbral(0.45);
196         _prgov->SetInput(imagedata);
197         _prgov->SetPoint(puntoactualprov);
198         _prgov->Update();
199         */
200
201         // Juan Francisco Carrillo Filter 
202         _prgov= axisExtractor02::New();
203         _prgov->SetParam(1);
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);
210         _prgov->Update();
211
212
213         vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
214         writer->SetInput(_prgov->GetOutput());
215     writer->SetFileName("c:/temp/salida_JF.vtk");
216     writer->SetFileTypeToASCII();
217     writer->Write();
218
219
220         // Visualisation - result vascular tree
221         _mapfinal = vtkPolyDataMapper::New();
222         _mapfinal->SetInput(_prgov->GetOutput());
223
224         _stripfinal = vtkActor::New();
225         _stripfinal->SetMapper(_mapfinal);
226         _stripfinal->GetProperty()->SetColor(1, 1, 1);
227         _stripfinal->GetProperty()->SetLineWidth(2);
228
229         _stripfinal->GetProperty()->BackfaceCullingOff();
230
231         // Visualisation - result volume
232         vtkImageData *imageOut = _prgov->GetVolumen();
233         imageOut->Update();
234
235     _isoMC6 = vtkMarchingCubes::New();
236     _isoMC6->SetInput(imageOut);
237     _isoMC6->SetValue(0, 1);
238         _isoMC6->Update();
239
240         _isoMapperMC6 = vtkPolyDataMapper::New();
241     _isoMapperMC6->SetInput(_isoMC6->GetOutput());
242     _isoMapperMC6->ScalarVisibilityOff();
243     _isoMapperMC6->ImmediateModeRenderingOn();
244
245         _isoActorMC6 = vtkActor::New();
246     _isoActorMC6->SetMapper(_isoMapperMC6);
247     _isoActorMC6->GetProperty()->SetColor( 0, 1, 0);
248     _isoActorMC6->GetProperty()->SetOpacity(0.25);
249  
250         // Visualisation - original volume
251     double range[2];
252     imagedata->GetScalarRange( range );
253
254     _mCubes = vtkMarchingCubes::New( );
255     _mCubes->SetInput( imagedata );
256     _mCubes->SetValue( 0, range[1] / 4 );
257
258     vtkStripper *stripper = vtkStripper::New();
259     stripper->SetInput( _mCubes->GetOutput( ) );
260
261     _surfMapper = vtkPolyDataMapper::New( );
262         _surfMapper->SetInput( stripper->GetOutput() );
263     _surfMapper->ScalarVisibilityOff( );
264     stripper->Delete();
265
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 );
271                 
272
273         // Update Controls
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));
278     
279         // Interface Update
280         vtkRenderer *ren = _imageviewer3D->GetRenderer();
281         ren->AddActor(_surfActor);
282         ren->AddActor(_isoActorMC6);
283         ren->AddActor(_stripfinal);
284
285 }
286
287
288
289 //------------------------------------------------------------------------
290 void wxEmptyPanelWidget::OnOpacity1(wxScrollEvent& event){
291         double value = ((double)_opacity1->GetValue())/100;
292     _surfActor->GetProperty( )->SetOpacity( value );
293         Refresh();
294 }
295 //------------------------------------------------------------------------
296 void wxEmptyPanelWidget::OnOpacity2(wxScrollEvent& event){
297         double value = ((double)_opacity2->GetValue())/100;
298     _isoActorMC6->GetProperty( )->SetOpacity( value );
299         Refresh();
300 }
301 //------------------------------------------------------------------------
302 void wxEmptyPanelWidget::OnIsoValue(wxScrollEvent& event){
303     wxBusyCursor wait;
304         _mCubes->SetValue(0, _isoValue->GetValue());
305         Refresh();
306 }