2 #include "vtkObjectFactory.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"
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"
43 #include "vtkStripper.h"
44 #include <vtkSTLReader.h>
47 #include "vtkTriangleFilter.h"
48 #include "vtkSTLWriter.h"
49 #include "vtkPolyDataConnectivityFilter.h"
50 #include "vtkClosePolyData.h"
51 #include "vtkAppendFilter.h"
53 #include "wxSTLWidget_02.h"
55 #include <wx/splitter.h>
57 #include <wx/filedlg.h>
61 //-------------------------------------------------------------------
62 //-------------------------------------------------------------------
63 //-------------------------------------------------------------------
64 wxSTLWidget_02::wxSTLWidget_02(wxWindow *parent, marInterface* mar)
65 : wxPanel( parent, -1)
67 _sensibility_JF = 0.5;
68 _maxSphereSize_JF = 30;
69 _minSphereSize_JF = 5;
71 _stlMarchingCubesLevel = 128;
72 _stlDeltaGaussLevel = 100;
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) );
82 mar->_experiment->getVOI( voi );
83 _mar->_experiment->setVOI( voi );
84 _mar->SetDicom(mar->_dicom);
85 _mar->initExperiment( );
88 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
89 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
90 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
91 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
93 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
94 pnlSplitter -> SetMinimumPaneSize( 150 );
95 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
96 this -> SetSizer(sizer);
98 // Result 2: Volume + Axis
101 _2_stripfinal = NULL;
102 _2_isoMapperMC6 = NULL;
103 _2_isoActorMC6 = NULL;
111 _loadSTLMapper = NULL;
112 _loadActorSTL = NULL;
116 arteryImageData = NULL;
117 joinMarchingCubes = NULL;
123 //-------------------------------------------------------------------
124 wxSTLWidget_02::~wxSTLWidget_02(){
128 //-------------------------------------------------------------------
129 wxPanel* wxSTLWidget_02::CreateViewPanel(wxWindow *parent)
131 wxPanel *panel = new wxPanel(parent,-1);
132 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
136 vtkImageData *imagedata;
137 imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
139 _wxMaracasMPR = new wxMaracasMPR( panel, new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
140 _wxMaracasMPR->ConfigureVTK();
142 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
143 panel->SetSizer(sizer);
144 panel->SetAutoLayout(true);
145 panel->SetSize(400,400);
149 //-------------------------------------------------------------------
150 wxPanel* wxSTLWidget_02::CreateControlPanel(wxWindow *parent)
152 wxPanel *panel = new wxPanel(parent,-1);
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 );
160 int tmp_sensibility= (int)(_sensibility_JF*100.0);
161 _sl_sensibility_JF->SetValue( tmp_sensibility );
163 _opacity_Res2VolJF ->SetSize(250,20); // Result 2 Volume 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"));
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 );
175 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
176 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
177 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
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);
190 sizer->Add(btnExtractTree2_JF);
191 sizer->Add(btnEraseTree2_JF);
193 wxButton *btnJoinRegions = new wxButton(panel,-1,_T("Join Regions"));
194 sizer->Add(btnJoinRegions);
195 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
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(" ")));
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 );
219 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
220 sizer->Add(stlSliderDeltaGauss);
222 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
223 sizer->Add(stlSliderMarchingCubes);
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);
228 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
229 sizer->Add(stlSliderOpacityInternal);
231 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
232 sizer->Add(stlSliderOpacityExternal);
234 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
235 sizer->Add(btnFileSTL);
236 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
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);
247 panel->SetSizer(sizer);
248 panel->SetAutoLayout(true);
249 panel->SetSize(400,600);
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 );
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 );
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 );
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
279 //------------------------------------------------------------------------
281 void wxSTLWidget_02::Refresh()
283 _wxMaracasMPR->RefreshView();
286 //------------------------------------------------------------------------
288 void wxSTLWidget_02::ConfigureVTK()
291 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
293 //CONFIGURACION ADICIONAL
294 this->ConfigureSTL();
295 this->ConfigureJoinRegions();
301 void wxSTLWidget_02::ResetTree2_JF()
304 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
307 ren->RemoveActor(_2_isoActorMC6);
310 ren->RemoveActor(_2_stripfinal);
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(); }
324 _2_stripfinal = NULL;
325 _2_isoMapperMC6 = NULL;
326 _2_isoActorMC6 = NULL;
335 //------------------------------------------------------------------------
336 void wxSTLWidget_02::ExtractTree2_JF(int x, int y, int z)
339 double opacity_Res2VolJF = ((double)_opacity_Res2VolJF->GetValue())/100;
340 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
342 double puntoactualprov[3];
346 puntoactualprov[0]=x;
347 puntoactualprov[1]=y;
348 puntoactualprov[2]=z;
350 imagedata->GetSpacing(espprin);
351 imagedata->GetExtent(extprin);
353 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
354 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
355 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
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);
368 //--------------------------------------------------------
370 marAxis *maraxis = this->_mar->_experiment->getAxis( );
374 vtkPolyData *inputAxisRadio = maraxis->GetAxisData();
375 _2_prgov->distanciaejes(inputAxisRadio,_2_prgov->GetOutput());
380 //--------------------------------------------------------
384 if (arteryImageData){
385 arteryImageData = joiner->join(arteryImageData, _2_prgov->GetVolumen());
388 arteryImageData = _2_prgov->GetVolumen();
396 // Visualisation - result vascular tree
397 vtkPolyData *polydata = _2_prgov->GetOutput();
398 _2_mapfinal = vtkPolyDataMapper::New();
399 _2_mapfinal->SetInput(polydata);
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();
407 // Visualisation - result volume
409 _2_isoMC6 = vtkMarchingCubes::New();
410 //_2_isoMC6->SetInput(_2_prgov->GetVolumen());
411 _2_isoMC6->SetInput(arteryImageData);
412 _2_isoMC6->SetValue(0, 128);
415 _2_isoMapperMC6 = vtkPolyDataMapper::New();
416 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
417 _2_isoMapperMC6->ScalarVisibilityOff();
418 _2_isoMapperMC6->ImmediateModeRenderingOn();
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 );
427 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
428 ren->AddActor(_2_isoActorMC6);
429 ren->AddActor(_2_stripfinal);
433 //------------------------------------------------------------------------
434 void wxSTLWidget_02::OnSensibility(wxScrollEvent& event)
436 _sensibility_JF = (double)(_sl_sensibility_JF->GetValue())/100;
438 //------------------------------------------------------------------------
439 void wxSTLWidget_02::OnOpacity_Res2VolJF(wxScrollEvent& event)
441 if (_2_isoActorMC6!=NULL){
442 double value = ((double)_opacity_Res2VolJF->GetValue())/100;
443 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
447 //------------------------------------------------------------------------
448 void wxSTLWidget_02::OnMaxSphereSize_JF(wxScrollEvent& event)
450 _maxSphereSize_JF = _sl_maxSphereSize_JF->GetValue();
452 //------------------------------------------------------------------------
453 void wxSTLWidget_02::OnMinSphereSize_JF(wxScrollEvent& event)
455 _minSphereSize_JF = _sl_minSphereSize_JF->GetValue();
457 //------------------------------------------------------------------------
458 void wxSTLWidget_02::OnBtnExtractTree2_JF(wxCommandEvent& event)
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 //------------------------------------
470 //------------------------------------------------------------------------
471 void wxSTLWidget_02::OnBtnEraseTree2_JF(wxCommandEvent& event)
476 //------------------------------------------------------------------------
477 void wxSTLWidget_02::OnOpacitySTLFile(wxScrollEvent& event)
479 if (_loadActorSTL!=NULL)
481 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
482 _loadActorSTL->GetProperty( )->SetOpacity( value );
486 //------------------------------------------------------------------------
487 void wxSTLWidget_02::Reset_vtk_STLFile()
490 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
492 ren->RemoveActor(_loadActorSTL);
496 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
497 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
500 _loadSTLMapper = NULL;
501 _loadActorSTL = NULL;
504 //------------------------------------------------------------------------
505 void wxSTLWidget_02::OnBtnSTLFileErase(wxCommandEvent& event)
510 //------------------------------------------------------------------------
511 void wxSTLWidget_02::OnBtnSTLFileLoad(wxCommandEvent& event)
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( ) );
519 if( dialog.ShowModal( ) == wxID_OK )
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);
534 //By default *always* update e_installation_directory:
535 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
536 _mar->saveParameters( );
539 // ------------------------------------------------------------------------
540 // START JOIN FUNCTIONS - DHC
541 // ------------------------------------------------------------------------
542 void wxSTLWidget_02::ConfigureJoinRegions()
544 arteryImageData = NULL;
545 joiner = new vtkJoiner();
549 void wxSTLWidget_02::OnJoinRegions(wxCommandEvent& event)
553 joinMarchingCubes= vtkMarchingCubes::New();
554 joinMarchingCubes->SetInput(arteryImageData);
555 joinMarchingCubes->SetValue(0, 128);
556 joinMarchingCubes->Update();
558 joinMapper = vtkPolyDataMapper::New();
559 joinMapper->SetInput(joinMarchingCubes->GetOutput());
560 joinMapper->ScalarVisibilityOff();
561 joinMapper->ImmediateModeRenderingOn();
563 joinActor = vtkActor::New();
564 joinActor->SetMapper(joinMapper);
565 joinActor->GetProperty()->SetColor(1.0, 0.3, 1.0);
566 joinActor->GetProperty()->SetOpacity( 0.9 );
569 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
570 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
571 ren->AddActor(joinActor);
574 // ------------------------------------------------------------------------
575 // END JOIN FUNCTIONS - DHC
576 // ------------------------------------------------------------------------
578 // ------------------------------------------------------------------------
579 // START STL FUNCTIONS - DHC
580 // ------------------------------------------------------------------------
582 void wxSTLWidget_02::ConfigureSTL()
584 stlExterna = vtkPolyData::New();
585 stlInterna = vtkPolyData::New();
587 dsm1 = vtkPolyDataMapper ::New();
588 dsm1->SetInput (stlInterna);
589 dsm1->ScalarVisibilityOff();
591 actorInternal = vtkActor::New();
592 actorInternal->SetMapper (dsm1);
593 actorInternal->GetProperty()->SetColor (0,1,0);
595 dsm2 = vtkPolyDataMapper ::New();
596 dsm2->SetInput (stlExterna);
597 dsm2->ScalarVisibilityOff();
599 actorExternal= vtkActor::New();
600 actorExternal->SetMapper (dsm2);
601 actorExternal->GetProperty()->SetRepresentationToWireframe();
603 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
604 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
605 ren->AddActor(actorInternal);
606 ren->AddActor(actorExternal);
608 stlExtractor = new vtkSTLExtractor();
611 void wxSTLWidget_02::generateSTLSurfaces()
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());
622 void wxSTLWidget_02::OnOpacitySTLExternal(wxScrollEvent& event){
623 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
624 actorExternal->GetProperty( )->SetOpacity( value );
629 void wxSTLWidget_02::OnOpacitySTLInternal(wxScrollEvent& event){
630 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
631 actorInternal->GetProperty( )->SetOpacity( value );
635 void wxSTLWidget_02::OnBtnCreateFileSTL(wxCommandEvent& event)
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( ) );
644 if( dialog.ShowModal( ) == wxID_OK )
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;
655 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
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() );
664 // 1.2 se escribe a disco el archivo stl de la superficie interna
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();
675 // 1.3 se escribe a disco el archivo stl de la superficie externa
676 filtro->SetInput(stlExterna);
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();
692 //By default *always* update e_installation_directory:
693 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
694 _mar->saveParameters( );
698 void wxSTLWidget_02::OnChangeSTLGaussLevel(wxScrollEvent& event)
701 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
702 generateSTLSurfaces();
707 void wxSTLWidget_02::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
710 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
711 generateSTLSurfaces();
717 // ------------------------------------------------------------------------
718 // END STL FUNCTIONS - DHC
719 // ------------------------------------------------------------------------