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){
156 marImageData* marimagedata = new marImageData(img);
158 _wxMaracasMPR->setMarImage(marimagedata, 1);
159 _wxMaracasMPR->ConfigureVTK();
160 this->ConfigureProcessing(marimagedata,0,0,0);
161 this->ConfigureSTL();
163 _wxMaracasMPR->Refresh();
167 //-------------------------------------------------------------------
168 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
170 wxPanel *panel = new wxPanel(parent,-1);
173 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
175 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
176 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
178 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
179 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
181 sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
182 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
184 panel->SetSizer(sizer);
185 panel->SetAutoLayout(true);
186 panel->SetSize(400,600);
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 wxPanel *panel = new wxPanel(parent,-1);
393 wxNotebook *noteBook = new wxNotebook(panel, -1);
394 noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
395 noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
396 noteBook->AddPage(CreateSmoothingPanel(noteBook) ,_T("2 ->") );
397 noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 " ) );
398 noteBook->SetSelection(0);
399 noteBook->SetSize(350,250);
400 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
401 sizer->Add(noteBook);
402 panel->SetSizer(sizer);
403 panel->SetAutoLayout(true);
404 panel->SetSize(400,600);
409 //------------------------------------------------------------------------
410 void wxSTLWidget_03::Refresh()
412 if (_wxMaracasMPR!=NULL){
413 _wxMaracasMPR->RefreshView();
417 //------------------------------------------------------------------------
420 void wxSTLWidget_03::ConfigureProcessing(marImageData *marimagedata, int x, int y, int z)
424 _imagedata=marimagedata->GetImageData(); // image t=0
425 _imagedata->UpdateInformation();
426 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
427 _imagedata->Update();
430 double puntoactualprov[3];
431 puntoactualprov[0] = x;
432 puntoactualprov[1] = y;
433 puntoactualprov[2] = z;
438 _imagedata->GetSpacing(espprin);
439 _imagedata->GetExtent(extprin);
443 // puntoactualprov[0]=puntoactualprov[0]*espprin[0];
444 // puntoactualprov[1]=puntoactualprov[1]*espprin[1];
445 // puntoactualprov[2]=puntoactualprov[2]*espprin[2];
447 _imagedata->GetScalarRange( _range );
451 /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
452 _sl_minSize->SetValue( (int)(_range[1]/4) );
454 _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
455 _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
458 minRangeValue = _range[0];
459 maxRangeValue = _range[1];
461 sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
462 sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
463 sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
464 sl_barrange_segmentation -> RefreshForce();
465 lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;
468 // _highthreshold->SetRange(_range[0], _range[1]);
469 // _highthreshold->SetValue( _range[1] );
471 // _zslice->SetRange(extprin[4], extprin[5]);
472 // _zslice->SetValue(extprin[5]/2);
474 _thresh = vtkImageThreshold::New();
475 _thresh->SetInput(_imagedata);
476 //_thresh->ReleaseDataFlagOff();
477 _thresh->SetInValue(255);
478 _thresh->SetOutputScalarTypeToUnsignedShort();
479 _thresh->SetOutValue(0);
480 //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
482 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
484 vtkImageCast *cast = vtkImageCast::New();
485 cast->SetInput(_thresh->GetOutput());
486 cast->SetOutputScalarTypeToUnsignedChar();
490 _connect = vtkImageSeedConnectivity::New();
491 _connect->SetInput(cast->GetOutput());
492 _connect->SetInputConnectValue(255);
493 _connect->SetOutputConnectedValue(255);
494 _connect->SetOutputUnconnectedValue(0);
495 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
496 // _connect->Update();
498 cast3 = vtkImageCast::New();
499 cast3->SetInput(_connect->GetOutput());
500 cast3->SetOutputScalarTypeToUnsignedShort();
504 _thresh2 = vtkImageThreshold::New();
505 _thresh2->SetInput(_imagedata);
506 //_thresh2->ReleaseDataFlagOff();
507 _thresh2->SetInValue(255);
508 _thresh2->SetOutputScalarTypeToUnsignedShort();
509 _thresh2->SetOutValue(0);
510 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
511 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
513 cast2 = vtkImageCast::New();
514 cast2->SetInput(_thresh2->GetOutput());
515 cast2->SetOutputScalarTypeToUnsignedChar();
518 _connect2 = vtkImageSeedConnectivity::New();
519 _connect2->SetInput(cast2->GetOutput());
520 _connect2->SetInputConnectValue(255);
521 _connect2->SetOutputConnectedValue(255);
522 _connect2->SetOutputUnconnectedValue(0);
523 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
526 cast4 = vtkImageCast::New();
527 cast4->SetInput(_connect2->GetOutput());
528 cast4->SetOutputScalarTypeToUnsignedShort();
532 //------------------------------------------------------------------------
536 void wxSTLWidget_03::ConfigureVTK()
539 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
540 //marImageData *marimagedata;// = _mar->_experiment->getDynData( )->GetMarImageData();
542 //CONFIGURACION ADICIONAL
543 this->ConfigureSTL();
544 //this->ConfigureProcessing(marimagedata,0,0,0);
548 //------------------------------------------------------------------------
550 void wxSTLWidget_03::ResetTree2_JF()
553 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
556 ren->RemoveActor(_2_isoActorMC6);
559 ren->RemoveActor(_2_stripfinal);
563 // if (_2_prgov ) { _2_prgov -> Delete(); }
564 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
565 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
566 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
567 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
568 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
573 _2_stripfinal = NULL;
574 _2_isoMapperMC6 = NULL;
575 _2_isoActorMC6 = NULL;
584 //------------------------------------------------------------------------
585 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
588 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
589 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
591 double puntoactualprov[3];
596 puntoactualprov[0] = x;
597 puntoactualprov[1] = y;
598 puntoactualprov[2] = z;
600 _imagedata->UpdateInformation();
601 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
602 _imagedata->Update();
604 _imagedata->GetSpacing(espprin);
605 _imagedata->GetExtent(extprin);
610 _connect->RemoveAllSeeds ();
611 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
617 _thresh->ThresholdBetween(3000, 3002 );
618 _thresh2->ThresholdBetween(3000, 3001);
619 // _thresh->Update();
620 // _thresh2->Update();
622 _thresh->ThresholdBetween(_minSize, _range[1] );
625 _thresh2->ThresholdBetween(_minSize, _maxSize);
629 _connect2->RemoveAllSeeds ();
630 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
637 // Visualisation - result volume
639 _2_isoMC6 = vtkMarchingCubes::New();
640 _2_isoMC6->SetInput(cast4->GetOutput());
642 _2_isoMC6->SetValue(0, 128);
645 _2_isoMapperMC6 = vtkPolyDataMapper::New();
646 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
647 _2_isoMapperMC6->ScalarVisibilityOff();
648 _2_isoMapperMC6->ImmediateModeRenderingOn();
650 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
652 if (_2_isoActorMC6!=NULL)
654 ren->RemoveActor(_2_isoActorMC6);
658 _2_isoActorMC6 = vtkActor::New();
659 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
660 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
661 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
665 ren->AddActor(_2_isoActorMC6);
669 //------------------------------------------------------------------------
670 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
672 if (_2_isoActorMC6!=NULL){
673 double value = ((double)_opacity_Vol->GetValue())/100;
674 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
678 //------------------------------------------------------------------------
680 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
682 /*wxSlider *sl_A=_sl_minSize;
683 wxSlider *sl_B=_sl_minSizeSpin;
684 int value = sl_A->GetValue();
685 int delta=(int)pow( 4 , sl_B->GetValue() );
686 int min=value - delta/2;
687 int max=value + delta/2;
693 sl_A->SetRange(min,max);
699 //------------------------------------------------------------------------
701 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
703 /*wxSlider *sl_A=_sl_maxSize;
704 wxSlider *sl_B=_sl_maxSizeSpin;
705 int value = sl_A->GetValue();
706 int delta = (int)pow( 4 , sl_B->GetValue() );
707 int min=value - delta/2;
708 int max=value + delta/2;
714 sl_A->SetRange(min,max);*/
717 //------------------------------------------------------------------------
719 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
721 wxSlider *sl_B=_sl_RangeSizeSpin;
723 int value = lastResizeRef_Value;
724 int delta = (int)pow( 4 , sl_B->GetValue() );
725 int startResized = value - delta/2;
726 int endResized = value + delta/2;
728 if( startResized < minRangeValue )
729 startResized = minRangeValue;
731 if( endResized > maxRangeValue )
732 endResized = maxRangeValue;
734 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
735 sl_barrange_segmentation -> RefreshForce();
738 //------------------------------------------------------------------------
739 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
741 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
743 //------------------------------------------------------------------------
744 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
746 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
748 //------------------------------------------------------------------------
749 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
751 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
753 //------------------------------------------------------------------------
755 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
757 wxString dirSTL;// = _mar->_parameters->getStringParam(
758 //marParameters::e_installation_directory );
759 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
760 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
761 dirSTL: wxGetHomeDir( ) );
763 if( dialog.ShowModal( ) == wxID_OK )
765 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
766 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
767 writer->SetInput(cast4->GetOutput());
773 //------------------------------------------------------------------------
774 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
777 _minSize = _sl_minSize->GetValue();
778 _maxSize = _sl_maxSize->GetValue();
780 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
781 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
782 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
783 ExtractSurface((int)(px),(int)(py),(int)(pz));
784 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
790 _minSize = sl_barrange_segmentation->GetStart();
791 _maxSize = sl_barrange_segmentation->GetEnd();
793 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
794 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
795 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
796 ExtractSurface((int)(px),(int)(py),(int)(pz));
797 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
802 //------------------------------------------------------------------------
803 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
805 if (_loadActorSTL!=NULL)
807 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
808 _loadActorSTL->GetProperty( )->SetOpacity( value );
812 //------------------------------------------------------------------------
813 void wxSTLWidget_03::Reset_vtk_STLFile()
816 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
818 ren->RemoveActor(_loadActorSTL);
822 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
823 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
826 _loadSTLMapper = NULL;
827 _loadActorSTL = NULL;
830 //------------------------------------------------------------------------
831 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
836 //------------------------------------------------------------------------
837 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
839 wxString dirSTL;// = _mar->_parameters->getStringParam(
840 //marParameters::e_installation_directory );
841 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
842 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
843 dirSTL: wxGetHomeDir( ) );
845 if( dialog.ShowModal( ) == wxID_OK )
848 vtkSTLReader *imgReader= vtkSTLReader::New();
849 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
850 _loadSTLMapper = vtkPolyDataMapper::New();
851 _loadSTLMapper->SetInput(imgReader->GetOutput());
852 _loadActorSTL = vtkActor::New();
853 _loadActorSTL->SetMapper(_loadSTLMapper);
854 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
855 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
856 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
857 ren->AddActor(_loadActorSTL);
860 //By default *always* update e_installation_directory:
861 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
862 //_mar->saveParameters( );
867 // ------------------------------------------------------------------------
868 // END JOIN FUNCTIONS - DHC
869 // ------------------------------------------------------------------------
871 // ------------------------------------------------------------------------
872 // START STL FUNCTIONS - DHC
873 // ------------------------------------------------------------------------
875 void wxSTLWidget_03::ConfigureSTL()
877 stlExterna = vtkPolyData::New();
878 stlInterna = vtkPolyData::New();
880 dsm1 = vtkPolyDataMapper ::New();
881 dsm1->SetInput (stlInterna);
882 dsm1->ScalarVisibilityOff();
884 actorInternal = vtkActor::New();
885 actorInternal->SetMapper (dsm1);
886 actorInternal->GetProperty()->SetColor (0,1,0);
888 dsm2 = vtkPolyDataMapper ::New();
889 dsm2->SetInput (stlExterna);
890 dsm2->ScalarVisibilityOff();
892 actorExternal= vtkActor::New();
893 actorExternal->SetMapper (dsm2);
894 actorExternal->GetProperty()->SetRepresentationToWireframe();
896 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
897 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
898 ren->AddActor(actorInternal);
899 ren->AddActor(actorExternal);
901 stlExtractor = new vtkSTLExtractor();
904 void wxSTLWidget_03::generateSTLSurfaces()
907 // stlExtractor->setVolume(_2_prgov->GetVolumen());
909 stlExtractor->setVolume(cast4->GetOutput());
911 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
912 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
913 stlExtractor->calculate();
914 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
915 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
919 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
920 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
921 actorExternal->GetProperty( )->SetOpacity( value );
926 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
927 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
928 actorInternal->GetProperty( )->SetOpacity( value );
932 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
935 wxString dirSTL;// = _mar->_parameters->getStringParam(
936 //marParameters::e_installation_directory );
937 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
940 // wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
941 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
944 if( dialog.ShowModal( ) == wxID_OK )
948 // ------------------------------------------------------------------------
949 // 1. GENERATE STL FILES
950 // ------------------------------------------------------------------------
951 // const char* fileprefix = "c:\\Creatis\\";
952 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
953 std::string filename;
955 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
957 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
958 filtro->SetInput(stlInterna);
959 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
960 pdcf->SetInput( filtro->GetOutput() );
961 vtkClosePolyData *cpd = vtkClosePolyData::New();
962 cpd->SetInput( pdcf->GetOutput() );
964 // 1.2 se escribe a disco el archivo stl de la superficie interna
966 vtkSTLWriter *writerI = vtkSTLWriter::New();
967 writerI->SetInput( cpd->GetOutput() );
968 // prefix = fileprefix;
969 filename=prefix+"_internal.stl";
970 writerI->SetFileName(filename.c_str());
971 writerI->SetFileTypeToASCII();
975 // 1.3 se escribe a disco el archivo stl de la superficie externa
976 filtro->SetInput(stlExterna);
978 vtkSTLWriter *writerE = vtkSTLWriter::New();
979 writerE->SetInput( cpd->GetOutput() );
980 // prefix = fileprefix;
981 filename=prefix+"_external.stl";
982 writerE->SetFileName( filename.c_str() );
983 writerE->SetFileTypeToASCII();
992 //By default *always* update e_installation_directory:
993 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
994 //_mar->saveParameters( );
998 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1001 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
1002 generateSTLSurfaces();
1007 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1010 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1011 generateSTLSurfaces();
1017 // ------------------------------------------------------------------------
1018 // END STL FUNCTIONS - DHC
1019 // ------------------------------------------------------------------------