]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxSTLWidget_03.cxx
5d376a3d95a304eb92d3b9ffaa62330274eff087
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxSTLWidget_03.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 "vtkObjectFactory.h"
28
29 #include "vtkActor.h"
30 #include "vtkCylinderSource.h"
31 #include "vtkPolyDataMapper.h"
32 #include "vtkRenderer.h"
33 #include "vtkRenderWindow.h"
34 #include "vtkRenderWindowInteractor.h"
35 #include "vtkProperty.h"
36 #include "vtkCamera.h"
37 #include "vtkPoints.h"
38 #include "vtkCellArray.h"
39 #include "vtkPolyData.h"
40 #include "vtkPolyDataMapper.h"
41 #include "vtkPolyDataWriter.h"
42 #include "vtkPolyDataReader.h"
43 #include "vtkImageReader.h"
44 #include "vtkImageViewer.h"
45 #include "vtkImageViewer2.h"
46 #include "vtkImageToStructuredPoints.h"
47 #include <vtkImageThreshold.h> 
48 #include "vtkImageWriter.h"
49
50
51 #include "vtkExtractVOI.h"
52 #include "vtkImageClip.h"
53 #include "vtkImageResample.h"
54 #include "vtkImageThreshold.h"
55 #include "vtkImageCast.h"
56 #include "vtkImageSeedConnectivity.h"
57 #include "vtkImageData.h"
58 #include "vtkMarchingCubes.h"
59 #include "vtkImageReslice.h"
60 #include "vtkTransform.h"
61 #include "vtkSphereSource.h"
62 #include "vtkDoubleArray.h"
63 #include "vtkPointData.h"
64 #include "vtkCommand.h"
65 #include "vtkCallbackCommand.h"
66 #include "vtkImageResample.h"
67 #include "vtkMath.h"
68 #include "vtkStripper.h"
69 #include <vtkSTLReader.h> 
70 #include "vtkMetaImageWriter.h"
71
72
73 #include "vtkTriangleFilter.h"
74 #include "vtkSTLWriter.h"
75 #include "vtkPolyDataConnectivityFilter.h"
76 #include "vtkClosePolyData.h"
77 #include "vtkAppendFilter.h"
78
79 #include "wxSTLWidget_03.h"
80
81 #include <wx/splitter.h>
82
83 #include <wx/filedlg.h>
84
85
86
87 //-------------------------------------------------------------------
88 //-------------------------------------------------------------------
89 //-------------------------------------------------------------------
90 wxSTLWidget_03::wxSTLWidget_03(wxWindow *parent)//, marInterface* mar)
91 : wxPanel( parent, -1) 
92 {
93         _imagedata=NULL;
94         cast2=NULL;
95         cast3=NULL;
96         cast4=NULL; // binary segmentation result
97         _thresh=NULL;
98         _thresh2=NULL;
99         _cast=NULL;
100         _connect=NULL;
101         _connect2=NULL;
102         _2_mapfinal=NULL;
103         _2_stripfinal=NULL;
104         _2_isoMapperMC6=NULL;
105         _2_isoActorMC6=NULL;
106         _2_isoMC6=NULL; 
107         _loadSTLMapper=NULL;
108         _loadActorSTL=NULL;
109         sl_barrange_segmentation=NULL;  
110         _imageviewer3D=NULL;    
111         _wxMaracasMPR=NULL;     
112         stlInterna=NULL;
113         stlExterna=NULL;        
114         stlSliderDeltaGauss=NULL;
115         stlSliderMarchingCubes=NULL;    
116         dsm1=NULL;
117     actorInternal=NULL;
118         stlSliderOpacityInternal=NULL;    
119         dsm2=NULL; 
120     actorExternal=NULL;
121         stlSliderOpacityExternal=NULL;
122         stlExtractor=NULL;   
123         _sl_opacity_STL_file=NULL;
124         arteryImageData=NULL;
125         joiner=NULL;
126         joinMarchingCubes=NULL;
127     joinMapper=NULL; 
128         joinActor=NULL; 
129         _maxSize                = 2000;
130         _minSize                = 300;
131         
132         _stlMarchingCubesLevel  = 128;
133         _stlDeltaGaussLevel             = 100;
134
135         /*_mar=new marInterface();      
136         _mar->_parameters->setRescaleSlope( mar->_parameters->getRescaleSlope() );
137         _mar->_parameters->setRescaleIntercept( mar->_parameters->getRescaleIntercept() );
138         _mar->_parameters->setIntParam( marParameters::e_voxel_type, marParameters::VOX_TYPE_MINIMUM );
139         _mar->_parameters->setDoubleParam( marParameters::e_voxel_x_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_x_dimension) );
140         _mar->_parameters->setDoubleParam( marParameters::e_voxel_y_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_y_dimension) );
141         _mar->_parameters->setDoubleParam( marParameters::e_voxel_z_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_z_dimension) );
142         int voi[6];
143         mar->_experiment->getVOI( voi );
144         _mar->_experiment->setVOI( voi );
145         _mar->SetDicom(mar->_dicom);
146         _mar->initExperiment( );*/
147          
148
149         wxBoxSizer              *sizer          = new wxBoxSizer(wxVERTICAL  );
150         wxSplitterWindow        *pnlSplitter    = new wxSplitterWindow( this , -1);
151         wxPanel                 *viewPanel      = CreateViewPanel(pnlSplitter);
152         wxPanel                 *controlPanel   = CreateControlPanel(pnlSplitter);
153
154         sizer           -> Add( pnlSplitter ,1,wxGROW  ,0);
155         pnlSplitter     -> SetMinimumPaneSize( 150 );
156         pnlSplitter     -> SplitVertically( viewPanel, controlPanel, 600 );
157
158 //      pnlSplitter     -> SplitVertically( new wxPanel(pnlSplitter,-1), new wxPanel(pnlSplitter,-1) , 600 );
159 //      pnlSplitter     -> SplitVertically( viewPanel, new wxPanel(pnlSplitter,-1) , 600 );
160
161         this            -> SetSizer(sizer);
162         
163
164
165 }
166 //-------------------------------------------------------------------
167 wxSTLWidget_03::~wxSTLWidget_03(){
168         //ResetTree2_JF();
169         //Reset_vtk_STLFile();
170
171         if(_imagedata!=NULL){
172                 _imagedata->Delete();   
173         }       
174         if(cast2){cast2->Delete();}
175         if(cast3){cast3->Delete();}
176         if(cast4){cast4->Delete();}
177         if(_thresh){_thresh->Delete();}
178         if(_thresh2){_thresh2->Delete();}
179         if(_cast){_cast->Delete();}
180         if(_connect){_connect->Delete();}
181         if(_connect2){_connect2->Delete();}
182         if(_2_mapfinal){_2_mapfinal->Delete();}
183         if(_2_stripfinal){_2_stripfinal->Delete();}
184         if(_2_isoMapperMC6){_2_isoMapperMC6->Delete();}
185         if(_2_isoActorMC6){_2_isoActorMC6->Delete();}
186         if(_2_isoMC6){_2_isoMC6->Delete();}
187         // Load STL file
188         if(_loadSTLMapper){_loadSTLMapper->Delete();}
189         if(_loadActorSTL){_loadActorSTL->Delete();}
190         if(sl_barrange_segmentation){delete sl_barrange_segmentation;}
191         if(_imageviewer3D){delete _imageviewer3D;}      
192         if(_wxMaracasMPR){delete _wxMaracasMPR;}
193         if(stlInterna){stlInterna->Delete();}
194         if(stlExterna){stlExterna->Delete();}   
195         if(dsm1){dsm1->Delete();}
196     if(actorInternal){actorInternal->Delete();}
197         if(dsm2){dsm2->Delete();} 
198     if(actorExternal){actorExternal->Delete();}
199         //if(stlExtractor){stlExtractor->Delete();}
200         if(arteryImageData){arteryImageData->Delete();}
201         if(joiner){delete joiner;}
202         if(joinMarchingCubes){joinMarchingCubes->Delete();}
203     if(joinMapper){joinMapper->Delete(); }
204         if(joinActor){joinActor->Delete();}
205 }
206 //-------------------------------------------------------------------
207 wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
208 {
209         wxPanel *panel          =       new wxPanel(parent,-1);
210     wxBoxSizer *sizer   =       new wxBoxSizer(wxVERTICAL);
211
212
213    // MPR
214         //vtkImageData *imagedata;
215         //imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
216         //imagedata->Update();  
217         _wxMaracasMPR = new wxMaracasMPR( panel);//JCP 10-03-2009, new marImageData(imagedata), 1 );
218         _wxMaracasMPR->ConfigureVTK();
219         
220         sizer->Add(     _wxMaracasMPR , 1, wxEXPAND, 0);
221         panel->SetSizer(sizer);
222         panel->SetAutoLayout(true);
223         panel->SetSize(400,400);
224         panel->Layout();
225         return panel;
226 }
227
228 void wxSTLWidget_03::setImage(vtkImageData* img){
229
230         _wxMaracasMPR->setImageData(img, 1);
231         _wxMaracasMPR->ConfigureVTK();
232
233
234         this->ConfigureProcessing(img,0,0,0);
235         this->ConfigureSTL();
236
237         _wxMaracasMPR->Refresh();
238         
239         //this->Refresh();
240 }
241 //-------------------------------------------------------------------
242 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
243 {
244         wxPanel *panel          = new wxPanel(parent,-1);
245
246
247     wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
248
249         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
250         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
251
252         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
253         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
254
255         sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
256         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
257
258         panel->SetSizer(sizer);
259         panel->SetAutoLayout(true);
260         panel->SetSize(400,600);
261         panel->Layout();
262
263
264         return panel;
265 }
266 //-------------------------------------------------------------------
267 wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
268 {
269         wxPanel *panel          = new wxPanel(parent,-1);
270
271
272         _opacity_Vol            = new wxSlider( panel, -1, 40, 0, 100                            , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
273         _opacity_Vol    ->SetSize(250,20);  
274         /*SIL
275         _sl_maxSize                     = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL  |  wxSL_AUTOTICKS | wxSL_LABELS );
276         _sl_minSize                     = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL  |  wxSL_AUTOTICKS | wxSL_LABELS );
277         
278         _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
279         _sl_minSizeSpin->SetRange(1,8);
280         _sl_minSizeSpin->SetValue(5);
281
282         _sl_maxSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
283         _sl_maxSizeSpin->SetRange(1,8);
284         _sl_maxSizeSpin->SetValue(5);
285
286         */
287
288         _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
289         _sl_RangeSizeSpin->SetRange(1,8);
290         _sl_RangeSizeSpin->SetValue(5);
291
292
293         //SIL//
294         sl_barrange_segmentation = new mBarRange(panel, 300,70);
295         sl_barrange_segmentation -> setVisibleLabels ( true );
296         sl_barrange_segmentation -> setIfWithActualDrawed( false );
297         sl_barrange_segmentation -> setActiveStateTo ( true );
298         sl_barrange_segmentation -> setRepresentedValues (0,  2000);
299         sl_barrange_segmentation -> setDeviceBlitStart (10,10);
300         sl_barrange_segmentation -> setDeviceEndMargin(10);
301         parent->SetBackgroundColour(wxColour(255,255,255));
302         sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
303
304
305         wxButton *btnExtract                            = new wxButton(panel,-1,_T("Segmentation"));
306         wxButton *btnSaveBinaryFile                     = new wxButton(panel,-1,_T("Save Binary File"));
307
308 //SIL// Connect(_sl_minSizeSpin->GetId()        , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxSTLWidget_03::OnMinSpin ); 
309 //SIL// Connect(_sl_maxSizeSpin->GetId()        , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxSTLWidget_03::OnMaxSpin ); 
310         Connect(_opacity_Vol->GetId()           , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol                                        ); 
311         Connect(btnExtract->GetId()                     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction                                      ); 
312         Connect(btnSaveBinaryFile->GetId()      , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile                          ); 
313
314         //SIL//
315         Connect(_sl_RangeSizeSpin->GetId()      , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin ); 
316         Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction)  &wxSTLWidget_03::OnStartChanged_range );
317         Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction)  &wxSTLWidget_03::OnEndChanged_range );      
318         Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction)  &wxSTLWidget_03::OnBarMoved_range );
319
320     wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
321
322         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
323         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
324
325
326         sizer->Add(new wxStaticText(panel,-1,_T("  - - -  Segmentation - - - ")));
327         sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
328         
329
330         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
331         sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
332
333         /*sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min")));
334         sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
335         sizer->Add(_sl_minSizeSpin, 1, wxALL|wxEXPAND, 0);*/
336         //sizer->Add(_sl_minSize, 1, wxALL|wxEXPAND, 0);
337
338         sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
339         sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
340         sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
341         sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
342         
343         //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" Threshold max")));
344         //SIL//sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
345         //SIL// sizer->Add(_sl_maxSizeSpin, 1, wxALL|wxEXPAND, 0);
346         //SIL//sizer->Add(_sl_maxSize, 1, wxALL|wxEXPAND, 0);
347         
348         sizer->Add(btnExtract);
349         sizer->Add(new wxStaticText(panel,-1,_T(" ")));
350
351         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
352         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
353         sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
354         sizer->Add(_opacity_Vol);
355
356         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
357         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
358         sizer->Add(btnSaveBinaryFile);
359         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
360         
361         panel->SetSizer(sizer);
362         panel->SetAutoLayout(true);
363         panel->SetSize(400,600);
364         panel->Layout();
365
366         return panel;
367 }
368 //-------------------------------------------------
369 wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
370 {
371         wxPanel *panel          = new wxPanel(parent,-1);
372
373         stlSliderDeltaGauss     = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
374         stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
375         stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
376         stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
377         wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
378
379         Connect(btnFileSTL->GetId()                             , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL                   );
380         Connect(stlSliderDeltaGauss->GetId()    , wxEVT_SCROLL_THUMBRELEASE             , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel                );
381         Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE             , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
382         Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal                 );
383         Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal                 );
384
385
386     wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
387
388         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
389         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
390
391         sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
392         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
393         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
394         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
395         
396         sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
397         sizer->Add(stlSliderDeltaGauss);
398
399         sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
400         sizer->Add(stlSliderMarchingCubes);
401
402         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
403         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
404         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
405         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
406
407         sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
408         sizer->Add(stlSliderOpacityInternal);
409
410         sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
411         sizer->Add(stlSliderOpacityExternal);
412
413         sizer->Add(btnFileSTL);
414         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
415
416
417         panel->SetSizer(sizer);
418         panel->SetAutoLayout(true);
419         panel->SetSize(400,600);
420         panel->Layout();
421         return panel;
422 }
423 //-------------------------------------------------
424 wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
425 {
426         wxPanel *panel          = new wxPanel(parent,-1);
427
428         wxButton *btnReadSTLFile                        = new wxButton(panel,-1,_T("Read STL File"));
429         wxButton *btnEraseReadSTLFile           = new wxButton(panel,-1,_T("Erase STL File"));
430         _sl_opacity_STL_file                            = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
431
432         Connect(btnReadSTLFile->GetId()                 , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad                     ); 
433         Connect(btnEraseReadSTLFile->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase                    ); 
434         Connect(_sl_opacity_STL_file->GetId()   , wxEVT_SCROLL_THUMBRELEASE     , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile                             ); 
435
436
437     wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
438
439         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
440         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
441         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
442         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
443
444         sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
445         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
446
447         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
448         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
449
450         sizer->Add(btnReadSTLFile );
451         sizer->Add(btnEraseReadSTLFile );
452         sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
453         sizer->Add(_sl_opacity_STL_file);
454
455
456         panel->SetSizer(sizer);
457         panel->SetAutoLayout(true);
458         panel->SetSize(400,600);
459         panel->Layout();
460         return panel;
461 }
462 //-------------------------------------------------------------------
463 wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
464 {
465         wxPanel *panel                  = new wxPanel(parent,-1);
466
467         wxNotebook *noteBook    = new wxNotebook(panel, -1);
468         noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
469         noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
470         noteBook->AddPage(CreateSmoothingPanel(noteBook)   ,_T("2 ->") );
471         noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 "  ) );
472         noteBook->SetSelection(0);
473         noteBook->SetSize(350,250);
474     wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
475         sizer->Add(noteBook);
476         panel->SetSizer(sizer);
477         panel->SetAutoLayout(true);
478         panel->SetSize(400,600);
479         panel->Layout();
480
481         return panel;
482 }
483 //------------------------------------------------------------------------
484 void wxSTLWidget_03::Refresh()
485 {
486         if (_wxMaracasMPR!=NULL){
487                 _wxMaracasMPR->RefreshView();
488         }
489 }
490
491 //------------------------------------------------------------------------
492
493
494 void wxSTLWidget_03::ConfigureProcessing(vtkImageData *img, int x, int y, int z)
495 {
496     wxBusyCursor wait;
497
498         _imagedata=img;
499
500
501         double puntoactualprov[3];
502         puntoactualprov[0] = x;
503         puntoactualprov[1] = y;
504         puntoactualprov[2] = z;
505
506         double espprin[3];
507         int extprin[6];                         
508         
509         _imagedata->GetSpacing(espprin);
510         _imagedata->GetExtent(extprin);
511
512
513 // MAZV 27 sep 2006
514 //      puntoactualprov[0]=puntoactualprov[0]*espprin[0];
515 //      puntoactualprov[1]=puntoactualprov[1]*espprin[1];
516 //      puntoactualprov[2]=puntoactualprov[2]*espprin[2];
517         
518     _imagedata->GetScalarRange( _range );
519
520         // Update Controls
521         //SIL//
522         /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
523         _sl_minSize->SetValue( (int)(_range[1]/4) );
524
525         _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
526         _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
527
528         //SIL//
529         minRangeValue = _range[0];
530         maxRangeValue = _range[1];
531
532         sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
533         sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
534         sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
535         sl_barrange_segmentation -> RefreshForce();     
536         lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;       
537
538 // MAZV 27 sep 2006
539 //      _highthreshold->SetRange(_range[0], _range[1]);
540 //      _highthreshold->SetValue( _range[1] );
541
542 //      _zslice->SetRange(extprin[4], extprin[5]);
543 //      _zslice->SetValue(extprin[5]/2);
544     
545         if(_thresh==NULL){
546                 _thresh = vtkImageThreshold::New();
547                 //_thresh->ReleaseDataFlagOff();
548                 _thresh->SetInValue(255);
549                 _thresh->SetOutputScalarTypeToUnsignedShort();
550                 _thresh->SetOutValue(0);
551                 //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
552                 //SIL//
553                 _cast = vtkImageCast::New();
554
555 //EED 2017-01-01 Migration VTK7
556 #if VTK_MAJOR_VERSION <= 5
557                 _cast->SetInput(_thresh->GetOutput());
558 #else
559                 _cast->SetInputData(_thresh->GetOutput());
560 #endif
561
562                 _cast->SetOutputScalarTypeToUnsignedChar();
563
564                 _connect = vtkImageSeedConnectivity::New();
565 //EED 2017-01-01 Migration VTK7
566 #if VTK_MAJOR_VERSION <= 5
567                 _connect->SetInput(_cast->GetOutput());
568 #else
569                 _connect->SetInputData(_cast->GetOutput());
570 #endif
571                 _connect->SetInputConnectValue(255);
572                 _connect->SetOutputConnectedValue(255);
573                 _connect->SetOutputUnconnectedValue(0);
574
575                 cast3 = vtkImageCast::New();
576 //EED 2017-01-01 Migration VTK7
577 #if VTK_MAJOR_VERSION <= 5
578                 cast3->SetInput(_connect->GetOutput());
579 #else
580                 cast3->SetInputData(_connect->GetOutput());
581 #endif
582                 cast3->SetOutputScalarTypeToUnsignedShort();
583
584                 _thresh2 = vtkImageThreshold::New();
585                 //_thresh2->ReleaseDataFlagOff();
586                 _thresh2->SetInValue(255);
587                 _thresh2->SetOutputScalarTypeToUnsignedShort();
588                 _thresh2->SetOutValue(0);
589                 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
590
591                 cast2 = vtkImageCast::New();
592 //EED 2017-01-01 Migration VTK7
593 #if VTK_MAJOR_VERSION <= 5
594                 cast2->SetInput(_thresh2->GetOutput());
595 #else
596                 cast2->SetInputData(_thresh2->GetOutput());
597 #endif
598                 cast2->SetOutputScalarTypeToUnsignedChar();
599                 _connect2 = vtkImageSeedConnectivity::New();
600 //EED 2017-01-01 Migration VTK7
601 #if VTK_MAJOR_VERSION <= 5
602                 _connect2->SetInput(cast2->GetOutput());
603 #else
604                 _connect2->SetInputData(cast2->GetOutput());
605 #endif
606                 _connect2->SetInputConnectValue(255);
607                 _connect2->SetOutputConnectedValue(255);
608                 _connect2->SetOutputUnconnectedValue(0);
609
610                 cast4 = vtkImageCast::New();
611 //EED 2017-01-01 Migration VTK7
612 #if VTK_MAJOR_VERSION <= 5
613                 cast4->SetInput(_connect2->GetOutput());
614 #else
615                 cast4->SetInputData(_connect2->GetOutput());
616 #endif
617                 cast4->SetOutputScalarTypeToUnsignedShort();
618         }
619         _thresh->RemoveAllInputs();
620 //EED 2017-01-01 Migration VTK7
621 #if VTK_MAJOR_VERSION <= 5
622         _thresh->SetInput(_imagedata);  
623 #else
624         _thresh->SetInputData(_imagedata);      
625 #endif
626         _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());    
627         _thresh->Update();
628         
629         _cast->Update();  
630         
631
632         _connect->RemoveAllSeeds();
633         _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
634         //_connect->Update();   
635         //cast3->Update();
636 //SIL// 
637         _thresh2->RemoveAllInputs();
638
639 //EED 2017-01-01 Migration VTK7
640 #if VTK_MAJOR_VERSION <= 5
641         _thresh2->SetInput(_imagedata); 
642 #else
643         _thresh2->SetInputData(_imagedata);     
644 #endif
645
646         _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
647         _thresh2->Update();
648         cast2->Update();
649         _connect2->RemoveAllSeeds();
650         _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
651         //_connect2->Update();  
652         //cast4->Update();
653 }
654
655 //------------------------------------------------------------------------
656
657
658
659 void wxSTLWidget_03::ConfigureVTK()
660 {
661         wxBusyCursor wait;
662 //      vtkImageData    *imagedata              = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
663         //marImageData  *marimagedata;//                = _mar->_experiment->getDynData( )->GetMarImageData();
664         
665         //CONFIGURACION ADICIONAL
666         this->ConfigureSTL();
667         //this->ConfigureProcessing(marimagedata,0,0,0);
668         
669 }
670
671 //------------------------------------------------------------------------
672
673 void wxSTLWidget_03::ResetTree2_JF()
674 {
675         // Remove 
676
677         try{
678
679                 
680
681                 // Delete 
682         //      if (_2_prgov            ) {     _2_prgov                -> Delete(); }
683                 if (_2_mapfinal         ) {     _2_mapfinal             -> Delete(); }
684                 if (_2_stripfinal       ) {     _2_stripfinal   -> Delete(); }
685                 if (_2_isoMapperMC6     ) {     _2_isoMapperMC6 -> Delete(); }
686                 if (_2_isoActorMC6      ) {     _2_isoActorMC6  -> Delete(); }
687                 if (_2_isoMC6           ) {     _2_isoMC6               -> Delete(); }
688
689                 // Init
690         //      _2_prgov                = NULL;
691                 _2_mapfinal             = NULL;
692                 _2_stripfinal   = NULL;
693                 _2_isoMapperMC6 = NULL;
694                 _2_isoActorMC6  = NULL;
695                 _2_isoMC6               = NULL;
696
697                 
698                 //vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
699
700                 /*if (_2_isoActorMC6){
701                         ren->RemoveActor(_2_isoActorMC6);
702                 }
703                 if (_2_stripfinal){
704                         ren->RemoveActor(_2_stripfinal);
705                 }*/
706
707                 
708         }catch(char* e){
709                 std::cout<<e<<std::endl;
710         }
711 }
712
713
714
715
716
717
718 //------------------------------------------------------------------------
719 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
720 {
721         
722         double opacityvol               = ((double)_opacity_Vol->GetValue())/100;
723 //      vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
724
725         double  puntoactualprov[3];
726         double  espprin[3];
727         int             extprin[6];                             
728
729
730         puntoactualprov[0]      =       x;
731         puntoactualprov[1]      =       y;
732         puntoactualprov[2]      =       z;
733         
734 //EED 2017-01-01 Migration VTK7
735 #if VTK_MAJOR_VERSION <= 5
736         _imagedata->UpdateInformation();
737         _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
738         _imagedata->Update();
739 #else
740         // ..
741 #endif
742
743         _imagedata->GetSpacing(espprin);
744         _imagedata->GetExtent(extprin);
745
746
747
748
749         _connect->RemoveAllSeeds ();
750         _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
751         _connect->Update();
752         cast3->Update();
753
754
755
756         _thresh->ThresholdBetween(3000, 3002 );
757         _thresh2->ThresholdBetween(3000, 3001);
758 //      _thresh->Update();
759 //      _thresh2->Update();
760
761         _thresh->ThresholdBetween(_minSize, _range[1] );
762         _thresh->Update();
763
764         _thresh2->ThresholdBetween(_minSize, _maxSize);
765         _thresh2->Update();
766
767         cast2->Update();
768         _connect2->RemoveAllSeeds ();
769         _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
770         _connect2->Update();
771         cast4->Update();
772
773
774
775
776         // Visualisation - result volume
777    
778     _2_isoMC6 = vtkMarchingCubes::New();
779 //EED 2017-01-01 Migration VTK7
780 #if VTK_MAJOR_VERSION <= 5
781         _2_isoMC6->SetInput(cast4->GetOutput());
782 #else
783         _2_isoMC6->SetInputData(cast4->GetOutput());
784 #endif
785
786     _2_isoMC6->SetValue(0, 128);
787         _2_isoMC6->Update();
788
789         _2_isoMapperMC6 = vtkPolyDataMapper::New();
790
791 //EED 2017-01-01 Migration VTK7
792 #if VTK_MAJOR_VERSION <= 5
793     _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
794 #else
795     _2_isoMapperMC6->SetInputData(_2_isoMC6->GetOutput());
796 #endif
797
798
799     _2_isoMapperMC6->ScalarVisibilityOff();
800     _2_isoMapperMC6->ImmediateModeRenderingOn();
801
802         vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
803
804         if (_2_isoActorMC6!=NULL)
805         {
806                 ren->RemoveActor(_2_isoActorMC6);
807         }
808
809
810         _2_isoActorMC6 = vtkActor::New();
811     _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
812     _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
813     _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
814     
815         // Interface Update
816
817         ren->AddActor(_2_isoActorMC6);
818
819 }
820
821 //------------------------------------------------------------------------
822 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
823 {
824         if (_2_isoActorMC6!=NULL){
825                 double value = ((double)_opacity_Vol->GetValue())/100;
826                 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
827                 Refresh();
828         }
829 }
830 //------------------------------------------------------------------------
831
832 void wxSTLWidget_03::OnMinSpin          (       wxScrollEvent &          event           )      
833 {
834         /*wxSlider *sl_A=_sl_minSize;
835         wxSlider *sl_B=_sl_minSizeSpin;
836         int value = sl_A->GetValue();
837         int delta=(int)pow( 4 , sl_B->GetValue() );
838         int min=value - delta/2;
839         int max=value + delta/2;
840         if (min<0)
841         {
842                 min=0;
843                 max=delta;
844         }
845         sl_A->SetRange(min,max);
846
847
848         */
849 }
850
851 //------------------------------------------------------------------------
852
853 void wxSTLWidget_03::OnMaxSpin          (       wxScrollEvent &          event           )      
854 {
855         /*wxSlider *sl_A=_sl_maxSize;
856         wxSlider *sl_B=_sl_maxSizeSpin;
857         int value = sl_A->GetValue();
858         int delta = (int)pow( 4 , sl_B->GetValue() );
859         int min=value - delta/2;
860         int max=value + delta/2;
861         if (min<0)
862         {
863                 min=0;
864                 max=delta;
865         }
866         sl_A->SetRange(min,max);*/      
867 }
868
869 //------------------------------------------------------------------------
870
871 void wxSTLWidget_03::OnRangeSpin        (       wxScrollEvent &          event           )      
872 {
873         wxSlider *sl_B=_sl_RangeSizeSpin;
874
875         int value = lastResizeRef_Value;
876         int delta = (int)pow((double) 4 , (double)sl_B->GetValue() );
877         int startResized = value - delta/2;
878         int endResized = value + delta/2;
879
880         if( startResized < minRangeValue )
881                 startResized = minRangeValue;
882
883         if( endResized > maxRangeValue )
884                 endResized = maxRangeValue;
885
886         sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
887         sl_barrange_segmentation -> RefreshForce();     
888 }
889
890 //------------------------------------------------------------------------
891 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
892 {
893         lastResizeRef_Value = sl_barrange_segmentation->GetStart();
894 }
895 //------------------------------------------------------------------------
896 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
897 {
898         lastResizeRef_Value = sl_barrange_segmentation->GetEnd();   
899 }
900 //------------------------------------------------------------------------
901 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
902 {
903         lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
904 }
905 //------------------------------------------------------------------------
906
907 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
908 {
909         wxString dirSTL;// = _mar->_parameters->getStringParam( 
910     //marParameters::e_installation_directory ); 
911         dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
912         wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
913         dirSTL: wxGetHomeDir( ) );
914
915         if( dialog.ShowModal( ) == wxID_OK ) 
916         {
917                 vtkMetaImageWriter  *writer= vtkMetaImageWriter::New();
918                 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );     
919 //EED 2017-01-01 Migration VTK7
920 #if VTK_MAJOR_VERSION <= 5
921                 writer->SetInput(cast4->GetOutput());
922 #else
923                 writer->SetInputData(cast4->GetOutput());
924 #endif
925                 writer->Write();
926                 writer->Delete();
927         }
928 }
929
930 //------------------------------------------------------------------------
931 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
932 {
933         /*wxBusyCursor wait;
934         _minSize = _sl_minSize->GetValue();
935         _maxSize = _sl_maxSize->GetValue();
936
937         double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
938         double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
939         double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
940         ExtractSurface((int)(px),(int)(py),(int)(pz));
941         generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
942
943         Refresh();
944 */
945         //SIL//
946         wxBusyCursor wait;
947         _minSize = sl_barrange_segmentation->GetStart();
948         _maxSize = sl_barrange_segmentation->GetEnd();
949
950         double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
951         double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
952         double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
953         ExtractSurface((int)(px),(int)(py),(int)(pz));
954         generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
955
956         Refresh();
957 }
958
959 //------------------------------------------------------------------------
960 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
961 {
962         if (_loadActorSTL!=NULL)
963         {
964                 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
965                 _loadActorSTL->GetProperty( )->SetOpacity( value );
966                 Refresh();
967         }
968 }
969 //------------------------------------------------------------------------
970 void wxSTLWidget_03::Reset_vtk_STLFile()
971 {
972         // Remove
973         try{
974                 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
975                 if (_loadActorSTL){
976                         ren->RemoveActor(_loadActorSTL);
977                 }
978
979                 // Delete 
980                 if (_loadSTLMapper              ) {     _loadSTLMapper          -> Delete(); }
981                 if (_loadActorSTL               ) {     _loadActorSTL           -> Delete(); }
982
983                 // Init
984                 _loadSTLMapper          = NULL;
985                 _loadActorSTL           = NULL;
986         }catch(char * e){
987                 std::cout<<e<<std::endl;
988         }
989
990 }
991 //------------------------------------------------------------------------
992 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
993 {
994         Reset_vtk_STLFile();
995         Refresh();
996 }
997 //------------------------------------------------------------------------
998 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
999 {
1000         wxString dirSTL;// = _mar->_parameters->getStringParam( 
1001     //marParameters::e_installation_directory ); 
1002         dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
1003         wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
1004         dirSTL: wxGetHomeDir( ) );
1005
1006         if( dialog.ShowModal( ) == wxID_OK ) 
1007         {
1008                 Reset_vtk_STLFile();
1009                 vtkSTLReader *imgReader= vtkSTLReader::New();
1010                 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );  
1011                 _loadSTLMapper = vtkPolyDataMapper::New();
1012 //EED 2017-01-01 Migration VTK7
1013 #if VTK_MAJOR_VERSION <= 5
1014                 _loadSTLMapper->SetInput(imgReader->GetOutput());
1015 #else
1016                 _loadSTLMapper->SetInputData(imgReader->GetOutput());
1017 #endif
1018                 _loadActorSTL = vtkActor::New();
1019                 _loadActorSTL->SetMapper(_loadSTLMapper);
1020                 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
1021                 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
1022                 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
1023                 ren->AddActor(_loadActorSTL);
1024                 imgReader->Delete();
1025         }
1026         //By default *always* update e_installation_directory:
1027         //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) ); 
1028         //_mar->saveParameters( );
1029 }
1030
1031
1032
1033 // ------------------------------------------------------------------------
1034 // END JOIN FUNCTIONS - DHC
1035 // ------------------------------------------------------------------------
1036
1037 // ------------------------------------------------------------------------
1038 // START STL FUNCTIONS - DHC
1039 // ------------------------------------------------------------------------
1040
1041 void wxSTLWidget_03::ConfigureSTL()
1042 {
1043
1044         if(stlExterna == NULL){
1045                 stlExterna = vtkPolyData::New();
1046                 stlInterna = vtkPolyData::New();
1047
1048                 dsm1 = vtkPolyDataMapper ::New();
1049 //EED 2017-01-01 Migration VTK7
1050 #if VTK_MAJOR_VERSION <= 5
1051                 dsm1->SetInput(stlInterna); 
1052 #else
1053                 dsm1->SetInputData(stlInterna); 
1054 #endif
1055                 dsm1->ScalarVisibilityOff();
1056
1057                 actorInternal = vtkActor::New();
1058                 actorInternal->SetMapper (dsm1);
1059                 actorInternal->GetProperty()->SetColor (0,1,0);
1060
1061                 dsm2 = vtkPolyDataMapper ::New();
1062
1063 //EED 2017-01-01 Migration VTK7
1064 #if VTK_MAJOR_VERSION <= 5
1065                 dsm2->SetInput(stlExterna);
1066 #else
1067                 dsm2->SetInputData(stlExterna);
1068 #endif
1069
1070                 dsm2->ScalarVisibilityOff();
1071
1072                 actorExternal= vtkActor::New();
1073                 actorExternal->SetMapper (dsm2);
1074                 actorExternal->GetProperty()->SetRepresentationToWireframe();
1075
1076         //    vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
1077                 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
1078                 ren->AddActor(actorInternal);
1079                 ren->AddActor(actorExternal);
1080
1081                 stlExtractor = new vtkSTLExtractor();  
1082
1083         }
1084
1085         
1086 }
1087
1088 void wxSTLWidget_03::generateSTLSurfaces()
1089 {
1090 // EED 09Janvier2007
1091 //      stlExtractor->setVolume(_2_prgov->GetVolumen());
1092
1093         stlExtractor->setVolume(cast4->GetOutput());
1094
1095         stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
1096         stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
1097         stlExtractor->calculate();
1098         stlInterna->DeepCopy(stlExtractor->getInnerSurface());
1099         stlExterna->DeepCopy(stlExtractor->getOuterSurface());
1100 }
1101
1102
1103 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
1104         double value = ((double)stlSliderOpacityExternal->GetValue())/100;
1105     actorExternal->GetProperty( )->SetOpacity( value );
1106         Refresh();
1107 }
1108
1109
1110 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
1111         double value = ((double)stlSliderOpacityInternal->GetValue())/100;
1112     actorInternal->GetProperty( )->SetOpacity( value );
1113         Refresh();
1114 }
1115
1116 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
1117 {
1118
1119         wxString dirSTL;// = _mar->_parameters->getStringParam( 
1120     //marParameters::e_installation_directory ); 
1121         dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
1122
1123         
1124 //      wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
1125
1126
1127 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1128 #if wxMAJOR_VERSION <= 2
1129         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
1130 #else
1131         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxFD_SAVE );
1132 #endif
1133
1134
1135         if( dialog.ShowModal( ) == wxID_OK ) 
1136         {
1137            
1138         
1139                 // ------------------------------------------------------------------------
1140                 //  1.  GENERATE STL FILES
1141                 // ------------------------------------------------------------------------
1142 //              const char* fileprefix = "c:\\Creatis\\";
1143                 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
1144                 std::string filename;
1145
1146                 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
1147
1148         vtkClosePolyData                                *cpd    = vtkClosePolyData::New();
1149         vtkTriangleFilter                               *filtro = vtkTriangleFilter::New();
1150                 vtkPolyDataConnectivityFilter   *pdcf   = vtkPolyDataConnectivityFilter::New();
1151
1152                 // 1.2 se escribe a disco el archivo stl de la superficie interna
1153 //EED 2017-01-01 Migration VTK7
1154 #if VTK_MAJOR_VERSION <= 5
1155                 filtro->SetInput(stlInterna);
1156         pdcf->SetInput( filtro->GetOutput() );
1157         cpd->SetInput( pdcf->GetOutput() );
1158         cpd->Update();
1159 #else
1160                 filtro->SetInputData(stlInterna);
1161         pdcf->SetInputData( filtro->GetOutput() );
1162         cpd->SetInputData( pdcf->GetOutput() );
1163 #endif
1164         vtkSTLWriter *writerI = vtkSTLWriter::New();
1165 //EED 2017-01-01 Migration VTK7
1166 #if VTK_MAJOR_VERSION <= 5
1167         writerI->SetInput( cpd->GetOutput() );
1168 #else
1169         writerI->SetInputData( cpd->GetOutput() );
1170 #endif
1171 //        prefix = fileprefix;
1172                 filename=prefix+"_internal.stl";
1173         writerI->SetFileName(filename.c_str());
1174         writerI->SetFileTypeToASCII();
1175         writerI->Write();
1176         writerI->Delete();
1177
1178                 // 1.3 se escribe a disco el archivo stl de la superficie externa
1179 //EED 2017-01-01 Migration VTK7
1180 #if VTK_MAJOR_VERSION <= 5
1181                 filtro->SetInput(stlExterna);
1182 #else
1183                 filtro->SetInputData(stlExterna);
1184 #endif
1185         cpd->Update();
1186         vtkSTLWriter *writerE = vtkSTLWriter::New();
1187 //EED 2017-01-01 Migration VTK7
1188 #if VTK_MAJOR_VERSION <= 5
1189         writerE->SetInput( cpd->GetOutput() );
1190 #else
1191         writerE->SetInputData( cpd->GetOutput() );
1192 #endif
1193 //        prefix = fileprefix;
1194                 filename=prefix+"_external.stl";
1195         writerE->SetFileName( filename.c_str() );
1196         writerE->SetFileTypeToASCII();
1197         writerE->Write();
1198         writerE->Delete();
1199    
1200         filtro->Delete();
1201         cpd->Delete();
1202         pdcf->Delete();
1203         }
1204
1205         //By default *always* update e_installation_directory:
1206         //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) ); 
1207         //_mar->saveParameters( );
1208 }
1209
1210
1211 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1212 {
1213         wxBusyCursor wait;
1214         _stlDeltaGaussLevel  = ((double)stlSliderDeltaGauss->GetValue())/100;
1215         generateSTLSurfaces();
1216         Refresh();
1217 }
1218
1219
1220 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1221 {
1222         wxBusyCursor wait;
1223         _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1224         generateSTLSurfaces();
1225         Refresh();
1226         
1227 }
1228
1229
1230 // ------------------------------------------------------------------------
1231 // END STL FUNCTIONS - DHC
1232 // ------------------------------------------------------------------------
1233
1234
1235
1236
1237
1238
1239