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