]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxPanelCuttingImageData.cxx
d16cff956e6c4ebb0a5305d4b9078f1ab1150aa0
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxPanelCuttingImageData.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
27 #include "wxPanelCuttingImageData.h"
28
29 //-------------------------------------------------------------------
30
31 #include <vtkProperty.h>
32 #include <vtkTextProperty.h>
33 #include <vtkProperty2D.h>
34 //-------------------------------------------------------------------
35 //-------------------------------------------------------------------
36
37 wxPanelCuttingImageData::wxPanelCuttingImageData (wxWindow *parent)
38 : wxPanel( parent, -1)
39 {
40         _imageData                      = NULL;
41         _histogrammeVector      = NULL;
42         _wxvtk3Dbaseview        = NULL;
43         _wxvtkbaseView          = NULL;
44         CreateInterface() ;
45         CreateModel();
46         Create3DViewObjects();
47 }
48
49 //-------------------------------------------------------------------
50 wxPanelCuttingImageData::~wxPanelCuttingImageData()
51 {
52
53
54         delete _modelCube;      
55         delete _modelSphere;    
56         delete _modelCylinder;  
57         _vtkcube                -> Delete();    
58         _vtksphere              -> Delete();    
59         _vtkcylinder    -> Delete();    
60         _cubeMapper             -> Delete();    
61         _sphereMapper   -> Delete();    
62         _cylinderMapper -> Delete();    
63         _cubeActor              -> Delete();    
64         _sphereActor    -> Delete();    
65         _cylinderActor  -> Delete();    
66 //      _xyplot->RemoveAllInputs();     
67         _xyplot                 -> Delete();    
68         _histogrammeVector->Delete();   
69         _renplotter->Delete();
70         
71         if(_wxvtkbaseView!=NULL){
72                 delete _wxvtkbaseView;
73         }
74         //delete _vtkclipping3Ddataviewer;
75         
76
77         //fclose(file);
78
79 }
80
81 //-------------------------------------------------------------------
82 void wxPanelCuttingImageData::RemoveActors()
83 {
84         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _actualActor );
85 }
86
87
88 //-------------------------------------------------------------------
89 void wxPanelCuttingImageData::SetWxVtk3DBaseView( wxVtk3DBaseView * wxvtk3Dbaseview )
90 {
91         _wxvtk3Dbaseview=wxvtk3Dbaseview;
92 }
93
94 //-------------------------------------------------------------------
95
96 void wxPanelCuttingImageData::SetVtkClipping3DDataViewer( vtkClipping3DDataViewer *vtkclipping3Ddataviewer )
97 {
98         this->_vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
99 }
100
101 //-------------------------------------------------------------------
102 void wxPanelCuttingImageData::Create3DViewObjects()
103 {
104         // Sphere
105         _vtksphere              = vtkSphereSource::New();
106         _vtksphere->SetThetaResolution (20);
107         _vtksphere->SetPhiResolution (20);
108         _sphereMapper   = vtkPolyDataMapper::New();
109 //EED 2017-01-01 Migration VTK7
110 #if VTK_MAJOR_VERSION <= 5
111         _sphereMapper->SetInput( _vtksphere->GetOutput() );
112 #else
113         _sphereMapper->SetInputData( _vtksphere->GetOutput() );
114 #endif
115         _sphereActor    = vtkActor::New();
116         _sphereActor->SetMapper(_sphereMapper);
117         _sphereActor->SetOrigin(0, 0, 0);
118         _sphereActor->SetPosition(0, 0, 0);
119         _sphereActor->GetProperty()->SetColor(1, 0, 0);
120         _sphereActor->SetUserTransform( _modelSphere->GetVtkTransform() );      
121
122         // cube
123         _vtkcube                = vtkCubeSource::New();
124         _vtkcube->SetXLength (1);
125         _vtkcube->SetYLength (1);
126         _vtkcube->SetZLength (1);
127         _cubeMapper             = vtkPolyDataMapper::New();
128 //EED 2017-01-01 Migration VTK7
129 #if VTK_MAJOR_VERSION <= 5
130         _cubeMapper->SetInput( _vtkcube->GetOutput() );
131 #else
132         _cubeMapper->SetInputData( _vtkcube->GetOutput() );
133 #endif
134         _cubeActor              = vtkActor::New();
135         _cubeActor->SetMapper(_cubeMapper);
136         _cubeActor->SetOrigin(0, 0, 0);
137         _cubeActor->SetPosition(0, 0, 0);
138         _cubeActor->GetProperty()->SetColor(1, 0, 0);
139         _cubeActor->SetUserTransform( _modelCube->GetVtkTransform() );          
140
141         // cylinder
142         _vtkcylinder    = vtkCylinderSource::New();
143         _vtkcylinder->SetResolution(20);
144         _cylinderMapper = vtkPolyDataMapper::New();
145
146 //EED 2017-01-01 Migration VTK7
147 #if VTK_MAJOR_VERSION <= 5
148         _cylinderMapper->SetInput( _vtkcylinder->GetOutput() );
149 #else
150         _cylinderMapper->SetInputData( _vtkcylinder->GetOutput() );
151 #endif
152
153         _cylinderActor  = vtkActor::New();
154         _cylinderActor->SetMapper(_cylinderMapper);
155         _cylinderActor->SetOrigin(0, 0, 0);
156         _cylinderActor->SetPosition(0, 0, 0);
157         _cylinderActor->GetProperty()->SetColor(1, 0, 0);
158         _cylinderActor->SetUserTransform( _modelCylinder->GetVtkTransform() );          
159
160
161 }
162
163 //-------------------------------------------------------------------
164 void wxPanelCuttingImageData::CreateModel()
165 {
166         _modelCube              = new figureCuttingCubeModel();
167         _modelSphere    = new figureCuttingSphereModel();
168         _modelCylinder  = new figureCuttingCylinderModel();
169
170 //      _modelCube->SetVtkTransform( _modelCube->GetVtkTransform()                      );
171 //      _modelSphere->SetVtkTransform( _modelSphere->GetVtkTransform()          );
172 //      _modelCylinder->SetVtkTransform( _modelCylinder->GetVtkTransform()      );
173 }
174
175 //-------------------------------------------------------------------
176
177 void wxPanelCuttingImageData::InitHistogramme()
178 {
179         double rangeA[2];
180         if (_imageData==NULL)
181         {
182                 rangeA[1]=1;
183         } else {
184                 _imageData->GetScalarRange(rangeA);
185         }
186 //EED 2017-01-01 Migration VTK7
187 #if VTK_MAJOR_VERSION <= 5
188         _xyplot->RemoveAllInputs();
189 #else
190         _xyplot->RemoveAllDataSetInputConnections();
191 #endif
192 /*
193         if ( _histogrammeVector!=NULL )
194         {
195                 _histogrammeVector -> Delete();
196         }
197 */
198         _histogrammeVector =  vtkImageData::New();
199     _histogrammeVector -> SetDimensions ( (int)(rangeA[1]),1,1 );
200 //EED 2017-01-01 Migration VTK7
201 #if VTK_MAJOR_VERSION <= 5
202     _histogrammeVector -> SetScalarTypeToUnsignedShort();
203     _histogrammeVector -> AllocateScalars();    
204     _histogrammeVector -> Update(); 
205 #else
206     _histogrammeVector -> AllocateScalars(VTK_UNSIGNED_SHORT,1);    
207 #endif
208         
209         unsigned short *p_vol = (unsigned short*)_histogrammeVector->GetScalarPointer(0,0,0);
210         int i,size = (int) (rangeA[1]);
211         for (i=0; i < size; i++)
212         {
213                 *p_vol=0;
214                 p_vol++;
215         }
216         _xyplot->SetXRange(0, rangeA[1]);
217         _xyplot->SetYRange(0, 10);
218
219
220 //EED 2017-01-01 Migration VTK7
221 #if VTK_MAJOR_VERSION <= 5
222         _xyplot->AddInput( _histogrammeVector );
223 #else
224         _xyplot->AddDataSetInput( _histogrammeVector );
225 #endif
226
227 }
228
229 //-------------------------------------------------------------------
230 wxWindow *wxPanelCuttingImageData::CreatePlotHistogrammeInterface()
231 {
232         _xyplot = vtkXYPlotActor::New();
233         InitHistogramme();
234         _xyplot->GetPositionCoordinate()->SetValue(0.00, 0.00, 0);
235         _xyplot->GetPosition2Coordinate()->SetValue(1.0, 1.00, 0); //relative to Position
236         _xyplot->SetXValuesToArcLength();
237         _xyplot->SetNumberOfXLabels(6);
238
239         _xyplot->SetTitle("Histogramme");
240         _xyplot->SetXTitle("Gray level");
241         _xyplot->SetYTitle("Occurrences ");
242         _xyplot->GetProperty()->SetColor(1, 0, 0);
243         _xyplot->GetProperty()->SetPointSize(2);
244         vtkTextProperty *tprop = _xyplot->GetTitleTextProperty();
245         tprop->SetColor( 1,0,1 );
246         tprop->BoldOff ();
247         _xyplot->SetAxisTitleTextProperty(tprop);
248         _xyplot->SetAxisLabelTextProperty(tprop);
249         _xyplot->PlotPointsOn();
250         _xyplot->GetProperty()->SetPointSize(3);
251
252         _wxvtkbaseView = new wxVtkBaseView(this);
253         _wxvtkbaseView->Configure();
254
255         _renplotter = vtkRenderer::New();
256         vtkRenderWindow *renWin = _wxvtkbaseView->GetRenWin();
257         renWin->AddRenderer( _renplotter );
258         _renplotter->AddActor2D( _xyplot );
259
260         return _wxvtkbaseView->GetWxVTKRenderWindowInteractor();
261 }
262
263 //-------------------------------------------------------------------
264
265 void wxPanelCuttingImageData::CreateInterface()
266 {
267         SetSize(300,500);
268         wxBoxSizer      *topsizer               = new wxBoxSizer(wxVERTICAL);   // Principal sizer
269
270         wxBoxSizer              *sizerH0        = new wxBoxSizer(wxHORIZONTAL   );  // type of segmentation figure
271         wxBoxSizer          *sizerH2    = new wxBoxSizer(wxHORIZONTAL   );      // scale
272         wxBoxSizer              *sizerH3        = new wxBoxSizer(wxHORIZONTAL   );      // rotation
273         wxBoxSizer              *sizerH4        = new wxBoxSizer(wxHORIZONTAL   );  // intern extern
274         wxBoxSizer              *sizerH5        = new wxBoxSizer(wxHORIZONTAL   );  // Isovalue
275         wxBoxSizer              *sizerH6        = new wxBoxSizer(wxHORIZONTAL   );  // Buttons
276         wxFlexGridSizer *sizerH7        = new wxFlexGridSizer(2                 );  // Volumic information 
277
278         
279         _typeFig        = new wxChoice(this,-1);
280         _opacityFig     = new wxSlider(this,-1,100,0,100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
281
282         _scaleX         = new wxSlider(this,-1,6,0,500  , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
283         _scaleY         = new wxSlider(this,-1,20,0,500 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
284         _scaleZ         = new wxSlider(this,-1,7,0,500  , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
285
286         _rotationX      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
287         _rotationY      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
288         _rotationZ      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
289
290         _volIntern              = new wxRadioButton(this,-1, _T("Volume intern " ));
291         _volExtern              = new wxRadioButton(this,-1, _T("Volume extern " ));
292
293         _histogrammeAccumulated = new wxCheckBox(this,-1,_T("Histogramme accumulated"));
294
295         _isoValue                               = new wxSlider(this,-1, 200, 0,2000, wxDefaultPosition,wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
296         _valueBeforeIsoValue    = new wxSlider(this,-1,-1,-1,2000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
297         _valueAfterIsoValue             = new wxSlider(this,-1,-1,-1,2000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
298
299         wxButton *btnExtract    = new wxButton(this, -1,_T("Extract"));
300
301         _infoToVo       = new wxStaticText(this,-1,_T("########################"));
302         _infoSuVoA      = new wxStaticText(this,-1,_T("############"));
303         _infoSuVo       = new wxStaticText(this,-1,_T("############"));
304         _infoPixLe      = new wxStaticText(this,-1,_T("############"));
305         _infoPixHi      = new wxStaticText(this,-1,_T("############"));
306
307
308         
309
310         _typeFig->Append(_T("Cylindre"));
311         _typeFig->Append(_T("Cube"));
312         _typeFig->Append(_T("Sphere"));
313         _typeFig->SetSelection(0);
314         _volIntern->SetValue(true);
315
316         Connect(_typeFig->GetId()                               , wxEVT_COMMAND_CHOICE_SELECTED         , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTypeFig ); 
317
318         Connect(_opacityFig->GetId()                    , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnOpacityFig ); 
319         Connect(_rotationX->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
320         Connect(_rotationY->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
321         Connect(_rotationZ->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
322         Connect(_scaleX->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
323         Connect(_scaleY->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
324         Connect(_scaleZ->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
325         Connect(btnExtract->GetId()                             , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnExtract   ); 
326          
327
328 //      wxStaticText *text=new wxStaticText(this,-1, " ");
329
330         sizerH0 -> Add( new wxStaticText(this,-1, _T("Fig. Type:   "),wxDefaultPosition, wxSize(50,20)) ,1,wxALL  ,0);
331         sizerH0 -> Add( _typeFig                ,1,wxALL  ,0);
332         sizerH0 -> Add( _opacityFig             ,1,wxALL|wxEXPAND  ,0);
333
334         sizerH2 -> Add( new wxStaticText(this,-1,_T("Scale :   "))              ,1,wxALL  ,0);
335         sizerH2 -> Add( _scaleX         ,1,wxALL | wxEXPAND ,0 );
336         sizerH2 -> Add( _scaleY         ,1,wxALL | wxEXPAND ,0 );
337         sizerH2 -> Add( _scaleZ         ,1,wxALL | wxEXPAND ,0 );
338
339         sizerH3 -> Add( new wxStaticText(this,-1,_T("Rotation :   "))   ,1,wxALL  ,0);
340         sizerH3 -> Add( _rotationX      ,1,wxALL | wxEXPAND ,0 );
341         sizerH3 -> Add( _rotationY      ,1,wxALL | wxEXPAND ,0 );
342         sizerH3 -> Add( _rotationZ      ,1,wxALL | wxEXPAND ,0 );
343
344
345         sizerH4 -> Add( new wxStaticText(this,-1,_T("Intern / Extern :   "))    ,1,wxALL  ,0);
346         sizerH4 -> Add( _volIntern                                              ,1,wxALL  ,0);
347         sizerH4 -> Add( new wxStaticText(this,-1, _T(" "))      ,1,wxALL  ,0);
348         sizerH4 -> Add( _volExtern                                              ,1,wxALL  ,0);
349
350         sizerH5 -> Add( new wxStaticText(this,-1,_T("Isovalue   "))     ,1,wxALL  ,0);
351         sizerH5 -> Add( _isoValue                                               ,1,wxALL | wxEXPAND ,0 );
352         sizerH5 -> Add( _valueBeforeIsoValue                    ,1,wxALL | wxEXPAND ,0 );
353         sizerH5 -> Add( _valueAfterIsoValue                             ,1,wxALL | wxEXPAND ,0 );
354
355         sizerH6 -> Add( new wxStaticText(this,-1, _T(" "))              ,1,wxALL  ,0);
356         sizerH6 -> Add( btnExtract      ,1,wxALL  ,0);
357
358         sizerH7 -> Add( new wxStaticText(this,-1,_T("Total Volume: "), wxDefaultPosition, wxSize(200,12))                       , 1 , wxALL  ,0);
359         sizerH7 -> Add( _infoToVo                                                                               , 1 , wxALL  ,0);
360         sizerH7 -> Add( new wxStaticText(this,-1,_T("SubVolume:   "), wxDefaultPosition, wxSize(200,12) )               , 1 , wxALL  ,0);
361         sizerH7 -> Add( _infoSuVo                                                                               , 1 , wxALL  ,0);
362         sizerH7 -> Add( new wxStaticText(this,-1,_T("SubVolume (ana.): "), wxDefaultPosition, wxSize(200,12))   , 1 , wxALL  ,0);
363         sizerH7 -> Add( _infoSuVoA                                                                              , 1 , wxALL  ,0);
364         sizerH7 -> Add( new wxStaticText(this,-1,_T("Pix < isovalue:   ") , wxDefaultPosition, wxSize(200,12))  , 1 , wxALL  ,0);
365         sizerH7 -> Add( _infoPixLe                                                                              , 1 , wxALL  ,0);
366         sizerH7 -> Add( new wxStaticText(this,-1,_T("Pix > isovalue: "), wxDefaultPosition, wxSize(200,12))     , 1 , wxALL  ,0);
367         sizerH7 -> Add( _infoPixHi                                                                              , 1 , wxALL  ,0);
368 //      sizerH7 -> SetMinSize(300, 120);
369
370         // Figure type
371         topsizer -> Add( sizerH0 ,1,wxALL|wxEXPAND  ,0);
372
373         // Scale
374         topsizer -> Add( sizerH2 ,1,wxALL|wxEXPAND  ,0);
375
376         // Rotation
377         topsizer -> Add( sizerH3 ,1,wxALL|wxEXPAND  ,0);
378
379         // Intern / Extern
380         topsizer -> Add( sizerH4 ,1,wxALL  ,0);
381
382
383         // Isovalue limite
384         topsizer -> Add( sizerH5 ,1,wxALL |wxEXPAND ,0);
385
386         // btn Extraction
387         topsizer -> Add( sizerH6        , 1 , wxALL  ,0);
388
389         // Histograme
390         topsizer -> Add( _histogrammeAccumulated ,1,  wxALL  ,0);
391
392         // Volumic information
393         topsizer -> Add( sizerH7                                , 1 , wxALL|wxEXPAND   ,0);
394
395
396
397 //    wxBoxSizer *sizerHor = new wxBoxSizer(wxHORIZONTAL);
398     wxBoxSizer *sizerHor = new wxBoxSizer(wxVERTICAL);
399         sizerHor -> Add( topsizer                               , 1 , wxALL | wxEXPAND  ,0);
400
401
402         wxWindow *panelPlotHistogramme = CreatePlotHistogrammeInterface();
403         sizerHor -> Add( panelPlotHistogramme   , 1 , wxGROW  ,0);
404
405
406         this->SetAutoLayout(true);
407         this->SetSizer( sizerHor );      
408         this->Layout(); 
409 //EEDxx2.4
410 //      this->FitInside();
411 }
412
413 //-------------------------------------------------------------------
414
415 void wxPanelCuttingImageData::OnExtract(wxCommandEvent& event)
416 {
417         wxBusyCursor wait;
418
419         bool                    inside;
420         bool                    volInt, volExt;
421         int                             xx,yy,zz;
422         unsigned short  *pOrg;
423         unsigned short  *p_histogramme;
424         int                             dim[3];
425         double                  spc[3];
426         long int                contAfter = 0;
427         long int                contBefor = 0;
428
429         double min=999999999;
430         double max=-999999999;
431
432         volExt=_volExtern->GetValue();
433         volInt=_volIntern->GetValue();
434         int isoValue                = _isoValue->GetValue();
435         int valueBeforeIsoValue = _valueBeforeIsoValue->GetValue(); 
436         int valueAfterIsoValue  = _valueAfterIsoValue ->GetValue(); 
437
438         InitHistogramme();
439         p_histogramme = (unsigned short*)_histogrammeVector->GetScalarPointer(0,0,0);
440
441         _imageData->GetDimensions(dim);    
442         _imageData->GetSpacing(spc);    
443         _actualCuttingModel->CalculeInversMatrix();
444
445         for (xx=0;xx<dim[0]; xx++)
446         {
447                 for (yy=0;yy<dim[1]; yy++)
448                 {
449                         for (zz=0;zz<dim[2];zz++)
450                         {
451                                 inside=_actualCuttingModel->IfPointInside(xx,yy,zz);
452                                 if (  ((inside==true)&&(volInt==true)) || ((!inside==true)&&(volExt==true)) )
453                                 {
454                                         pOrg=(unsigned short*)_imageData->GetScalarPointer (xx,yy,zz); 
455
456                                         if ((*pOrg)<isoValue)
457                                         {
458                                                 contBefor++;
459                                                 if (valueBeforeIsoValue!=-1)
460                                                 {
461                                                         *pOrg=valueBeforeIsoValue;
462                                                 }
463                                         } else {
464                                                 contAfter++;
465                                                 if (valueAfterIsoValue!=-1)
466                                                 {
467                                                         *pOrg=valueAfterIsoValue;
468                                                 } // if
469                                         } // if isovalue
470
471                                         p_histogramme[*pOrg]++;
472                                         if (*pOrg<min) min=*pOrg; 
473                                         if (*pOrg>max) max=*pOrg; 
474                                 } // if inside
475                         } // for zz
476                 } // for yy
477         } // for xx
478
479
480         // Information
481         wxString infoToVo;
482         wxString infoSuVo;
483         wxString infoSuVoA;
484         wxString infoPixLe;
485         wxString infoPixHi;
486
487         double volumeUnit = spc[0]*spc[1]*spc[2];
488         long int totalSubVolume = contBefor + contAfter;
489         double contBeforPorc    = 100*(double)contBefor/(double)totalSubVolume;
490         double contAfterPorc    = 100*(double)contAfter/(double)totalSubVolume;
491         infoToVo.Printf(_T("%dx%dx%d = %d"),dim[0],dim[1],dim[2], dim[0]*dim[1]*dim[2] );
492         infoSuVo.Printf(_T("%ld") , totalSubVolume);
493         infoSuVoA.Printf(_T("%.2f"), _actualCuttingModel->GetTheoricVolume() );
494         infoPixLe.Printf(_T("%ld pix.   (%.2f %s)  -  %.2f mm^3"),contBefor, contBeforPorc ,_T("%"),contBefor*volumeUnit);
495         infoPixHi.Printf(_T("%ld pix.   (%.2f %s)  -  %.2f mm^3"),contAfter, contAfterPorc ,_T("%"),contAfter*volumeUnit);
496
497         _infoToVo->SetLabel(infoToVo);
498         _infoSuVo->SetLabel(infoSuVo);
499         _infoSuVoA->SetLabel(infoSuVoA);
500         _infoPixLe->SetLabel(infoPixLe);
501         _infoPixHi->SetLabel(infoPixHi);
502
503         // Histogram
504         if ( _histogrammeAccumulated->GetValue()==true )
505         {
506                 int dimHist[3];
507                 _histogrammeVector -> GetDimensions ( dimHist );
508
509                 int i,size=dimHist[0];
510                 for (i=1; i<=size; i++)
511                 {
512                         p_histogramme[i] = p_histogramme[i] + p_histogramme[i-1];
513                 }
514         }
515         double range[2];
516
517 //EED 2017-01-01 Migration VTK7
518 #if VTK_MAJOR_VERSION <= 5
519         _histogrammeVector->Update();
520 #else
521         _histogrammeVector->Modified();
522 #endif
523
524         _histogrammeVector->GetScalarRange(range);
525         _xyplot->SetYRange( 0   , range[1]      );
526         _xyplot->SetXRange( min , max           );
527
528         _vtkclipping3Ddataviewer->RefreshSurface();
529         _wxvtkbaseView->Refresh();
530
531 //      _wxvtkbaseView->RefreshView();
532         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
533 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
534 #if wxMAJOR_VERSION <= 2
535         _wxvtkbaseView->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
536 #else
537         _wxvtkbaseView->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessWindowEvent(newevent1);
538 #endif
539 }
540
541
542 //-------------------------------------------------------------------
543 void wxPanelCuttingImageData::OnTypeFig(wxCommandEvent& event)
544 {
545         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _actualActor );
546
547         if (_typeFig->GetSelection()==0){
548                 _actualCuttingModel=_modelCylinder;
549                 _actualActor=_cylinderActor;
550         }
551         if (_typeFig->GetSelection()==1){
552                 _actualCuttingModel=_modelCube;
553                 _actualActor=_cubeActor;
554         }
555         if (_typeFig->GetSelection()==2){
556                 _actualCuttingModel=_modelSphere;
557                 _actualActor=_sphereActor;
558         }
559         _wxvtk3Dbaseview->GetRenderer()->AddActor( _actualActor );
560         RefreshOpacity();
561         RefreshView();
562 }
563
564 //-------------------------------------------------------------------
565 void wxPanelCuttingImageData::RefreshOpacity()
566 {
567         double op= _opacityFig->GetValue()/100.0;
568         _actualActor->GetProperty()->SetOpacity( op );
569 }
570
571 //-------------------------------------------------------------------
572 void wxPanelCuttingImageData::OnOpacityFig(wxScrollEvent& event)
573 {
574         RefreshOpacity();
575         Refresh();
576 }
577 //-------------------------------------------------------------------
578 void wxPanelCuttingImageData::RefreshView()
579 {
580         SetParamsOfTransformation( );
581         Refresh();
582 }
583 //-------------------------------------------------------------------
584 void wxPanelCuttingImageData::Refresh()
585 {
586         _wxvtk3Dbaseview->Refresh();
587 }
588
589 //-------------------------------------------------------------------
590 void wxPanelCuttingImageData::SetParamsOfTransformation( )
591 {
592         double spc[3];
593         vtkImageData *vtkimagedata = _vtkmprbasedata->GetImageData();
594         vtkimagedata->GetSpacing(spc);
595         int px = (int) (_vtkmprbasedata->GetX() );
596         int py = (int) (_vtkmprbasedata->GetY() );
597         int pz = (int) (_vtkmprbasedata->GetZ() );
598         int sx = (int) (_scaleX->GetValue() * spc[0] );
599         int sy = (int) (_scaleY->GetValue() * spc[1] );
600         int sz = (int) (_scaleZ->GetValue() * spc[2] );
601         _actualCuttingModel     -> SetScale             ( sx    , sy    , sz );
602         _actualCuttingModel     -> SetPosition  ( px    , py , pz       );
603         _actualCuttingModel     -> SetRotation  ( _rotationX->GetValue()        , _rotationY->GetValue() , _rotationZ->GetValue()       );
604         _actualCuttingModel     -> SetSpacing   ( spc[0]        , spc[1]    , spc[2] );
605         _actualCuttingModel     -> CalculeMatrix();
606 }
607
608 //-------------------------------------------------------------------
609
610 void wxPanelCuttingImageData::OnTransform(wxScrollEvent& event)
611 {
612         RefreshView();
613 }
614
615 //-------------------------------------------------------------------
616 void wxPanelCuttingImageData::SetVtkMPRBaseData( vtkMPRBaseData *vtkmprbasedata )
617 {
618         _vtkmprbasedata = vtkmprbasedata;
619         _imageData              = _vtkmprbasedata->GetImageData();
620 }
621
622 //-------------------------------------------------------------------
623
624 void wxPanelCuttingImageData::Configure()
625 {
626         _actualCuttingModel=_modelCylinder;
627         _actualActor=_cylinderActor;
628         _wxvtk3Dbaseview->GetRenderer()->AddActor( _actualActor );
629         SetParamsOfTransformation();
630         RefreshView();
631 }
632