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>
45 #include "vtkMetaImageWriter.h"
48 #include "vtkTriangleFilter.h"
49 #include "vtkSTLWriter.h"
50 #include "vtkPolyDataConnectivityFilter.h"
51 #include "vtkClosePolyData.h"
52 #include "vtkAppendFilter.h"
54 #include "wxSTLWidget_03.h"
56 #include <wx/splitter.h>
58 #include <wx/filedlg.h>
62 //-------------------------------------------------------------------
63 //-------------------------------------------------------------------
64 //-------------------------------------------------------------------
65 wxSTLWidget_03::wxSTLWidget_03(wxWindow *parent)//, marInterface* mar)
66 : wxPanel( parent, -1)
72 _stlMarchingCubesLevel = 128;
73 _stlDeltaGaussLevel = 100;
75 /*_mar=new marInterface();
76 _mar->_parameters->setRescaleSlope( mar->_parameters->getRescaleSlope() );
77 _mar->_parameters->setRescaleIntercept( mar->_parameters->getRescaleIntercept() );
78 _mar->_parameters->setIntParam( marParameters::e_voxel_type, marParameters::VOX_TYPE_MINIMUM );
79 _mar->_parameters->setDoubleParam( marParameters::e_voxel_x_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_x_dimension) );
80 _mar->_parameters->setDoubleParam( marParameters::e_voxel_y_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_y_dimension) );
81 _mar->_parameters->setDoubleParam( marParameters::e_voxel_z_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_z_dimension) );
83 mar->_experiment->getVOI( voi );
84 _mar->_experiment->setVOI( voi );
85 _mar->SetDicom(mar->_dicom);
86 _mar->initExperiment( );*/
89 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
90 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
91 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
92 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
94 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
95 pnlSplitter -> SetMinimumPaneSize( 150 );
96 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
98 // pnlSplitter -> SplitVertically( new wxPanel(pnlSplitter,-1), new wxPanel(pnlSplitter,-1) , 600 );
99 // pnlSplitter -> SplitVertically( viewPanel, new wxPanel(pnlSplitter,-1) , 600 );
101 this -> SetSizer(sizer);
103 // Result 2: Volume + Axis
106 _2_stripfinal = NULL;
107 _2_isoMapperMC6 = NULL;
108 _2_isoActorMC6 = NULL;
115 _loadSTLMapper = NULL;
116 _loadActorSTL = NULL;
120 arteryImageData = NULL;
121 joinMarchingCubes = NULL;
127 //-------------------------------------------------------------------
128 wxSTLWidget_03::~wxSTLWidget_03(){
132 //-------------------------------------------------------------------
133 wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
135 wxPanel *panel = new wxPanel(parent,-1);
136 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
140 //vtkImageData *imagedata;
141 //imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
142 //imagedata->Update();
143 _wxMaracasMPR = new wxMaracasMPR( panel);//JCP 10-03-2009, new marImageData(imagedata), 1 );
144 _wxMaracasMPR->ConfigureVTK();
146 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
147 panel->SetSizer(sizer);
148 panel->SetAutoLayout(true);
149 panel->SetSize(400,400);
154 void wxSTLWidget_03::setImage(vtkImageData* img){
157 _wxMaracasMPR->setMarImage(new marImageData(img), 1);
158 _wxMaracasMPR->ConfigureVTK();
160 //-------------------------------------------------------------------
161 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
163 wxPanel *panel = new wxPanel(parent,-1);
166 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
168 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
169 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
171 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
172 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
174 sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
175 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
177 panel->SetSizer(sizer);
178 panel->SetAutoLayout(true);
179 panel->SetSize(400,600);
185 //-------------------------------------------------------------------
186 wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
188 wxPanel *panel = new wxPanel(parent,-1);
191 _opacity_Vol = new wxSlider( panel, -1, 40, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
192 _opacity_Vol ->SetSize(250,20);
194 _sl_maxSize = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
195 _sl_minSize = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
197 _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
198 _sl_minSizeSpin->SetRange(1,8);
199 _sl_minSizeSpin->SetValue(5);
201 _sl_maxSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
202 _sl_maxSizeSpin->SetRange(1,8);
203 _sl_maxSizeSpin->SetValue(5);
207 _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
208 _sl_RangeSizeSpin->SetRange(1,8);
209 _sl_RangeSizeSpin->SetValue(5);
213 sl_barrange_segmentation = new mBarRange(panel, 300,70);
214 sl_barrange_segmentation -> setVisibleLabels ( true );
215 sl_barrange_segmentation -> setIfWithActualDrawed( false );
216 sl_barrange_segmentation -> setActiveStateTo ( true );
217 sl_barrange_segmentation -> setRepresentedValues (0, 2000);
218 sl_barrange_segmentation -> setDeviceBlitStart (10,10);
219 sl_barrange_segmentation -> setDeviceEndMargin(10);
220 parent->SetBackgroundColour(wxColour(255,255,255));
221 sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
224 wxButton *btnExtract = new wxButton(panel,-1,_T("Segmentation"));
225 wxButton *btnSaveBinaryFile = new wxButton(panel,-1,_T("Save Binary File"));
227 //SIL// Connect(_sl_minSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMinSpin );
228 //SIL// Connect(_sl_maxSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMaxSpin );
229 Connect(_opacity_Vol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol );
230 Connect(btnExtract->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction );
231 Connect(btnSaveBinaryFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile );
234 Connect(_sl_RangeSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin );
235 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnStartChanged_range );
236 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnEndChanged_range );
237 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnBarMoved_range );
239 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
241 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
242 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
245 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Segmentation - - - ")));
246 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
249 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
250 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
252 /*sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min")));
253 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
254 sizer->Add(_sl_minSizeSpin, 1, wxALL|wxEXPAND, 0);*/
255 //sizer->Add(_sl_minSize, 1, wxALL|wxEXPAND, 0);
257 sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
258 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
259 sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
260 sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
262 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" Threshold max")));
263 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" ")));
264 //SIL// sizer->Add(_sl_maxSizeSpin, 1, wxALL|wxEXPAND, 0);
265 //SIL//sizer->Add(_sl_maxSize, 1, wxALL|wxEXPAND, 0);
267 sizer->Add(btnExtract);
268 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
270 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
271 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
272 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
273 sizer->Add(_opacity_Vol);
275 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
276 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
277 sizer->Add(btnSaveBinaryFile);
278 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
280 panel->SetSizer(sizer);
281 panel->SetAutoLayout(true);
282 panel->SetSize(400,600);
287 //-------------------------------------------------
288 wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
290 wxPanel *panel = new wxPanel(parent,-1);
292 stlSliderDeltaGauss = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
293 stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
294 stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
295 stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
296 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
298 Connect(btnFileSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL );
299 Connect(stlSliderDeltaGauss->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel );
300 Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
301 Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal );
302 Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal );
305 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
307 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
308 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
310 sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
311 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
312 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
313 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
315 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
316 sizer->Add(stlSliderDeltaGauss);
318 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
319 sizer->Add(stlSliderMarchingCubes);
321 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
322 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
323 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
324 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
326 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
327 sizer->Add(stlSliderOpacityInternal);
329 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
330 sizer->Add(stlSliderOpacityExternal);
332 sizer->Add(btnFileSTL);
333 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
336 panel->SetSizer(sizer);
337 panel->SetAutoLayout(true);
338 panel->SetSize(400,600);
342 //-------------------------------------------------
343 wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
345 wxPanel *panel = new wxPanel(parent,-1);
347 wxButton *btnReadSTLFile = new wxButton(panel,-1,_T("Read STL File"));
348 wxButton *btnEraseReadSTLFile = new wxButton(panel,-1,_T("Erase STL File"));
349 _sl_opacity_STL_file = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
351 Connect(btnReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad );
352 Connect(btnEraseReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase );
353 Connect(_sl_opacity_STL_file->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile );
356 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
358 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
359 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
360 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
361 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
363 sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
364 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
366 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
367 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
369 sizer->Add(btnReadSTLFile );
370 sizer->Add(btnEraseReadSTLFile );
371 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
372 sizer->Add(_sl_opacity_STL_file);
375 panel->SetSizer(sizer);
376 panel->SetAutoLayout(true);
377 panel->SetSize(400,600);
381 //-------------------------------------------------------------------
382 wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
384 wxPanel *panel = new wxPanel(parent,-1);
386 wxNotebook *noteBook = new wxNotebook(panel, -1);
387 noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
388 noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
389 noteBook->AddPage(CreateSmoothingPanel(noteBook) ,_T("2 ->") );
390 noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 " ) );
391 noteBook->SetSelection(0);
392 noteBook->SetSize(350,250);
393 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
394 sizer->Add(noteBook);
395 panel->SetSizer(sizer);
396 panel->SetAutoLayout(true);
397 panel->SetSize(400,600);
402 //------------------------------------------------------------------------
403 void wxSTLWidget_03::Refresh()
405 if (_wxMaracasMPR!=NULL){
406 _wxMaracasMPR->RefreshView();
410 //------------------------------------------------------------------------
413 void wxSTLWidget_03::ConfigureProcessing(marImageData *marimagedata, int x, int y, int z)
417 _imagedata=marimagedata->GetImageData(); // image t=0
418 _imagedata->UpdateInformation();
419 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
420 _imagedata->Update();
423 double puntoactualprov[3];
424 puntoactualprov[0] = x;
425 puntoactualprov[1] = y;
426 puntoactualprov[2] = z;
431 _imagedata->GetSpacing(espprin);
432 _imagedata->GetExtent(extprin);
436 // puntoactualprov[0]=puntoactualprov[0]*espprin[0];
437 // puntoactualprov[1]=puntoactualprov[1]*espprin[1];
438 // puntoactualprov[2]=puntoactualprov[2]*espprin[2];
440 _imagedata->GetScalarRange( _range );
444 /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
445 _sl_minSize->SetValue( (int)(_range[1]/4) );
447 _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
448 _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
451 minRangeValue = _range[0];
452 maxRangeValue = _range[1];
454 sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
455 sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
456 sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
457 sl_barrange_segmentation -> RefreshForce();
458 lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;
461 // _highthreshold->SetRange(_range[0], _range[1]);
462 // _highthreshold->SetValue( _range[1] );
464 // _zslice->SetRange(extprin[4], extprin[5]);
465 // _zslice->SetValue(extprin[5]/2);
467 _thresh = vtkImageThreshold::New();
468 _thresh->SetInput(_imagedata);
469 //_thresh->ReleaseDataFlagOff();
470 _thresh->SetInValue(255);
471 _thresh->SetOutputScalarTypeToUnsignedShort();
472 _thresh->SetOutValue(0);
473 //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
475 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
477 vtkImageCast *cast = vtkImageCast::New();
478 cast->SetInput(_thresh->GetOutput());
479 cast->SetOutputScalarTypeToUnsignedChar();
483 _connect = vtkImageSeedConnectivity::New();
484 _connect->SetInput(cast->GetOutput());
485 _connect->SetInputConnectValue(255);
486 _connect->SetOutputConnectedValue(255);
487 _connect->SetOutputUnconnectedValue(0);
488 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
489 // _connect->Update();
491 cast3 = vtkImageCast::New();
492 cast3->SetInput(_connect->GetOutput());
493 cast3->SetOutputScalarTypeToUnsignedShort();
497 _thresh2 = vtkImageThreshold::New();
498 _thresh2->SetInput(_imagedata);
499 //_thresh2->ReleaseDataFlagOff();
500 _thresh2->SetInValue(255);
501 _thresh2->SetOutputScalarTypeToUnsignedShort();
502 _thresh2->SetOutValue(0);
503 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
504 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
506 cast2 = vtkImageCast::New();
507 cast2->SetInput(_thresh2->GetOutput());
508 cast2->SetOutputScalarTypeToUnsignedChar();
511 _connect2 = vtkImageSeedConnectivity::New();
512 _connect2->SetInput(cast2->GetOutput());
513 _connect2->SetInputConnectValue(255);
514 _connect2->SetOutputConnectedValue(255);
515 _connect2->SetOutputUnconnectedValue(0);
516 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
519 cast4 = vtkImageCast::New();
520 cast4->SetInput(_connect2->GetOutput());
521 cast4->SetOutputScalarTypeToUnsignedShort();
525 //------------------------------------------------------------------------
529 void wxSTLWidget_03::ConfigureVTK()
532 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
533 marImageData *marimagedata;// = _mar->_experiment->getDynData( )->GetMarImageData();
535 //CONFIGURACION ADICIONAL
536 this->ConfigureSTL();
537 this->ConfigureProcessing(marimagedata,0,0,0);
541 //------------------------------------------------------------------------
543 void wxSTLWidget_03::ResetTree2_JF()
546 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
549 ren->RemoveActor(_2_isoActorMC6);
552 ren->RemoveActor(_2_stripfinal);
556 // if (_2_prgov ) { _2_prgov -> Delete(); }
557 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
558 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
559 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
560 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
561 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
566 _2_stripfinal = NULL;
567 _2_isoMapperMC6 = NULL;
568 _2_isoActorMC6 = NULL;
577 //------------------------------------------------------------------------
578 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
581 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
582 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
584 double puntoactualprov[3];
589 puntoactualprov[0] = x;
590 puntoactualprov[1] = y;
591 puntoactualprov[2] = z;
593 _imagedata->UpdateInformation();
594 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
595 _imagedata->Update();
597 _imagedata->GetSpacing(espprin);
598 _imagedata->GetExtent(extprin);
603 _connect->RemoveAllSeeds ();
604 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
610 _thresh->ThresholdBetween(3000, 3002 );
611 _thresh2->ThresholdBetween(3000, 3001);
612 // _thresh->Update();
613 // _thresh2->Update();
615 _thresh->ThresholdBetween(_minSize, _range[1] );
618 _thresh2->ThresholdBetween(_minSize, _maxSize);
622 _connect2->RemoveAllSeeds ();
623 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
630 // Visualisation - result volume
632 _2_isoMC6 = vtkMarchingCubes::New();
633 _2_isoMC6->SetInput(cast4->GetOutput());
635 _2_isoMC6->SetValue(0, 128);
638 _2_isoMapperMC6 = vtkPolyDataMapper::New();
639 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
640 _2_isoMapperMC6->ScalarVisibilityOff();
641 _2_isoMapperMC6->ImmediateModeRenderingOn();
643 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
645 if (_2_isoActorMC6!=NULL)
647 ren->RemoveActor(_2_isoActorMC6);
651 _2_isoActorMC6 = vtkActor::New();
652 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
653 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
654 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
658 ren->AddActor(_2_isoActorMC6);
662 //------------------------------------------------------------------------
663 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
665 if (_2_isoActorMC6!=NULL){
666 double value = ((double)_opacity_Vol->GetValue())/100;
667 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
671 //------------------------------------------------------------------------
673 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
675 /*wxSlider *sl_A=_sl_minSize;
676 wxSlider *sl_B=_sl_minSizeSpin;
677 int value = sl_A->GetValue();
678 int delta=(int)pow( 4 , sl_B->GetValue() );
679 int min=value - delta/2;
680 int max=value + delta/2;
686 sl_A->SetRange(min,max);
692 //------------------------------------------------------------------------
694 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
696 /*wxSlider *sl_A=_sl_maxSize;
697 wxSlider *sl_B=_sl_maxSizeSpin;
698 int value = sl_A->GetValue();
699 int delta = (int)pow( 4 , sl_B->GetValue() );
700 int min=value - delta/2;
701 int max=value + delta/2;
707 sl_A->SetRange(min,max);*/
710 //------------------------------------------------------------------------
712 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
714 wxSlider *sl_B=_sl_RangeSizeSpin;
716 int value = lastResizeRef_Value;
717 int delta = (int)pow( 4 , sl_B->GetValue() );
718 int startResized = value - delta/2;
719 int endResized = value + delta/2;
721 if( startResized < minRangeValue )
722 startResized = minRangeValue;
724 if( endResized > maxRangeValue )
725 endResized = maxRangeValue;
727 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
728 sl_barrange_segmentation -> RefreshForce();
731 //------------------------------------------------------------------------
732 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
734 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
736 //------------------------------------------------------------------------
737 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
739 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
741 //------------------------------------------------------------------------
742 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
744 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
746 //------------------------------------------------------------------------
748 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
750 wxString dirSTL;// = _mar->_parameters->getStringParam(
751 //marParameters::e_installation_directory );
752 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
753 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
754 dirSTL: wxGetHomeDir( ) );
756 if( dialog.ShowModal( ) == wxID_OK )
758 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
759 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
760 writer->SetInput(cast4->GetOutput());
766 //------------------------------------------------------------------------
767 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
770 _minSize = _sl_minSize->GetValue();
771 _maxSize = _sl_maxSize->GetValue();
773 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
774 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
775 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
776 ExtractSurface((int)(px),(int)(py),(int)(pz));
777 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
783 _minSize = sl_barrange_segmentation->GetStart();
784 _maxSize = sl_barrange_segmentation->GetEnd();
786 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
787 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
788 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
789 ExtractSurface((int)(px),(int)(py),(int)(pz));
790 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
795 //------------------------------------------------------------------------
796 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
798 if (_loadActorSTL!=NULL)
800 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
801 _loadActorSTL->GetProperty( )->SetOpacity( value );
805 //------------------------------------------------------------------------
806 void wxSTLWidget_03::Reset_vtk_STLFile()
809 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
811 ren->RemoveActor(_loadActorSTL);
815 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
816 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
819 _loadSTLMapper = NULL;
820 _loadActorSTL = NULL;
823 //------------------------------------------------------------------------
824 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
829 //------------------------------------------------------------------------
830 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
832 wxString dirSTL;// = _mar->_parameters->getStringParam(
833 //marParameters::e_installation_directory );
834 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
835 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
836 dirSTL: wxGetHomeDir( ) );
838 if( dialog.ShowModal( ) == wxID_OK )
841 vtkSTLReader *imgReader= vtkSTLReader::New();
842 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
843 _loadSTLMapper = vtkPolyDataMapper::New();
844 _loadSTLMapper->SetInput(imgReader->GetOutput());
845 _loadActorSTL = vtkActor::New();
846 _loadActorSTL->SetMapper(_loadSTLMapper);
847 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
848 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
849 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
850 ren->AddActor(_loadActorSTL);
853 //By default *always* update e_installation_directory:
854 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
855 //_mar->saveParameters( );
860 // ------------------------------------------------------------------------
861 // END JOIN FUNCTIONS - DHC
862 // ------------------------------------------------------------------------
864 // ------------------------------------------------------------------------
865 // START STL FUNCTIONS - DHC
866 // ------------------------------------------------------------------------
868 void wxSTLWidget_03::ConfigureSTL()
870 stlExterna = vtkPolyData::New();
871 stlInterna = vtkPolyData::New();
873 dsm1 = vtkPolyDataMapper ::New();
874 dsm1->SetInput (stlInterna);
875 dsm1->ScalarVisibilityOff();
877 actorInternal = vtkActor::New();
878 actorInternal->SetMapper (dsm1);
879 actorInternal->GetProperty()->SetColor (0,1,0);
881 dsm2 = vtkPolyDataMapper ::New();
882 dsm2->SetInput (stlExterna);
883 dsm2->ScalarVisibilityOff();
885 actorExternal= vtkActor::New();
886 actorExternal->SetMapper (dsm2);
887 actorExternal->GetProperty()->SetRepresentationToWireframe();
889 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
890 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
891 ren->AddActor(actorInternal);
892 ren->AddActor(actorExternal);
894 stlExtractor = new vtkSTLExtractor();
897 void wxSTLWidget_03::generateSTLSurfaces()
900 // stlExtractor->setVolume(_2_prgov->GetVolumen());
902 stlExtractor->setVolume(cast4->GetOutput());
904 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
905 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
906 stlExtractor->calculate();
907 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
908 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
912 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
913 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
914 actorExternal->GetProperty( )->SetOpacity( value );
919 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
920 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
921 actorInternal->GetProperty( )->SetOpacity( value );
925 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
928 wxString dirSTL;// = _mar->_parameters->getStringParam(
929 //marParameters::e_installation_directory );
930 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
933 // wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
934 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
937 if( dialog.ShowModal( ) == wxID_OK )
941 // ------------------------------------------------------------------------
942 // 1. GENERATE STL FILES
943 // ------------------------------------------------------------------------
944 // const char* fileprefix = "c:\\Creatis\\";
945 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
946 std::string filename;
948 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
950 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
951 filtro->SetInput(stlInterna);
952 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
953 pdcf->SetInput( filtro->GetOutput() );
954 vtkClosePolyData *cpd = vtkClosePolyData::New();
955 cpd->SetInput( pdcf->GetOutput() );
957 // 1.2 se escribe a disco el archivo stl de la superficie interna
959 vtkSTLWriter *writerI = vtkSTLWriter::New();
960 writerI->SetInput( cpd->GetOutput() );
961 // prefix = fileprefix;
962 filename=prefix+"_internal.stl";
963 writerI->SetFileName(filename.c_str());
964 writerI->SetFileTypeToASCII();
968 // 1.3 se escribe a disco el archivo stl de la superficie externa
969 filtro->SetInput(stlExterna);
971 vtkSTLWriter *writerE = vtkSTLWriter::New();
972 writerE->SetInput( cpd->GetOutput() );
973 // prefix = fileprefix;
974 filename=prefix+"_external.stl";
975 writerE->SetFileName( filename.c_str() );
976 writerE->SetFileTypeToASCII();
985 //By default *always* update e_installation_directory:
986 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
987 //_mar->saveParameters( );
991 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
994 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
995 generateSTLSurfaces();
1000 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1003 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1004 generateSTLSurfaces();
1010 // ------------------------------------------------------------------------
1011 // END STL FUNCTIONS - DHC
1012 // ------------------------------------------------------------------------