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 printf("EED wxSTLWidget_03::wxSTLWidget_03 01\n");
93 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
94 printf("EED wxSTLWidget_03::wxSTLWidget_03 02\n");
96 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
97 pnlSplitter -> SetMinimumPaneSize( 150 );
98 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
100 // pnlSplitter -> SplitVertically( new wxPanel(pnlSplitter,-1), new wxPanel(pnlSplitter,-1) , 600 );
101 // pnlSplitter -> SplitVertically( viewPanel, new wxPanel(pnlSplitter,-1) , 600 );
103 this -> SetSizer(sizer);
105 // Result 2: Volume + Axis
108 _2_stripfinal = NULL;
109 _2_isoMapperMC6 = NULL;
110 _2_isoActorMC6 = NULL;
117 _loadSTLMapper = NULL;
118 _loadActorSTL = NULL;
122 arteryImageData = NULL;
123 joinMarchingCubes = NULL;
126 printf("EED wxSTLWidget_03::wxSTLWidget_03 03\n");
130 //-------------------------------------------------------------------
131 wxSTLWidget_03::~wxSTLWidget_03(){
135 //-------------------------------------------------------------------
136 wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
138 wxPanel *panel = new wxPanel(parent,-1);
139 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
143 vtkImageData *imagedata;
144 imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
146 printf("EED wxSTLWidget_03::CreateViewPanel 01 \n");
147 _wxMaracasMPR = new wxMaracasMPR( panel, new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
148 printf("EED wxSTLWidget_03::CreateViewPanel 02 \n");
149 _wxMaracasMPR->ConfigureVTK();
150 printf("EED wxSTLWidget_03::CreateViewPanel 03 \n");
152 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
153 panel->SetSizer(sizer);
154 panel->SetAutoLayout(true);
155 panel->SetSize(400,400);
157 printf("EED wxSTLWidget_03::CreateViewPanel 04 \n");
160 //-------------------------------------------------------------------
161 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
163 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 01\n");
164 wxPanel *panel = new wxPanel(parent,-1);
166 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 02\n");
168 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
169 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 03\n");
171 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
172 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
173 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 04\n");
175 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
176 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
177 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 05\n");
179 sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
180 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
181 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 06\n");
183 panel->SetSizer(sizer);
184 panel->SetAutoLayout(true);
185 panel->SetSize(400,600);
187 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 07\n");
192 //-------------------------------------------------------------------
193 wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
195 wxPanel *panel = new wxPanel(parent,-1);
198 _opacity_Vol = new wxSlider( panel, -1, 40, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
199 _opacity_Vol ->SetSize(250,20);
201 _sl_maxSize = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
202 _sl_minSize = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
204 _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
205 _sl_minSizeSpin->SetRange(1,8);
206 _sl_minSizeSpin->SetValue(5);
208 _sl_maxSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
209 _sl_maxSizeSpin->SetRange(1,8);
210 _sl_maxSizeSpin->SetValue(5);
214 _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
215 _sl_RangeSizeSpin->SetRange(1,8);
216 _sl_RangeSizeSpin->SetValue(5);
220 sl_barrange_segmentation = new mBarRange(panel, 300,70);
221 sl_barrange_segmentation -> setVisibleLabels ( true );
222 sl_barrange_segmentation -> setIfWithActualDrawed( false );
223 sl_barrange_segmentation -> setActiveStateTo ( true );
224 sl_barrange_segmentation -> setRepresentedValues (0, 2000);
225 sl_barrange_segmentation -> setDeviceBlitStart (10,10);
226 sl_barrange_segmentation -> setDeviceEndMargin(10);
227 parent->SetBackgroundColour(wxColour(255,255,255));
228 sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
231 wxButton *btnExtract = new wxButton(panel,-1,_T("Segmentation"));
232 wxButton *btnSaveBinaryFile = new wxButton(panel,-1,_T("Save Binary File"));
234 //SIL// Connect(_sl_minSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMinSpin );
235 //SIL// Connect(_sl_maxSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMaxSpin );
236 Connect(_opacity_Vol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol );
237 Connect(btnExtract->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction );
238 Connect(btnSaveBinaryFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile );
241 Connect(_sl_RangeSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin );
242 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnStartChanged_range );
243 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnEndChanged_range );
244 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnBarMoved_range );
246 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
248 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
249 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
252 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Segmentation - - - ")));
253 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
256 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
257 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
259 /*sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min")));
260 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
261 sizer->Add(_sl_minSizeSpin, 1, wxALL|wxEXPAND, 0);*/
262 //sizer->Add(_sl_minSize, 1, wxALL|wxEXPAND, 0);
264 sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
265 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
266 sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
267 sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
269 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" Threshold max")));
270 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" ")));
271 //SIL// sizer->Add(_sl_maxSizeSpin, 1, wxALL|wxEXPAND, 0);
272 //SIL//sizer->Add(_sl_maxSize, 1, wxALL|wxEXPAND, 0);
274 sizer->Add(btnExtract);
275 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
277 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
278 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
279 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
280 sizer->Add(_opacity_Vol);
282 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
283 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
284 sizer->Add(btnSaveBinaryFile);
285 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
287 panel->SetSizer(sizer);
288 panel->SetAutoLayout(true);
289 panel->SetSize(400,600);
294 //-------------------------------------------------
295 wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
297 wxPanel *panel = new wxPanel(parent,-1);
299 stlSliderDeltaGauss = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
300 stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
301 stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
302 stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
303 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
305 Connect(btnFileSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL );
306 Connect(stlSliderDeltaGauss->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel );
307 Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
308 Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal );
309 Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal );
312 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
314 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
315 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
317 sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
318 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
319 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
320 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
322 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
323 sizer->Add(stlSliderDeltaGauss);
325 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
326 sizer->Add(stlSliderMarchingCubes);
328 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
329 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
330 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
331 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
333 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
334 sizer->Add(stlSliderOpacityInternal);
336 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
337 sizer->Add(stlSliderOpacityExternal);
339 sizer->Add(btnFileSTL);
340 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
343 panel->SetSizer(sizer);
344 panel->SetAutoLayout(true);
345 panel->SetSize(400,600);
349 //-------------------------------------------------
350 wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
352 wxPanel *panel = new wxPanel(parent,-1);
354 wxButton *btnReadSTLFile = new wxButton(panel,-1,_T("Read STL File"));
355 wxButton *btnEraseReadSTLFile = new wxButton(panel,-1,_T("Erase STL File"));
356 _sl_opacity_STL_file = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
358 Connect(btnReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad );
359 Connect(btnEraseReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase );
360 Connect(_sl_opacity_STL_file->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile );
363 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
365 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
366 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
367 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
368 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
370 sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
371 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
373 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
374 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
376 sizer->Add(btnReadSTLFile );
377 sizer->Add(btnEraseReadSTLFile );
378 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
379 sizer->Add(_sl_opacity_STL_file);
382 panel->SetSizer(sizer);
383 panel->SetAutoLayout(true);
384 panel->SetSize(400,600);
388 //-------------------------------------------------------------------
389 wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
391 printf("EED wxSTLWidget_03::CreateControlPanel 01\n");
392 wxPanel *panel = new wxPanel(parent,-1);
394 wxNotebook *noteBook = new wxNotebook(panel, -1);
395 printf("EED wxSTLWidget_03::CreateControlPanel 02\n");
396 noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
397 printf("EED wxSTLWidget_03::CreateControlPanel 03\n");
398 noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
399 printf("EED wxSTLWidget_03::CreateControlPanel 04\n");
400 noteBook->AddPage(CreateSmoothingPanel(noteBook) ,_T("2 ->") );
401 printf("EED wxSTLWidget_03::CreateControlPanel 05\n");
402 noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 " ) );
403 printf("EED wxSTLWidget_03::CreateControlPanel 06\n");
404 noteBook->SetSelection(0);
405 noteBook->SetSize(350,250);
406 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
407 sizer->Add(noteBook);
408 panel->SetSizer(sizer);
409 panel->SetAutoLayout(true);
410 panel->SetSize(400,600);
413 printf("EED wxSTLWidget_03::CreateControlPanel 07\n");
416 //------------------------------------------------------------------------
417 void wxSTLWidget_03::Refresh()
419 if (_wxMaracasMPR!=NULL){
420 _wxMaracasMPR->RefreshView();
424 //------------------------------------------------------------------------
427 void wxSTLWidget_03::ConfigureProcessing(marImageData *marimagedata, int x, int y, int z)
431 _imagedata=marimagedata->GetImageData(); // image t=0
432 _imagedata->UpdateInformation();
433 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
434 _imagedata->Update();
437 double puntoactualprov[3];
438 puntoactualprov[0] = x;
439 puntoactualprov[1] = y;
440 puntoactualprov[2] = z;
445 _imagedata->GetSpacing(espprin);
446 _imagedata->GetExtent(extprin);
450 // puntoactualprov[0]=puntoactualprov[0]*espprin[0];
451 // puntoactualprov[1]=puntoactualprov[1]*espprin[1];
452 // puntoactualprov[2]=puntoactualprov[2]*espprin[2];
454 _imagedata->GetScalarRange( _range );
458 /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
459 _sl_minSize->SetValue( (int)(_range[1]/4) );
461 _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
462 _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
465 minRangeValue = _range[0];
466 maxRangeValue = _range[1];
468 sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
469 sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
470 sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
471 sl_barrange_segmentation -> RefreshForce();
472 lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;
475 // _highthreshold->SetRange(_range[0], _range[1]);
476 // _highthreshold->SetValue( _range[1] );
478 // _zslice->SetRange(extprin[4], extprin[5]);
479 // _zslice->SetValue(extprin[5]/2);
481 _thresh = vtkImageThreshold::New();
482 _thresh->SetInput(_imagedata);
483 //_thresh->ReleaseDataFlagOff();
484 _thresh->SetInValue(255);
485 _thresh->SetOutputScalarTypeToUnsignedShort();
486 _thresh->SetOutValue(0);
487 //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
489 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
491 vtkImageCast *cast = vtkImageCast::New();
492 cast->SetInput(_thresh->GetOutput());
493 cast->SetOutputScalarTypeToUnsignedChar();
497 _connect = vtkImageSeedConnectivity::New();
498 _connect->SetInput(cast->GetOutput());
499 _connect->SetInputConnectValue(255);
500 _connect->SetOutputConnectedValue(255);
501 _connect->SetOutputUnconnectedValue(0);
502 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
503 // _connect->Update();
505 cast3 = vtkImageCast::New();
506 cast3->SetInput(_connect->GetOutput());
507 cast3->SetOutputScalarTypeToUnsignedShort();
511 _thresh2 = vtkImageThreshold::New();
512 _thresh2->SetInput(_imagedata);
513 //_thresh2->ReleaseDataFlagOff();
514 _thresh2->SetInValue(255);
515 _thresh2->SetOutputScalarTypeToUnsignedShort();
516 _thresh2->SetOutValue(0);
517 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
518 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
520 cast2 = vtkImageCast::New();
521 cast2->SetInput(_thresh2->GetOutput());
522 cast2->SetOutputScalarTypeToUnsignedChar();
525 _connect2 = vtkImageSeedConnectivity::New();
526 _connect2->SetInput(cast2->GetOutput());
527 _connect2->SetInputConnectValue(255);
528 _connect2->SetOutputConnectedValue(255);
529 _connect2->SetOutputUnconnectedValue(0);
530 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
533 cast4 = vtkImageCast::New();
534 cast4->SetInput(_connect2->GetOutput());
535 cast4->SetOutputScalarTypeToUnsignedShort();
539 //------------------------------------------------------------------------
543 void wxSTLWidget_03::ConfigureVTK()
546 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
547 marImageData *marimagedata = _mar->_experiment->getDynData( )->GetMarImageData();
549 //CONFIGURACION ADICIONAL
550 this->ConfigureSTL();
551 this->ConfigureProcessing(marimagedata,0,0,0);
555 //------------------------------------------------------------------------
557 void wxSTLWidget_03::ResetTree2_JF()
560 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
563 ren->RemoveActor(_2_isoActorMC6);
566 ren->RemoveActor(_2_stripfinal);
570 // if (_2_prgov ) { _2_prgov -> Delete(); }
571 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
572 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
573 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
574 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
575 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
580 _2_stripfinal = NULL;
581 _2_isoMapperMC6 = NULL;
582 _2_isoActorMC6 = NULL;
591 //------------------------------------------------------------------------
592 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
595 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
596 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
598 double puntoactualprov[3];
603 puntoactualprov[0] = x;
604 puntoactualprov[1] = y;
605 puntoactualprov[2] = z;
607 _imagedata->UpdateInformation();
608 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
609 _imagedata->Update();
611 _imagedata->GetSpacing(espprin);
612 _imagedata->GetExtent(extprin);
617 _connect->RemoveAllSeeds ();
618 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
624 _thresh->ThresholdBetween(3000, 3002 );
625 _thresh2->ThresholdBetween(3000, 3001);
626 // _thresh->Update();
627 // _thresh2->Update();
629 _thresh->ThresholdBetween(_minSize, _range[1] );
632 _thresh2->ThresholdBetween(_minSize, _maxSize);
636 _connect2->RemoveAllSeeds ();
637 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
644 // Visualisation - result volume
646 _2_isoMC6 = vtkMarchingCubes::New();
647 _2_isoMC6->SetInput(cast4->GetOutput());
649 _2_isoMC6->SetValue(0, 128);
652 _2_isoMapperMC6 = vtkPolyDataMapper::New();
653 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
654 _2_isoMapperMC6->ScalarVisibilityOff();
655 _2_isoMapperMC6->ImmediateModeRenderingOn();
657 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
659 if (_2_isoActorMC6!=NULL)
661 ren->RemoveActor(_2_isoActorMC6);
665 _2_isoActorMC6 = vtkActor::New();
666 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
667 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
668 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
672 ren->AddActor(_2_isoActorMC6);
676 //------------------------------------------------------------------------
677 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
679 if (_2_isoActorMC6!=NULL){
680 double value = ((double)_opacity_Vol->GetValue())/100;
681 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
685 //------------------------------------------------------------------------
687 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
689 /*wxSlider *sl_A=_sl_minSize;
690 wxSlider *sl_B=_sl_minSizeSpin;
691 int value = sl_A->GetValue();
692 int delta=(int)pow( 4 , sl_B->GetValue() );
693 int min=value - delta/2;
694 int max=value + delta/2;
700 sl_A->SetRange(min,max);
706 //------------------------------------------------------------------------
708 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
710 /*wxSlider *sl_A=_sl_maxSize;
711 wxSlider *sl_B=_sl_maxSizeSpin;
712 int value = sl_A->GetValue();
713 int delta = (int)pow( 4 , sl_B->GetValue() );
714 int min=value - delta/2;
715 int max=value + delta/2;
721 sl_A->SetRange(min,max);*/
724 //------------------------------------------------------------------------
726 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
728 wxSlider *sl_B=_sl_RangeSizeSpin;
730 int value = lastResizeRef_Value;
731 int delta = (int)pow( 4 , sl_B->GetValue() );
732 int startResized = value - delta/2;
733 int endResized = value + delta/2;
735 if( startResized < minRangeValue )
736 startResized = minRangeValue;
738 if( endResized > maxRangeValue )
739 endResized = maxRangeValue;
741 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
742 sl_barrange_segmentation -> RefreshForce();
745 //------------------------------------------------------------------------
746 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
748 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
750 //------------------------------------------------------------------------
751 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
753 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
755 //------------------------------------------------------------------------
756 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
758 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
760 //------------------------------------------------------------------------
762 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
764 wxString dirSTL = _mar->_parameters->getStringParam(
765 marParameters::e_installation_directory );
766 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
767 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
768 dirSTL: wxGetHomeDir( ) );
770 if( dialog.ShowModal( ) == wxID_OK )
772 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
773 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
774 writer->SetInput(cast4->GetOutput());
780 //------------------------------------------------------------------------
781 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
784 _minSize = _sl_minSize->GetValue();
785 _maxSize = _sl_maxSize->GetValue();
787 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
788 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
789 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
790 ExtractSurface((int)(px),(int)(py),(int)(pz));
791 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
797 _minSize = sl_barrange_segmentation->GetStart();
798 _maxSize = sl_barrange_segmentation->GetEnd();
800 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
801 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
802 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
803 ExtractSurface((int)(px),(int)(py),(int)(pz));
804 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
809 //------------------------------------------------------------------------
810 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
812 if (_loadActorSTL!=NULL)
814 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
815 _loadActorSTL->GetProperty( )->SetOpacity( value );
819 //------------------------------------------------------------------------
820 void wxSTLWidget_03::Reset_vtk_STLFile()
823 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
825 ren->RemoveActor(_loadActorSTL);
829 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
830 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
833 _loadSTLMapper = NULL;
834 _loadActorSTL = NULL;
837 //------------------------------------------------------------------------
838 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
843 //------------------------------------------------------------------------
844 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
846 wxString dirSTL = _mar->_parameters->getStringParam(
847 marParameters::e_installation_directory );
848 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
849 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
850 dirSTL: wxGetHomeDir( ) );
852 if( dialog.ShowModal( ) == wxID_OK )
855 vtkSTLReader *imgReader= vtkSTLReader::New();
856 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
857 _loadSTLMapper = vtkPolyDataMapper::New();
858 _loadSTLMapper->SetInput(imgReader->GetOutput());
859 _loadActorSTL = vtkActor::New();
860 _loadActorSTL->SetMapper(_loadSTLMapper);
861 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
862 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
863 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
864 ren->AddActor(_loadActorSTL);
867 //By default *always* update e_installation_directory:
868 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
869 _mar->saveParameters( );
874 // ------------------------------------------------------------------------
875 // END JOIN FUNCTIONS - DHC
876 // ------------------------------------------------------------------------
878 // ------------------------------------------------------------------------
879 // START STL FUNCTIONS - DHC
880 // ------------------------------------------------------------------------
882 void wxSTLWidget_03::ConfigureSTL()
884 stlExterna = vtkPolyData::New();
885 stlInterna = vtkPolyData::New();
887 dsm1 = vtkPolyDataMapper ::New();
888 dsm1->SetInput (stlInterna);
889 dsm1->ScalarVisibilityOff();
891 actorInternal = vtkActor::New();
892 actorInternal->SetMapper (dsm1);
893 actorInternal->GetProperty()->SetColor (0,1,0);
895 dsm2 = vtkPolyDataMapper ::New();
896 dsm2->SetInput (stlExterna);
897 dsm2->ScalarVisibilityOff();
899 actorExternal= vtkActor::New();
900 actorExternal->SetMapper (dsm2);
901 actorExternal->GetProperty()->SetRepresentationToWireframe();
903 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
904 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
905 ren->AddActor(actorInternal);
906 ren->AddActor(actorExternal);
908 stlExtractor = new vtkSTLExtractor();
911 void wxSTLWidget_03::generateSTLSurfaces()
914 // stlExtractor->setVolume(_2_prgov->GetVolumen());
916 stlExtractor->setVolume(cast4->GetOutput());
918 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
919 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
920 stlExtractor->calculate();
921 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
922 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
926 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
927 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
928 actorExternal->GetProperty( )->SetOpacity( value );
933 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
934 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
935 actorInternal->GetProperty( )->SetOpacity( value );
939 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
942 wxString dirSTL = _mar->_parameters->getStringParam(
943 marParameters::e_installation_directory );
944 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
947 // wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
948 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
951 if( dialog.ShowModal( ) == wxID_OK )
955 // ------------------------------------------------------------------------
956 // 1. GENERATE STL FILES
957 // ------------------------------------------------------------------------
958 // const char* fileprefix = "c:\\Creatis\\";
959 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
960 std::string filename;
962 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
964 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
965 filtro->SetInput(stlInterna);
966 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
967 pdcf->SetInput( filtro->GetOutput() );
968 vtkClosePolyData *cpd = vtkClosePolyData::New();
969 cpd->SetInput( pdcf->GetOutput() );
971 // 1.2 se escribe a disco el archivo stl de la superficie interna
973 vtkSTLWriter *writerI = vtkSTLWriter::New();
974 writerI->SetInput( cpd->GetOutput() );
975 // prefix = fileprefix;
976 filename=prefix+"_internal.stl";
977 writerI->SetFileName(filename.c_str());
978 writerI->SetFileTypeToASCII();
982 // 1.3 se escribe a disco el archivo stl de la superficie externa
983 filtro->SetInput(stlExterna);
985 vtkSTLWriter *writerE = vtkSTLWriter::New();
986 writerE->SetInput( cpd->GetOutput() );
987 // prefix = fileprefix;
988 filename=prefix+"_external.stl";
989 writerE->SetFileName( filename.c_str() );
990 writerE->SetFileTypeToASCII();
999 //By default *always* update e_installation_directory:
1000 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
1001 _mar->saveParameters( );
1005 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1008 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
1009 generateSTLSurfaces();
1014 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1017 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1018 generateSTLSurfaces();
1024 // ------------------------------------------------------------------------
1025 // END STL FUNCTIONS - DHC
1026 // ------------------------------------------------------------------------