]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/include/wxSTLWidget_02.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / include / wxSTLWidget_02.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "vtkObjectFactory.h"
27
28 #include "vtkActor.h"
29 #include "vtkCylinderSource.h"
30 #include "vtkPolyDataMapper.h"
31 #include "vtkRenderer.h"
32 #include "vtkRenderWindow.h"
33 #include "vtkRenderWindowInteractor.h"
34 #include "vtkProperty.h"
35 #include "vtkCamera.h"
36 #include "vtkPoints.h"
37 #include "vtkCellArray.h"
38 #include "vtkPolyData.h"
39 #include "vtkPolyDataMapper.h"
40 #include "vtkPolyDataWriter.h"
41 #include "vtkPolyDataReader.h"
42 #include "vtkImageReader.h"
43 #include "vtkImageViewer.h"
44 #include "vtkImageViewer2.h"
45 #include "vtkImageToStructuredPoints.h"
46 #include <vtkImageThreshold.h> 
47 #include "vtkImageWriter.h"
48
49
50 #include "vtkExtractVOI.h"
51 #include "vtkImageClip.h"
52 #include "vtkImageResample.h"
53 #include "vtkImageThreshold.h"
54 #include "vtkImageCast.h"
55 #include "vtkImageSeedConnectivity.h"
56 #include "vtkImageData.h"
57 #include "vtkMarchingCubes.h"
58 #include "vtkImageReslice.h"
59 #include "vtkTransform.h"
60 #include "vtkSphereSource.h"
61 #include "vtkDoubleArray.h"
62 #include "vtkPointData.h"
63 #include "vtkCommand.h"
64 #include "vtkCallbackCommand.h"
65 #include "vtkImageResample.h"
66 #include "vtkMath.h"
67 #include "vtkStripper.h"
68 #include <vtkSTLReader.h> 
69
70
71 #include "vtkTriangleFilter.h"
72 #include "vtkSTLWriter.h"
73 #include "vtkPolyDataConnectivityFilter.h"
74 #include "vtkClosePolyData.h"
75 #include "vtkAppendFilter.h"
76
77 #include "wxSTLWidget_02.h"
78
79 #include <wx/splitter.h>
80
81 #include <wx/filedlg.h>
82
83
84
85 //-------------------------------------------------------------------
86 //-------------------------------------------------------------------
87 //-------------------------------------------------------------------
88 wxSTLWidget_02::wxSTLWidget_02(wxWindow *parent, marInterface* mar)
89 : wxPanel( parent, -1) 
90 {
91         _sensibility_JF                 = 0.5;
92         _maxSphereSize_JF               = 30;
93         _minSphereSize_JF               = 5;
94
95         _stlMarchingCubesLevel  = 128;
96         _stlDeltaGaussLevel             = 100;
97
98         _mar=new marInterface();        
99         _mar->_parameters->setRescaleSlope( mar->_parameters->getRescaleSlope() );
100         _mar->_parameters->setRescaleIntercept( mar->_parameters->getRescaleIntercept() );
101         _mar->_parameters->setIntParam( marParameters::e_voxel_type, marParameters::VOX_TYPE_MINIMUM );
102         _mar->_parameters->setDoubleParam( marParameters::e_voxel_x_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_x_dimension) );
103         _mar->_parameters->setDoubleParam( marParameters::e_voxel_y_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_y_dimension) );
104         _mar->_parameters->setDoubleParam( marParameters::e_voxel_z_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_z_dimension) );
105         int voi[6];
106         mar->_experiment->getVOI( voi );
107         _mar->_experiment->setVOI( voi );
108         _mar->SetDicom(mar->_dicom);
109         _mar->initExperiment( );
110          
111
112         wxBoxSizer                      *sizer                  = new wxBoxSizer(wxVERTICAL  );
113     wxSplitterWindow    *pnlSplitter    = new wxSplitterWindow( this , -1);
114         wxPanel                         *viewPanel              = CreateViewPanel(pnlSplitter);
115         wxPanel                         *controlPanel   = CreateControlPanel(pnlSplitter);
116
117         sizer           -> Add( pnlSplitter ,1,wxGROW  ,0);
118         pnlSplitter     -> SetMinimumPaneSize( 150 );
119     pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
120         this            -> SetSizer(sizer);
121
122         // Result 2: Volume + Axis
123         _2_prgov                        = NULL;
124         _2_mapfinal                     = NULL;
125         _2_stripfinal           = NULL;
126         _2_isoMapperMC6         = NULL;
127         _2_isoActorMC6          = NULL;
128         _2_isoMC6                       = NULL;
129
130
131         //DHC STL SURFACES
132         stlInterna = NULL;
133         stlExterna = NULL;
134
135         _loadSTLMapper          = NULL;
136         _loadActorSTL           = NULL;
137
138         
139         //JOIN REGIONS
140         arteryImageData         = NULL;
141         joinMarchingCubes       = NULL;
142     joinMapper                  = NULL; 
143         joinActor                       = NULL;
144
145
146 }
147 //-------------------------------------------------------------------
148 wxSTLWidget_02::~wxSTLWidget_02(){
149         ResetTree2_JF();
150         Reset_vtk_STLFile();
151 }
152 //-------------------------------------------------------------------
153 wxPanel* wxSTLWidget_02::CreateViewPanel(wxWindow *parent)
154 {
155         wxPanel *panel          =       new wxPanel(parent,-1);
156     wxBoxSizer *sizer   =       new wxBoxSizer(wxVERTICAL);
157
158
159    // MPR
160         vtkImageData *imagedata;
161         imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
162         imagedata->Update();    
163         _wxMaracasMPR = new wxMaracasMPR( panel, new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
164         _wxMaracasMPR->ConfigureVTK();
165         
166         sizer->Add(     _wxMaracasMPR , 1, wxEXPAND, 0);
167         panel->SetSizer(sizer);
168         panel->SetAutoLayout(true);
169         panel->SetSize(400,400);
170         panel->Layout();
171         return panel;
172 }
173 //-------------------------------------------------------------------
174 wxPanel* wxSTLWidget_02::CreateControlPanel(wxWindow *parent)
175 {
176         wxPanel *panel                  = new wxPanel(parent,-1);
177         
178         _opacity_Res2VolJF              = new wxSlider( panel, -1, 25, 0, 100                            , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
179         _sl_sensibility_JF              = new wxSlider( panel, -1, 0 , 0, 100                            , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
180         _sl_maxSphereSize_JF    = new wxSlider( panel, -1, _maxSphereSize_JF, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
181         _sl_minSphereSize_JF    = new wxSlider( panel, -1, _minSphereSize_JF , 0, 20 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
182
183
184         int tmp_sensibility= (int)(_sensibility_JF*100.0);
185         _sl_sensibility_JF->SetValue( tmp_sensibility );
186
187         _opacity_Res2VolJF      ->SetSize(250,20);  // Result 2 Volume JF
188
189         //Extract Tree 2 JF
190         wxButton *btnExtractTree2_JF    = new wxButton(panel,-1,_T("Extract Tree 2 JF"));
191         wxButton *btnEraseTree2_JF              = new wxButton(panel,-1,_T("Erase Tree 2 JF"));
192
193
194         wxButton *btnReadSTLFile                        = new wxButton(panel,-1,_T("Read STL File"));
195         wxButton *btnEraseReadSTLFile           = new wxButton(panel,-1,_T("Erase STL File"));
196         _sl_opacity_STL_file                            = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
197
198
199     wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
200         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
201         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
202
203
204         sizer->Add(new wxStaticText(panel,-1,_T("  - - -  Segmentation - - - ")));
205         sizer->Add(new wxStaticText(panel,-1,_T("  "))); 
206         sizer->Add(new wxStaticText(panel,-1,_T(" % Sensibility")));
207         sizer->Add(_sl_sensibility_JF);
208         sizer->Add(new wxStaticText(panel,-1,_T(" Biggest radium")));
209         sizer->Add(_sl_maxSphereSize_JF);
210         sizer->Add(new wxStaticText(panel,-1,_T(" Minimum radium")));
211         sizer->Add(_sl_minSphereSize_JF);
212
213
214         sizer->Add(btnExtractTree2_JF);
215         sizer->Add(btnEraseTree2_JF);
216
217         wxButton *btnJoinRegions = new wxButton(panel,-1,_T("Join Regions"));
218         sizer->Add(btnJoinRegions);
219         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
220
221
222         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
223         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
224         sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
225         sizer->Add(_opacity_Res2VolJF);
226         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
227         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
228         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
229         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
230
231
232 //-- STL WIDGETS
233         
234         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
235         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
236     sizer->Add(new wxStaticText(panel,-1,_T("  - - -  STL - - - ")));
237     sizer->Add(new wxStaticText(panel,-1,_T("  ")));
238         stlSliderDeltaGauss     = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
239         stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
240         
241
242
243         sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
244         sizer->Add(stlSliderDeltaGauss);
245
246         sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
247         sizer->Add(stlSliderMarchingCubes);
248
249         stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
250         stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
251
252         sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
253         sizer->Add(stlSliderOpacityInternal);
254
255         sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
256         sizer->Add(stlSliderOpacityExternal);
257
258         wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
259         sizer->Add(btnFileSTL);
260         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
261 //-- STL WIDGETS
262         
263
264         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
265         sizer->Add(new wxStaticText(panel,-1,_T("  ")));
266         sizer->Add(btnReadSTLFile );
267         sizer->Add(btnEraseReadSTLFile );
268         sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
269         sizer->Add(_sl_opacity_STL_file);
270
271         panel->SetSizer(sizer);
272         panel->SetAutoLayout(true);
273         panel->SetSize(400,600);
274         panel->Layout();
275
276         Connect(_opacity_Res2VolJF->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &wxSTLWidget_02::OnOpacity_Res2VolJF  ); 
277         Connect(_sl_sensibility_JF->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &wxSTLWidget_02::OnSensibility        ); 
278         Connect(_sl_maxSphereSize_JF->GetId()           , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &wxSTLWidget_02::OnMaxSphereSize_JF   ); 
279         Connect(_sl_minSphereSize_JF->GetId()           , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &wxSTLWidget_02::OnMinSphereSize_JF   ); 
280
281
282         Connect(btnExtractTree2_JF->GetId()             , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnExtractTree2_JF ); 
283         Connect(btnEraseTree2_JF->GetId()               , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnEraseTree2_JF   ); 
284         Connect(btnJoinRegions->GetId()                 , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_02::OnJoinRegions        ); 
285
286         
287         Connect(btnReadSTLFile->GetId()                 , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnSTLFileLoad     ); 
288         Connect(btnEraseReadSTLFile->GetId()    , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnSTLFileErase    ); 
289         Connect(_sl_opacity_STL_file->GetId()   , wxEVT_COMMAND_SLIDER_UPDATED  , (wxObjectEventFunction) &wxSTLWidget_02::OnOpacitySTLFile             ); 
290
291
292         // -- STL CONNECT WIDGETS
293         Connect(btnFileSTL->GetId()                             , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxSTLWidget_02::OnBtnCreateFileSTL         );
294         Connect(stlSliderDeltaGauss->GetId()    , wxEVT_SCROLL_THUMBRELEASE             , (wxObjectEventFunction) &wxSTLWidget_02::OnChangeSTLGaussLevel        );
295         Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE             , (wxObjectEventFunction) &wxSTLWidget_02::OnChangeSTLMarchingCubesLevel);
296         Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnOpacitySTLInternal);
297         Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_02::OnOpacitySTLExternal);
298         // -- STL CONNECT WIDGETS
299
300         return panel;
301 }
302
303 //------------------------------------------------------------------------
304
305 void wxSTLWidget_02::Refresh()
306 {
307         _wxMaracasMPR->RefreshView();
308 }
309
310 //------------------------------------------------------------------------
311
312 void wxSTLWidget_02::ConfigureVTK()
313 {
314     wxBusyCursor wait;
315         vtkImageData    *imagedata              = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
316
317         //CONFIGURACION ADICIONAL
318     this->ConfigureSTL();
319         this->ConfigureJoinRegions();
320
321         
322 }
323
324
325 void wxSTLWidget_02::ResetTree2_JF()
326 {
327         // Remove 
328         vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
329
330     if (_2_isoActorMC6){
331                 ren->RemoveActor(_2_isoActorMC6);
332         }
333     if (_2_stripfinal){
334                 ren->RemoveActor(_2_stripfinal);
335         }
336
337         // Delete 
338         if (_2_prgov            ) {     _2_prgov                -> Delete(); }
339         if (_2_mapfinal         ) {     _2_mapfinal             -> Delete(); }
340         if (_2_stripfinal       ) {     _2_stripfinal   -> Delete(); }
341         if (_2_isoMapperMC6     ) {     _2_isoMapperMC6 -> Delete(); }
342         if (_2_isoActorMC6      ) {     _2_isoActorMC6  -> Delete(); }
343         if (_2_isoMC6           ) {     _2_isoMC6               -> Delete(); }
344
345         // Init
346         _2_prgov                = NULL;
347         _2_mapfinal             = NULL;
348         _2_stripfinal   = NULL;
349         _2_isoMapperMC6 = NULL;
350         _2_isoActorMC6  = NULL;
351         _2_isoMC6               = NULL;
352 }
353
354
355
356
357
358
359 //------------------------------------------------------------------------
360 void wxSTLWidget_02::ExtractTree2_JF(int x, int y, int z)
361 {
362         
363         double opacity_Res2VolJF = ((double)_opacity_Res2VolJF->GetValue())/100;
364         vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
365
366         double  puntoactualprov[3];
367         double  espprin[3];
368         int             extprin[6];                             
369
370         puntoactualprov[0]=x;
371         puntoactualprov[1]=y;
372         puntoactualprov[2]=z;
373         
374         imagedata->GetSpacing(espprin);
375         imagedata->GetExtent(extprin);
376
377         puntoactualprov[0]=puntoactualprov[0]*espprin[0];
378         puntoactualprov[1]=puntoactualprov[1]*espprin[1];
379         puntoactualprov[2]=puntoactualprov[2]*espprin[2];
380         
381         _2_prgov= axisExtractor02::New();
382         _2_prgov->SetParam(1);
383         _2_prgov->SetParam2(1);
384         _2_prgov->SetParam3(_sensibility_JF);
385         _2_prgov->SetMaxant(_maxSphereSize_JF);
386         _2_prgov->SetMinant(_minSphereSize_JF);
387         _2_prgov->SetInput(imagedata);
388         _2_prgov->SetPoint(puntoactualprov);
389         _2_prgov->Update();
390
391
392         //--------------------------------------------------------
393
394         marAxis *maraxis = this->_mar->_experiment->getAxis( );
395         
396
397         if (maraxis!=NULL) {
398                 vtkPolyData  *inputAxisRadio    = maraxis->GetAxisData();
399                 _2_prgov->distanciaejes(inputAxisRadio,_2_prgov->GetOutput());
400
401                         
402         }
403
404         //--------------------------------------------------------
405         
406         
407         //ADICIONAR SEGMENTO
408         if (arteryImageData){
409                 arteryImageData = joiner->join(arteryImageData, _2_prgov->GetVolumen());
410         }
411         else{
412                 arteryImageData = _2_prgov->GetVolumen();
413         }
414         
415         //ADICIONAR SEGMENTO
416
417         
418                 
419                 
420         // Visualisation - result vascular tree
421         vtkPolyData *polydata   =       _2_prgov->GetOutput();
422         _2_mapfinal = vtkPolyDataMapper::New();
423         _2_mapfinal->SetInput(polydata);
424
425         _2_stripfinal = vtkActor::New();
426         _2_stripfinal->SetMapper(_2_mapfinal);
427         _2_stripfinal->GetProperty()->SetColor(0.0, 0.0, 1.0);
428         _2_stripfinal->GetProperty()->SetLineWidth(2);
429         _2_stripfinal->GetProperty()->BackfaceCullingOff();
430
431         // Visualisation - result volume
432    
433     _2_isoMC6 = vtkMarchingCubes::New();
434     //_2_isoMC6->SetInput(_2_prgov->GetVolumen());
435         _2_isoMC6->SetInput(arteryImageData);
436     _2_isoMC6->SetValue(0, 128);
437         _2_isoMC6->Update();
438
439         _2_isoMapperMC6 = vtkPolyDataMapper::New();
440     _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
441     _2_isoMapperMC6->ScalarVisibilityOff();
442     _2_isoMapperMC6->ImmediateModeRenderingOn();
443
444         _2_isoActorMC6 = vtkActor::New();
445     _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
446     _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
447     _2_isoActorMC6->GetProperty()->SetOpacity( opacity_Res2VolJF );
448     
449         // Interface Update
450
451         vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
452         ren->AddActor(_2_isoActorMC6);
453         ren->AddActor(_2_stripfinal);
454
455 }
456
457 //------------------------------------------------------------------------
458 void wxSTLWidget_02::OnSensibility(wxScrollEvent& event)
459 {
460         _sensibility_JF = (double)(_sl_sensibility_JF->GetValue())/100;
461 }
462 //------------------------------------------------------------------------
463 void wxSTLWidget_02::OnOpacity_Res2VolJF(wxScrollEvent& event)
464 {
465         if (_2_isoActorMC6!=NULL){
466                 double value = ((double)_opacity_Res2VolJF->GetValue())/100;
467                 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
468                 Refresh();
469         }
470 }
471 //------------------------------------------------------------------------
472 void wxSTLWidget_02::OnMaxSphereSize_JF(wxScrollEvent& event)
473 {
474         _maxSphereSize_JF = _sl_maxSphereSize_JF->GetValue();
475 }
476 //------------------------------------------------------------------------
477 void wxSTLWidget_02::OnMinSphereSize_JF(wxScrollEvent& event)
478 {
479         _minSphereSize_JF = _sl_minSphereSize_JF->GetValue();
480 }
481 //------------------------------------------------------------------------
482 void wxSTLWidget_02::OnBtnExtractTree2_JF(wxCommandEvent& event)
483 {
484         wxBusyCursor wait;              
485         double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
486         double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
487         double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
488         ExtractTree2_JF( (int)(px) , (int)(py) , (int)(pz) );
489         //------------------------------------
490         generateSTLSurfaces(); //DHC: AFTER EXTRACTING THE TREE, THE STL SURFACES ARE CALCULATED.
491         //------------------------------------
492         Refresh();
493 }
494 //------------------------------------------------------------------------
495 void wxSTLWidget_02::OnBtnEraseTree2_JF(wxCommandEvent& event)
496 {
497         ResetTree2_JF();
498         Refresh();
499 }
500 //------------------------------------------------------------------------
501 void wxSTLWidget_02::OnOpacitySTLFile(wxScrollEvent& event)
502 {
503         if (_loadActorSTL!=NULL)
504         {
505                 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
506                 _loadActorSTL->GetProperty( )->SetOpacity( value );
507                 Refresh();
508         }
509 }
510 //------------------------------------------------------------------------
511 void wxSTLWidget_02::Reset_vtk_STLFile()
512 {
513         // Remove
514         vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
515     if (_loadActorSTL){
516                 ren->RemoveActor(_loadActorSTL);
517         }
518
519         // Delete 
520         if (_loadSTLMapper              ) {     _loadSTLMapper          -> Delete(); }
521         if (_loadActorSTL               ) {     _loadActorSTL           -> Delete(); }
522
523         // Init
524         _loadSTLMapper          = NULL;
525         _loadActorSTL           = NULL;
526
527 }
528 //------------------------------------------------------------------------
529 void wxSTLWidget_02::OnBtnSTLFileErase(wxCommandEvent& event)
530 {
531         Reset_vtk_STLFile();
532         Refresh();
533 }
534 //------------------------------------------------------------------------
535 void wxSTLWidget_02::OnBtnSTLFileLoad(wxCommandEvent& event)
536 {
537         wxString dirSTL = _mar->_parameters->getStringParam( 
538     marParameters::e_installation_directory ); 
539         dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
540         wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
541         dirSTL: wxGetHomeDir( ) );
542
543         if( dialog.ShowModal( ) == wxID_OK ) 
544         {
545                 Reset_vtk_STLFile();
546                 vtkSTLReader *imgReader= vtkSTLReader::New();
547                 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );  
548                 _loadSTLMapper = vtkPolyDataMapper::New();
549                 _loadSTLMapper->SetInput(imgReader->GetOutput());
550                 _loadActorSTL = vtkActor::New();
551                 _loadActorSTL->SetMapper(_loadSTLMapper);
552                 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
553                 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
554                 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
555                 ren->AddActor(_loadActorSTL);
556                 imgReader->Delete();
557         }
558         //By default *always* update e_installation_directory:
559         _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) ); 
560         _mar->saveParameters( );
561 }
562
563 // ------------------------------------------------------------------------
564 // START JOIN FUNCTIONS - DHC
565 // ------------------------------------------------------------------------
566 void wxSTLWidget_02::ConfigureJoinRegions()
567 {
568         arteryImageData = NULL;
569         joiner = new vtkJoiner();
570 }
571
572
573 void wxSTLWidget_02::OnJoinRegions(wxCommandEvent& event)
574 {
575         
576    
577     joinMarchingCubes= vtkMarchingCubes::New();
578     joinMarchingCubes->SetInput(arteryImageData);
579     joinMarchingCubes->SetValue(0, 128);
580         joinMarchingCubes->Update();
581
582         joinMapper = vtkPolyDataMapper::New();
583     joinMapper->SetInput(joinMarchingCubes->GetOutput());
584     joinMapper->ScalarVisibilityOff();
585     joinMapper->ImmediateModeRenderingOn();
586
587         joinActor = vtkActor::New();
588     joinActor->SetMapper(joinMapper);
589     joinActor->GetProperty()->SetColor(1.0, 0.3, 1.0);
590     joinActor->GetProperty()->SetOpacity( 0.9 );
591     
592         // Interface Update
593 //      vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
594         vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
595         ren->AddActor(joinActor);
596
597 }
598 // ------------------------------------------------------------------------
599 // END JOIN FUNCTIONS - DHC
600 // ------------------------------------------------------------------------
601
602 // ------------------------------------------------------------------------
603 // START STL FUNCTIONS - DHC
604 // ------------------------------------------------------------------------
605
606 void wxSTLWidget_02::ConfigureSTL()
607 {
608         stlExterna = vtkPolyData::New();
609         stlInterna = vtkPolyData::New();
610
611         dsm1 = vtkPolyDataMapper ::New();
612     dsm1->SetInput (stlInterna); 
613     dsm1->ScalarVisibilityOff();
614
615     actorInternal = vtkActor::New();
616     actorInternal->SetMapper (dsm1);
617     actorInternal->GetProperty()->SetColor (0,1,0);
618
619     dsm2 = vtkPolyDataMapper ::New();
620     dsm2->SetInput (stlExterna);
621     dsm2->ScalarVisibilityOff();
622
623     actorExternal= vtkActor::New();
624     actorExternal->SetMapper (dsm2);
625     actorExternal->GetProperty()->SetRepresentationToWireframe();
626
627 //    vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
628         vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
629     ren->AddActor(actorInternal);
630     ren->AddActor(actorExternal);
631
632         stlExtractor = new vtkSTLExtractor();  
633 }
634
635 void wxSTLWidget_02::generateSTLSurfaces()
636 {
637         stlExtractor->setVolume(_2_prgov->GetVolumen());
638         stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
639         stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
640         stlExtractor->calculate();
641         stlInterna->DeepCopy(stlExtractor->getInnerSurface());
642         stlExterna->DeepCopy(stlExtractor->getOuterSurface());
643 }
644
645
646 void wxSTLWidget_02::OnOpacitySTLExternal(wxScrollEvent& event){
647         double value = ((double)stlSliderOpacityExternal->GetValue())/100;
648     actorExternal->GetProperty( )->SetOpacity( value );
649         Refresh();
650 }
651
652
653 void wxSTLWidget_02::OnOpacitySTLInternal(wxScrollEvent& event){
654         double value = ((double)stlSliderOpacityInternal->GetValue())/100;
655     actorInternal->GetProperty( )->SetOpacity( value );
656         Refresh();
657 }
658
659 void wxSTLWidget_02::OnBtnCreateFileSTL(wxCommandEvent& event)
660 {
661
662         wxString dirSTL = _mar->_parameters->getStringParam( 
663     marParameters::e_installation_directory ); 
664         dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
665         wxDirDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
666         dirSTL: wxGetHomeDir( ) );
667
668         if( dialog.ShowModal( ) == wxID_OK ) 
669         {
670            
671         
672                 // ------------------------------------------------------------------------
673                 //  1.  GENERATE STL FILES
674                 // ------------------------------------------------------------------------
675 //              const char* fileprefix = "c:\\Creatis\\";
676                 std::string prefix( dialog.GetPath().mb_str(wxConvUTF8) );
677                 std::string filename;
678
679                 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
680
681         vtkTriangleFilter *filtro = vtkTriangleFilter::New();
682                 filtro->SetInput(stlInterna);
683                 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
684         pdcf->SetInput( filtro->GetOutput() );
685         vtkClosePolyData *cpd = vtkClosePolyData::New();
686         cpd->SetInput( pdcf->GetOutput() );
687
688                 // 1.2 se escribe a disco el archivo stl de la superficie interna
689         cpd->Update();
690         vtkSTLWriter *writerI = vtkSTLWriter::New();
691         writerI->SetInput( cpd->GetOutput() );
692 //        prefix = fileprefix;
693                 filename=prefix+"\\internal.stl";
694         writerI->SetFileName(filename.c_str());
695         writerI->SetFileTypeToASCII();
696         writerI->Write();
697         writerI->Delete();
698
699                 // 1.3 se escribe a disco el archivo stl de la superficie externa
700                 filtro->SetInput(stlExterna);
701         cpd->Update();
702         vtkSTLWriter *writerE = vtkSTLWriter::New();
703         writerE->SetInput( cpd->GetOutput() );
704 //        prefix = fileprefix;
705                 filename=prefix+"\\external.stl";
706         writerE->SetFileName( filename.c_str() );
707         writerE->SetFileTypeToASCII();
708         writerE->Write();
709         writerE->Delete();
710    
711         filtro->Delete();
712         cpd->Delete();
713         pdcf->Delete();
714         }
715
716         //By default *always* update e_installation_directory:
717         _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) ); 
718         _mar->saveParameters( );
719 }
720
721
722 void wxSTLWidget_02::OnChangeSTLGaussLevel(wxScrollEvent& event)
723 {
724         wxBusyCursor wait;
725         _stlDeltaGaussLevel  = ((double)stlSliderDeltaGauss->GetValue())/100;
726         generateSTLSurfaces();
727         Refresh();
728 }
729
730
731 void wxSTLWidget_02::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
732 {
733         wxBusyCursor wait;
734         _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
735         generateSTLSurfaces();
736         Refresh();
737         
738 }
739
740
741 // ------------------------------------------------------------------------
742 // END STL FUNCTIONS - DHC
743 // ------------------------------------------------------------------------
744
745
746
747
748
749
750