1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 #include "vtkObjectFactory.h"
30 #include "vtkCylinderSource.h"
31 #include "vtkPolyDataMapper.h"
32 #include "vtkRenderer.h"
33 #include "vtkRenderWindow.h"
34 #include "vtkRenderWindowInteractor.h"
35 #include "vtkProperty.h"
36 #include "vtkCamera.h"
37 #include "vtkPoints.h"
38 #include "vtkCellArray.h"
39 #include "vtkPolyData.h"
40 #include "vtkPolyDataMapper.h"
41 #include "vtkPolyDataWriter.h"
42 #include "vtkPolyDataReader.h"
43 #include "vtkImageReader.h"
44 #include "vtkImageViewer.h"
45 #include "vtkImageViewer2.h"
46 #include "vtkImageToStructuredPoints.h"
47 #include <vtkImageThreshold.h>
48 #include "vtkImageWriter.h"
51 #include "vtkExtractVOI.h"
52 #include "vtkImageClip.h"
53 #include "vtkImageResample.h"
54 #include "vtkImageThreshold.h"
55 #include "vtkImageCast.h"
56 #include "vtkImageSeedConnectivity.h"
57 #include "vtkImageData.h"
58 #include "vtkMarchingCubes.h"
59 #include "vtkImageReslice.h"
60 #include "vtkTransform.h"
61 #include "vtkSphereSource.h"
62 #include "vtkDoubleArray.h"
63 #include "vtkPointData.h"
64 #include "vtkCommand.h"
65 #include "vtkCallbackCommand.h"
66 #include "vtkImageResample.h"
68 #include "vtkStripper.h"
69 #include <vtkSTLReader.h>
70 #include "vtkMetaImageWriter.h"
73 #include "vtkTriangleFilter.h"
74 #include "vtkSTLWriter.h"
75 #include "vtkPolyDataConnectivityFilter.h"
76 #include "vtkClosePolyData.h"
77 #include "vtkAppendFilter.h"
79 #include "wxSTLWidget_03.h"
81 #include <wx/splitter.h>
83 #include <wx/filedlg.h>
87 //-------------------------------------------------------------------
88 //-------------------------------------------------------------------
89 //-------------------------------------------------------------------
90 wxSTLWidget_03::wxSTLWidget_03(wxWindow *parent)//, marInterface* mar)
91 : wxPanel( parent, -1)
96 cast4=NULL; // binary segmentation result
104 _2_isoMapperMC6=NULL;
109 sl_barrange_segmentation=NULL;
114 stlSliderDeltaGauss=NULL;
115 stlSliderMarchingCubes=NULL;
118 stlSliderOpacityInternal=NULL;
121 stlSliderOpacityExternal=NULL;
123 _sl_opacity_STL_file=NULL;
124 arteryImageData=NULL;
126 joinMarchingCubes=NULL;
132 _stlMarchingCubesLevel = 128;
133 _stlDeltaGaussLevel = 100;
135 /*_mar=new marInterface();
136 _mar->_parameters->setRescaleSlope( mar->_parameters->getRescaleSlope() );
137 _mar->_parameters->setRescaleIntercept( mar->_parameters->getRescaleIntercept() );
138 _mar->_parameters->setIntParam( marParameters::e_voxel_type, marParameters::VOX_TYPE_MINIMUM );
139 _mar->_parameters->setDoubleParam( marParameters::e_voxel_x_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_x_dimension) );
140 _mar->_parameters->setDoubleParam( marParameters::e_voxel_y_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_y_dimension) );
141 _mar->_parameters->setDoubleParam( marParameters::e_voxel_z_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_z_dimension) );
143 mar->_experiment->getVOI( voi );
144 _mar->_experiment->setVOI( voi );
145 _mar->SetDicom(mar->_dicom);
146 _mar->initExperiment( );*/
149 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
150 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
151 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
152 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
154 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
155 pnlSplitter -> SetMinimumPaneSize( 150 );
156 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
158 // pnlSplitter -> SplitVertically( new wxPanel(pnlSplitter,-1), new wxPanel(pnlSplitter,-1) , 600 );
159 // pnlSplitter -> SplitVertically( viewPanel, new wxPanel(pnlSplitter,-1) , 600 );
161 this -> SetSizer(sizer);
166 //-------------------------------------------------------------------
167 wxSTLWidget_03::~wxSTLWidget_03(){
169 //Reset_vtk_STLFile();
171 if(_imagedata!=NULL){
172 _imagedata->Delete();
174 if(cast2){cast2->Delete();}
175 if(cast3){cast3->Delete();}
176 if(cast4){cast4->Delete();}
177 if(_thresh){_thresh->Delete();}
178 if(_thresh2){_thresh2->Delete();}
179 if(_cast){_cast->Delete();}
180 if(_connect){_connect->Delete();}
181 if(_connect2){_connect2->Delete();}
182 if(_2_mapfinal){_2_mapfinal->Delete();}
183 if(_2_stripfinal){_2_stripfinal->Delete();}
184 if(_2_isoMapperMC6){_2_isoMapperMC6->Delete();}
185 if(_2_isoActorMC6){_2_isoActorMC6->Delete();}
186 if(_2_isoMC6){_2_isoMC6->Delete();}
188 if(_loadSTLMapper){_loadSTLMapper->Delete();}
189 if(_loadActorSTL){_loadActorSTL->Delete();}
190 if(sl_barrange_segmentation){delete sl_barrange_segmentation;}
191 if(_imageviewer3D){delete _imageviewer3D;}
192 if(_wxMaracasMPR){delete _wxMaracasMPR;}
193 if(stlInterna){stlInterna->Delete();}
194 if(stlExterna){stlExterna->Delete();}
195 if(dsm1){dsm1->Delete();}
196 if(actorInternal){actorInternal->Delete();}
197 if(dsm2){dsm2->Delete();}
198 if(actorExternal){actorExternal->Delete();}
199 //if(stlExtractor){stlExtractor->Delete();}
200 if(arteryImageData){arteryImageData->Delete();}
201 if(joiner){delete joiner;}
202 if(joinMarchingCubes){joinMarchingCubes->Delete();}
203 if(joinMapper){joinMapper->Delete(); }
204 if(joinActor){joinActor->Delete();}
206 //-------------------------------------------------------------------
207 wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
209 wxPanel *panel = new wxPanel(parent,-1);
210 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
214 //vtkImageData *imagedata;
215 //imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
216 //imagedata->Update();
217 _wxMaracasMPR = new wxMaracasMPR( panel);//JCP 10-03-2009, new marImageData(imagedata), 1 );
218 _wxMaracasMPR->ConfigureVTK();
220 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
221 panel->SetSizer(sizer);
222 panel->SetAutoLayout(true);
223 panel->SetSize(400,400);
228 void wxSTLWidget_03::setImage(vtkImageData* img){
230 _wxMaracasMPR->setImageData(img, 1);
231 _wxMaracasMPR->ConfigureVTK();
234 this->ConfigureProcessing(img,0,0,0);
235 this->ConfigureSTL();
237 _wxMaracasMPR->Refresh();
241 //-------------------------------------------------------------------
242 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
244 wxPanel *panel = new wxPanel(parent,-1);
247 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
249 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
250 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
252 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
253 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
255 sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
256 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
258 panel->SetSizer(sizer);
259 panel->SetAutoLayout(true);
260 panel->SetSize(400,600);
266 //-------------------------------------------------------------------
267 wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
269 wxPanel *panel = new wxPanel(parent,-1);
272 _opacity_Vol = new wxSlider( panel, -1, 40, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
273 _opacity_Vol ->SetSize(250,20);
275 _sl_maxSize = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
276 _sl_minSize = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
278 _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxDefaultSize, wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
279 _sl_minSizeSpin->SetRange(1,8);
280 _sl_minSizeSpin->SetValue(5);
282 _sl_maxSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxDefaultSize, wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
283 _sl_maxSizeSpin->SetRange(1,8);
284 _sl_maxSizeSpin->SetValue(5);
288 _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition ,wxDefaultSize, wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
289 _sl_RangeSizeSpin->SetRange(1,8);
290 _sl_RangeSizeSpin->SetValue(5);
294 sl_barrange_segmentation = new mBarRange(panel, 300,70);
295 sl_barrange_segmentation -> setVisibleLabels ( true );
296 sl_barrange_segmentation -> setIfWithActualDrawed( false );
297 sl_barrange_segmentation -> setActiveStateTo ( true );
298 sl_barrange_segmentation -> setRepresentedValues (0, 2000);
299 sl_barrange_segmentation -> setDeviceBlitStart (10,10);
300 sl_barrange_segmentation -> setDeviceEndMargin(10);
301 parent->SetBackgroundColour(wxColour(255,255,255));
302 sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
305 wxButton *btnExtract = new wxButton(panel,-1,_T("Segmentation"));
306 wxButton *btnSaveBinaryFile = new wxButton(panel,-1,_T("Save Binary File"));
308 //SIL// Connect(_sl_minSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMinSpin );
309 //SIL// Connect(_sl_maxSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMaxSpin );
310 Connect(_opacity_Vol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol );
311 Connect(btnExtract->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction );
312 Connect(btnSaveBinaryFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile );
315 Connect(_sl_RangeSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin );
316 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnStartChanged_range );
317 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnEndChanged_range );
318 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnBarMoved_range );
320 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
322 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
323 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
326 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Segmentation - - - ")));
327 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(" Threshold min")));
334 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
335 sizer->Add(_sl_minSizeSpin, 1, wxALL|wxEXPAND, 0);*/
336 //sizer->Add(_sl_minSize, 1, wxALL|wxEXPAND, 0);
338 sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
339 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
340 sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
341 sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
343 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" Threshold max")));
344 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" ")));
345 //SIL// sizer->Add(_sl_maxSizeSpin, 1, wxALL|wxEXPAND, 0);
346 //SIL//sizer->Add(_sl_maxSize, 1, wxALL|wxEXPAND, 0);
348 sizer->Add(btnExtract);
349 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
351 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
352 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
353 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
354 sizer->Add(_opacity_Vol);
356 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
357 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
358 sizer->Add(btnSaveBinaryFile);
359 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
361 panel->SetSizer(sizer);
362 panel->SetAutoLayout(true);
363 panel->SetSize(400,600);
368 //-------------------------------------------------
369 wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
371 wxPanel *panel = new wxPanel(parent,-1);
373 stlSliderDeltaGauss = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
374 stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
375 stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
376 stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
377 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
379 Connect(btnFileSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL );
380 Connect(stlSliderDeltaGauss->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel );
381 Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
382 Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal );
383 Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal );
386 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
388 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
389 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
391 sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
392 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
393 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
394 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
396 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
397 sizer->Add(stlSliderDeltaGauss);
399 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
400 sizer->Add(stlSliderMarchingCubes);
402 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
403 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
404 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
405 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
407 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
408 sizer->Add(stlSliderOpacityInternal);
410 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
411 sizer->Add(stlSliderOpacityExternal);
413 sizer->Add(btnFileSTL);
414 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
417 panel->SetSizer(sizer);
418 panel->SetAutoLayout(true);
419 panel->SetSize(400,600);
423 //-------------------------------------------------
424 wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
426 wxPanel *panel = new wxPanel(parent,-1);
428 wxButton *btnReadSTLFile = new wxButton(panel,-1,_T("Read STL File"));
429 wxButton *btnEraseReadSTLFile = new wxButton(panel,-1,_T("Erase STL File"));
430 _sl_opacity_STL_file = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
432 Connect(btnReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad );
433 Connect(btnEraseReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase );
434 Connect(_sl_opacity_STL_file->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile );
437 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
439 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
440 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
441 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
442 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
444 sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
445 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
447 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
448 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
450 sizer->Add(btnReadSTLFile );
451 sizer->Add(btnEraseReadSTLFile );
452 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
453 sizer->Add(_sl_opacity_STL_file);
456 panel->SetSizer(sizer);
457 panel->SetAutoLayout(true);
458 panel->SetSize(400,600);
462 //-------------------------------------------------------------------
463 wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
465 wxPanel *panel = new wxPanel(parent,-1);
467 wxNotebook *noteBook = new wxNotebook(panel, -1);
468 noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
469 noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
470 noteBook->AddPage(CreateSmoothingPanel(noteBook) ,_T("2 ->") );
471 noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 " ) );
472 noteBook->SetSelection(0);
473 noteBook->SetSize(350,250);
474 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
475 sizer->Add(noteBook);
476 panel->SetSizer(sizer);
477 panel->SetAutoLayout(true);
478 panel->SetSize(400,600);
483 //------------------------------------------------------------------------
484 void wxSTLWidget_03::Refresh()
486 if (_wxMaracasMPR!=NULL){
487 _wxMaracasMPR->RefreshView();
491 //------------------------------------------------------------------------
494 void wxSTLWidget_03::ConfigureProcessing(vtkImageData *img, int x, int y, int z)
501 double puntoactualprov[3];
502 puntoactualprov[0] = x;
503 puntoactualprov[1] = y;
504 puntoactualprov[2] = z;
509 _imagedata->GetSpacing(espprin);
510 _imagedata->GetExtent(extprin);
514 // puntoactualprov[0]=puntoactualprov[0]*espprin[0];
515 // puntoactualprov[1]=puntoactualprov[1]*espprin[1];
516 // puntoactualprov[2]=puntoactualprov[2]*espprin[2];
518 _imagedata->GetScalarRange( _range );
522 /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
523 _sl_minSize->SetValue( (int)(_range[1]/4) );
525 _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
526 _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
529 minRangeValue = _range[0];
530 maxRangeValue = _range[1];
532 sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
533 sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
534 sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
535 sl_barrange_segmentation -> RefreshForce();
536 lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;
539 // _highthreshold->SetRange(_range[0], _range[1]);
540 // _highthreshold->SetValue( _range[1] );
542 // _zslice->SetRange(extprin[4], extprin[5]);
543 // _zslice->SetValue(extprin[5]/2);
546 _thresh = vtkImageThreshold::New();
547 //_thresh->ReleaseDataFlagOff();
548 _thresh->SetInValue(255);
549 _thresh->SetOutputScalarTypeToUnsignedShort();
550 _thresh->SetOutValue(0);
551 //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
553 _cast = vtkImageCast::New();
555 //EED 2017-01-01 Migration VTK7
556 #if VTK_MAJOR_VERSION <= 5
557 _cast->SetInput(_thresh->GetOutput());
559 _cast->SetInputData(_thresh->GetOutput());
562 _cast->SetOutputScalarTypeToUnsignedChar();
564 _connect = vtkImageSeedConnectivity::New();
565 //EED 2017-01-01 Migration VTK7
566 #if VTK_MAJOR_VERSION <= 5
567 _connect->SetInput(_cast->GetOutput());
569 _connect->SetInputData(_cast->GetOutput());
571 _connect->SetInputConnectValue(255);
572 _connect->SetOutputConnectedValue(255);
573 _connect->SetOutputUnconnectedValue(0);
575 cast3 = vtkImageCast::New();
576 //EED 2017-01-01 Migration VTK7
577 #if VTK_MAJOR_VERSION <= 5
578 cast3->SetInput(_connect->GetOutput());
580 cast3->SetInputData(_connect->GetOutput());
582 cast3->SetOutputScalarTypeToUnsignedShort();
584 _thresh2 = vtkImageThreshold::New();
585 //_thresh2->ReleaseDataFlagOff();
586 _thresh2->SetInValue(255);
587 _thresh2->SetOutputScalarTypeToUnsignedShort();
588 _thresh2->SetOutValue(0);
589 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
591 cast2 = vtkImageCast::New();
592 //EED 2017-01-01 Migration VTK7
593 #if VTK_MAJOR_VERSION <= 5
594 cast2->SetInput(_thresh2->GetOutput());
596 cast2->SetInputData(_thresh2->GetOutput());
598 cast2->SetOutputScalarTypeToUnsignedChar();
599 _connect2 = vtkImageSeedConnectivity::New();
600 //EED 2017-01-01 Migration VTK7
601 #if VTK_MAJOR_VERSION <= 5
602 _connect2->SetInput(cast2->GetOutput());
604 _connect2->SetInputData(cast2->GetOutput());
606 _connect2->SetInputConnectValue(255);
607 _connect2->SetOutputConnectedValue(255);
608 _connect2->SetOutputUnconnectedValue(0);
610 cast4 = vtkImageCast::New();
611 //EED 2017-01-01 Migration VTK7
612 #if VTK_MAJOR_VERSION <= 5
613 cast4->SetInput(_connect2->GetOutput());
615 cast4->SetInputData(_connect2->GetOutput());
617 cast4->SetOutputScalarTypeToUnsignedShort();
619 _thresh->RemoveAllInputs();
620 //EED 2017-01-01 Migration VTK7
621 #if VTK_MAJOR_VERSION <= 5
622 _thresh->SetInput(_imagedata);
624 _thresh->SetInputData(_imagedata);
626 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
632 _connect->RemoveAllSeeds();
633 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
634 //_connect->Update();
637 _thresh2->RemoveAllInputs();
639 //EED 2017-01-01 Migration VTK7
640 #if VTK_MAJOR_VERSION <= 5
641 _thresh2->SetInput(_imagedata);
643 _thresh2->SetInputData(_imagedata);
646 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
649 _connect2->RemoveAllSeeds();
650 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
651 //_connect2->Update();
655 //------------------------------------------------------------------------
659 void wxSTLWidget_03::ConfigureVTK()
662 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
663 //marImageData *marimagedata;// = _mar->_experiment->getDynData( )->GetMarImageData();
665 //CONFIGURACION ADICIONAL
666 this->ConfigureSTL();
667 //this->ConfigureProcessing(marimagedata,0,0,0);
671 //------------------------------------------------------------------------
673 void wxSTLWidget_03::ResetTree2_JF()
682 // if (_2_prgov ) { _2_prgov -> Delete(); }
683 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
684 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
685 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
686 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
687 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
692 _2_stripfinal = NULL;
693 _2_isoMapperMC6 = NULL;
694 _2_isoActorMC6 = NULL;
698 //vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
700 /*if (_2_isoActorMC6){
701 ren->RemoveActor(_2_isoActorMC6);
704 ren->RemoveActor(_2_stripfinal);
709 std::cout<<e<<std::endl;
718 //------------------------------------------------------------------------
719 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
722 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
723 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
725 double puntoactualprov[3];
730 puntoactualprov[0] = x;
731 puntoactualprov[1] = y;
732 puntoactualprov[2] = z;
734 //EED 2017-01-01 Migration VTK7
735 #if VTK_MAJOR_VERSION <= 5
736 _imagedata->UpdateInformation();
737 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
738 _imagedata->Update();
743 _imagedata->GetSpacing(espprin);
744 _imagedata->GetExtent(extprin);
749 _connect->RemoveAllSeeds ();
750 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
756 _thresh->ThresholdBetween(3000, 3002 );
757 _thresh2->ThresholdBetween(3000, 3001);
758 // _thresh->Update();
759 // _thresh2->Update();
761 _thresh->ThresholdBetween(_minSize, _range[1] );
764 _thresh2->ThresholdBetween(_minSize, _maxSize);
768 _connect2->RemoveAllSeeds ();
769 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
776 // Visualisation - result volume
778 _2_isoMC6 = vtkMarchingCubes::New();
779 //EED 2017-01-01 Migration VTK7
780 #if VTK_MAJOR_VERSION <= 5
781 _2_isoMC6->SetInput(cast4->GetOutput());
783 _2_isoMC6->SetInputData(cast4->GetOutput());
786 _2_isoMC6->SetValue(0, 128);
789 _2_isoMapperMC6 = vtkPolyDataMapper::New();
791 //EED 2017-01-01 Migration VTK7
792 #if VTK_MAJOR_VERSION <= 5
793 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
794 _2_isoMapperMC6->ImmediateModeRenderingOn();
796 _2_isoMapperMC6->SetInputData(_2_isoMC6->GetOutput());
800 _2_isoMapperMC6->ScalarVisibilityOff();
802 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
804 if (_2_isoActorMC6!=NULL)
806 ren->RemoveActor(_2_isoActorMC6);
810 _2_isoActorMC6 = vtkActor::New();
811 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
812 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
813 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
817 ren->AddActor(_2_isoActorMC6);
821 //------------------------------------------------------------------------
822 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
824 if (_2_isoActorMC6!=NULL){
825 double value = ((double)_opacity_Vol->GetValue())/100;
826 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
830 //------------------------------------------------------------------------
832 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
834 /*wxSlider *sl_A=_sl_minSize;
835 wxSlider *sl_B=_sl_minSizeSpin;
836 int value = sl_A->GetValue();
837 int delta=(int)pow( 4 , sl_B->GetValue() );
838 int min=value - delta/2;
839 int max=value + delta/2;
845 sl_A->SetRange(min,max);
851 //------------------------------------------------------------------------
853 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
855 /*wxSlider *sl_A=_sl_maxSize;
856 wxSlider *sl_B=_sl_maxSizeSpin;
857 int value = sl_A->GetValue();
858 int delta = (int)pow( 4 , sl_B->GetValue() );
859 int min=value - delta/2;
860 int max=value + delta/2;
866 sl_A->SetRange(min,max);*/
869 //------------------------------------------------------------------------
871 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
873 wxSlider *sl_B=_sl_RangeSizeSpin;
875 int value = lastResizeRef_Value;
876 int delta = (int)pow((double) 4 , (double)sl_B->GetValue() );
877 int startResized = value - delta/2;
878 int endResized = value + delta/2;
880 if( startResized < minRangeValue )
881 startResized = minRangeValue;
883 if( endResized > maxRangeValue )
884 endResized = maxRangeValue;
886 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
887 sl_barrange_segmentation -> RefreshForce();
890 //------------------------------------------------------------------------
891 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
893 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
895 //------------------------------------------------------------------------
896 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
898 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
900 //------------------------------------------------------------------------
901 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
903 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
905 //------------------------------------------------------------------------
907 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
909 wxString dirSTL;// = _mar->_parameters->getStringParam(
910 //marParameters::e_installation_directory );
911 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
912 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
913 dirSTL: wxGetHomeDir( ) );
915 if( dialog.ShowModal( ) == wxID_OK )
917 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
918 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
919 //EED 2017-01-01 Migration VTK7
920 #if VTK_MAJOR_VERSION <= 5
921 writer->SetInput(cast4->GetOutput());
923 writer->SetInputData(cast4->GetOutput());
930 //------------------------------------------------------------------------
931 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
934 _minSize = _sl_minSize->GetValue();
935 _maxSize = _sl_maxSize->GetValue();
937 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
938 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
939 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
940 ExtractSurface((int)(px),(int)(py),(int)(pz));
941 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
947 _minSize = sl_barrange_segmentation->GetStart();
948 _maxSize = sl_barrange_segmentation->GetEnd();
950 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
951 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
952 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
953 ExtractSurface((int)(px),(int)(py),(int)(pz));
954 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
959 //------------------------------------------------------------------------
960 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
962 if (_loadActorSTL!=NULL)
964 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
965 _loadActorSTL->GetProperty( )->SetOpacity( value );
969 //------------------------------------------------------------------------
970 void wxSTLWidget_03::Reset_vtk_STLFile()
974 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
976 ren->RemoveActor(_loadActorSTL);
980 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
981 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
984 _loadSTLMapper = NULL;
985 _loadActorSTL = NULL;
987 std::cout<<e<<std::endl;
991 //------------------------------------------------------------------------
992 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
997 //------------------------------------------------------------------------
998 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
1000 wxString dirSTL;// = _mar->_parameters->getStringParam(
1001 //marParameters::e_installation_directory );
1002 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
1003 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
1004 dirSTL: wxGetHomeDir( ) );
1006 if( dialog.ShowModal( ) == wxID_OK )
1008 Reset_vtk_STLFile();
1009 vtkSTLReader *imgReader= vtkSTLReader::New();
1010 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
1011 _loadSTLMapper = vtkPolyDataMapper::New();
1012 //EED 2017-01-01 Migration VTK7
1013 #if VTK_MAJOR_VERSION <= 5
1014 _loadSTLMapper->SetInput(imgReader->GetOutput());
1016 _loadSTLMapper->SetInputData(imgReader->GetOutput());
1018 _loadActorSTL = vtkActor::New();
1019 _loadActorSTL->SetMapper(_loadSTLMapper);
1020 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
1021 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
1022 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
1023 ren->AddActor(_loadActorSTL);
1024 imgReader->Delete();
1026 //By default *always* update e_installation_directory:
1027 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
1028 //_mar->saveParameters( );
1033 // ------------------------------------------------------------------------
1034 // END JOIN FUNCTIONS - DHC
1035 // ------------------------------------------------------------------------
1037 // ------------------------------------------------------------------------
1038 // START STL FUNCTIONS - DHC
1039 // ------------------------------------------------------------------------
1041 void wxSTLWidget_03::ConfigureSTL()
1044 if(stlExterna == NULL){
1045 stlExterna = vtkPolyData::New();
1046 stlInterna = vtkPolyData::New();
1048 dsm1 = vtkPolyDataMapper ::New();
1049 //EED 2017-01-01 Migration VTK7
1050 #if VTK_MAJOR_VERSION <= 5
1051 dsm1->SetInput(stlInterna);
1053 dsm1->SetInputData(stlInterna);
1055 dsm1->ScalarVisibilityOff();
1057 actorInternal = vtkActor::New();
1058 actorInternal->SetMapper (dsm1);
1059 actorInternal->GetProperty()->SetColor (0,1,0);
1061 dsm2 = vtkPolyDataMapper ::New();
1063 //EED 2017-01-01 Migration VTK7
1064 #if VTK_MAJOR_VERSION <= 5
1065 dsm2->SetInput(stlExterna);
1067 dsm2->SetInputData(stlExterna);
1070 dsm2->ScalarVisibilityOff();
1072 actorExternal= vtkActor::New();
1073 actorExternal->SetMapper (dsm2);
1074 actorExternal->GetProperty()->SetRepresentationToWireframe();
1076 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
1077 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
1078 ren->AddActor(actorInternal);
1079 ren->AddActor(actorExternal);
1081 stlExtractor = new vtkSTLExtractor();
1088 void wxSTLWidget_03::generateSTLSurfaces()
1090 // EED 09Janvier2007
1091 // stlExtractor->setVolume(_2_prgov->GetVolumen());
1093 stlExtractor->setVolume(cast4->GetOutput());
1095 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
1096 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
1097 stlExtractor->calculate();
1098 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
1099 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
1103 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
1104 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
1105 actorExternal->GetProperty( )->SetOpacity( value );
1110 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
1111 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
1112 actorInternal->GetProperty( )->SetOpacity( value );
1116 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
1119 wxString dirSTL;// = _mar->_parameters->getStringParam(
1120 //marParameters::e_installation_directory );
1121 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
1124 // wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
1127 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1128 #if wxMAJOR_VERSION <= 2
1129 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
1131 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxFD_SAVE );
1135 if( dialog.ShowModal( ) == wxID_OK )
1139 // ------------------------------------------------------------------------
1140 // 1. GENERATE STL FILES
1141 // ------------------------------------------------------------------------
1142 // const char* fileprefix = "c:\\Creatis\\";
1143 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
1144 std::string filename;
1146 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
1148 vtkClosePolyData *cpd = vtkClosePolyData::New();
1149 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
1150 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
1152 // 1.2 se escribe a disco el archivo stl de la superficie interna
1153 //EED 2017-01-01 Migration VTK7
1154 #if VTK_MAJOR_VERSION <= 5
1155 filtro->SetInput(stlInterna);
1156 pdcf->SetInput( filtro->GetOutput() );
1157 cpd->SetInput( pdcf->GetOutput() );
1160 filtro->SetInputData(stlInterna);
1161 pdcf->SetInputData( filtro->GetOutput() );
1162 cpd->SetInputData( pdcf->GetOutput() );
1164 vtkSTLWriter *writerI = vtkSTLWriter::New();
1165 //EED 2017-01-01 Migration VTK7
1166 #if VTK_MAJOR_VERSION <= 5
1167 writerI->SetInput( cpd->GetOutput() );
1169 writerI->SetInputData( cpd->GetOutput() );
1171 // prefix = fileprefix;
1172 filename=prefix+"_internal.stl";
1173 writerI->SetFileName(filename.c_str());
1174 writerI->SetFileTypeToASCII();
1178 // 1.3 se escribe a disco el archivo stl de la superficie externa
1179 //EED 2017-01-01 Migration VTK7
1180 #if VTK_MAJOR_VERSION <= 5
1181 filtro->SetInput(stlExterna);
1183 filtro->SetInputData(stlExterna);
1186 vtkSTLWriter *writerE = vtkSTLWriter::New();
1187 //EED 2017-01-01 Migration VTK7
1188 #if VTK_MAJOR_VERSION <= 5
1189 writerE->SetInput( cpd->GetOutput() );
1191 writerE->SetInputData( cpd->GetOutput() );
1193 // prefix = fileprefix;
1194 filename=prefix+"_external.stl";
1195 writerE->SetFileName( filename.c_str() );
1196 writerE->SetFileTypeToASCII();
1205 //By default *always* update e_installation_directory:
1206 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
1207 //_mar->saveParameters( );
1211 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1214 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
1215 generateSTLSurfaces();
1220 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1223 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1224 generateSTLSurfaces();
1230 // ------------------------------------------------------------------------
1231 // END STL FUNCTIONS - DHC
1232 // ------------------------------------------------------------------------