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)
71 cast4=NULL; // binary segmentation result
84 sl_barrange_segmentation=NULL;
89 stlSliderDeltaGauss=NULL;
90 stlSliderMarchingCubes=NULL;
93 stlSliderOpacityInternal=NULL;
96 stlSliderOpacityExternal=NULL;
98 _sl_opacity_STL_file=NULL;
101 joinMarchingCubes=NULL;
107 _stlMarchingCubesLevel = 128;
108 _stlDeltaGaussLevel = 100;
110 /*_mar=new marInterface();
111 _mar->_parameters->setRescaleSlope( mar->_parameters->getRescaleSlope() );
112 _mar->_parameters->setRescaleIntercept( mar->_parameters->getRescaleIntercept() );
113 _mar->_parameters->setIntParam( marParameters::e_voxel_type, marParameters::VOX_TYPE_MINIMUM );
114 _mar->_parameters->setDoubleParam( marParameters::e_voxel_x_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_x_dimension) );
115 _mar->_parameters->setDoubleParam( marParameters::e_voxel_y_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_y_dimension) );
116 _mar->_parameters->setDoubleParam( marParameters::e_voxel_z_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_z_dimension) );
118 mar->_experiment->getVOI( voi );
119 _mar->_experiment->setVOI( voi );
120 _mar->SetDicom(mar->_dicom);
121 _mar->initExperiment( );*/
124 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
125 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
126 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
127 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
129 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
130 pnlSplitter -> SetMinimumPaneSize( 150 );
131 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
133 // pnlSplitter -> SplitVertically( new wxPanel(pnlSplitter,-1), new wxPanel(pnlSplitter,-1) , 600 );
134 // pnlSplitter -> SplitVertically( viewPanel, new wxPanel(pnlSplitter,-1) , 600 );
136 this -> SetSizer(sizer);
141 //-------------------------------------------------------------------
142 wxSTLWidget_03::~wxSTLWidget_03(){
144 //Reset_vtk_STLFile();
146 if(_imagedata!=NULL){
147 _imagedata->Delete();
149 if(cast2){cast2->Delete();}
150 if(cast3){cast3->Delete();}
151 if(cast4){cast4->Delete();}
152 if(_thresh){_thresh->Delete();}
153 if(_thresh2){_thresh2->Delete();}
154 if(_cast){_cast->Delete();}
155 if(_connect){_connect->Delete();}
156 if(_connect2){_connect2->Delete();}
157 if(_2_mapfinal){_2_mapfinal->Delete();}
158 if(_2_stripfinal){_2_stripfinal->Delete();}
159 if(_2_isoMapperMC6){_2_isoMapperMC6->Delete();}
160 if(_2_isoActorMC6){_2_isoActorMC6->Delete();}
161 if(_2_isoMC6){_2_isoMC6->Delete();}
163 if(_loadSTLMapper){_loadSTLMapper->Delete();}
164 if(_loadActorSTL){_loadActorSTL->Delete();}
165 if(sl_barrange_segmentation){delete sl_barrange_segmentation;}
166 if(_imageviewer3D){delete _imageviewer3D;}
167 if(_wxMaracasMPR){delete _wxMaracasMPR;}
168 if(stlInterna){stlInterna->Delete();}
169 if(stlExterna){stlExterna->Delete();}
170 if(dsm1){dsm1->Delete();}
171 if(actorInternal){actorInternal->Delete();}
172 if(dsm2){dsm2->Delete();}
173 if(actorExternal){actorExternal->Delete();}
174 //if(stlExtractor){stlExtractor->Delete();}
175 if(arteryImageData){arteryImageData->Delete();}
176 if(joiner){delete joiner;}
177 if(joinMarchingCubes){joinMarchingCubes->Delete();}
178 if(joinMapper){joinMapper->Delete(); }
179 if(joinActor){joinActor->Delete();}
181 //-------------------------------------------------------------------
182 wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
184 wxPanel *panel = new wxPanel(parent,-1);
185 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
189 //vtkImageData *imagedata;
190 //imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
191 //imagedata->Update();
192 _wxMaracasMPR = new wxMaracasMPR( panel);//JCP 10-03-2009, new marImageData(imagedata), 1 );
193 _wxMaracasMPR->ConfigureVTK();
195 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
196 panel->SetSizer(sizer);
197 panel->SetAutoLayout(true);
198 panel->SetSize(400,400);
203 void wxSTLWidget_03::setImage(vtkImageData* img){
205 _wxMaracasMPR->setImageData(img, 1);
206 _wxMaracasMPR->ConfigureVTK();
209 this->ConfigureProcessing(img,0,0,0);
210 this->ConfigureSTL();
212 _wxMaracasMPR->Refresh();
216 //-------------------------------------------------------------------
217 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
219 wxPanel *panel = new wxPanel(parent,-1);
222 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
224 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
225 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
227 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
228 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
230 sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
231 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
233 panel->SetSizer(sizer);
234 panel->SetAutoLayout(true);
235 panel->SetSize(400,600);
241 //-------------------------------------------------------------------
242 wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
244 wxPanel *panel = new wxPanel(parent,-1);
247 _opacity_Vol = new wxSlider( panel, -1, 40, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
248 _opacity_Vol ->SetSize(250,20);
250 _sl_maxSize = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
251 _sl_minSize = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
253 _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
254 _sl_minSizeSpin->SetRange(1,8);
255 _sl_minSizeSpin->SetValue(5);
257 _sl_maxSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
258 _sl_maxSizeSpin->SetRange(1,8);
259 _sl_maxSizeSpin->SetValue(5);
263 _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
264 _sl_RangeSizeSpin->SetRange(1,8);
265 _sl_RangeSizeSpin->SetValue(5);
269 sl_barrange_segmentation = new mBarRange(panel, 300,70);
270 sl_barrange_segmentation -> setVisibleLabels ( true );
271 sl_barrange_segmentation -> setIfWithActualDrawed( false );
272 sl_barrange_segmentation -> setActiveStateTo ( true );
273 sl_barrange_segmentation -> setRepresentedValues (0, 2000);
274 sl_barrange_segmentation -> setDeviceBlitStart (10,10);
275 sl_barrange_segmentation -> setDeviceEndMargin(10);
276 parent->SetBackgroundColour(wxColour(255,255,255));
277 sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
280 wxButton *btnExtract = new wxButton(panel,-1,_T("Segmentation"));
281 wxButton *btnSaveBinaryFile = new wxButton(panel,-1,_T("Save Binary File"));
283 //SIL// Connect(_sl_minSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMinSpin );
284 //SIL// Connect(_sl_maxSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMaxSpin );
285 Connect(_opacity_Vol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol );
286 Connect(btnExtract->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction );
287 Connect(btnSaveBinaryFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile );
290 Connect(_sl_RangeSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin );
291 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnStartChanged_range );
292 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnEndChanged_range );
293 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnBarMoved_range );
295 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
297 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
298 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
301 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Segmentation - - - ")));
302 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
305 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
306 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
308 /*sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min")));
309 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
310 sizer->Add(_sl_minSizeSpin, 1, wxALL|wxEXPAND, 0);*/
311 //sizer->Add(_sl_minSize, 1, wxALL|wxEXPAND, 0);
313 sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
314 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
315 sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
316 sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
318 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" Threshold max")));
319 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" ")));
320 //SIL// sizer->Add(_sl_maxSizeSpin, 1, wxALL|wxEXPAND, 0);
321 //SIL//sizer->Add(_sl_maxSize, 1, wxALL|wxEXPAND, 0);
323 sizer->Add(btnExtract);
324 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
326 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
327 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
328 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
329 sizer->Add(_opacity_Vol);
331 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
332 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
333 sizer->Add(btnSaveBinaryFile);
334 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
336 panel->SetSizer(sizer);
337 panel->SetAutoLayout(true);
338 panel->SetSize(400,600);
343 //-------------------------------------------------
344 wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
346 wxPanel *panel = new wxPanel(parent,-1);
348 stlSliderDeltaGauss = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
349 stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
350 stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
351 stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
352 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
354 Connect(btnFileSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL );
355 Connect(stlSliderDeltaGauss->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel );
356 Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
357 Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal );
358 Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal );
361 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
363 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
364 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
366 sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
367 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
368 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
369 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
371 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
372 sizer->Add(stlSliderDeltaGauss);
374 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
375 sizer->Add(stlSliderMarchingCubes);
377 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
378 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
379 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
380 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
382 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
383 sizer->Add(stlSliderOpacityInternal);
385 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
386 sizer->Add(stlSliderOpacityExternal);
388 sizer->Add(btnFileSTL);
389 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
392 panel->SetSizer(sizer);
393 panel->SetAutoLayout(true);
394 panel->SetSize(400,600);
398 //-------------------------------------------------
399 wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
401 wxPanel *panel = new wxPanel(parent,-1);
403 wxButton *btnReadSTLFile = new wxButton(panel,-1,_T("Read STL File"));
404 wxButton *btnEraseReadSTLFile = new wxButton(panel,-1,_T("Erase STL File"));
405 _sl_opacity_STL_file = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
407 Connect(btnReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad );
408 Connect(btnEraseReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase );
409 Connect(_sl_opacity_STL_file->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile );
412 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
414 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
415 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
416 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
417 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
419 sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
420 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
422 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
423 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
425 sizer->Add(btnReadSTLFile );
426 sizer->Add(btnEraseReadSTLFile );
427 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
428 sizer->Add(_sl_opacity_STL_file);
431 panel->SetSizer(sizer);
432 panel->SetAutoLayout(true);
433 panel->SetSize(400,600);
437 //-------------------------------------------------------------------
438 wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
440 wxPanel *panel = new wxPanel(parent,-1);
442 wxNotebook *noteBook = new wxNotebook(panel, -1);
443 noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
444 noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
445 noteBook->AddPage(CreateSmoothingPanel(noteBook) ,_T("2 ->") );
446 noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 " ) );
447 noteBook->SetSelection(0);
448 noteBook->SetSize(350,250);
449 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
450 sizer->Add(noteBook);
451 panel->SetSizer(sizer);
452 panel->SetAutoLayout(true);
453 panel->SetSize(400,600);
458 //------------------------------------------------------------------------
459 void wxSTLWidget_03::Refresh()
461 if (_wxMaracasMPR!=NULL){
462 _wxMaracasMPR->RefreshView();
466 //------------------------------------------------------------------------
469 void wxSTLWidget_03::ConfigureProcessing(vtkImageData *img, int x, int y, int z)
476 double puntoactualprov[3];
477 puntoactualprov[0] = x;
478 puntoactualprov[1] = y;
479 puntoactualprov[2] = z;
484 _imagedata->GetSpacing(espprin);
485 _imagedata->GetExtent(extprin);
489 // puntoactualprov[0]=puntoactualprov[0]*espprin[0];
490 // puntoactualprov[1]=puntoactualprov[1]*espprin[1];
491 // puntoactualprov[2]=puntoactualprov[2]*espprin[2];
493 _imagedata->GetScalarRange( _range );
497 /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
498 _sl_minSize->SetValue( (int)(_range[1]/4) );
500 _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
501 _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
504 minRangeValue = _range[0];
505 maxRangeValue = _range[1];
507 sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
508 sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
509 sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
510 sl_barrange_segmentation -> RefreshForce();
511 lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;
514 // _highthreshold->SetRange(_range[0], _range[1]);
515 // _highthreshold->SetValue( _range[1] );
517 // _zslice->SetRange(extprin[4], extprin[5]);
518 // _zslice->SetValue(extprin[5]/2);
521 _thresh = vtkImageThreshold::New();
522 //_thresh->ReleaseDataFlagOff();
523 _thresh->SetInValue(255);
524 _thresh->SetOutputScalarTypeToUnsignedShort();
525 _thresh->SetOutValue(0);
526 //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
528 _cast = vtkImageCast::New();
529 _cast->SetInput(_thresh->GetOutput());
530 _cast->SetOutputScalarTypeToUnsignedChar();
532 _connect = vtkImageSeedConnectivity::New();
533 _connect->SetInput(_cast->GetOutput());
534 _connect->SetInputConnectValue(255);
535 _connect->SetOutputConnectedValue(255);
536 _connect->SetOutputUnconnectedValue(0);
538 cast3 = vtkImageCast::New();
539 cast3->SetInput(_connect->GetOutput());
540 cast3->SetOutputScalarTypeToUnsignedShort();
542 _thresh2 = vtkImageThreshold::New();
543 //_thresh2->ReleaseDataFlagOff();
544 _thresh2->SetInValue(255);
545 _thresh2->SetOutputScalarTypeToUnsignedShort();
546 _thresh2->SetOutValue(0);
547 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
549 cast2 = vtkImageCast::New();
550 cast2->SetInput(_thresh2->GetOutput());
551 cast2->SetOutputScalarTypeToUnsignedChar();
552 _connect2 = vtkImageSeedConnectivity::New();
553 _connect2->SetInput(cast2->GetOutput());
554 _connect2->SetInputConnectValue(255);
555 _connect2->SetOutputConnectedValue(255);
556 _connect2->SetOutputUnconnectedValue(0);
558 cast4 = vtkImageCast::New();
559 cast4->SetInput(_connect2->GetOutput());
560 cast4->SetOutputScalarTypeToUnsignedShort();
562 _thresh->RemoveAllInputs();
563 _thresh->SetInput(_imagedata);
564 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
570 _connect->RemoveAllSeeds();
571 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
572 //_connect->Update();
575 _thresh2->RemoveAllInputs();
576 _thresh2->SetInput(_imagedata);
577 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
580 _connect2->RemoveAllSeeds();
581 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
582 //_connect2->Update();
586 //------------------------------------------------------------------------
590 void wxSTLWidget_03::ConfigureVTK()
593 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
594 //marImageData *marimagedata;// = _mar->_experiment->getDynData( )->GetMarImageData();
596 //CONFIGURACION ADICIONAL
597 this->ConfigureSTL();
598 //this->ConfigureProcessing(marimagedata,0,0,0);
602 //------------------------------------------------------------------------
604 void wxSTLWidget_03::ResetTree2_JF()
613 // if (_2_prgov ) { _2_prgov -> Delete(); }
614 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
615 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
616 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
617 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
618 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
623 _2_stripfinal = NULL;
624 _2_isoMapperMC6 = NULL;
625 _2_isoActorMC6 = NULL;
629 //vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
631 /*if (_2_isoActorMC6){
632 ren->RemoveActor(_2_isoActorMC6);
635 ren->RemoveActor(_2_stripfinal);
640 std::cout<<e<<std::endl;
649 //------------------------------------------------------------------------
650 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
653 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
654 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
656 double puntoactualprov[3];
661 puntoactualprov[0] = x;
662 puntoactualprov[1] = y;
663 puntoactualprov[2] = z;
665 _imagedata->UpdateInformation();
666 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
667 _imagedata->Update();
669 _imagedata->GetSpacing(espprin);
670 _imagedata->GetExtent(extprin);
675 _connect->RemoveAllSeeds ();
676 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
682 _thresh->ThresholdBetween(3000, 3002 );
683 _thresh2->ThresholdBetween(3000, 3001);
684 // _thresh->Update();
685 // _thresh2->Update();
687 _thresh->ThresholdBetween(_minSize, _range[1] );
690 _thresh2->ThresholdBetween(_minSize, _maxSize);
694 _connect2->RemoveAllSeeds ();
695 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
702 // Visualisation - result volume
704 _2_isoMC6 = vtkMarchingCubes::New();
705 _2_isoMC6->SetInput(cast4->GetOutput());
707 _2_isoMC6->SetValue(0, 128);
710 _2_isoMapperMC6 = vtkPolyDataMapper::New();
711 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
712 _2_isoMapperMC6->ScalarVisibilityOff();
713 _2_isoMapperMC6->ImmediateModeRenderingOn();
715 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
717 if (_2_isoActorMC6!=NULL)
719 ren->RemoveActor(_2_isoActorMC6);
723 _2_isoActorMC6 = vtkActor::New();
724 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
725 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
726 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
730 ren->AddActor(_2_isoActorMC6);
734 //------------------------------------------------------------------------
735 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
737 if (_2_isoActorMC6!=NULL){
738 double value = ((double)_opacity_Vol->GetValue())/100;
739 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
743 //------------------------------------------------------------------------
745 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
747 /*wxSlider *sl_A=_sl_minSize;
748 wxSlider *sl_B=_sl_minSizeSpin;
749 int value = sl_A->GetValue();
750 int delta=(int)pow( 4 , sl_B->GetValue() );
751 int min=value - delta/2;
752 int max=value + delta/2;
758 sl_A->SetRange(min,max);
764 //------------------------------------------------------------------------
766 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
768 /*wxSlider *sl_A=_sl_maxSize;
769 wxSlider *sl_B=_sl_maxSizeSpin;
770 int value = sl_A->GetValue();
771 int delta = (int)pow( 4 , sl_B->GetValue() );
772 int min=value - delta/2;
773 int max=value + delta/2;
779 sl_A->SetRange(min,max);*/
782 //------------------------------------------------------------------------
784 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
786 wxSlider *sl_B=_sl_RangeSizeSpin;
788 int value = lastResizeRef_Value;
789 int delta = (int)pow((double) 4 , (double)sl_B->GetValue() );
790 int startResized = value - delta/2;
791 int endResized = value + delta/2;
793 if( startResized < minRangeValue )
794 startResized = minRangeValue;
796 if( endResized > maxRangeValue )
797 endResized = maxRangeValue;
799 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
800 sl_barrange_segmentation -> RefreshForce();
803 //------------------------------------------------------------------------
804 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
806 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
808 //------------------------------------------------------------------------
809 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
811 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
813 //------------------------------------------------------------------------
814 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
816 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
818 //------------------------------------------------------------------------
820 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
822 wxString dirSTL;// = _mar->_parameters->getStringParam(
823 //marParameters::e_installation_directory );
824 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
825 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
826 dirSTL: wxGetHomeDir( ) );
828 if( dialog.ShowModal( ) == wxID_OK )
830 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
831 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
832 writer->SetInput(cast4->GetOutput());
838 //------------------------------------------------------------------------
839 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
842 _minSize = _sl_minSize->GetValue();
843 _maxSize = _sl_maxSize->GetValue();
845 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
846 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
847 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
848 ExtractSurface((int)(px),(int)(py),(int)(pz));
849 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
855 _minSize = sl_barrange_segmentation->GetStart();
856 _maxSize = sl_barrange_segmentation->GetEnd();
858 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
859 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
860 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
861 ExtractSurface((int)(px),(int)(py),(int)(pz));
862 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
867 //------------------------------------------------------------------------
868 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
870 if (_loadActorSTL!=NULL)
872 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
873 _loadActorSTL->GetProperty( )->SetOpacity( value );
877 //------------------------------------------------------------------------
878 void wxSTLWidget_03::Reset_vtk_STLFile()
882 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
884 ren->RemoveActor(_loadActorSTL);
888 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
889 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
892 _loadSTLMapper = NULL;
893 _loadActorSTL = NULL;
895 std::cout<<e<<std::endl;
899 //------------------------------------------------------------------------
900 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
905 //------------------------------------------------------------------------
906 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
908 wxString dirSTL;// = _mar->_parameters->getStringParam(
909 //marParameters::e_installation_directory );
910 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
911 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
912 dirSTL: wxGetHomeDir( ) );
914 if( dialog.ShowModal( ) == wxID_OK )
917 vtkSTLReader *imgReader= vtkSTLReader::New();
918 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
919 _loadSTLMapper = vtkPolyDataMapper::New();
920 _loadSTLMapper->SetInput(imgReader->GetOutput());
921 _loadActorSTL = vtkActor::New();
922 _loadActorSTL->SetMapper(_loadSTLMapper);
923 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
924 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
925 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
926 ren->AddActor(_loadActorSTL);
929 //By default *always* update e_installation_directory:
930 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
931 //_mar->saveParameters( );
936 // ------------------------------------------------------------------------
937 // END JOIN FUNCTIONS - DHC
938 // ------------------------------------------------------------------------
940 // ------------------------------------------------------------------------
941 // START STL FUNCTIONS - DHC
942 // ------------------------------------------------------------------------
944 void wxSTLWidget_03::ConfigureSTL()
947 if(stlExterna == NULL){
948 stlExterna = vtkPolyData::New();
949 stlInterna = vtkPolyData::New();
951 dsm1 = vtkPolyDataMapper ::New();
952 dsm1->SetInput (stlInterna);
953 dsm1->ScalarVisibilityOff();
955 actorInternal = vtkActor::New();
956 actorInternal->SetMapper (dsm1);
957 actorInternal->GetProperty()->SetColor (0,1,0);
959 dsm2 = vtkPolyDataMapper ::New();
960 dsm2->SetInput (stlExterna);
961 dsm2->ScalarVisibilityOff();
963 actorExternal= vtkActor::New();
964 actorExternal->SetMapper (dsm2);
965 actorExternal->GetProperty()->SetRepresentationToWireframe();
967 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
968 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
969 ren->AddActor(actorInternal);
970 ren->AddActor(actorExternal);
972 stlExtractor = new vtkSTLExtractor();
979 void wxSTLWidget_03::generateSTLSurfaces()
982 // stlExtractor->setVolume(_2_prgov->GetVolumen());
984 stlExtractor->setVolume(cast4->GetOutput());
986 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
987 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
988 stlExtractor->calculate();
989 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
990 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
994 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
995 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
996 actorExternal->GetProperty( )->SetOpacity( value );
1001 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
1002 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
1003 actorInternal->GetProperty( )->SetOpacity( value );
1007 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
1010 wxString dirSTL;// = _mar->_parameters->getStringParam(
1011 //marParameters::e_installation_directory );
1012 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
1015 // wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
1016 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
1019 if( dialog.ShowModal( ) == wxID_OK )
1023 // ------------------------------------------------------------------------
1024 // 1. GENERATE STL FILES
1025 // ------------------------------------------------------------------------
1026 // const char* fileprefix = "c:\\Creatis\\";
1027 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
1028 std::string filename;
1030 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
1032 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
1033 filtro->SetInput(stlInterna);
1034 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
1035 pdcf->SetInput( filtro->GetOutput() );
1036 vtkClosePolyData *cpd = vtkClosePolyData::New();
1037 cpd->SetInput( pdcf->GetOutput() );
1039 // 1.2 se escribe a disco el archivo stl de la superficie interna
1041 vtkSTLWriter *writerI = vtkSTLWriter::New();
1042 writerI->SetInput( cpd->GetOutput() );
1043 // prefix = fileprefix;
1044 filename=prefix+"_internal.stl";
1045 writerI->SetFileName(filename.c_str());
1046 writerI->SetFileTypeToASCII();
1050 // 1.3 se escribe a disco el archivo stl de la superficie externa
1051 filtro->SetInput(stlExterna);
1053 vtkSTLWriter *writerE = vtkSTLWriter::New();
1054 writerE->SetInput( cpd->GetOutput() );
1055 // prefix = fileprefix;
1056 filename=prefix+"_external.stl";
1057 writerE->SetFileName( filename.c_str() );
1058 writerE->SetFileTypeToASCII();
1067 //By default *always* update e_installation_directory:
1068 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
1069 //_mar->saveParameters( );
1073 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1076 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
1077 generateSTLSurfaces();
1082 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1085 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1086 generateSTLSurfaces();
1092 // ------------------------------------------------------------------------
1093 // END STL FUNCTIONS - DHC
1094 // ------------------------------------------------------------------------