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();
145 //imagedata->Update();
146 printf("EED wxSTLWidget_03::CreateViewPanel 01 \n");
147 _wxMaracasMPR = new wxMaracasMPR( panel);//JCP 10-03-2009, new marImageData(imagedata), 1 );
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");
161 void wxSTLWidget_03::setImage(vtkImageData* img){
164 _wxMaracasMPR->setMarImage(new marImageData(img), 1);
165 _wxMaracasMPR->ConfigureVTK();
167 //-------------------------------------------------------------------
168 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
170 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 01\n");
171 wxPanel *panel = new wxPanel(parent,-1);
173 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 02\n");
175 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
176 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 03\n");
178 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
179 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
180 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 04\n");
182 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
183 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
184 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 05\n");
186 sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
187 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
188 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 06\n");
190 panel->SetSizer(sizer);
191 panel->SetAutoLayout(true);
192 panel->SetSize(400,600);
194 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 07\n");
199 //-------------------------------------------------------------------
200 wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
202 wxPanel *panel = new wxPanel(parent,-1);
205 _opacity_Vol = new wxSlider( panel, -1, 40, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
206 _opacity_Vol ->SetSize(250,20);
208 _sl_maxSize = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
209 _sl_minSize = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
211 _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
212 _sl_minSizeSpin->SetRange(1,8);
213 _sl_minSizeSpin->SetValue(5);
215 _sl_maxSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
216 _sl_maxSizeSpin->SetRange(1,8);
217 _sl_maxSizeSpin->SetValue(5);
221 _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
222 _sl_RangeSizeSpin->SetRange(1,8);
223 _sl_RangeSizeSpin->SetValue(5);
227 sl_barrange_segmentation = new mBarRange(panel, 300,70);
228 sl_barrange_segmentation -> setVisibleLabels ( true );
229 sl_barrange_segmentation -> setIfWithActualDrawed( false );
230 sl_barrange_segmentation -> setActiveStateTo ( true );
231 sl_barrange_segmentation -> setRepresentedValues (0, 2000);
232 sl_barrange_segmentation -> setDeviceBlitStart (10,10);
233 sl_barrange_segmentation -> setDeviceEndMargin(10);
234 parent->SetBackgroundColour(wxColour(255,255,255));
235 sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
238 wxButton *btnExtract = new wxButton(panel,-1,_T("Segmentation"));
239 wxButton *btnSaveBinaryFile = new wxButton(panel,-1,_T("Save Binary File"));
241 //SIL// Connect(_sl_minSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMinSpin );
242 //SIL// Connect(_sl_maxSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMaxSpin );
243 Connect(_opacity_Vol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol );
244 Connect(btnExtract->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction );
245 Connect(btnSaveBinaryFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile );
248 Connect(_sl_RangeSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin );
249 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnStartChanged_range );
250 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnEndChanged_range );
251 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnBarMoved_range );
253 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
255 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
256 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
259 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Segmentation - - - ")));
260 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
263 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
264 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
266 /*sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min")));
267 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
268 sizer->Add(_sl_minSizeSpin, 1, wxALL|wxEXPAND, 0);*/
269 //sizer->Add(_sl_minSize, 1, wxALL|wxEXPAND, 0);
271 sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
272 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
273 sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
274 sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
276 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" Threshold max")));
277 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" ")));
278 //SIL// sizer->Add(_sl_maxSizeSpin, 1, wxALL|wxEXPAND, 0);
279 //SIL//sizer->Add(_sl_maxSize, 1, wxALL|wxEXPAND, 0);
281 sizer->Add(btnExtract);
282 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
284 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
285 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
286 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
287 sizer->Add(_opacity_Vol);
289 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
290 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
291 sizer->Add(btnSaveBinaryFile);
292 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
294 panel->SetSizer(sizer);
295 panel->SetAutoLayout(true);
296 panel->SetSize(400,600);
301 //-------------------------------------------------
302 wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
304 wxPanel *panel = new wxPanel(parent,-1);
306 stlSliderDeltaGauss = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
307 stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
308 stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
309 stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
310 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
312 Connect(btnFileSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL );
313 Connect(stlSliderDeltaGauss->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel );
314 Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
315 Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal );
316 Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal );
319 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
321 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
322 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
324 sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
325 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
326 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
327 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
329 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
330 sizer->Add(stlSliderDeltaGauss);
332 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
333 sizer->Add(stlSliderMarchingCubes);
335 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
336 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
337 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
338 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
340 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
341 sizer->Add(stlSliderOpacityInternal);
343 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
344 sizer->Add(stlSliderOpacityExternal);
346 sizer->Add(btnFileSTL);
347 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
350 panel->SetSizer(sizer);
351 panel->SetAutoLayout(true);
352 panel->SetSize(400,600);
356 //-------------------------------------------------
357 wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
359 wxPanel *panel = new wxPanel(parent,-1);
361 wxButton *btnReadSTLFile = new wxButton(panel,-1,_T("Read STL File"));
362 wxButton *btnEraseReadSTLFile = new wxButton(panel,-1,_T("Erase STL File"));
363 _sl_opacity_STL_file = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
365 Connect(btnReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad );
366 Connect(btnEraseReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase );
367 Connect(_sl_opacity_STL_file->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile );
370 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
372 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
373 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
374 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
375 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
377 sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
378 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
380 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
381 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
383 sizer->Add(btnReadSTLFile );
384 sizer->Add(btnEraseReadSTLFile );
385 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
386 sizer->Add(_sl_opacity_STL_file);
389 panel->SetSizer(sizer);
390 panel->SetAutoLayout(true);
391 panel->SetSize(400,600);
395 //-------------------------------------------------------------------
396 wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
398 printf("EED wxSTLWidget_03::CreateControlPanel 01\n");
399 wxPanel *panel = new wxPanel(parent,-1);
401 wxNotebook *noteBook = new wxNotebook(panel, -1);
402 printf("EED wxSTLWidget_03::CreateControlPanel 02\n");
403 noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
404 printf("EED wxSTLWidget_03::CreateControlPanel 03\n");
405 noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
406 printf("EED wxSTLWidget_03::CreateControlPanel 04\n");
407 noteBook->AddPage(CreateSmoothingPanel(noteBook) ,_T("2 ->") );
408 printf("EED wxSTLWidget_03::CreateControlPanel 05\n");
409 noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 " ) );
410 printf("EED wxSTLWidget_03::CreateControlPanel 06\n");
411 noteBook->SetSelection(0);
412 noteBook->SetSize(350,250);
413 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
414 sizer->Add(noteBook);
415 panel->SetSizer(sizer);
416 panel->SetAutoLayout(true);
417 panel->SetSize(400,600);
420 printf("EED wxSTLWidget_03::CreateControlPanel 07\n");
423 //------------------------------------------------------------------------
424 void wxSTLWidget_03::Refresh()
426 if (_wxMaracasMPR!=NULL){
427 _wxMaracasMPR->RefreshView();
431 //------------------------------------------------------------------------
434 void wxSTLWidget_03::ConfigureProcessing(marImageData *marimagedata, int x, int y, int z)
438 _imagedata=marimagedata->GetImageData(); // image t=0
439 _imagedata->UpdateInformation();
440 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
441 _imagedata->Update();
444 double puntoactualprov[3];
445 puntoactualprov[0] = x;
446 puntoactualprov[1] = y;
447 puntoactualprov[2] = z;
452 _imagedata->GetSpacing(espprin);
453 _imagedata->GetExtent(extprin);
457 // puntoactualprov[0]=puntoactualprov[0]*espprin[0];
458 // puntoactualprov[1]=puntoactualprov[1]*espprin[1];
459 // puntoactualprov[2]=puntoactualprov[2]*espprin[2];
461 _imagedata->GetScalarRange( _range );
465 /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
466 _sl_minSize->SetValue( (int)(_range[1]/4) );
468 _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
469 _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
472 minRangeValue = _range[0];
473 maxRangeValue = _range[1];
475 sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
476 sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
477 sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
478 sl_barrange_segmentation -> RefreshForce();
479 lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;
482 // _highthreshold->SetRange(_range[0], _range[1]);
483 // _highthreshold->SetValue( _range[1] );
485 // _zslice->SetRange(extprin[4], extprin[5]);
486 // _zslice->SetValue(extprin[5]/2);
488 _thresh = vtkImageThreshold::New();
489 _thresh->SetInput(_imagedata);
490 //_thresh->ReleaseDataFlagOff();
491 _thresh->SetInValue(255);
492 _thresh->SetOutputScalarTypeToUnsignedShort();
493 _thresh->SetOutValue(0);
494 //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
496 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
498 vtkImageCast *cast = vtkImageCast::New();
499 cast->SetInput(_thresh->GetOutput());
500 cast->SetOutputScalarTypeToUnsignedChar();
504 _connect = vtkImageSeedConnectivity::New();
505 _connect->SetInput(cast->GetOutput());
506 _connect->SetInputConnectValue(255);
507 _connect->SetOutputConnectedValue(255);
508 _connect->SetOutputUnconnectedValue(0);
509 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
510 // _connect->Update();
512 cast3 = vtkImageCast::New();
513 cast3->SetInput(_connect->GetOutput());
514 cast3->SetOutputScalarTypeToUnsignedShort();
518 _thresh2 = vtkImageThreshold::New();
519 _thresh2->SetInput(_imagedata);
520 //_thresh2->ReleaseDataFlagOff();
521 _thresh2->SetInValue(255);
522 _thresh2->SetOutputScalarTypeToUnsignedShort();
523 _thresh2->SetOutValue(0);
524 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
525 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
527 cast2 = vtkImageCast::New();
528 cast2->SetInput(_thresh2->GetOutput());
529 cast2->SetOutputScalarTypeToUnsignedChar();
532 _connect2 = vtkImageSeedConnectivity::New();
533 _connect2->SetInput(cast2->GetOutput());
534 _connect2->SetInputConnectValue(255);
535 _connect2->SetOutputConnectedValue(255);
536 _connect2->SetOutputUnconnectedValue(0);
537 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
540 cast4 = vtkImageCast::New();
541 cast4->SetInput(_connect2->GetOutput());
542 cast4->SetOutputScalarTypeToUnsignedShort();
546 //------------------------------------------------------------------------
550 void wxSTLWidget_03::ConfigureVTK()
553 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
554 marImageData *marimagedata;// = _mar->_experiment->getDynData( )->GetMarImageData();
556 //CONFIGURACION ADICIONAL
557 this->ConfigureSTL();
558 this->ConfigureProcessing(marimagedata,0,0,0);
562 //------------------------------------------------------------------------
564 void wxSTLWidget_03::ResetTree2_JF()
567 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
570 ren->RemoveActor(_2_isoActorMC6);
573 ren->RemoveActor(_2_stripfinal);
577 // if (_2_prgov ) { _2_prgov -> Delete(); }
578 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
579 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
580 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
581 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
582 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
587 _2_stripfinal = NULL;
588 _2_isoMapperMC6 = NULL;
589 _2_isoActorMC6 = NULL;
598 //------------------------------------------------------------------------
599 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
602 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
603 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
605 double puntoactualprov[3];
610 puntoactualprov[0] = x;
611 puntoactualprov[1] = y;
612 puntoactualprov[2] = z;
614 _imagedata->UpdateInformation();
615 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
616 _imagedata->Update();
618 _imagedata->GetSpacing(espprin);
619 _imagedata->GetExtent(extprin);
624 _connect->RemoveAllSeeds ();
625 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
631 _thresh->ThresholdBetween(3000, 3002 );
632 _thresh2->ThresholdBetween(3000, 3001);
633 // _thresh->Update();
634 // _thresh2->Update();
636 _thresh->ThresholdBetween(_minSize, _range[1] );
639 _thresh2->ThresholdBetween(_minSize, _maxSize);
643 _connect2->RemoveAllSeeds ();
644 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
651 // Visualisation - result volume
653 _2_isoMC6 = vtkMarchingCubes::New();
654 _2_isoMC6->SetInput(cast4->GetOutput());
656 _2_isoMC6->SetValue(0, 128);
659 _2_isoMapperMC6 = vtkPolyDataMapper::New();
660 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
661 _2_isoMapperMC6->ScalarVisibilityOff();
662 _2_isoMapperMC6->ImmediateModeRenderingOn();
664 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
666 if (_2_isoActorMC6!=NULL)
668 ren->RemoveActor(_2_isoActorMC6);
672 _2_isoActorMC6 = vtkActor::New();
673 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
674 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
675 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
679 ren->AddActor(_2_isoActorMC6);
683 //------------------------------------------------------------------------
684 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
686 if (_2_isoActorMC6!=NULL){
687 double value = ((double)_opacity_Vol->GetValue())/100;
688 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
692 //------------------------------------------------------------------------
694 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
696 /*wxSlider *sl_A=_sl_minSize;
697 wxSlider *sl_B=_sl_minSizeSpin;
698 int value = sl_A->GetValue();
699 int delta=(int)pow( 4 , sl_B->GetValue() );
700 int min=value - delta/2;
701 int max=value + delta/2;
707 sl_A->SetRange(min,max);
713 //------------------------------------------------------------------------
715 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
717 /*wxSlider *sl_A=_sl_maxSize;
718 wxSlider *sl_B=_sl_maxSizeSpin;
719 int value = sl_A->GetValue();
720 int delta = (int)pow( 4 , sl_B->GetValue() );
721 int min=value - delta/2;
722 int max=value + delta/2;
728 sl_A->SetRange(min,max);*/
731 //------------------------------------------------------------------------
733 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
735 wxSlider *sl_B=_sl_RangeSizeSpin;
737 int value = lastResizeRef_Value;
738 int delta = (int)pow( 4 , sl_B->GetValue() );
739 int startResized = value - delta/2;
740 int endResized = value + delta/2;
742 if( startResized < minRangeValue )
743 startResized = minRangeValue;
745 if( endResized > maxRangeValue )
746 endResized = maxRangeValue;
748 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
749 sl_barrange_segmentation -> RefreshForce();
752 //------------------------------------------------------------------------
753 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
755 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
757 //------------------------------------------------------------------------
758 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
760 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
762 //------------------------------------------------------------------------
763 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
765 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
767 //------------------------------------------------------------------------
769 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
771 wxString dirSTL;// = _mar->_parameters->getStringParam(
772 //marParameters::e_installation_directory );
773 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
774 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
775 dirSTL: wxGetHomeDir( ) );
777 if( dialog.ShowModal( ) == wxID_OK )
779 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
780 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
781 writer->SetInput(cast4->GetOutput());
787 //------------------------------------------------------------------------
788 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
791 _minSize = _sl_minSize->GetValue();
792 _maxSize = _sl_maxSize->GetValue();
794 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
795 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
796 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
797 ExtractSurface((int)(px),(int)(py),(int)(pz));
798 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
804 _minSize = sl_barrange_segmentation->GetStart();
805 _maxSize = sl_barrange_segmentation->GetEnd();
807 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
808 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
809 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
810 ExtractSurface((int)(px),(int)(py),(int)(pz));
811 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
816 //------------------------------------------------------------------------
817 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
819 if (_loadActorSTL!=NULL)
821 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
822 _loadActorSTL->GetProperty( )->SetOpacity( value );
826 //------------------------------------------------------------------------
827 void wxSTLWidget_03::Reset_vtk_STLFile()
830 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
832 ren->RemoveActor(_loadActorSTL);
836 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
837 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
840 _loadSTLMapper = NULL;
841 _loadActorSTL = NULL;
844 //------------------------------------------------------------------------
845 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
850 //------------------------------------------------------------------------
851 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
853 wxString dirSTL;// = _mar->_parameters->getStringParam(
854 //marParameters::e_installation_directory );
855 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
856 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
857 dirSTL: wxGetHomeDir( ) );
859 if( dialog.ShowModal( ) == wxID_OK )
862 vtkSTLReader *imgReader= vtkSTLReader::New();
863 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
864 _loadSTLMapper = vtkPolyDataMapper::New();
865 _loadSTLMapper->SetInput(imgReader->GetOutput());
866 _loadActorSTL = vtkActor::New();
867 _loadActorSTL->SetMapper(_loadSTLMapper);
868 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
869 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
870 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
871 ren->AddActor(_loadActorSTL);
874 //By default *always* update e_installation_directory:
875 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
876 //_mar->saveParameters( );
881 // ------------------------------------------------------------------------
882 // END JOIN FUNCTIONS - DHC
883 // ------------------------------------------------------------------------
885 // ------------------------------------------------------------------------
886 // START STL FUNCTIONS - DHC
887 // ------------------------------------------------------------------------
889 void wxSTLWidget_03::ConfigureSTL()
891 stlExterna = vtkPolyData::New();
892 stlInterna = vtkPolyData::New();
894 dsm1 = vtkPolyDataMapper ::New();
895 dsm1->SetInput (stlInterna);
896 dsm1->ScalarVisibilityOff();
898 actorInternal = vtkActor::New();
899 actorInternal->SetMapper (dsm1);
900 actorInternal->GetProperty()->SetColor (0,1,0);
902 dsm2 = vtkPolyDataMapper ::New();
903 dsm2->SetInput (stlExterna);
904 dsm2->ScalarVisibilityOff();
906 actorExternal= vtkActor::New();
907 actorExternal->SetMapper (dsm2);
908 actorExternal->GetProperty()->SetRepresentationToWireframe();
910 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
911 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
912 ren->AddActor(actorInternal);
913 ren->AddActor(actorExternal);
915 stlExtractor = new vtkSTLExtractor();
918 void wxSTLWidget_03::generateSTLSurfaces()
921 // stlExtractor->setVolume(_2_prgov->GetVolumen());
923 stlExtractor->setVolume(cast4->GetOutput());
925 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
926 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
927 stlExtractor->calculate();
928 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
929 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
933 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
934 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
935 actorExternal->GetProperty( )->SetOpacity( value );
940 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
941 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
942 actorInternal->GetProperty( )->SetOpacity( value );
946 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
949 wxString dirSTL;// = _mar->_parameters->getStringParam(
950 //marParameters::e_installation_directory );
951 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
954 // wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
955 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
958 if( dialog.ShowModal( ) == wxID_OK )
962 // ------------------------------------------------------------------------
963 // 1. GENERATE STL FILES
964 // ------------------------------------------------------------------------
965 // const char* fileprefix = "c:\\Creatis\\";
966 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
967 std::string filename;
969 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
971 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
972 filtro->SetInput(stlInterna);
973 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
974 pdcf->SetInput( filtro->GetOutput() );
975 vtkClosePolyData *cpd = vtkClosePolyData::New();
976 cpd->SetInput( pdcf->GetOutput() );
978 // 1.2 se escribe a disco el archivo stl de la superficie interna
980 vtkSTLWriter *writerI = vtkSTLWriter::New();
981 writerI->SetInput( cpd->GetOutput() );
982 // prefix = fileprefix;
983 filename=prefix+"_internal.stl";
984 writerI->SetFileName(filename.c_str());
985 writerI->SetFileTypeToASCII();
989 // 1.3 se escribe a disco el archivo stl de la superficie externa
990 filtro->SetInput(stlExterna);
992 vtkSTLWriter *writerE = vtkSTLWriter::New();
993 writerE->SetInput( cpd->GetOutput() );
994 // prefix = fileprefix;
995 filename=prefix+"_external.stl";
996 writerE->SetFileName( filename.c_str() );
997 writerE->SetFileTypeToASCII();
1006 //By default *always* update e_installation_directory:
1007 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
1008 //_mar->saveParameters( );
1012 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1015 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
1016 generateSTLSurfaces();
1021 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1024 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1025 generateSTLSurfaces();
1031 // ------------------------------------------------------------------------
1032 // END STL FUNCTIONS - DHC
1033 // ------------------------------------------------------------------------