2 #include "vtkObjectFactory.h"
5 #include "vtkCylinderSource.h"
6 #include "vtkPolyDataMapper.h"
7 #include "vtkRenderer.h"
8 #include "vtkRenderWindow.h"
9 #include "vtkRenderWindowInteractor.h"
10 #include "vtkProperty.h"
11 #include "vtkCamera.h"
12 #include "vtkPoints.h"
13 #include "vtkCellArray.h"
14 #include "vtkPolyData.h"
15 #include "vtkPolyDataMapper.h"
16 #include "vtkPolyDataWriter.h"
17 #include "vtkPolyDataReader.h"
18 #include "vtkImageReader.h"
19 #include "vtkImageViewer.h"
20 #include "vtkImageViewer2.h"
21 #include "vtkImageToStructuredPoints.h"
22 #include <vtkImageThreshold.h>
24 #include "vtkExtractVOI.h"
25 #include "vtkImageClip.h"
26 #include "vtkImageResample.h"
27 #include "vtkImageThreshold.h"
28 #include "vtkImageCast.h"
29 #include "vtkImageSeedConnectivity.h"
30 #include "vtkImageData.h"
31 #include "vtkMarchingCubes.h"
32 #include "vtkImageReslice.h"
33 #include "vtkTransform.h"
34 #include "vtkSphereSource.h"
35 #include "vtkDoubleArray.h"
36 #include "vtkPointData.h"
37 #include "vtkCommand.h"
38 #include "vtkCallbackCommand.h"
39 #include "vtkImageResample.h"
41 #include "vtkStripper.h"
43 #include "wxEmptyPanelWidget_2.h"
45 #include <wx/splitter.h>
49 //-------------------------------------------------------------------
50 //-------------------------------------------------------------------
51 //-------------------------------------------------------------------
52 vtkStandardNewMacro(TreeExtraction_MH_JFC);
53 //-------------------------------------------------------------------
55 TreeExtraction_MH_JFC::TreeExtraction_MH_JFC(){
57 _imagedataResult = NULL;
60 //-------------------------------------------------------------------
61 TreeExtraction_MH_JFC::~TreeExtraction_MH_JFC(){
64 //-------------------------------------------------------------------
65 void TreeExtraction_MH_JFC::Reset(){
66 if (_imagedataResult!=NULL){
67 _imagedataResult->Delete();
70 //-------------------------------------------------------------------
71 void TreeExtraction_MH_JFC::SetInput(marExperiment *input){
72 _marExperiment = input;
75 //-------------------------------------------------------------------
76 void TreeExtraction_MH_JFC::BruleVolume(vtkImageData *imagedata, int x,int y,int z,int r , int value)
79 int i, j, k, ii,jj,kk;
80 imagedata->GetExtent(ext);
92 ptr=(unsigned short *) imagedata->GetScalarPointer(i,j,k);
96 tmpsqrt=ii*ii + jj*jj + kk*kk;
97 if ((ptr!=NULL) && ( sqrt(tmpsqrt)<=r))
112 //-------------------------------------------------------------------
113 void TreeExtraction_MH_JFC::BruleVolume(vtkImageData *imagedata,vtkPolyData *inputAxisRadio, int value)
116 double point[3],radio;
117 double fractpart, intpart;
118 int i,maxPoints=inputAxisRadio->GetPoints()->GetNumberOfPoints();
119 vtkDoubleArray *allRadios = (vtkDoubleArray*)(inputAxisRadio->GetPointData()->GetScalars("radio"));
120 for (i=0; i<maxPoints; i++){
121 inputAxisRadio->GetPoints()->GetPoint(i,point);
122 radio=allRadios->GetValue(i);
126 fractpart = modf (radio , &intpart);
130 r = (int)( intpart );
131 BruleVolume(imagedata,x,y,z,r,value);
136 //-------------------------------------------------------------------
138 void TreeExtraction_MH_JFC::FindVit( marExperiment *newExperiment , int actualAxis , double *pointBif , double *vit )
143 int jPoint,maxPoints;
146 maxAxis=newExperiment->getNumberOfAxes();
147 for (iAxis=0;iAxis<maxAxis;iAxis++){
148 if (iAxis!=actualAxis){
149 newExperiment->setAxis(iAxis);
150 marAxis *maraxis = newExperiment->getAxis( );
152 vtkPolyData *axisVtk = maraxis->GetAxisData();
153 maxPoints=axisVtk->GetPoints()->GetNumberOfPoints();
154 for (jPoint=0; jPoint<maxPoints; jPoint++){
155 axisVtk->GetPoints()->GetPoint(jPoint,point);
156 dx = pointBif[0]-point[0];
157 dy = pointBif[1]-point[1];
158 dz = pointBif[2]-point[2];
159 dist = sqrt( dx*dx + dy*dy + dz*dz );
160 if ((min==-1) || (dist<min)) {
167 } // if maraxis!=NULL
172 //-------------------------------------------------------------------
173 void TreeExtraction_MH_JFC::Execute(int count, int sens, double *vit, int cleanLevel)
175 //------------Arbre Extraction --------------
176 // Call Maracas axis extraction
183 int idActualAxis_Before = _marExperiment->getNumberOfAxes();
184 _marExperiment->extractVascularTree( sens , vit, cleanLevel );
187 dif = difftime (end,start);
189 ff=fopen("c:/temp/MaracasTIME.txt","a+");
190 fprintf(ff,"\n TreeExtraction_MH_JFC::Execute %d \n",count);
191 fprintf(ff,"evt %.2lf \n",dif);
194 int idActualAxis = _marExperiment->getNumberOfAxes();
195 // Bifurcation Detection JFC
196 marAxis *maraxis = _marExperiment->getAxis( );
197 if ((maraxis!=NULL) && (idActualAxis_Before!=idActualAxis)) {
198 vtkImageData *imagedata = _marExperiment->getDynData( )->getVolume( )->castVtk();
199 vtkPolyData *inputAxisRadio = maraxis->GetAxisData();
205 _prgov = carotidaBifurcacion::New();
206 _prgov->SetMaxPropRadio(5);
207 _prgov->SetHumbral(0.45);
208 _prgov->SetMaxPropMasa(10);
209 _prgov->SetMinPropMasa(0.01);
210 _prgov->SetInput( inputAxisRadio );
211 _prgov->SetInput2( imagedata );
215 dif = difftime (end,start);
216 ff=fopen("c:/temp/MaracasTIME.txt","a+");
217 fprintf(ff,"\tcB %.2lf \n",dif);
223 BruleVolume(imagedata , inputAxisRadio , 0 );
224 BruleVolume(_imagedataResult , inputAxisRadio , idActualAxis );
225 inputAxisRadio->Delete();
229 // LOOP for branch extraction
230 vtkPolyData *bifurcations = _prgov->GetOutput();
231 int i,maxPoints = bifurcations->GetPoints()->GetNumberOfPoints();
233 double point[3], vit[3];
234 for (i=0; i<maxPoints; i++){
235 bifurcations->GetPoints()->GetPoint(i,point);
239 FindVit( _marExperiment , idActualAxis , point , vit );
240 _marExperiment->setStartPoint( x , y , z );
242 Execute(count, 0 , vit , (int)_cleanLevel );
244 bifurcations->Delete();
252 //-------------------------------------------------------------------
253 void TreeExtraction_MH_JFC::InitImagaDataResult(){
255 vtkImageData *imagedata = _marExperiment->getDynData( )->getVolume( )->castVtk();
257 _imagedataResult = vtkImageData::New();
259 imagedata->GetDimensions(dim);
260 _imagedataResult->SetScalarType(imagedata->GetScalarType());
262 _imagedataResult->SetDimensions(dim[0],dim[1],dim[2]);
263 _imagedataResult->SetExtent( 0 , dim[0]-1 , 0 , dim[1]-1 , 0 , dim[2]-1 );
264 _imagedataResult->SetWholeExtent(0 , dim[0]-1 , 0 , dim[1]-1 , 0 , dim[2]-1 );
265 _imagedataResult->SetSpacing( imagedata->GetSpacing() );
266 _imagedataResult->SetOrigin( 0,0,0 );
267 _imagedataResult->Update();
268 _imagedataResult->UpdateData();
271 for ( i=0 ; i<dim[0] ; i++ ){
272 for ( j=0 ; j<dim[1] ; j++ ){
273 for ( k=0 ; k<dim[2] ; k++ ){
274 ptr = (unsigned short *) _imagedataResult->GetScalarPointer(i,j,k);
280 //-------------------------------------------------------------------
281 void TreeExtraction_MH_JFC::Update(){
284 ff=fopen("c:/temp/MaracasTIME.txt","w");
287 InitImagaDataResult();
288 Execute(_branchLevel);
290 //-------------------------------------------------------------------
291 marExperiment* TreeExtraction_MH_JFC::GetInput(){
292 return _marExperiment;
294 //-------------------------------------------------------------------
295 vtkImageData* TreeExtraction_MH_JFC::GetVolume(){
296 return _imagedataResult;
298 //-------------------------------------------------------------------
299 void TreeExtraction_MH_JFC::SetBranchLevel(int branchLevel){
300 _branchLevel = branchLevel;
302 //-------------------------------------------------------------------
303 void TreeExtraction_MH_JFC::SetCleanTreeLevel( int cleanLevel ){
304 _cleanLevel = (double)cleanLevel;
307 //-------------------------------------------------------------------
308 //-------------------------------------------------------------------
309 //-------------------------------------------------------------------
310 wxEmptyPanelWidget_2::wxEmptyPanelWidget_2(wxWindow *parent, marInterface* mar)
311 : wxPanel( parent, -1)
314 _sensibility_JF = 0.5;
317 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
318 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
319 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
320 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
322 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
323 pnlSplitter -> SetMinimumPaneSize( 150 );
324 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
325 this -> SetSizer(sizer);
332 // Result 1: Volume + Axis
335 _1_stripfinal = NULL;
336 _1_isoMapperMC6 = NULL;
337 _1_isoActorMC6 = NULL;
340 // Result 2: Volume + Axis
343 _2_stripfinal = NULL;
344 _2_isoMapperMC6 = NULL;
345 _2_isoActorMC6 = NULL;
349 _isoMapperMC1 = NULL;
352 _imageThresholdMC1 = NULL;
355 _treeExtraction = NULL;
358 //-------------------------------------------------------------------
359 wxEmptyPanelWidget_2::~wxEmptyPanelWidget_2(){
360 // Erase Original Volule
361 if (_mCubes ) { _mCubes -> Delete(); }
362 if (_surfMapper ) { _surfMapper -> Delete(); }
363 if (_surfActor ) { _surfActor -> Delete(); }
365 // Erase result: Volume + Axis
370 //-------------------------------------------------------------------
371 wxPanel* wxEmptyPanelWidget_2::CreateViewPanel(wxWindow *parent)
373 wxPanel *panel = new wxPanel(parent,-1);
374 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
375 _maracasSurfaceWidget = new wxSurfaceWidget(panel);
376 sizer->Add(_maracasSurfaceWidget , 1, wxEXPAND, 0);
377 panel->SetSizer(sizer);
378 panel->SetAutoLayout(true);
379 panel->SetSize(400,400);
383 //-------------------------------------------------------------------
384 wxPanel* wxEmptyPanelWidget_2::CreateControlPanel(wxWindow *parent)
386 wxPanel *panel = new wxPanel(parent,-1);
387 _opacity_OrigVol = new wxSlider( panel, -1, 30, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
388 _isoValue = new wxSlider( panel, -1, 0 , 0, 3000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
389 _opacity_Res1VolJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
390 _opacity_Res2VolJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
391 _sl_sensibility_JF = new wxSlider( panel, -1, 0 , 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
392 _branchLevel = new wxSlider( panel, -1, 2 , 1, 10 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
393 _opacity_ResVolMHJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
394 _isoValue_MH_JFC = new wxSlider( panel, -1, 0 , 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
395 _cleanTree_MH_JFC = new wxSlider( panel, -1, 400 , 0, 1000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
397 int tmp_sensibility= (int)(_sensibility_JF*100.0);
398 _sl_sensibility_JF->SetValue( tmp_sensibility );
401 _opacity_OrigVol ->SetSize(250,20); // Original Volume
402 _isoValue ->SetSize(250,20);
403 _opacity_Res1VolJF ->SetSize(250,20); // Result 1 Volume JF
404 _opacity_Res2VolJF ->SetSize(250,20); // Result 2 Volume JF
405 _branchLevel ->SetSize(250,20);
406 _opacity_ResVolMHJF ->SetSize(250,20); // Result Volume MH+JFC
409 wxButton *btnExtractTree1_JF = new wxButton(panel,-1,_T("Extract Tree 1 JF"));
410 wxButton *btnEraseTree1_JF = new wxButton(panel,-1,_T("Erase Tree 1 JF"));
413 wxButton *btnExtractTree2_JF = new wxButton(panel,-1,_T("Extract Tree 2 JF"));
414 wxButton *btnEraseTree2_JF = new wxButton(panel,-1,_T("Erase Tree 2 JF"));
416 //Extract Tree MH + JF
417 wxButton *btnExtractTree_MH_JFC = new wxButton(panel,-1,_T("Extract Tree MH + JFC"));
418 wxButton *btnEraseTree_MH_JFC = new wxButton(panel,-1,_T("Erase Tree MH + JFC"));
421 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
422 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
423 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
424 sizer->Add(new wxStaticText(panel,-1,_T("Isovalue - Original Volume")));
425 sizer->Add(_isoValue);
426 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Original Volume")));
427 sizer->Add(_opacity_OrigVol);
429 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
430 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
431 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Juan Francisco Module 1 - - - ")));
432 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
433 sizer->Add(btnExtractTree1_JF);
434 sizer->Add(btnEraseTree1_JF);
435 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
436 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
437 sizer->Add(_opacity_Res1VolJF);
439 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
440 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
441 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Juan Francisco Module 2 - - - ")));
442 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
443 sizer->Add(new wxStaticText(panel,-1,_T(" % Sensibility")));
444 sizer->Add(_sl_sensibility_JF);
445 sizer->Add(btnExtractTree2_JF);
446 sizer->Add(btnEraseTree2_JF);
447 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
448 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
449 sizer->Add(_opacity_Res2VolJF);
452 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
453 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
454 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
455 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
456 sizer->Add(new wxStaticText(panel,-1,_T(" - - - MH + JFC - - - ")));
457 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
458 sizer->Add(btnExtractTree_MH_JFC);
459 sizer->Add(btnEraseTree_MH_JFC);
460 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
461 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
462 sizer->Add(new wxStaticText(panel,-1,_T("Branch Level MH+JFC")));
463 sizer->Add(_branchLevel);
464 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
465 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume MH+JFC")));
466 sizer->Add(_opacity_ResVolMHJF);
467 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
468 sizer->Add(new wxStaticText(panel,-1,_T("IsoValue - Result Volume MH+JFC")));
469 sizer->Add(_isoValue_MH_JFC);
470 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
471 sizer->Add(new wxStaticText(panel,-1,_T("signal level (Clean Tree)")));
472 sizer->Add(_cleanTree_MH_JFC);
474 panel->SetSizer(sizer);
475 panel->SetAutoLayout(true);
476 panel->SetSize(400,400);
478 Connect(_opacity_OrigVol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_OrigVol );
479 Connect(_isoValue->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnIsoValue );
480 Connect(_opacity_Res1VolJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_Res1VolJF );
481 Connect(_opacity_Res2VolJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_Res2VolJF );
482 Connect(_sl_sensibility_JF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnSensibility );
484 Connect(btnExtractTree1_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree1_JF );
485 Connect(btnEraseTree1_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree1_JF );
486 Connect(btnExtractTree2_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree2_JF );
487 Connect(btnEraseTree2_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree2_JF );
489 Connect(btnExtractTree_MH_JFC->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree_MH_JFC);
490 Connect(btnEraseTree_MH_JFC->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree_MH_JFC );
491 Connect(_branchLevel->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBranchLevel );
492 Connect(_opacity_ResVolMHJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_ResVolMHJF );
493 Connect(_isoValue_MH_JFC->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnIsoValue_MH_JFC );
494 Connect(_cleanTree_MH_JFC->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnCleanTree_MH_JFC );
498 //------------------------------------------------------------------------
499 void wxEmptyPanelWidget_2::Refresh()
501 _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->Render();
503 //------------------------------------------------------------------------
504 void wxEmptyPanelWidget_2::ConfigureVTK()
507 // _imageviewer3D->Configure();
508 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
509 double opacity_OrigVol = ((double)(_opacity_OrigVol->GetValue()))/100;
512 // Visualisation - original volume
514 imagedata->GetScalarRange( range );
515 isoValue=range[1] / 8;
517 _mCubes = vtkMarchingCubes::New( );
518 _mCubes->SetInput( imagedata );
519 _mCubes->SetValue( 0, isoValue );
521 vtkStripper *stripper = vtkStripper::New();
522 stripper->SetInput( _mCubes->GetOutput( ) );
524 _surfMapper = vtkPolyDataMapper::New( );
525 _surfMapper->SetInput( stripper->GetOutput() );
526 _surfMapper->ScalarVisibilityOff( );
529 _surfActor = vtkActor::New( );
530 _surfActor->SetMapper( _surfMapper );
531 _surfActor->PickableOff( );
532 _surfActor->GetProperty( )->SetColor( 0, 0, 0.8 );
533 _surfActor->GetProperty( )->SetOpacity( opacity_OrigVol );
536 _isoValue->SetRange( (int)(range[0]), (int)(range[1]) );
537 _isoValue->SetValue( (int)isoValue );
540 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
541 ren->AddActor(_surfActor);
544 _maracasSurfaceWidget->ShowMARACASData( _mar );
548 //------------------------------------------------------------------------
549 void wxEmptyPanelWidget_2::ResetTree1_JF()
552 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
554 ren->RemoveActor(_1_isoActorMC6);
557 ren->RemoveActor(_1_stripfinal);
561 if (_1_prgov ) { _1_prgov -> Delete(); }
562 if (_1_mapfinal ) { _1_mapfinal -> Delete(); }
563 if (_1_stripfinal ) { _1_stripfinal -> Delete(); }
564 if (_1_isoMapperMC6 ) { _1_isoMapperMC6 -> Delete(); }
565 if (_1_isoActorMC6 ) { _1_isoActorMC6 -> Delete(); }
566 if (_1_isoMC6 ) { _1_isoMC6 -> Delete(); }
571 _1_stripfinal = NULL;
572 _1_isoMapperMC6 = NULL;
573 _1_isoActorMC6 = NULL;
577 //------------------------------------------------------------------------
578 void wxEmptyPanelWidget_2::ResetTree2_JF()
581 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
583 ren->RemoveActor(_2_isoActorMC6);
586 ren->RemoveActor(_2_stripfinal);
590 if (_2_prgov ) { _2_prgov -> Delete(); }
591 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
592 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
593 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
594 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
595 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
600 _2_stripfinal = NULL;
601 _2_isoMapperMC6 = NULL;
602 _2_isoActorMC6 = NULL;
608 //------------------------------------------------------------------------
609 void wxEmptyPanelWidget_2::ExtractTree1_JF(int x, int y, int z)
611 double opacity_Res1VolJF = ((double)_opacity_Res1VolJF->GetValue())/100;
612 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
614 double puntoactualprov[3];
618 puntoactualprov[0]=x;
619 puntoactualprov[1]=y;
620 puntoactualprov[2]=z;
622 imagedata->GetSpacing(espprin);
623 imagedata->GetExtent(extprin);
625 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
626 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
627 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
629 // Juan Francisco Carrillo Filter
630 _1_prgov= axisExtractor::New();
631 _1_prgov->SetHumbral(0.45);
632 _1_prgov->SetInput(imagedata);
633 _1_prgov->SetPoint(puntoactualprov);
636 // Visualisation - result vascular tree
637 _1_mapfinal = vtkPolyDataMapper::New();
638 _1_mapfinal->SetInput(_1_prgov->GetOutput());
640 _1_stripfinal = vtkActor::New();
641 _1_stripfinal->SetMapper(_1_mapfinal);
642 _1_stripfinal->GetProperty()->SetColor(1, 1, 1);
643 _1_stripfinal->GetProperty()->SetLineWidth(2);
644 _1_stripfinal->GetProperty()->BackfaceCullingOff();
646 // Visualisation - result volume
647 vtkImageData *imageOut = _1_prgov->GetVolumen();
650 _1_isoMC6 = vtkMarchingCubes::New();
651 _1_isoMC6->SetInput(imageOut);
652 _1_isoMC6->SetValue(0, 1);
655 _1_isoMapperMC6 = vtkPolyDataMapper::New();
656 _1_isoMapperMC6->SetInput(_1_isoMC6->GetOutput());
657 _1_isoMapperMC6->ScalarVisibilityOff();
658 _1_isoMapperMC6->ImmediateModeRenderingOn();
660 _1_isoActorMC6 = vtkActor::New();
661 _1_isoActorMC6->SetMapper(_1_isoMapperMC6);
662 _1_isoActorMC6->GetProperty()->SetColor( 0, 1, 0);
663 _1_isoActorMC6->GetProperty()->SetOpacity( opacity_Res1VolJF );
667 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
668 ren->AddActor(_1_isoActorMC6);
669 ren->AddActor(_1_stripfinal);
673 //------------------------------------------------------------------------
674 void wxEmptyPanelWidget_2::ExtractTree2_JF(int x, int y, int z)
676 double opacity_Res2VolJF = ((double)_opacity_Res2VolJF->GetValue())/100;
677 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
679 double puntoactualprov[3];
683 puntoactualprov[0]=x;
684 puntoactualprov[1]=y;
685 puntoactualprov[2]=z;
687 imagedata->GetSpacing(espprin);
688 imagedata->GetExtent(extprin);
690 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
691 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
692 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
694 _2_prgov= axisExtractor02::New();
695 _2_prgov->SetParam(1);
696 _2_prgov->SetParam2(1);
697 _2_prgov->SetParam3(_sensibility_JF);
698 _2_prgov->SetMaxant(20);
699 _2_prgov->SetMinant(5);
700 _2_prgov->SetInput(imagedata);
701 _2_prgov->SetPoint(puntoactualprov);
704 // Visualisation - result vascular tree
705 _2_mapfinal = vtkPolyDataMapper::New();
706 _2_mapfinal->SetInput(_2_prgov->GetOutput());
708 _2_stripfinal = vtkActor::New();
709 _2_stripfinal->SetMapper(_2_mapfinal);
710 _2_stripfinal->GetProperty()->SetColor(0.3, 0.3, 0.3);
711 _2_stripfinal->GetProperty()->SetLineWidth(2);
712 _2_stripfinal->GetProperty()->BackfaceCullingOff();
714 // Visualisation - result volume
715 vtkImageData *imageOut = _2_prgov->GetVolumen();
718 _2_isoMC6 = vtkMarchingCubes::New();
719 _2_isoMC6->SetInput(imageOut);
720 _2_isoMC6->SetValue(0, 1);
723 _2_isoMapperMC6 = vtkPolyDataMapper::New();
724 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
725 _2_isoMapperMC6->ScalarVisibilityOff();
726 _2_isoMapperMC6->ImmediateModeRenderingOn();
728 _2_isoActorMC6 = vtkActor::New();
729 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
730 _2_isoActorMC6->GetProperty()->SetColor( 1, 1, 0);
731 _2_isoActorMC6->GetProperty()->SetOpacity( opacity_Res2VolJF );
734 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
735 ren->AddActor(_2_isoActorMC6);
736 ren->AddActor(_2_stripfinal);
739 //------------------------------------------------------------------------
740 void wxEmptyPanelWidget_2::OnOpacity_OrigVol(wxScrollEvent& event)
742 double value = ((double)_opacity_OrigVol->GetValue())/100;
743 _surfActor->GetProperty( )->SetOpacity( value );
746 //------------------------------------------------------------------------
747 void wxEmptyPanelWidget_2::OnOpacity_Res1VolJF(wxScrollEvent& event)
749 if (_1_isoActorMC6!=NULL){
750 double value = ((double)_opacity_Res1VolJF->GetValue())/100;
751 _1_isoActorMC6->GetProperty( )->SetOpacity( value );
755 //------------------------------------------------------------------------
756 void wxEmptyPanelWidget_2::OnOpacity_Res2VolJF(wxScrollEvent& event)
758 if (_2_isoActorMC6!=NULL){
759 double value = ((double)_opacity_Res2VolJF->GetValue())/100;
760 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
765 //------------------------------------------------------------------------
766 void wxEmptyPanelWidget_2::OnIsoValue(wxScrollEvent& event)
769 _mCubes->SetValue(0, _isoValue->GetValue());
772 //------------------------------------------------------------------------
773 void wxEmptyPanelWidget_2::OnBtnExtractTree1_JF(wxCommandEvent& event)
777 vtk3DSurfaceWidget *world3D = _maracasSurfaceWidget->GetVtk3DSurfaceWidget();
778 if( world3D->GetInitialSphere() ){
780 world3D->GetSphereCenter( point );
781 ExtractTree1_JF((int)point[0],(int)point[1],(int)point[2]);
786 //------------------------------------------------------------------------
787 void wxEmptyPanelWidget_2::OnBtnExtractTree2_JF(wxCommandEvent& event)
791 vtk3DSurfaceWidget *world3D = _maracasSurfaceWidget->GetVtk3DSurfaceWidget();
792 if( world3D->GetInitialSphere() ){
794 world3D->GetSphereCenter( point );
795 ExtractTree2_JF((int)point[0],(int)point[1],(int)point[2]);
800 //------------------------------------------------------------------------
801 void wxEmptyPanelWidget_2::OnBtnEraseTree1_JF(wxCommandEvent& event)
806 //------------------------------------------------------------------------
807 void wxEmptyPanelWidget_2::OnBtnEraseTree2_JF(wxCommandEvent& event)
813 //------------------------------------------------------------------------
814 void wxEmptyPanelWidget_2::PaintVascularTree_MH_JFC(marExperiment * newExperiment)
816 vtkActor *branchActor;
817 vtkPolyData *axisVtk;
818 vtkPolyDataMapper *branchMapper;
819 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
821 int i,maxAxis=newExperiment->getNumberOfAxes();
822 for (i=0;i<maxAxis;i++){
823 newExperiment->setAxis(i);
824 marAxis *maraxis =newExperiment->getAxis( );
826 axisVtk = maraxis->Draw();
827 branchMapper = vtkPolyDataMapper::New( );
828 branchMapper->SetInput( axisVtk );
829 branchMapper->Update();
830 branchActor = vtkActor::New( );
831 branchActor->SetMapper( branchMapper );
832 branchActor->GetProperty()->SetColor( 1, 1, 1 );
833 if (i== 0) { branchActor->GetProperty()->SetColor( 0 , 0 , 0.3 ); }
834 if (i== 1) { branchActor->GetProperty()->SetColor( 0 , 0.3 , 0.3 ); }
835 if (i== 2) { branchActor->GetProperty()->SetColor( 0.3, 0.3 , 0.3 ); }
836 if (i== 3) { branchActor->GetProperty()->SetColor( 0.0, 0.0 , 0.6 ); }
837 if (i== 4) { branchActor->GetProperty()->SetColor( 0.0, 0.6 , 0.6 ); }
838 if (i== 5) { branchActor->GetProperty()->SetColor( 0.6, 0.6 , 0.6 ); }
839 if (i== 7) { branchActor->GetProperty()->SetColor( 0.0, 0.0 , 0.9 ); }
840 if (i== 8) { branchActor->GetProperty()->SetColor( 0.0, 0.9 , 0.9 ); }
841 if (i== 9) { branchActor->GetProperty()->SetColor( 0.9, 0.9 , 0.9 ); }
842 if (i==10) { branchActor->GetProperty()->SetColor( 0.9, 0.0 , 0.0 ); }
843 if (i==11) { branchActor->GetProperty()->SetColor( 0.6, 0.0 , 0.0 ); }
844 if (i==12) { branchActor->GetProperty()->SetColor( 0.3, 0.0 , 0.0 ); }
845 if (i==13) { branchActor->GetProperty()->SetColor( 0.6, 0.6 , 0.0 ); }
846 if (i==14) { branchActor->GetProperty()->SetColor( 0.3, 0.3 , 0.0 ); }
847 if (i==15) { branchActor->GetProperty()->SetColor( 0.9, 0.9 , 0.0 ); }
848 branchActor->GetProperty()->SetLineWidth( 2.0 );
849 ren->AddActor( branchActor );
851 _lstAxisVtk.push_back( axisVtk );
852 _lstBranchActor.push_back( branchActor );
853 _lstBranchMapper.push_back( branchMapper );
859 //------------------------------------------------------------------------
860 void wxEmptyPanelWidget_2::PaintVascularVolume_MH_JFC(vtkImageData * image)
863 // Visualisation - result volume
866 _imageThresholdMC1=vtkImageThreshold::New();
867 _imageThresholdMC1->SetInput(image);
868 _imageThresholdMC1->ThresholdBetween(0,100);
869 _imageThresholdMC1->SetOutValue ( 0 );
870 _imageThresholdMC1->Update();
872 _isoMC1 = vtkMarchingCubes::New();
873 _isoMC1->SetInput(_imageThresholdMC1->GetOutput() );
874 _isoMC1->SetValue(0, 1);
877 _isoMapperMC1 = vtkPolyDataMapper::New();
878 _isoMapperMC1->SetInput(_isoMC1->GetOutput());
879 _isoMapperMC1->ScalarVisibilityOff();
880 _isoMapperMC1->ImmediateModeRenderingOn();
881 _isoMapperMC1->Update();
883 _isoActorMC1 = vtkActor::New();
884 _isoActorMC1->SetMapper(_isoMapperMC1);
885 _isoActorMC1->GetProperty()->SetColor( 1, 0, 0);
886 _isoActorMC1->GetProperty()->SetOpacity( 0.4 );
889 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
890 ren->AddActor(_isoActorMC1);
893 //------------------------------------------------------------------------
894 void wxEmptyPanelWidget_2::WriteSignals(marExperiment *newExperiment){
899 int maxAxis = newExperiment->getNumberOfAxes();
902 ff=fopen("c:/Temp/MaracasTEMP.TXT", "w");
906 for (i=0;i<maxAxis;i++){
907 newExperiment->setAxis(i);
908 marAxis *maraxis =newExperiment->getAxis( );
910 if ( j < maraxis->getNumberOfControlPoints() ){
912 value= (int)(maraxis->getSignal((uint32_t)j) );
913 fprintf(ff,"%d\t", value );
926 //------------------------------------------------------------------------
927 void wxEmptyPanelWidget_2::OnBtnExtractTree_MH_JFC(wxCommandEvent& event)
929 if ((_lstBranchActor.size()==0)
931 (_maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetInitialSphere() ) )
938 _mar->_experiment->getVOI(voiA);
940 voiB[1]=voiA[1]-voiA[0];
942 voiB[3]=voiA[3]-voiA[2];
944 voiB[5]=voiA[5]-voiA[4];
945 marExperiment *newExperiment = new marExperiment( _mar->_experiment->getParameters() );
946 newExperiment->setVOI( voiB );
947 newExperiment->initExperiment( _mar->_experiment->getDynData( )->getVolume() );
951 _mar->_experiment->getDynData( )->getVolume( )->castVtk()->GetExtent( extent );
952 _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetSphereCenter( point );
953 int x = (int)point[0] - extent[0];
954 int y = (int)point[1] - extent[2];
955 int z = (int)point[2] - extent[4];
956 newExperiment->setStartPoint( x, y, z);
958 // Vascular tree extraction
959 _treeExtraction = TreeExtraction_MH_JFC::New();
960 _treeExtraction->SetInput(newExperiment);
961 _treeExtraction->SetCleanTreeLevel( _cleanTree_MH_JFC->GetValue() );
962 _treeExtraction->SetBranchLevel( _branchLevel->GetValue() );
963 _treeExtraction->Update();
965 //Paint Vascular Tree
966 PaintVascularTree_MH_JFC(newExperiment);
967 //Paint Vascular Volume
968 PaintVascularVolume_MH_JFC( _treeExtraction->GetVolume() );
971 WriteSignals(newExperiment);
974 delete newExperiment;
977 //------------------------------------------------------------------------
978 void wxEmptyPanelWidget_2::OnBtnEraseTree_MH_JFC(wxCommandEvent& event)
984 //------------------------------------------------------------------------
985 void wxEmptyPanelWidget_2::ResetTree_MH_JFC()
988 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
990 size=_lstAxisVtk.size();
991 size=_lstBranchMapper.size();
992 size=_lstBranchActor.size();
993 for (i=0;i<size;i++){
994 if (_lstBranchActor[i]!=NULL){
995 ren->RemoveActor( _lstBranchActor[i] );
998 for (i=0;i<size;i++){
1000 if (_lstAxisVtk[i] != NULL ) { _lstAxisVtk[i] -> Delete(); }
1001 // if (_lstBranchMapper[i] != NULL ) { _lstBranchMapper[i] -> Delete(); }
1002 if (_lstBranchActor[i] != NULL ) { _lstBranchActor[i] -> Delete(); }
1004 _lstAxisVtk[i] = NULL;
1005 _lstBranchActor[i] = NULL;
1006 _lstBranchMapper[i] = NULL;
1008 _lstAxisVtk.clear();
1009 _lstBranchActor.clear();
1010 _lstBranchMapper.clear();
1014 ren->RemoveActor(_isoActorMC1);
1018 if (_isoMapperMC1 ) { _isoMapperMC1 -> Delete(); }
1019 if (_isoActorMC1 ) { _isoActorMC1 -> Delete(); }
1020 if (_isoMC1 ) { _isoMC1 -> Delete(); }
1021 if (_imageThresholdMC1 ) { _imageThresholdMC1 -> Delete(); }
1025 _isoMapperMC1 = NULL;
1026 _isoActorMC1 = NULL;
1028 _imageThresholdMC1 = NULL;
1031 // if (_treeExtraction ) { _treeExtraction -> Delete(); } // EED
1032 // _treeExtraction=NULL;
1036 //------------------------------------------------------------------------
1037 void wxEmptyPanelWidget_2::OnOpacity_ResVolMHJF(wxScrollEvent& event)
1039 if (_isoActorMC1!=NULL){
1040 double value = ((double)_opacity_ResVolMHJF->GetValue())/100;
1041 _isoActorMC1->GetProperty( )->SetOpacity( value );
1045 //------------------------------------------------------------------------
1046 void wxEmptyPanelWidget_2::OnBranchLevel(wxScrollEvent& event)
1050 //------------------------------------------------------------------------
1051 void wxEmptyPanelWidget_2::OnIsoValue_MH_JFC(wxScrollEvent& event)
1053 if (_imageThresholdMC1!=NULL){
1055 double threshold = _isoValue_MH_JFC->GetValue();
1057 _imageThresholdMC1->ThresholdBetween(threshold, threshold );
1059 _imageThresholdMC1->ThresholdBetween(0, 1000 );
1064 //------------------------------------------------------------------------
1065 void wxEmptyPanelWidget_2::OnCleanTree_MH_JFC(wxScrollEvent& event)
1069 //------------------------------------------------------------------------
1070 void wxEmptyPanelWidget_2::OnSensibility(wxScrollEvent& event)
1072 _sensibility_JF = (double)(_sl_sensibility_JF->GetValue())/100;