1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "vtkObjectFactory.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"
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"
67 #include "vtkStripper.h"
68 #include <vtkSTLReader.h>
71 #include "vtkTriangleFilter.h"
72 #include "vtkSTLWriter.h"
73 #include "vtkPolyDataConnectivityFilter.h"
74 #include "vtkClosePolyData.h"
75 #include "vtkAppendFilter.h"
77 #include "wxSTLWidget_02.h"
79 #include <wx/splitter.h>
81 #include <wx/filedlg.h>
85 //-------------------------------------------------------------------
86 //-------------------------------------------------------------------
87 //-------------------------------------------------------------------
88 wxSTLWidget_02::wxSTLWidget_02(wxWindow *parent, marInterface* mar)
89 : wxPanel( parent, -1)
91 _sensibility_JF = 0.5;
92 _maxSphereSize_JF = 30;
93 _minSphereSize_JF = 5;
95 _stlMarchingCubesLevel = 128;
96 _stlDeltaGaussLevel = 100;
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) );
106 mar->_experiment->getVOI( voi );
107 _mar->_experiment->setVOI( voi );
108 _mar->SetDicom(mar->_dicom);
109 _mar->initExperiment( );
112 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
113 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
114 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
115 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
117 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
118 pnlSplitter -> SetMinimumPaneSize( 150 );
119 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
120 this -> SetSizer(sizer);
122 // Result 2: Volume + Axis
125 _2_stripfinal = NULL;
126 _2_isoMapperMC6 = NULL;
127 _2_isoActorMC6 = NULL;
135 _loadSTLMapper = NULL;
136 _loadActorSTL = NULL;
140 arteryImageData = NULL;
141 joinMarchingCubes = NULL;
147 //-------------------------------------------------------------------
148 wxSTLWidget_02::~wxSTLWidget_02(){
152 //-------------------------------------------------------------------
153 wxPanel* wxSTLWidget_02::CreateViewPanel(wxWindow *parent)
155 wxPanel *panel = new wxPanel(parent,-1);
156 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
160 vtkImageData *imagedata;
161 imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
163 _wxMaracasMPR = new wxMaracasMPR( panel, new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
164 _wxMaracasMPR->ConfigureVTK();
166 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
167 panel->SetSizer(sizer);
168 panel->SetAutoLayout(true);
169 panel->SetSize(400,400);
173 //-------------------------------------------------------------------
174 wxPanel* wxSTLWidget_02::CreateControlPanel(wxWindow *parent)
176 wxPanel *panel = new wxPanel(parent,-1);
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 );
184 int tmp_sensibility= (int)(_sensibility_JF*100.0);
185 _sl_sensibility_JF->SetValue( tmp_sensibility );
187 _opacity_Res2VolJF ->SetSize(250,20); // Result 2 Volume 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"));
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 );
199 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
200 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
201 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
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);
214 sizer->Add(btnExtractTree2_JF);
215 sizer->Add(btnEraseTree2_JF);
217 wxButton *btnJoinRegions = new wxButton(panel,-1,_T("Join Regions"));
218 sizer->Add(btnJoinRegions);
219 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
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(" ")));
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 );
243 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
244 sizer->Add(stlSliderDeltaGauss);
246 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
247 sizer->Add(stlSliderMarchingCubes);
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);
252 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
253 sizer->Add(stlSliderOpacityInternal);
255 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
256 sizer->Add(stlSliderOpacityExternal);
258 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
259 sizer->Add(btnFileSTL);
260 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
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);
271 panel->SetSizer(sizer);
272 panel->SetAutoLayout(true);
273 panel->SetSize(400,600);
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 );
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 );
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 );
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
303 //------------------------------------------------------------------------
305 void wxSTLWidget_02::Refresh()
307 _wxMaracasMPR->RefreshView();
310 //------------------------------------------------------------------------
312 void wxSTLWidget_02::ConfigureVTK()
315 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
317 //CONFIGURACION ADICIONAL
318 this->ConfigureSTL();
319 this->ConfigureJoinRegions();
325 void wxSTLWidget_02::ResetTree2_JF()
328 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
331 ren->RemoveActor(_2_isoActorMC6);
334 ren->RemoveActor(_2_stripfinal);
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(); }
348 _2_stripfinal = NULL;
349 _2_isoMapperMC6 = NULL;
350 _2_isoActorMC6 = NULL;
359 //------------------------------------------------------------------------
360 void wxSTLWidget_02::ExtractTree2_JF(int x, int y, int z)
363 double opacity_Res2VolJF = ((double)_opacity_Res2VolJF->GetValue())/100;
364 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
366 double puntoactualprov[3];
370 puntoactualprov[0]=x;
371 puntoactualprov[1]=y;
372 puntoactualprov[2]=z;
374 imagedata->GetSpacing(espprin);
375 imagedata->GetExtent(extprin);
377 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
378 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
379 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
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);
392 //--------------------------------------------------------
394 marAxis *maraxis = this->_mar->_experiment->getAxis( );
398 vtkPolyData *inputAxisRadio = maraxis->GetAxisData();
399 _2_prgov->distanciaejes(inputAxisRadio,_2_prgov->GetOutput());
404 //--------------------------------------------------------
408 if (arteryImageData){
409 arteryImageData = joiner->join(arteryImageData, _2_prgov->GetVolumen());
412 arteryImageData = _2_prgov->GetVolumen();
420 // Visualisation - result vascular tree
421 vtkPolyData *polydata = _2_prgov->GetOutput();
422 _2_mapfinal = vtkPolyDataMapper::New();
423 _2_mapfinal->SetInput(polydata);
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();
431 // Visualisation - result volume
433 _2_isoMC6 = vtkMarchingCubes::New();
434 //_2_isoMC6->SetInput(_2_prgov->GetVolumen());
435 _2_isoMC6->SetInput(arteryImageData);
436 _2_isoMC6->SetValue(0, 128);
439 _2_isoMapperMC6 = vtkPolyDataMapper::New();
440 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
441 _2_isoMapperMC6->ScalarVisibilityOff();
442 _2_isoMapperMC6->ImmediateModeRenderingOn();
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 );
451 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
452 ren->AddActor(_2_isoActorMC6);
453 ren->AddActor(_2_stripfinal);
457 //------------------------------------------------------------------------
458 void wxSTLWidget_02::OnSensibility(wxScrollEvent& event)
460 _sensibility_JF = (double)(_sl_sensibility_JF->GetValue())/100;
462 //------------------------------------------------------------------------
463 void wxSTLWidget_02::OnOpacity_Res2VolJF(wxScrollEvent& event)
465 if (_2_isoActorMC6!=NULL){
466 double value = ((double)_opacity_Res2VolJF->GetValue())/100;
467 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
471 //------------------------------------------------------------------------
472 void wxSTLWidget_02::OnMaxSphereSize_JF(wxScrollEvent& event)
474 _maxSphereSize_JF = _sl_maxSphereSize_JF->GetValue();
476 //------------------------------------------------------------------------
477 void wxSTLWidget_02::OnMinSphereSize_JF(wxScrollEvent& event)
479 _minSphereSize_JF = _sl_minSphereSize_JF->GetValue();
481 //------------------------------------------------------------------------
482 void wxSTLWidget_02::OnBtnExtractTree2_JF(wxCommandEvent& event)
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 //------------------------------------
494 //------------------------------------------------------------------------
495 void wxSTLWidget_02::OnBtnEraseTree2_JF(wxCommandEvent& event)
500 //------------------------------------------------------------------------
501 void wxSTLWidget_02::OnOpacitySTLFile(wxScrollEvent& event)
503 if (_loadActorSTL!=NULL)
505 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
506 _loadActorSTL->GetProperty( )->SetOpacity( value );
510 //------------------------------------------------------------------------
511 void wxSTLWidget_02::Reset_vtk_STLFile()
514 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
516 ren->RemoveActor(_loadActorSTL);
520 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
521 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
524 _loadSTLMapper = NULL;
525 _loadActorSTL = NULL;
528 //------------------------------------------------------------------------
529 void wxSTLWidget_02::OnBtnSTLFileErase(wxCommandEvent& event)
534 //------------------------------------------------------------------------
535 void wxSTLWidget_02::OnBtnSTLFileLoad(wxCommandEvent& event)
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( ) );
543 if( dialog.ShowModal( ) == wxID_OK )
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);
558 //By default *always* update e_installation_directory:
559 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
560 _mar->saveParameters( );
563 // ------------------------------------------------------------------------
564 // START JOIN FUNCTIONS - DHC
565 // ------------------------------------------------------------------------
566 void wxSTLWidget_02::ConfigureJoinRegions()
568 arteryImageData = NULL;
569 joiner = new vtkJoiner();
573 void wxSTLWidget_02::OnJoinRegions(wxCommandEvent& event)
577 joinMarchingCubes= vtkMarchingCubes::New();
578 joinMarchingCubes->SetInput(arteryImageData);
579 joinMarchingCubes->SetValue(0, 128);
580 joinMarchingCubes->Update();
582 joinMapper = vtkPolyDataMapper::New();
583 joinMapper->SetInput(joinMarchingCubes->GetOutput());
584 joinMapper->ScalarVisibilityOff();
585 joinMapper->ImmediateModeRenderingOn();
587 joinActor = vtkActor::New();
588 joinActor->SetMapper(joinMapper);
589 joinActor->GetProperty()->SetColor(1.0, 0.3, 1.0);
590 joinActor->GetProperty()->SetOpacity( 0.9 );
593 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
594 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
595 ren->AddActor(joinActor);
598 // ------------------------------------------------------------------------
599 // END JOIN FUNCTIONS - DHC
600 // ------------------------------------------------------------------------
602 // ------------------------------------------------------------------------
603 // START STL FUNCTIONS - DHC
604 // ------------------------------------------------------------------------
606 void wxSTLWidget_02::ConfigureSTL()
608 stlExterna = vtkPolyData::New();
609 stlInterna = vtkPolyData::New();
611 dsm1 = vtkPolyDataMapper ::New();
612 dsm1->SetInput (stlInterna);
613 dsm1->ScalarVisibilityOff();
615 actorInternal = vtkActor::New();
616 actorInternal->SetMapper (dsm1);
617 actorInternal->GetProperty()->SetColor (0,1,0);
619 dsm2 = vtkPolyDataMapper ::New();
620 dsm2->SetInput (stlExterna);
621 dsm2->ScalarVisibilityOff();
623 actorExternal= vtkActor::New();
624 actorExternal->SetMapper (dsm2);
625 actorExternal->GetProperty()->SetRepresentationToWireframe();
627 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
628 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
629 ren->AddActor(actorInternal);
630 ren->AddActor(actorExternal);
632 stlExtractor = new vtkSTLExtractor();
635 void wxSTLWidget_02::generateSTLSurfaces()
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());
646 void wxSTLWidget_02::OnOpacitySTLExternal(wxScrollEvent& event){
647 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
648 actorExternal->GetProperty( )->SetOpacity( value );
653 void wxSTLWidget_02::OnOpacitySTLInternal(wxScrollEvent& event){
654 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
655 actorInternal->GetProperty( )->SetOpacity( value );
659 void wxSTLWidget_02::OnBtnCreateFileSTL(wxCommandEvent& event)
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( ) );
668 if( dialog.ShowModal( ) == wxID_OK )
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;
679 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
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() );
688 // 1.2 se escribe a disco el archivo stl de la superficie interna
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();
699 // 1.3 se escribe a disco el archivo stl de la superficie externa
700 filtro->SetInput(stlExterna);
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();
716 //By default *always* update e_installation_directory:
717 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
718 _mar->saveParameters( );
722 void wxSTLWidget_02::OnChangeSTLGaussLevel(wxScrollEvent& event)
725 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
726 generateSTLSurfaces();
731 void wxSTLWidget_02::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
734 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
735 generateSTLSurfaces();
741 // ------------------------------------------------------------------------
742 // END STL FUNCTIONS - DHC
743 // ------------------------------------------------------------------------