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)
97 _stlMarchingCubesLevel = 128;
98 _stlDeltaGaussLevel = 100;
100 _mar=new marInterface();
101 _mar->_parameters->setRescaleSlope( mar->_parameters->getRescaleSlope() );
102 _mar->_parameters->setRescaleIntercept( mar->_parameters->getRescaleIntercept() );
103 _mar->_parameters->setIntParam( marParameters::e_voxel_type, marParameters::VOX_TYPE_MINIMUM );
104 _mar->_parameters->setDoubleParam( marParameters::e_voxel_x_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_x_dimension) );
105 _mar->_parameters->setDoubleParam( marParameters::e_voxel_y_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_y_dimension) );
106 _mar->_parameters->setDoubleParam( marParameters::e_voxel_z_dimension, mar->_parameters->getDoubleParam(marParameters::e_voxel_z_dimension) );
108 mar->_experiment->getVOI( voi );
109 _mar->_experiment->setVOI( voi );
110 _mar->SetDicom(mar->_dicom);
111 _mar->initExperiment( );
114 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
115 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
116 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
117 printf("EED wxSTLWidget_03::wxSTLWidget_03 01\n");
118 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
119 printf("EED wxSTLWidget_03::wxSTLWidget_03 02\n");
121 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
122 pnlSplitter -> SetMinimumPaneSize( 150 );
123 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
125 // pnlSplitter -> SplitVertically( new wxPanel(pnlSplitter,-1), new wxPanel(pnlSplitter,-1) , 600 );
126 // pnlSplitter -> SplitVertically( viewPanel, new wxPanel(pnlSplitter,-1) , 600 );
128 this -> SetSizer(sizer);
130 // Result 2: Volume + Axis
133 _2_stripfinal = NULL;
134 _2_isoMapperMC6 = NULL;
135 _2_isoActorMC6 = NULL;
142 _loadSTLMapper = NULL;
143 _loadActorSTL = NULL;
147 arteryImageData = NULL;
148 joinMarchingCubes = NULL;
151 printf("EED wxSTLWidget_03::wxSTLWidget_03 03\n");
155 //-------------------------------------------------------------------
156 wxSTLWidget_03::~wxSTLWidget_03(){
160 //-------------------------------------------------------------------
161 wxPanel* wxSTLWidget_03::CreateViewPanel(wxWindow *parent)
163 wxPanel *panel = new wxPanel(parent,-1);
164 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
168 vtkImageData *imagedata;
169 imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
171 printf("EED wxSTLWidget_03::CreateViewPanel 01 \n");
172 _wxMaracasMPR = new wxMaracasMPR( panel, new marImageData(imagedata), _mar->_parameters->getVoxelSize() );
173 printf("EED wxSTLWidget_03::CreateViewPanel 02 \n");
174 _wxMaracasMPR->ConfigureVTK();
175 printf("EED wxSTLWidget_03::CreateViewPanel 03 \n");
177 sizer->Add( _wxMaracasMPR , 1, wxEXPAND, 0);
178 panel->SetSizer(sizer);
179 panel->SetAutoLayout(true);
180 panel->SetSize(400,400);
182 printf("EED wxSTLWidget_03::CreateViewPanel 04 \n");
185 //-------------------------------------------------------------------
186 wxWindow* wxSTLWidget_03::CreateSelectAPointPanel(wxWindow *parent)
188 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 01\n");
189 wxPanel *panel = new wxPanel(parent,-1);
191 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 02\n");
193 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
194 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 03\n");
196 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
197 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
198 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 04\n");
200 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
201 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
202 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 05\n");
204 sizer->Add(new wxStaticText(panel,-1,_T(" Select a 3D Point...")));
205 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
206 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 06\n");
208 panel->SetSizer(sizer);
209 panel->SetAutoLayout(true);
210 panel->SetSize(400,600);
212 printf("EED wxSTLWidget_03::CreateSelectAPointPanel 07\n");
217 //-------------------------------------------------------------------
218 wxWindow* wxSTLWidget_03::CreateSegmentationPanel(wxWindow *parent)
220 wxPanel *panel = new wxPanel(parent,-1);
223 _opacity_Vol = new wxSlider( panel, -1, 40, 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
224 _opacity_Vol ->SetSize(250,20);
226 _sl_maxSize = new wxSlider( panel, -1, 300 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
227 _sl_minSize = new wxSlider( panel, -1, 200 , 0, 2000 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS );
229 _sl_minSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
230 _sl_minSizeSpin->SetRange(1,8);
231 _sl_minSizeSpin->SetValue(5);
233 _sl_maxSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
234 _sl_maxSizeSpin->SetRange(1,8);
235 _sl_maxSizeSpin->SetValue(5);
239 _sl_RangeSizeSpin = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT );
240 _sl_RangeSizeSpin->SetRange(1,8);
241 _sl_RangeSizeSpin->SetValue(5);
245 sl_barrange_segmentation = new mBarRange(panel, 300,70);
246 sl_barrange_segmentation -> setVisibleLabels ( true );
247 sl_barrange_segmentation -> setIfWithActualDrawed( false );
248 sl_barrange_segmentation -> setActiveStateTo ( true );
249 sl_barrange_segmentation -> setRepresentedValues (0, 2000);
250 sl_barrange_segmentation -> setDeviceBlitStart (10,10);
251 sl_barrange_segmentation -> setDeviceEndMargin(10);
252 parent->SetBackgroundColour(wxColour(255,255,255));
253 sl_barrange_segmentation-> setBackgroundColor( wxColour(255,255,255 ));
256 wxButton *btnExtract = new wxButton(panel,-1,_T("Segmentation"));
257 wxButton *btnSaveBinaryFile = new wxButton(panel,-1,_T("Save Binary File"));
259 //SIL// Connect(_sl_minSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMinSpin );
260 //SIL// Connect(_sl_maxSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnMaxSpin );
261 Connect(_opacity_Vol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacity_Vol );
262 Connect(btnExtract->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnExtraction );
263 Connect(btnSaveBinaryFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSaveBinaryFile );
266 Connect(_sl_RangeSizeSpin->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnRangeSpin );
267 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_START,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnStartChanged_range );
268 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_END,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnEndChanged_range );
269 Connect(sl_barrange_segmentation->GetId(),wxEVT_TSBAR_MOVED,(wxObjectEventFunction) (wxCommandEventFunction) &wxSTLWidget_03::OnBarMoved_range );
271 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
273 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
274 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
277 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Segmentation - - - ")));
278 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
281 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
282 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
284 /*sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min")));
285 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
286 sizer->Add(_sl_minSizeSpin, 1, wxALL|wxEXPAND, 0);*/
287 //sizer->Add(_sl_minSize, 1, wxALL|wxEXPAND, 0);
289 sizer->Add(new wxStaticText(panel,-1,_T(" Threshold min-max")));
290 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
291 sizer->Add(_sl_RangeSizeSpin, 1, wxALL|wxEXPAND, 0);
292 sizer->Add(sl_barrange_segmentation,3,wxALL|wxGROW,0 );
294 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" Threshold max")));
295 //SIL//sizer->Add(new wxStaticText(panel,-1,_T(" ")));
296 //SIL// sizer->Add(_sl_maxSizeSpin, 1, wxALL|wxEXPAND, 0);
297 //SIL//sizer->Add(_sl_maxSize, 1, wxALL|wxEXPAND, 0);
299 sizer->Add(btnExtract);
300 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
302 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
303 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
304 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
305 sizer->Add(_opacity_Vol);
307 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
308 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
309 sizer->Add(btnSaveBinaryFile);
310 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
312 panel->SetSizer(sizer);
313 panel->SetAutoLayout(true);
314 panel->SetSize(400,600);
319 //-------------------------------------------------
320 wxWindow* wxSTLWidget_03::CreateSmoothingPanel(wxWindow *parent)
322 wxPanel *panel = new wxPanel(parent,-1);
324 stlSliderDeltaGauss = new wxSlider( panel, -1, (int)(_stlDeltaGaussLevel) , 0, 300 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
325 stlSliderMarchingCubes= new wxSlider( panel, -1, (int)(_stlMarchingCubesLevel) , 0, 256 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
326 stlSliderOpacityInternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
327 stlSliderOpacityExternal = new wxSlider(panel, -1, 100,0,100, wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS);
328 wxButton *btnFileSTL = new wxButton(panel,-1,_T("Generate STL files"));
330 Connect(btnFileSTL->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnCreateFileSTL );
331 Connect(stlSliderDeltaGauss->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLGaussLevel );
332 Connect(stlSliderMarchingCubes->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnChangeSTLMarchingCubesLevel);
333 Connect(stlSliderOpacityInternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLInternal );
334 Connect(stlSliderOpacityExternal->GetId(), wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLExternal );
337 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
339 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
340 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
342 sizer->Add(new wxStaticText(panel,-1,_T("-- Smoothing --")));
343 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
344 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
345 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
347 sizer->Add(new wxStaticText(panel,-1,_T(" Delta Gauss")));
348 sizer->Add(stlSliderDeltaGauss);
350 sizer->Add(new wxStaticText(panel,-1,_T(" Marching Cubes Level")));
351 sizer->Add(stlSliderMarchingCubes);
353 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
354 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
355 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
356 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
358 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL Internal")));
359 sizer->Add(stlSliderOpacityInternal);
361 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL External")));
362 sizer->Add(stlSliderOpacityExternal);
364 sizer->Add(btnFileSTL);
365 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
368 panel->SetSizer(sizer);
369 panel->SetAutoLayout(true);
370 panel->SetSize(400,600);
374 //-------------------------------------------------
375 wxWindow* wxSTLWidget_03::CreateReadSTLFilePanel(wxWindow *parent)
377 wxPanel *panel = new wxPanel(parent,-1);
379 wxButton *btnReadSTLFile = new wxButton(panel,-1,_T("Read STL File"));
380 wxButton *btnEraseReadSTLFile = new wxButton(panel,-1,_T("Erase STL File"));
381 _sl_opacity_STL_file = new wxSlider( panel, -1, 100 , 0, 100 , wxDefaultPosition, wxSize(200,40), wxSL_HORIZONTAL | wxSL_LABELS );
383 Connect(btnReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileLoad );
384 Connect(btnEraseReadSTLFile->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxSTLWidget_03::OnBtnSTLFileErase );
385 Connect(_sl_opacity_STL_file->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxSTLWidget_03::OnOpacitySTLFile );
388 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
390 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
391 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
392 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
393 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
395 sizer->Add(new wxStaticText(panel,-1,_T("-- Read STL File --")));
396 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
398 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
399 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
401 sizer->Add(btnReadSTLFile );
402 sizer->Add(btnEraseReadSTLFile );
403 sizer->Add(new wxStaticText(panel, -1,_T(" Opacity STL File")));
404 sizer->Add(_sl_opacity_STL_file);
407 panel->SetSizer(sizer);
408 panel->SetAutoLayout(true);
409 panel->SetSize(400,600);
413 //-------------------------------------------------------------------
414 wxPanel* wxSTLWidget_03::CreateControlPanel(wxWindow *parent)
416 printf("EED wxSTLWidget_03::CreateControlPanel 01\n");
417 wxPanel *panel = new wxPanel(parent,-1);
419 wxNotebook *noteBook = new wxNotebook(panel, -1);
420 printf("EED wxSTLWidget_03::CreateControlPanel 02\n");
421 noteBook->AddPage(CreateSelectAPointPanel(noteBook),_T("0 ->") );
422 printf("EED wxSTLWidget_03::CreateControlPanel 03\n");
423 noteBook->AddPage(CreateSegmentationPanel(noteBook),_T("1 ->") );
424 printf("EED wxSTLWidget_03::CreateControlPanel 04\n");
425 noteBook->AddPage(CreateSmoothingPanel(noteBook) ,_T("2 ->") );
426 printf("EED wxSTLWidget_03::CreateControlPanel 05\n");
427 noteBook->AddPage(CreateReadSTLFilePanel(noteBook) ,_T("3 " ) );
428 printf("EED wxSTLWidget_03::CreateControlPanel 06\n");
429 noteBook->SetSelection(0);
430 noteBook->SetSize(350,250);
431 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
432 sizer->Add(noteBook);
433 panel->SetSizer(sizer);
434 panel->SetAutoLayout(true);
435 panel->SetSize(400,600);
438 printf("EED wxSTLWidget_03::CreateControlPanel 07\n");
441 //------------------------------------------------------------------------
442 void wxSTLWidget_03::Refresh()
444 if (_wxMaracasMPR!=NULL){
445 _wxMaracasMPR->RefreshView();
449 //------------------------------------------------------------------------
452 void wxSTLWidget_03::ConfigureProcessing(marImageData *marimagedata, int x, int y, int z)
456 _imagedata=marimagedata->GetImageData(); // image t=0
457 _imagedata->UpdateInformation();
458 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
459 _imagedata->Update();
462 double puntoactualprov[3];
463 puntoactualprov[0] = x;
464 puntoactualprov[1] = y;
465 puntoactualprov[2] = z;
470 _imagedata->GetSpacing(espprin);
471 _imagedata->GetExtent(extprin);
475 // puntoactualprov[0]=puntoactualprov[0]*espprin[0];
476 // puntoactualprov[1]=puntoactualprov[1]*espprin[1];
477 // puntoactualprov[2]=puntoactualprov[2]*espprin[2];
479 _imagedata->GetScalarRange( _range );
483 /*_sl_minSize->SetRange( (int)(_range[0]), (int)( _range[1]) );
484 _sl_minSize->SetValue( (int)(_range[1]/4) );
486 _sl_maxSize->SetRange( (int)(_range[0]) , (int)(_range[1]));
487 _sl_maxSize->SetValue( (int)(_range[1]/2) );*/
490 minRangeValue = _range[0];
491 maxRangeValue = _range[1];
493 sl_barrange_segmentation ->setRepresentedValues(minRangeValue, maxRangeValue);
494 sl_barrange_segmentation ->SetStart((int)(maxRangeValue/4));
495 sl_barrange_segmentation ->SetEnd((int)(maxRangeValue/2));
496 sl_barrange_segmentation -> RefreshForce();
497 lastResizeRef_Value = ( maxRangeValue - minRangeValue)/2;
500 // _highthreshold->SetRange(_range[0], _range[1]);
501 // _highthreshold->SetValue( _range[1] );
503 // _zslice->SetRange(extprin[4], extprin[5]);
504 // _zslice->SetValue(extprin[5]/2);
506 _thresh = vtkImageThreshold::New();
507 _thresh->SetInput(_imagedata);
508 //_thresh->ReleaseDataFlagOff();
509 _thresh->SetInValue(255);
510 _thresh->SetOutputScalarTypeToUnsignedShort();
511 _thresh->SetOutValue(0);
512 //_thresh->ThresholdBetween(_sl_minSize->GetValue(), _range[1]);
514 _thresh->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
516 vtkImageCast *cast = vtkImageCast::New();
517 cast->SetInput(_thresh->GetOutput());
518 cast->SetOutputScalarTypeToUnsignedChar();
522 _connect = vtkImageSeedConnectivity::New();
523 _connect->SetInput(cast->GetOutput());
524 _connect->SetInputConnectValue(255);
525 _connect->SetOutputConnectedValue(255);
526 _connect->SetOutputUnconnectedValue(0);
527 _connect->AddSeed((int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
528 // _connect->Update();
530 cast3 = vtkImageCast::New();
531 cast3->SetInput(_connect->GetOutput());
532 cast3->SetOutputScalarTypeToUnsignedShort();
536 _thresh2 = vtkImageThreshold::New();
537 _thresh2->SetInput(_imagedata);
538 //_thresh2->ReleaseDataFlagOff();
539 _thresh2->SetInValue(255);
540 _thresh2->SetOutputScalarTypeToUnsignedShort();
541 _thresh2->SetOutValue(0);
542 //SIL//_thresh2->ThresholdBetween(_sl_minSize->GetValue(), _sl_maxSize->GetValue());
543 _thresh2->ThresholdBetween(sl_barrange_segmentation->GetStart(), sl_barrange_segmentation->GetEnd());
545 cast2 = vtkImageCast::New();
546 cast2->SetInput(_thresh2->GetOutput());
547 cast2->SetOutputScalarTypeToUnsignedChar();
550 _connect2 = vtkImageSeedConnectivity::New();
551 _connect2->SetInput(cast2->GetOutput());
552 _connect2->SetInputConnectValue(255);
553 _connect2->SetOutputConnectedValue(255);
554 _connect2->SetOutputUnconnectedValue(0);
555 _connect2->AddSeed( (int)(puntoactualprov[0]), (int)(puntoactualprov[1]), (int)(puntoactualprov[2]));
558 cast4 = vtkImageCast::New();
559 cast4->SetInput(_connect2->GetOutput());
560 cast4->SetOutputScalarTypeToUnsignedShort();
564 //------------------------------------------------------------------------
568 void wxSTLWidget_03::ConfigureVTK()
571 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
572 marImageData *marimagedata = _mar->_experiment->getDynData( )->GetMarImageData();
574 //CONFIGURACION ADICIONAL
575 this->ConfigureSTL();
576 this->ConfigureProcessing(marimagedata,0,0,0);
580 //------------------------------------------------------------------------
582 void wxSTLWidget_03::ResetTree2_JF()
585 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
588 ren->RemoveActor(_2_isoActorMC6);
591 ren->RemoveActor(_2_stripfinal);
595 // if (_2_prgov ) { _2_prgov -> Delete(); }
596 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
597 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
598 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
599 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
600 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
605 _2_stripfinal = NULL;
606 _2_isoMapperMC6 = NULL;
607 _2_isoActorMC6 = NULL;
616 //------------------------------------------------------------------------
617 void wxSTLWidget_03::ExtractSurface(int x, int y, int z)
620 double opacityvol = ((double)_opacity_Vol->GetValue())/100;
621 // vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
623 double puntoactualprov[3];
628 puntoactualprov[0] = x;
629 puntoactualprov[1] = y;
630 puntoactualprov[2] = z;
632 _imagedata->UpdateInformation();
633 _imagedata->SetUpdateExtent(_imagedata->GetWholeExtent());
634 _imagedata->Update();
636 _imagedata->GetSpacing(espprin);
637 _imagedata->GetExtent(extprin);
642 _connect->RemoveAllSeeds ();
643 _connect->AddSeed( (int)(puntoactualprov[0] ), (int)(puntoactualprov[1]) ,(int)( puntoactualprov[2]) );
649 _thresh->ThresholdBetween(3000, 3002 );
650 _thresh2->ThresholdBetween(3000, 3001);
651 // _thresh->Update();
652 // _thresh2->Update();
654 _thresh->ThresholdBetween(_minSize, _range[1] );
657 _thresh2->ThresholdBetween(_minSize, _maxSize);
661 _connect2->RemoveAllSeeds ();
662 _connect2->AddSeed( (int)(puntoactualprov[0]) , (int)(puntoactualprov[1]) , (int)(puntoactualprov[2]) );
669 // Visualisation - result volume
671 _2_isoMC6 = vtkMarchingCubes::New();
672 _2_isoMC6->SetInput(cast4->GetOutput());
674 _2_isoMC6->SetValue(0, 128);
677 _2_isoMapperMC6 = vtkPolyDataMapper::New();
678 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
679 _2_isoMapperMC6->ScalarVisibilityOff();
680 _2_isoMapperMC6->ImmediateModeRenderingOn();
682 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
684 if (_2_isoActorMC6!=NULL)
686 ren->RemoveActor(_2_isoActorMC6);
690 _2_isoActorMC6 = vtkActor::New();
691 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
692 _2_isoActorMC6->GetProperty()->SetColor(1.0, 1.0, 0.5);
693 _2_isoActorMC6->GetProperty()->SetOpacity( opacityvol );
697 ren->AddActor(_2_isoActorMC6);
701 //------------------------------------------------------------------------
702 void wxSTLWidget_03::OnOpacity_Vol(wxScrollEvent& event)
704 if (_2_isoActorMC6!=NULL){
705 double value = ((double)_opacity_Vol->GetValue())/100;
706 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
710 //------------------------------------------------------------------------
712 void wxSTLWidget_03::OnMinSpin ( wxScrollEvent & event )
714 /*wxSlider *sl_A=_sl_minSize;
715 wxSlider *sl_B=_sl_minSizeSpin;
716 int value = sl_A->GetValue();
717 int delta=(int)pow( 4 , sl_B->GetValue() );
718 int min=value - delta/2;
719 int max=value + delta/2;
725 sl_A->SetRange(min,max);
731 //------------------------------------------------------------------------
733 void wxSTLWidget_03::OnMaxSpin ( wxScrollEvent & event )
735 /*wxSlider *sl_A=_sl_maxSize;
736 wxSlider *sl_B=_sl_maxSizeSpin;
737 int value = sl_A->GetValue();
738 int delta = (int)pow( 4 , sl_B->GetValue() );
739 int min=value - delta/2;
740 int max=value + delta/2;
746 sl_A->SetRange(min,max);*/
749 //------------------------------------------------------------------------
751 void wxSTLWidget_03::OnRangeSpin ( wxScrollEvent & event )
753 wxSlider *sl_B=_sl_RangeSizeSpin;
755 int value = lastResizeRef_Value;
756 int delta = (int)pow( 4 , sl_B->GetValue() );
757 int startResized = value - delta/2;
758 int endResized = value + delta/2;
760 if( startResized < minRangeValue )
761 startResized = minRangeValue;
763 if( endResized > maxRangeValue )
764 endResized = maxRangeValue;
766 sl_barrange_segmentation->setRepresentedValues(startResized,endResized);
767 sl_barrange_segmentation -> RefreshForce();
770 //------------------------------------------------------------------------
771 void wxSTLWidget_03:: OnStartChanged_range(wxCommandEvent& event)
773 lastResizeRef_Value = sl_barrange_segmentation->GetStart();
775 //------------------------------------------------------------------------
776 void wxSTLWidget_03:: OnEndChanged_range(wxCommandEvent& event)
778 lastResizeRef_Value = sl_barrange_segmentation->GetEnd();
780 //------------------------------------------------------------------------
781 void wxSTLWidget_03:: OnBarMoved_range(wxCommandEvent& event)
783 lastResizeRef_Value = (sl_barrange_segmentation->GetEnd() - sl_barrange_segmentation->GetStart())/2 ;
785 //------------------------------------------------------------------------
787 void wxSTLWidget_03::OnBtnSaveBinaryFile(wxCommandEvent& event)
789 wxString dirSTL = _mar->_parameters->getStringParam(
790 marParameters::e_installation_directory );
791 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
792 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
793 dirSTL: wxGetHomeDir( ) );
795 if( dialog.ShowModal( ) == wxID_OK )
797 vtkMetaImageWriter *writer= vtkMetaImageWriter::New();
798 writer->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
799 writer->SetInput(cast4->GetOutput());
805 //------------------------------------------------------------------------
806 void wxSTLWidget_03::OnBtnExtraction(wxCommandEvent& event)
809 _minSize = _sl_minSize->GetValue();
810 _maxSize = _sl_maxSize->GetValue();
812 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
813 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
814 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
815 ExtractSurface((int)(px),(int)(py),(int)(pz));
816 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
822 _minSize = sl_barrange_segmentation->GetStart();
823 _maxSize = sl_barrange_segmentation->GetEnd();
825 double px=_wxMaracasMPR->GetVtkMPRBaseData()->GetX();
826 double py=_wxMaracasMPR->GetVtkMPRBaseData()->GetY();
827 double pz=_wxMaracasMPR->GetVtkMPRBaseData()->GetZ();
828 ExtractSurface((int)(px),(int)(py),(int)(pz));
829 generateSTLSurfaces(); //DHC: AFTER SEGMENTATION THE TREE, THE STL SURFACES ARE CALCULATED.
834 //------------------------------------------------------------------------
835 void wxSTLWidget_03::OnOpacitySTLFile(wxScrollEvent& event)
837 if (_loadActorSTL!=NULL)
839 double value = ((double)_sl_opacity_STL_file->GetValue())/100;
840 _loadActorSTL->GetProperty( )->SetOpacity( value );
844 //------------------------------------------------------------------------
845 void wxSTLWidget_03::Reset_vtk_STLFile()
848 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
850 ren->RemoveActor(_loadActorSTL);
854 if (_loadSTLMapper ) { _loadSTLMapper -> Delete(); }
855 if (_loadActorSTL ) { _loadActorSTL -> Delete(); }
858 _loadSTLMapper = NULL;
859 _loadActorSTL = NULL;
862 //------------------------------------------------------------------------
863 void wxSTLWidget_03::OnBtnSTLFileErase(wxCommandEvent& event)
868 //------------------------------------------------------------------------
869 void wxSTLWidget_03::OnBtnSTLFileLoad(wxCommandEvent& event)
871 wxString dirSTL = _mar->_parameters->getStringParam(
872 marParameters::e_installation_directory );
873 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
874 wxFileDialog dialog( this, _T("Choose a directory..."), ( !dirSTL.IsEmpty( ) )?
875 dirSTL: wxGetHomeDir( ) );
877 if( dialog.ShowModal( ) == wxID_OK )
880 vtkSTLReader *imgReader= vtkSTLReader::New();
881 imgReader->SetFileName( dialog.GetPath().mb_str(wxConvUTF8) );
882 _loadSTLMapper = vtkPolyDataMapper::New();
883 _loadSTLMapper->SetInput(imgReader->GetOutput());
884 _loadActorSTL = vtkActor::New();
885 _loadActorSTL->SetMapper(_loadSTLMapper);
886 _loadActorSTL->GetProperty()->SetColor( 1, 0, 0);
887 _loadActorSTL->GetProperty()->SetOpacity( 0.5 );
888 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
889 ren->AddActor(_loadActorSTL);
892 //By default *always* update e_installation_directory:
893 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
894 _mar->saveParameters( );
899 // ------------------------------------------------------------------------
900 // END JOIN FUNCTIONS - DHC
901 // ------------------------------------------------------------------------
903 // ------------------------------------------------------------------------
904 // START STL FUNCTIONS - DHC
905 // ------------------------------------------------------------------------
907 void wxSTLWidget_03::ConfigureSTL()
909 stlExterna = vtkPolyData::New();
910 stlInterna = vtkPolyData::New();
912 dsm1 = vtkPolyDataMapper ::New();
913 dsm1->SetInput (stlInterna);
914 dsm1->ScalarVisibilityOff();
916 actorInternal = vtkActor::New();
917 actorInternal->SetMapper (dsm1);
918 actorInternal->GetProperty()->SetColor (0,1,0);
920 dsm2 = vtkPolyDataMapper ::New();
921 dsm2->SetInput (stlExterna);
922 dsm2->ScalarVisibilityOff();
924 actorExternal= vtkActor::New();
925 actorExternal->SetMapper (dsm2);
926 actorExternal->GetProperty()->SetRepresentationToWireframe();
928 // vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
929 vtkRenderer *ren = _wxMaracasMPR->GetWxvtkmpr3Dview_BB()->GetWxvtk3Dbaseview()->GetRenderer();
930 ren->AddActor(actorInternal);
931 ren->AddActor(actorExternal);
933 stlExtractor = new vtkSTLExtractor();
936 void wxSTLWidget_03::generateSTLSurfaces()
939 // stlExtractor->setVolume(_2_prgov->GetVolumen());
941 stlExtractor->setVolume(cast4->GetOutput());
943 stlExtractor->setSigmaLevel(_stlDeltaGaussLevel);
944 stlExtractor->setMarchingCubesLevel(_stlMarchingCubesLevel);
945 stlExtractor->calculate();
946 stlInterna->DeepCopy(stlExtractor->getInnerSurface());
947 stlExterna->DeepCopy(stlExtractor->getOuterSurface());
951 void wxSTLWidget_03::OnOpacitySTLExternal(wxScrollEvent& event){
952 double value = ((double)stlSliderOpacityExternal->GetValue())/100;
953 actorExternal->GetProperty( )->SetOpacity( value );
958 void wxSTLWidget_03::OnOpacitySTLInternal(wxScrollEvent& event){
959 double value = ((double)stlSliderOpacityInternal->GetValue())/100;
960 actorInternal->GetProperty( )->SetOpacity( value );
964 void wxSTLWidget_03::OnBtnCreateFileSTL(wxCommandEvent& event)
967 wxString dirSTL = _mar->_parameters->getStringParam(
968 marParameters::e_installation_directory );
969 dirSTL = ( dirSTL == _T("NO_DIRECTORY") ) ? wxGetHomeDir( ) : dirSTL;
972 // wxDirDialog dialog( this, "Choose a directory...", ( !dirSTL.IsEmpty( ) )?dirSTL: wxGetHomeDir( ) );
973 wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
976 if( dialog.ShowModal( ) == wxID_OK )
980 // ------------------------------------------------------------------------
981 // 1. GENERATE STL FILES
982 // ------------------------------------------------------------------------
983 // const char* fileprefix = "c:\\Creatis\\";
984 std::string prefix ( dialog.GetPath().mb_str(wxConvUTF8) );
985 std::string filename;
987 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
989 vtkTriangleFilter *filtro = vtkTriangleFilter::New();
990 filtro->SetInput(stlInterna);
991 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
992 pdcf->SetInput( filtro->GetOutput() );
993 vtkClosePolyData *cpd = vtkClosePolyData::New();
994 cpd->SetInput( pdcf->GetOutput() );
996 // 1.2 se escribe a disco el archivo stl de la superficie interna
998 vtkSTLWriter *writerI = vtkSTLWriter::New();
999 writerI->SetInput( cpd->GetOutput() );
1000 // prefix = fileprefix;
1001 filename=prefix+"_internal.stl";
1002 writerI->SetFileName(filename.c_str());
1003 writerI->SetFileTypeToASCII();
1007 // 1.3 se escribe a disco el archivo stl de la superficie externa
1008 filtro->SetInput(stlExterna);
1010 vtkSTLWriter *writerE = vtkSTLWriter::New();
1011 writerE->SetInput( cpd->GetOutput() );
1012 // prefix = fileprefix;
1013 filename=prefix+"_external.stl";
1014 writerE->SetFileName( filename.c_str() );
1015 writerE->SetFileTypeToASCII();
1024 //By default *always* update e_installation_directory:
1025 _mar->_parameters->setStringParam( marParameters::e_installation_directory, dialog.GetPath( ) );
1026 _mar->saveParameters( );
1030 void wxSTLWidget_03::OnChangeSTLGaussLevel(wxScrollEvent& event)
1033 _stlDeltaGaussLevel = ((double)stlSliderDeltaGauss->GetValue())/100;
1034 generateSTLSurfaces();
1039 void wxSTLWidget_03::OnChangeSTLMarchingCubesLevel(wxScrollEvent& event)
1042 _stlMarchingCubesLevel = ((double)stlSliderMarchingCubes->GetValue());
1043 generateSTLSurfaces();
1049 // ------------------------------------------------------------------------
1050 // END STL FUNCTIONS - DHC
1051 // ------------------------------------------------------------------------