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, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
273 _opacity_Vol ->SetSize(250,20);
275 _sl_maxSize = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
276 _sl_minSize = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
278 _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), 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 , wxSize(25,45), 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 , wxSize(25,45), 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();
554 _cast->SetInput(_thresh->GetOutput());
555 _cast->SetOutputScalarTypeToUnsignedChar();
557 _connect = vtkImageSeedConnectivity::New();
558 _connect->SetInput(_cast->GetOutput());
559 _connect->SetInputConnectValue(255);
560 _connect->SetOutputConnectedValue(255);
561 _connect->SetOutputUnconnectedValue(0);
563 cast3 = vtkImageCast::New();
564 cast3->SetInput(_connect->GetOutput());
565 cast3->SetOutputScalarTypeToUnsignedShort();
567 _thresh2 = vtkImageThreshold::New();
568 //_thresh2->ReleaseDataFlagOff();
569 _thresh2->SetInValue(255);
570 _thresh2->SetOutputScalarTypeToUnsignedShort();
571 _thresh2->SetOutValue(0);
572 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
574 cast2 = vtkImageCast::New();
575 cast2->SetInput(_thresh2->GetOutput());
576 cast2->SetOutputScalarTypeToUnsignedChar();
577 _connect2 = vtkImageSeedConnectivity::New();
578 _connect2->SetInput(cast2->GetOutput());
579 _connect2->SetInputConnectValue(255);
580 _connect2->SetOutputConnectedValue(255);
581 _connect2->SetOutputUnconnectedValue(0);
583 cast4 = vtkImageCast::New();
584 cast4->SetInput(_connect2->GetOutput());
585 cast4->SetOutputScalarTypeToUnsignedShort();
587 _thresh->RemoveAllInputs();
588 _thresh->SetInput(_imagedata);
589 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
595 _connect->RemoveAllSeeds();
596 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
597 //_connect->Update();
600 _thresh2->RemoveAllInputs();
601 _thresh2->SetInput(_imagedata);
602 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
605 _connect2->RemoveAllSeeds();
606 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
607 //_connect2->Update();
611 //------------------------------------------------------------------------
615 void wxSTLWidget_03::ConfigureVTK()
618 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
619 //marImageData *marimagedata;// = _mar->_experiment->getDynData( )->GetMarImageData();
621 //CONFIGURACION ADICIONAL
622 this->ConfigureSTL();
623 //this->ConfigureProcessing(marimagedata,0,0,0);
627 //------------------------------------------------------------------------
629 void wxSTLWidget_03::ResetTree2_JF()
638 // if (_2_prgov ) { _2_prgov -> Delete(); }
639 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
640 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
641 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
642 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
643 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
648 _2_stripfinal = NULL;
649 _2_isoMapperMC6 = NULL;
650 _2_isoActorMC6 = NULL;
654 //vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
656 /*if (_2_isoActorMC6){
657 ren->RemoveActor(_2_isoActorMC6);
660 ren->RemoveActor(_2_stripfinal);
665 std::cout<<e<<std::endl;
674 //------------------------------------------------------------------------
675 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
678 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
679 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
681 double puntoactualprov[3];
686 puntoactualprov[0] = x;
687 puntoactualprov[1] = y;
688 puntoactualprov[2] = z;
690 _imagedata->UpdateInformation();
691 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
692 _imagedata->Update();
694 _imagedata->GetSpacing(espprin);
695 _imagedata->GetExtent(extprin);
700 _connect->RemoveAllSeeds ();
701 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
707 _thresh->ThresholdBetween(3000, 3002 );
708 _thresh2->ThresholdBetween(3000, 3001);
709 // _thresh->Update();
710 // _thresh2->Update();
712 _thresh->ThresholdBetween(_minSize, _range[1] );
715 _thresh2->ThresholdBetween(_minSize, _maxSize);
719 _connect2->RemoveAllSeeds ();
720 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
727 // Visualisation - result volume
729 _2_isoMC6 = vtkMarchingCubes::New();
730 _2_isoMC6->SetInput(cast4->GetOutput());
732 _2_isoMC6->SetValue(0, 128);
735 _2_isoMapperMC6 = vtkPolyDataMapper::New();
736 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
737 _2_isoMapperMC6->ScalarVisibilityOff();
738 _2_isoMapperMC6->ImmediateModeRenderingOn();
740 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
742 if (_2_isoActorMC6!=NULL)
744 ren->RemoveActor(_2_isoActorMC6);
748 _2_isoActorMC6 = vtkActor::New();
749 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
750 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
751 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
755 ren->AddActor(_2_isoActorMC6);
759 //------------------------------------------------------------------------
760 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
762 if (_2_isoActorMC6!=NULL){
763 double value = ((double)_opacity_Vol->GetValue())/100;
764 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
768 //------------------------------------------------------------------------
770 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
772 /*wxSlider *sl_A=_sl_minSize;
773 wxSlider *sl_B=_sl_minSizeSpin;
774 int value = sl_A->GetValue();
775 int delta=(int)pow( 4 , sl_B->GetValue() );
776 int min=value - delta/2;
777 int max=value + delta/2;
783 sl_A->SetRange(min,max);
789 //------------------------------------------------------------------------
791 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
793 /*wxSlider *sl_A=_sl_maxSize;
794 wxSlider *sl_B=_sl_maxSizeSpin;
795 int value = sl_A->GetValue();
796 int delta = (int)pow( 4 , sl_B->GetValue() );
797 int min=value - delta/2;
798 int max=value + delta/2;
804 sl_A->SetRange(min,max);*/
807 //------------------------------------------------------------------------
809 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
811 wxSlider *sl_B=_sl_RangeSizeSpin;
813 int value = lastResizeRef_Value;
814 int delta = (int)pow((double) 4 , (double)sl_B->GetValue() );
815 int startResized = value - delta/2;
816 int endResized = value + delta/2;
818 if( startResized < minRangeValue )
819 startResized = minRangeValue;
821 if( endResized > maxRangeValue )
822 endResized = maxRangeValue;
824 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
825 sl_barrange_segmentation -> RefreshForce();
828 //------------------------------------------------------------------------
829 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
831 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
833 //------------------------------------------------------------------------
834 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
836 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
838 //------------------------------------------------------------------------
839 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
841 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
843 //------------------------------------------------------------------------
845 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
847 wxString dirSTL;// = _mar->_parameters->getStringParam(
848 //marParameters::e_installation_directory );
849 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
850 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
851 dirSTL: wxGetHomeDir( ) );
853 if( dialog.ShowModal( ) == wxID_OK )
855 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
856 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
857 writer->SetInput(cast4->GetOutput());
863 //------------------------------------------------------------------------
864 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
867 _minSize = _sl_minSize->GetValue();
868 _maxSize = _sl_maxSize->GetValue();
870 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
871 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
872 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
873 ExtractSurface((int)(px),(int)(py),(int)(pz));
874 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
880 _minSize = sl_barrange_segmentation->GetStart();
881 _maxSize = sl_barrange_segmentation->GetEnd();
883 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
884 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
885 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
886 ExtractSurface((int)(px),(int)(py),(int)(pz));
887 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
892 //------------------------------------------------------------------------
893 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
895 if (_loadActorSTL!=NULL)
897 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
898 _loadActorSTL->GetProperty( )->SetOpacity( value );
902 //------------------------------------------------------------------------
903 void wxSTLWidget_03::Reset_vtk_STLFile()
907 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
909 ren->RemoveActor(_loadActorSTL);
913 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
914 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
917 _loadSTLMapper = NULL;
918 _loadActorSTL = NULL;
920 std::cout<<e<<std::endl;
924 //------------------------------------------------------------------------
925 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
930 //------------------------------------------------------------------------
931 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
933 wxString dirSTL;// = _mar->_parameters->getStringParam(
934 //marParameters::e_installation_directory );
935 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
936 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
937 dirSTL: wxGetHomeDir( ) );
939 if( dialog.ShowModal( ) == wxID_OK )
942 vtkSTLReader *imgReader= vtkSTLReader::New();
943 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
944 _loadSTLMapper = vtkPolyDataMapper::New();
945 _loadSTLMapper->SetInput(imgReader->GetOutput());
946 _loadActorSTL = vtkActor::New();
947 _loadActorSTL->SetMapper(_loadSTLMapper);
948 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
949 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
950 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
951 ren->AddActor(_loadActorSTL);
954 //By default *always* update e_installation_directory:
955 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
956 //_mar->saveParameters( );
961 // ------------------------------------------------------------------------
962 // END JOIN FUNCTIONS - DHC
963 // ------------------------------------------------------------------------
965 // ------------------------------------------------------------------------
966 // START STL FUNCTIONS - DHC
967 // ------------------------------------------------------------------------
969 void wxSTLWidget_03::ConfigureSTL()
972 if(stlExterna == NULL){
973 stlExterna = vtkPolyData::New();
974 stlInterna = vtkPolyData::New();
976 dsm1 = vtkPolyDataMapper ::New();
977 dsm1->SetInput (stlInterna);
978 dsm1->ScalarVisibilityOff();
980 actorInternal = vtkActor::New();
981 actorInternal->SetMapper (dsm1);
982 actorInternal->GetProperty()->SetColor (0,1,0);
984 dsm2 = vtkPolyDataMapper ::New();
985 dsm2->SetInput (stlExterna);
986 dsm2->ScalarVisibilityOff();
988 actorExternal= vtkActor::New();
989 actorExternal->SetMapper (dsm2);
990 actorExternal->GetProperty()->SetRepresentationToWireframe();
992 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
993 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
994 ren->AddActor(actorInternal);
995 ren->AddActor(actorExternal);
997 stlExtractor = new vtkSTLExtractor();
1004 void wxSTLWidget_03::generateSTLSurfaces()
1006 // EED 09Janvier2007
1007 // stlExtractor->setVolume(_2_prgov->GetVolumen());
1009 stlExtractor->setVolume(cast4->GetOutput());
1011 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
1012 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
1013 stlExtractor->calculate();
1014 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
1015 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
1019 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
1020 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
1021 actorExternal->GetProperty( )->SetOpacity( value );
1026 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
1027 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
1028 actorInternal->GetProperty( )->SetOpacity( value );
1032 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
1035 wxString dirSTL;// = _mar->_parameters->getStringParam(
1036 //marParameters::e_installation_directory );
1037 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
1040 // wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
1041 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
1044 if( dialog.ShowModal( ) == wxID_OK )
1048 // ------------------------------------------------------------------------
1049 // 1. GENERATE STL FILES
1050 // ------------------------------------------------------------------------
1051 // const char* fileprefix = "c:\\Creatis\\";
1052 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
1053 std::string filename;
1055 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
1057 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
1058 filtro->SetInput(stlInterna);
1059 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
1060 pdcf->SetInput( filtro->GetOutput() );
1061 vtkClosePolyData *cpd = vtkClosePolyData::New();
1062 cpd->SetInput( pdcf->GetOutput() );
1064 // 1.2 se escribe a disco el archivo stl de la superficie interna
1066 vtkSTLWriter *writerI = vtkSTLWriter::New();
1067 writerI->SetInput( cpd->GetOutput() );
1068 // prefix = fileprefix;
1069 filename=prefix+"_internal.stl";
1070 writerI->SetFileName(filename.c_str());
1071 writerI->SetFileTypeToASCII();
1075 // 1.3 se escribe a disco el archivo stl de la superficie externa
1076 filtro->SetInput(stlExterna);
1078 vtkSTLWriter *writerE = vtkSTLWriter::New();
1079 writerE->SetInput( cpd->GetOutput() );
1080 // prefix = fileprefix;
1081 filename=prefix+"_external.stl";
1082 writerE->SetFileName( filename.c_str() );
1083 writerE->SetFileTypeToASCII();
1092 //By default *always* update e_installation_directory:
1093 //_mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
1094 //_mar->saveParameters( );
1098 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1101 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
1102 generateSTLSurfaces();
1107 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1110 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1111 generateSTLSurfaces();
1117 // ------------------------------------------------------------------------
1118 // END STL FUNCTIONS - DHC
1119 // ------------------------------------------------------------------------