]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxSTLWidget_03.cxx
Support #1768 CREATIS Licence insertion
[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                 _cast->SetInput(_thresh->GetOutput());
555                 _cast->SetOutputScalarTypeToUnsignedChar();
556
557                 _connect = vtkImageSeedConnectivity::New();
558                 _connect->SetInput(_cast->GetOutput());
559                 _connect->SetInputConnectValue(255);
560                 _connect->SetOutputConnectedValue(255);
561                 _connect->SetOutputUnconnectedValue(0);
562
563                 cast3 = vtkImageCast::New();
564                 cast3->SetInput(_connect->GetOutput());
565                 cast3->SetOutputScalarTypeToUnsignedShort();
566
567                 _thresh2 = vtkImageThreshold::New();
568                 //_thresh2->ReleaseDataFlagOff();
569                 _thresh2->SetInValue(255);
570                 _thresh2->SetOutputScalarTypeToUnsignedShort();
571                 _thresh2->SetOutValue(0);
572                 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
573
574                 cast2 = vtkImageCast::New();
575                 cast2->SetInput(_thresh2->GetOutput());
576                 cast2->SetOutputScalarTypeToUnsignedChar();
577                 _connect2 = vtkImageSeedConnectivity::New();
578                 _connect2->SetInput(cast2->GetOutput());
579                 _connect2->SetInputConnectValue(255);
580                 _connect2->SetOutputConnectedValue(255);
581                 _connect2->SetOutputUnconnectedValue(0);
582
583                 cast4 = vtkImageCast::New();
584                 cast4->SetInput(_connect2->GetOutput());
585                 cast4->SetOutputScalarTypeToUnsignedShort();
586         }
587         _thresh->RemoveAllInputs();
588         _thresh->SetInput(_imagedata);  
589         _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());    
590         _thresh->Update();
591         
592         _cast->Update();  
593         
594
595         _connect->RemoveAllSeeds();
596         _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
597         //_connect->Update();   
598         //cast3->Update();
599 //SIL// 
600         _thresh2->RemoveAllInputs();
601         _thresh2->SetInput(_imagedata); 
602         _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
603         _thresh2->Update();
604         cast2->Update();
605         _connect2->RemoveAllSeeds();
606         _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
607         //_connect2->Update();  
608         //cast4->Update();
609 }
610
611 //------------------------------------------------------------------------
612
613
614
615 void wxSTLWidget_03::ConfigureVTK()
616 {
617         wxBusyCursor wait;
618 //      vtkImageData    *imagedata              = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
619         //marImageData  *marimagedata;//                = _mar->_experiment->getDynData( )->GetMarImageData();
620         
621         //CONFIGURACION ADICIONAL
622         this->ConfigureSTL();
623         //this->ConfigureProcessing(marimagedata,0,0,0);
624         
625 }
626
627 //------------------------------------------------------------------------
628
629 void wxSTLWidget_03::ResetTree2_JF()
630 {
631         // Remove 
632
633         try{
634
635                 
636
637                 // Delete 
638         //      if (_2_prgov            ) {     _2_prgov                -> Delete(); }
639                 if (_2_mapfinal         ) {     _2_mapfinal             -> Delete(); }
640                 if (_2_stripfinal       ) {     _2_stripfinal   -> Delete(); }
641                 if (_2_isoMapperMC6     ) {     _2_isoMapperMC6 -> Delete(); }
642                 if (_2_isoActorMC6      ) {     _2_isoActorMC6  -> Delete(); }
643                 if (_2_isoMC6           ) {     _2_isoMC6               -> Delete(); }
644
645                 // Init
646         //      _2_prgov                = NULL;
647                 _2_mapfinal             = NULL;
648                 _2_stripfinal   = NULL;
649                 _2_isoMapperMC6 = NULL;
650                 _2_isoActorMC6  = NULL;
651                 _2_isoMC6               = NULL;
652
653                 
654                 //vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
655
656                 /*if (_2_isoActorMC6){
657                         ren->RemoveActor(_2_isoActorMC6);
658                 }
659                 if (_2_stripfinal){
660                         ren->RemoveActor(_2_stripfinal);
661                 }*/
662
663                 
664         }catch(char* e){
665                 std::cout<<e<<std::endl;
666         }
667 }
668
669
670
671
672
673
674 //------------------------------------------------------------------------
675 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
676 {
677         
678         double opacityvol               = ((double)_opacity_Vol->GetValue())/100;
679 //      vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
680
681         double  puntoactualprov[3];
682         double  espprin[3];
683         int             extprin[6];                             
684
685
686         puntoactualprov[0]      =       x;
687         puntoactualprov[1]      =       y;
688         puntoactualprov[2]      =       z;
689         
690         _imagedata->UpdateInformation();
691         _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
692         _imagedata->Update();
693
694         _imagedata->GetSpacing(espprin);
695         _imagedata->GetExtent(extprin);
696
697
698
699
700         _connect->RemoveAllSeeds ();
701         _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
702         _connect->Update();
703         cast3->Update();
704
705
706
707         _thresh->ThresholdBetween(3000, 3002 );
708         _thresh2->ThresholdBetween(3000, 3001);
709 //      _thresh->Update();
710 //      _thresh2->Update();
711
712         _thresh->ThresholdBetween(_minSize, _range[1] );
713         _thresh->Update();
714
715         _thresh2->ThresholdBetween(_minSize, _maxSize);
716         _thresh2->Update();
717
718         cast2->Update();
719         _connect2->RemoveAllSeeds ();
720         _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
721         _connect2->Update();
722         cast4->Update();
723
724
725
726
727         // Visualisation - result volume
728    
729     _2_isoMC6 = vtkMarchingCubes::New();
730         _2_isoMC6->SetInput(cast4->GetOutput());
731
732     _2_isoMC6->SetValue(0, 128);
733         _2_isoMC6->Update();
734
735         _2_isoMapperMC6 = vtkPolyDataMapper::New();
736     _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
737     _2_isoMapperMC6->ScalarVisibilityOff();
738     _2_isoMapperMC6->ImmediateModeRenderingOn();
739
740         vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
741
742         if (_2_isoActorMC6!=NULL)
743         {
744                 ren->RemoveActor(_2_isoActorMC6);
745         }
746
747
748         _2_isoActorMC6 = vtkActor::New();
749     _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
750     _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
751     _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
752     
753         // Interface Update
754
755         ren->AddActor(_2_isoActorMC6);
756
757 }
758
759 //------------------------------------------------------------------------
760 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
761 {
762         if (_2_isoActorMC6!=NULL){
763                 double value = ((double)_opacity_Vol->GetValue())/100;
764                 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
765                 Refresh();
766         }
767 }
768 //------------------------------------------------------------------------
769
770 void wxSTLWidget_03::OnMinSpin          (       wxScrollEvent &          event           )      
771 {
772         /*wxSlider *sl_A=_sl_minSize;
773         wxSlider *sl_B=_sl_minSizeSpin;
774         int value = sl_A->GetValue();
775         int delta=(int)pow( 4 , sl_B->GetValue() );
776         int min=value - delta/2;
777         int max=value + delta/2;
778         if (min<0)
779         {
780                 min=0;
781                 max=delta;
782         }
783         sl_A->SetRange(min,max);
784
785
786         */
787 }
788
789 //------------------------------------------------------------------------
790
791 void wxSTLWidget_03::OnMaxSpin          (       wxScrollEvent &          event           )      
792 {
793         /*wxSlider *sl_A=_sl_maxSize;
794         wxSlider *sl_B=_sl_maxSizeSpin;
795         int value = sl_A->GetValue();
796         int delta = (int)pow( 4 , sl_B->GetValue() );
797         int min=value - delta/2;
798         int max=value + delta/2;
799         if (min<0)
800         {
801                 min=0;
802                 max=delta;
803         }
804         sl_A->SetRange(min,max);*/      
805 }
806
807 //------------------------------------------------------------------------
808
809 void wxSTLWidget_03::OnRangeSpin        (       wxScrollEvent &          event           )      
810 {
811         wxSlider *sl_B=_sl_RangeSizeSpin;
812
813         int value = lastResizeRef_Value;
814         int delta = (int)pow((double) 4 , (double)sl_B->GetValue() );
815         int startResized = value - delta/2;
816         int endResized = value + delta/2;
817
818         if( startResized < minRangeValue )
819                 startResized = minRangeValue;
820
821         if( endResized > maxRangeValue )
822                 endResized = maxRangeValue;
823
824         sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
825         sl_barrange_segmentation -> RefreshForce();     
826 }
827
828 //------------------------------------------------------------------------
829 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
830 {
831         lastResizeRef_Value = sl_barrange_segmentation->GetStart();
832 }
833 //------------------------------------------------------------------------
834 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
835 {
836         lastResizeRef_Value = sl_barrange_segmentation->GetEnd();   
837 }
838 //------------------------------------------------------------------------
839 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
840 {
841         lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
842 }
843 //------------------------------------------------------------------------
844
845 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
846 {
847         wxString dirSTL;// = _mar->_parameters->getStringParam( 
848     //marParameters::e_installation_directory ); 
849         dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
850         wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
851         dirSTL: wxGetHomeDir( ) );
852
853         if( dialog.ShowModal( ) == wxID_OK ) 
854         {
855                 vtkMetaImageWriter  *writer= vtkMetaImageWriter::New();
856                 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );     
857                 writer->SetInput(cast4->GetOutput());
858                 writer->Write();
859                 writer->Delete();
860         }
861 }
862
863 //------------------------------------------------------------------------
864 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
865 {
866         /*wxBusyCursor wait;
867         _minSize = _sl_minSize->GetValue();
868         _maxSize = _sl_maxSize->GetValue();
869
870         double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
871         double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
872         double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
873         ExtractSurface((int)(px),(int)(py),(int)(pz));
874         generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
875
876         Refresh();
877 */
878         //SIL//
879         wxBusyCursor wait;
880         _minSize = sl_barrange_segmentation->GetStart();
881         _maxSize = sl_barrange_segmentation->GetEnd();
882
883         double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
884         double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
885         double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
886         ExtractSurface((int)(px),(int)(py),(int)(pz));
887         generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
888
889         Refresh();
890 }
891
892 //------------------------------------------------------------------------
893 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
894 {
895         if (_loadActorSTL!=NULL)
896         {
897                 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
898                 _loadActorSTL->GetProperty( )->SetOpacity( value );
899                 Refresh();
900         }
901 }
902 //------------------------------------------------------------------------
903 void wxSTLWidget_03::Reset_vtk_STLFile()
904 {
905         // Remove
906         try{
907                 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
908                 if (_loadActorSTL){
909                         ren->RemoveActor(_loadActorSTL);
910                 }
911
912                 // Delete 
913                 if (_loadSTLMapper              ) {     _loadSTLMapper          -> Delete(); }
914                 if (_loadActorSTL               ) {     _loadActorSTL           -> Delete(); }
915
916                 // Init
917                 _loadSTLMapper          = NULL;
918                 _loadActorSTL           = NULL;
919         }catch(char * e){
920                 std::cout<<e<<std::endl;
921         }
922
923 }
924 //------------------------------------------------------------------------
925 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
926 {
927         Reset_vtk_STLFile();
928         Refresh();
929 }
930 //------------------------------------------------------------------------
931 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
932 {
933         wxString dirSTL;// = _mar->_parameters->getStringParam( 
934     //marParameters::e_installation_directory ); 
935         dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
936         wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
937         dirSTL: wxGetHomeDir( ) );
938
939         if( dialog.ShowModal( ) == wxID_OK ) 
940         {
941                 Reset_vtk_STLFile();
942                 vtkSTLReader *imgReader= vtkSTLReader::New();
943                 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );  
944                 _loadSTLMapper = vtkPolyDataMapper::New();
945                 _loadSTLMapper->SetInput(imgReader->GetOutput());
946                 _loadActorSTL = vtkActor::New();
947                 _loadActorSTL->SetMapper(_loadSTLMapper);
948                 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
949                 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
950                 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
951                 ren->AddActor(_loadActorSTL);
952                 imgReader->Delete();
953         }
954         //By default *always* update e_installation_directory:
955         //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) ); 
956         //_mar->saveParameters( );
957 }
958
959
960
961 // ------------------------------------------------------------------------
962 // END JOIN FUNCTIONS - DHC
963 // ------------------------------------------------------------------------
964
965 // ------------------------------------------------------------------------
966 // START STL FUNCTIONS - DHC
967 // ------------------------------------------------------------------------
968
969 void wxSTLWidget_03::ConfigureSTL()
970 {
971
972         if(stlExterna == NULL){
973                 stlExterna = vtkPolyData::New();
974                 stlInterna = vtkPolyData::New();
975
976                 dsm1 = vtkPolyDataMapper ::New();
977                 dsm1->SetInput (stlInterna); 
978                 dsm1->ScalarVisibilityOff();
979
980                 actorInternal = vtkActor::New();
981                 actorInternal->SetMapper (dsm1);
982                 actorInternal->GetProperty()->SetColor (0,1,0);
983
984                 dsm2 = vtkPolyDataMapper ::New();
985                 dsm2->SetInput (stlExterna);
986                 dsm2->ScalarVisibilityOff();
987
988                 actorExternal= vtkActor::New();
989                 actorExternal->SetMapper (dsm2);
990                 actorExternal->GetProperty()->SetRepresentationToWireframe();
991
992         //    vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
993                 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
994                 ren->AddActor(actorInternal);
995                 ren->AddActor(actorExternal);
996
997                 stlExtractor = new vtkSTLExtractor();  
998
999         }
1000
1001         
1002 }
1003
1004 void wxSTLWidget_03::generateSTLSurfaces()
1005 {
1006 // EED 09Janvier2007
1007 //      stlExtractor->setVolume(_2_prgov->GetVolumen());
1008
1009         stlExtractor->setVolume(cast4->GetOutput());
1010
1011         stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
1012         stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
1013         stlExtractor->calculate();
1014         stlInterna->DeepCopy(stlExtractor->getInnerSurface());
1015         stlExterna->DeepCopy(stlExtractor->getOuterSurface());
1016 }
1017
1018
1019 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
1020         double value = ((double)stlSliderOpacityExternal->GetValue())/100;
1021     actorExternal->GetProperty( )->SetOpacity( value );
1022         Refresh();
1023 }
1024
1025
1026 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
1027         double value = ((double)stlSliderOpacityInternal->GetValue())/100;
1028     actorInternal->GetProperty( )->SetOpacity( value );
1029         Refresh();
1030 }
1031
1032 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
1033 {
1034
1035         wxString dirSTL;// = _mar->_parameters->getStringParam( 
1036     //marParameters::e_installation_directory ); 
1037         dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
1038
1039         
1040 //      wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
1041         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
1042
1043
1044         if( dialog.ShowModal( ) == wxID_OK ) 
1045         {
1046            
1047         
1048                 // ------------------------------------------------------------------------
1049                 //  1.  GENERATE STL FILES
1050                 // ------------------------------------------------------------------------
1051 //              const char* fileprefix = "c:\\Creatis\\";
1052                 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
1053                 std::string filename;
1054
1055                 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
1056
1057         vtkTriangleFilter *filtro = vtkTriangleFilter::New();
1058                 filtro->SetInput(stlInterna);
1059                 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
1060         pdcf->SetInput( filtro->GetOutput() );
1061         vtkClosePolyData *cpd = vtkClosePolyData::New();
1062         cpd->SetInput( pdcf->GetOutput() );
1063
1064                 // 1.2 se escribe a disco el archivo stl de la superficie interna
1065         cpd->Update();
1066         vtkSTLWriter *writerI = vtkSTLWriter::New();
1067         writerI->SetInput( cpd->GetOutput() );
1068 //        prefix = fileprefix;
1069                 filename=prefix+"_internal.stl";
1070         writerI->SetFileName(filename.c_str());
1071         writerI->SetFileTypeToASCII();
1072         writerI->Write();
1073         writerI->Delete();
1074
1075                 // 1.3 se escribe a disco el archivo stl de la superficie externa
1076                 filtro->SetInput(stlExterna);
1077         cpd->Update();
1078         vtkSTLWriter *writerE = vtkSTLWriter::New();
1079         writerE->SetInput( cpd->GetOutput() );
1080 //        prefix = fileprefix;
1081                 filename=prefix+"_external.stl";
1082         writerE->SetFileName( filename.c_str() );
1083         writerE->SetFileTypeToASCII();
1084         writerE->Write();
1085         writerE->Delete();
1086    
1087         filtro->Delete();
1088         cpd->Delete();
1089         pdcf->Delete();
1090         }
1091
1092         //By default *always* update e_installation_directory:
1093         //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) ); 
1094         //_mar->saveParameters( );
1095 }
1096
1097
1098 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1099 {
1100         wxBusyCursor wait;
1101         _stlDeltaGaussLevel  = ((double)stlSliderDeltaGauss->GetValue())/100;
1102         generateSTLSurfaces();
1103         Refresh();
1104 }
1105
1106
1107 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1108 {
1109         wxBusyCursor wait;
1110         _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1111         generateSTLSurfaces();
1112         Refresh();
1113         
1114 }
1115
1116
1117 // ------------------------------------------------------------------------
1118 // END STL FUNCTIONS - DHC
1119 // ------------------------------------------------------------------------
1120
1121
1122
1123
1124
1125
1126