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 # ------------------------------------------------------------------------ */
26 #include "vtkObjectFactory.h"
29 #include "vtkCylinderSource.h"
30 #include "vtkPolyDataMapper.h"
31 #include "vtkRenderer.h"
32 #include "vtkRenderWindow.h"
33 #include "vtkRenderWindowInteractor.h"
34 #include "vtkProperty.h"
35 #include "vtkCamera.h"
36 #include "vtkPoints.h"
37 #include "vtkCellArray.h"
38 #include "vtkPolyData.h"
39 #include "vtkPolyDataMapper.h"
40 #include "vtkPolyDataWriter.h"
41 #include "vtkPolyDataReader.h"
42 #include "vtkImageReader.h"
43 #include "vtkImageViewer.h"
44 #include "vtkImageViewer2.h"
45 #include "vtkImageToStructuredPoints.h"
46 #include <vtkImageThreshold.h>
48 #include "vtkExtractVOI.h"
49 #include "vtkImageClip.h"
50 #include "vtkImageResample.h"
51 #include "vtkImageThreshold.h"
52 #include "vtkImageCast.h"
53 #include "vtkImageSeedConnectivity.h"
54 #include "vtkImageData.h"
55 #include "vtkMarchingCubes.h"
56 #include "vtkImageReslice.h"
57 #include "vtkTransform.h"
58 #include "vtkSphereSource.h"
59 #include "vtkDoubleArray.h"
60 #include "vtkPointData.h"
61 #include "vtkCommand.h"
62 #include "vtkCallbackCommand.h"
63 #include "vtkImageResample.h"
65 #include "vtkStripper.h"
67 #include "wxEmptyPanelWidget_2.h"
69 #include <wx/splitter.h>
73 //-------------------------------------------------------------------
74 //-------------------------------------------------------------------
75 //-------------------------------------------------------------------
76 vtkStandardNewMacro(TreeExtraction_MH_JFC);
77 //-------------------------------------------------------------------
79 TreeExtraction_MH_JFC::TreeExtraction_MH_JFC(){
81 _imagedataResult = NULL;
84 //-------------------------------------------------------------------
85 TreeExtraction_MH_JFC::~TreeExtraction_MH_JFC(){
88 //-------------------------------------------------------------------
89 void TreeExtraction_MH_JFC::Reset(){
90 if (_imagedataResult!=NULL){
91 _imagedataResult->Delete();
94 //-------------------------------------------------------------------
95 void TreeExtraction_MH_JFC::SetInput(marExperiment *input){
96 _marExperiment = input;
99 //-------------------------------------------------------------------
100 void TreeExtraction_MH_JFC::BruleVolume(vtkImageData *imagedata, int x,int y,int z,int r , int value)
103 int i, j, k, ii,jj,kk;
104 imagedata->GetExtent(ext);
116 ptr=(unsigned short *) imagedata->GetScalarPointer(i,j,k);
120 tmpsqrt=ii*ii + jj*jj + kk*kk;
121 if ((ptr!=NULL) && ( sqrt(tmpsqrt)<=r))
136 //-------------------------------------------------------------------
137 void TreeExtraction_MH_JFC::BruleVolume(vtkImageData *imagedata,vtkPolyData *inputAxisRadio, int value)
140 double point[3],radio;
141 double fractpart, intpart;
142 int i,maxPoints=inputAxisRadio->GetPoints()->GetNumberOfPoints();
143 vtkDoubleArray *allRadios = (vtkDoubleArray*)(inputAxisRadio->GetPointData()->GetScalars("radio"));
144 for (i=0; i<maxPoints; i++){
145 inputAxisRadio->GetPoints()->GetPoint(i,point);
146 radio=allRadios->GetValue(i);
150 fractpart = modf (radio , &intpart);
154 r = (int)( intpart );
155 BruleVolume(imagedata,x,y,z,r,value);
160 //-------------------------------------------------------------------
162 void TreeExtraction_MH_JFC::FindVit( marExperiment *newExperiment , int actualAxis , double *pointBif , double *vit )
167 int jPoint,maxPoints;
170 maxAxis=newExperiment->getNumberOfAxes();
171 for (iAxis=0;iAxis<maxAxis;iAxis++){
172 if (iAxis!=actualAxis){
173 newExperiment->setAxis(iAxis);
174 marAxis *maraxis = newExperiment->getAxis( );
176 vtkPolyData *axisVtk = maraxis->GetAxisData();
177 maxPoints=axisVtk->GetPoints()->GetNumberOfPoints();
178 for (jPoint=0; jPoint<maxPoints; jPoint++){
179 axisVtk->GetPoints()->GetPoint(jPoint,point);
180 dx = pointBif[0]-point[0];
181 dy = pointBif[1]-point[1];
182 dz = pointBif[2]-point[2];
183 dist = sqrt( dx*dx + dy*dy + dz*dz );
184 if ((min==-1) || (dist<min)) {
191 } // if maraxis!=NULL
196 //-------------------------------------------------------------------
197 void TreeExtraction_MH_JFC::Execute(int count, int sens, double *vit, int cleanLevel)
199 //------------Arbre Extraction --------------
200 // Call Maracas axis extraction
207 int idActualAxis_Before = _marExperiment->getNumberOfAxes();
208 _marExperiment->extractVascularTree( sens , vit, cleanLevel );
211 dif = difftime (end,start);
213 ff=fopen("c:/temp/MaracasTIME.txt","a+");
214 fprintf(ff,"\n TreeExtraction_MH_JFC::Execute %d \n",count);
215 fprintf(ff,"evt %.2lf \n",dif);
218 int idActualAxis = _marExperiment->getNumberOfAxes();
219 // Bifurcation Detection JFC
220 marAxis *maraxis = _marExperiment->getAxis( );
221 if ((maraxis!=NULL) && (idActualAxis_Before!=idActualAxis)) {
222 vtkImageData *imagedata = _marExperiment->getDynData( )->getVolume( )->castVtk();
223 vtkPolyData *inputAxisRadio = maraxis->GetAxisData();
229 _prgov = carotidaBifurcacion::New();
230 _prgov->SetMaxPropRadio(5);
231 _prgov->SetHumbral(0.45);
232 _prgov->SetMaxPropMasa(10);
233 _prgov->SetMinPropMasa(0.01);
234 _prgov->SetInput( inputAxisRadio );
235 _prgov->SetInput2( imagedata );
239 dif = difftime (end,start);
240 ff=fopen("c:/temp/MaracasTIME.txt","a+");
241 fprintf(ff,"\tcB %.2lf \n",dif);
247 BruleVolume(imagedata , inputAxisRadio , 0 );
248 BruleVolume(_imagedataResult , inputAxisRadio , idActualAxis );
249 inputAxisRadio->Delete();
253 // LOOP for branch extraction
254 vtkPolyData *bifurcations = _prgov->GetOutput();
255 int i,maxPoints = bifurcations->GetPoints()->GetNumberOfPoints();
257 double point[3], vit[3];
258 for (i=0; i<maxPoints; i++){
259 bifurcations->GetPoints()->GetPoint(i,point);
263 FindVit( _marExperiment , idActualAxis , point , vit );
264 _marExperiment->setStartPoint( x , y , z );
266 Execute(count, 0 , vit , (int)_cleanLevel );
268 bifurcations->Delete();
276 //-------------------------------------------------------------------
277 void TreeExtraction_MH_JFC::InitImagaDataResult(){
279 vtkImageData *imagedata = _marExperiment->getDynData( )->getVolume( )->castVtk();
281 _imagedataResult = vtkImageData::New();
283 imagedata->GetDimensions(dim);
284 _imagedataResult->SetScalarType(imagedata->GetScalarType());
286 _imagedataResult->SetDimensions(dim[0],dim[1],dim[2]);
287 _imagedataResult->SetExtent( 0 , dim[0]-1 , 0 , dim[1]-1 , 0 , dim[2]-1 );
288 _imagedataResult->SetWholeExtent(0 , dim[0]-1 , 0 , dim[1]-1 , 0 , dim[2]-1 );
289 _imagedataResult->SetSpacing( imagedata->GetSpacing() );
290 _imagedataResult->SetOrigin( 0,0,0 );
291 _imagedataResult->Update();
292 _imagedataResult->UpdateData();
295 for ( i=0 ; i<dim[0] ; i++ ){
296 for ( j=0 ; j<dim[1] ; j++ ){
297 for ( k=0 ; k<dim[2] ; k++ ){
298 ptr = (unsigned short *) _imagedataResult->GetScalarPointer(i,j,k);
304 //-------------------------------------------------------------------
305 void TreeExtraction_MH_JFC::Update(){
308 ff=fopen("c:/temp/MaracasTIME.txt","w");
311 InitImagaDataResult();
312 Execute(_branchLevel);
314 //-------------------------------------------------------------------
315 marExperiment* TreeExtraction_MH_JFC::GetInput(){
316 return _marExperiment;
318 //-------------------------------------------------------------------
319 vtkImageData* TreeExtraction_MH_JFC::GetVolume(){
320 return _imagedataResult;
322 //-------------------------------------------------------------------
323 void TreeExtraction_MH_JFC::SetBranchLevel(int branchLevel){
324 _branchLevel = branchLevel;
326 //-------------------------------------------------------------------
327 void TreeExtraction_MH_JFC::SetCleanTreeLevel( int cleanLevel ){
328 _cleanLevel = (double)cleanLevel;
331 //-------------------------------------------------------------------
332 //-------------------------------------------------------------------
333 //-------------------------------------------------------------------
334 wxEmptyPanelWidget_2::wxEmptyPanelWidget_2(wxWindow *parent, marInterface* mar)
335 : wxPanel( parent, -1)
338 _sensibility_JF = 0.5;
341 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
342 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
343 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
344 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
346 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
347 pnlSplitter -> SetMinimumPaneSize( 150 );
348 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
349 this -> SetSizer(sizer);
356 // Result 1: Volume + Axis
359 _1_stripfinal = NULL;
360 _1_isoMapperMC6 = NULL;
361 _1_isoActorMC6 = NULL;
364 // Result 2: Volume + Axis
367 _2_stripfinal = NULL;
368 _2_isoMapperMC6 = NULL;
369 _2_isoActorMC6 = NULL;
373 _isoMapperMC1 = NULL;
376 _imageThresholdMC1 = NULL;
379 _treeExtraction = NULL;
382 //-------------------------------------------------------------------
383 wxEmptyPanelWidget_2::~wxEmptyPanelWidget_2(){
384 // Erase Original Volule
385 if (_mCubes ) { _mCubes -> Delete(); }
386 if (_surfMapper ) { _surfMapper -> Delete(); }
387 if (_surfActor ) { _surfActor -> Delete(); }
389 // Erase result: Volume + Axis
394 //-------------------------------------------------------------------
395 wxPanel* wxEmptyPanelWidget_2::CreateViewPanel(wxWindow *parent)
397 wxPanel *panel = new wxPanel(parent,-1);
398 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
399 _maracasSurfaceWidget = new wxSurfaceWidget(panel);
400 sizer->Add(_maracasSurfaceWidget , 1, wxEXPAND, 0);
401 panel->SetSizer(sizer);
402 panel->SetAutoLayout(true);
403 panel->SetSize(400,400);
407 //-------------------------------------------------------------------
408 wxPanel* wxEmptyPanelWidget_2::CreateControlPanel(wxWindow *parent)
410 wxPanel *panel = new wxPanel(parent,-1);
411 _opacity_OrigVol = new wxSlider( panel, -1, 30, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
412 _isoValue = new wxSlider( panel, -1, 0 , 0, 3000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
413 _opacity_Res1VolJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
414 _opacity_Res2VolJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
415 _sl_sensibility_JF = new wxSlider( panel, -1, 0 , 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
416 _branchLevel = new wxSlider( panel, -1, 2 , 1, 10 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
417 _opacity_ResVolMHJF = new wxSlider( panel, -1, 25, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
418 _isoValue_MH_JFC = new wxSlider( panel, -1, 0 , 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
419 _cleanTree_MH_JFC = new wxSlider( panel, -1, 400 , 0, 1000 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
421 int tmp_sensibility= (int)(_sensibility_JF*100.0);
422 _sl_sensibility_JF->SetValue( tmp_sensibility );
425 _opacity_OrigVol ->SetSize(250,20); // Original Volume
426 _isoValue ->SetSize(250,20);
427 _opacity_Res1VolJF ->SetSize(250,20); // Result 1 Volume JF
428 _opacity_Res2VolJF ->SetSize(250,20); // Result 2 Volume JF
429 _branchLevel ->SetSize(250,20);
430 _opacity_ResVolMHJF ->SetSize(250,20); // Result Volume MH+JFC
433 wxButton *btnExtractTree1_JF = new wxButton(panel,-1,_T("Extract Tree 1 JF"));
434 wxButton *btnEraseTree1_JF = new wxButton(panel,-1,_T("Erase Tree 1 JF"));
437 wxButton *btnExtractTree2_JF = new wxButton(panel,-1,_T("Extract Tree 2 JF"));
438 wxButton *btnEraseTree2_JF = new wxButton(panel,-1,_T("Erase Tree 2 JF"));
440 //Extract Tree MH + JF
441 wxButton *btnExtractTree_MH_JFC = new wxButton(panel,-1,_T("Extract Tree MH + JFC"));
442 wxButton *btnEraseTree_MH_JFC = new wxButton(panel,-1,_T("Erase Tree MH + JFC"));
445 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
446 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
447 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
448 sizer->Add(new wxStaticText(panel,-1,_T("Isovalue - Original Volume")));
449 sizer->Add(_isoValue);
450 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Original Volume")));
451 sizer->Add(_opacity_OrigVol);
453 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
454 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
455 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Juan Francisco Module 1 - - - ")));
456 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
457 sizer->Add(btnExtractTree1_JF);
458 sizer->Add(btnEraseTree1_JF);
459 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
460 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
461 sizer->Add(_opacity_Res1VolJF);
463 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
464 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
465 sizer->Add(new wxStaticText(panel,-1,_T(" - - - Juan Francisco Module 2 - - - ")));
466 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
467 sizer->Add(new wxStaticText(panel,-1,_T(" % Sensibility")));
468 sizer->Add(_sl_sensibility_JF);
469 sizer->Add(btnExtractTree2_JF);
470 sizer->Add(btnEraseTree2_JF);
471 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
472 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
473 sizer->Add(_opacity_Res2VolJF);
476 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
477 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
478 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
479 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
480 sizer->Add(new wxStaticText(panel,-1,_T(" - - - MH + JFC - - - ")));
481 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
482 sizer->Add(btnExtractTree_MH_JFC);
483 sizer->Add(btnEraseTree_MH_JFC);
484 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
485 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
486 sizer->Add(new wxStaticText(panel,-1,_T("Branch Level MH+JFC")));
487 sizer->Add(_branchLevel);
488 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
489 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume MH+JFC")));
490 sizer->Add(_opacity_ResVolMHJF);
491 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
492 sizer->Add(new wxStaticText(panel,-1,_T("IsoValue - Result Volume MH+JFC")));
493 sizer->Add(_isoValue_MH_JFC);
494 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
495 sizer->Add(new wxStaticText(panel,-1,_T("signal level (Clean Tree)")));
496 sizer->Add(_cleanTree_MH_JFC);
498 panel->SetSizer(sizer);
499 panel->SetAutoLayout(true);
500 panel->SetSize(400,400);
502 Connect(_opacity_OrigVol->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_OrigVol );
503 Connect(_isoValue->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnIsoValue );
504 Connect(_opacity_Res1VolJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_Res1VolJF );
505 Connect(_opacity_Res2VolJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_Res2VolJF );
506 Connect(_sl_sensibility_JF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnSensibility );
508 Connect(btnExtractTree1_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree1_JF );
509 Connect(btnEraseTree1_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree1_JF );
510 Connect(btnExtractTree2_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree2_JF );
511 Connect(btnEraseTree2_JF->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree2_JF );
513 Connect(btnExtractTree_MH_JFC->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnExtractTree_MH_JFC);
514 Connect(btnEraseTree_MH_JFC->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBtnEraseTree_MH_JFC );
515 Connect(_branchLevel->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnBranchLevel );
516 Connect(_opacity_ResVolMHJF->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnOpacity_ResVolMHJF );
517 Connect(_isoValue_MH_JFC->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnIsoValue_MH_JFC );
518 Connect(_cleanTree_MH_JFC->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget_2::OnCleanTree_MH_JFC );
522 //------------------------------------------------------------------------
523 void wxEmptyPanelWidget_2::Refresh()
525 _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->Render();
527 //------------------------------------------------------------------------
528 void wxEmptyPanelWidget_2::ConfigureVTK()
531 // _imageviewer3D->Configure();
532 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
533 double opacity_OrigVol = ((double)(_opacity_OrigVol->GetValue()))/100;
536 // Visualisation - original volume
538 imagedata->GetScalarRange( range );
539 isoValue=range[1] / 8;
541 _mCubes = vtkMarchingCubes::New( );
542 _mCubes->SetInput( imagedata );
543 _mCubes->SetValue( 0, isoValue );
545 vtkStripper *stripper = vtkStripper::New();
546 stripper->SetInput( _mCubes->GetOutput( ) );
548 _surfMapper = vtkPolyDataMapper::New( );
549 _surfMapper->SetInput( stripper->GetOutput() );
550 _surfMapper->ScalarVisibilityOff( );
553 _surfActor = vtkActor::New( );
554 _surfActor->SetMapper( _surfMapper );
555 _surfActor->PickableOff( );
556 _surfActor->GetProperty( )->SetColor( 0, 0, 0.8 );
557 _surfActor->GetProperty( )->SetOpacity( opacity_OrigVol );
560 _isoValue->SetRange( (int)(range[0]), (int)(range[1]) );
561 _isoValue->SetValue( (int)isoValue );
564 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
565 ren->AddActor(_surfActor);
568 _maracasSurfaceWidget->ShowMARACASData( _mar );
572 //------------------------------------------------------------------------
573 void wxEmptyPanelWidget_2::ResetTree1_JF()
576 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
578 ren->RemoveActor(_1_isoActorMC6);
581 ren->RemoveActor(_1_stripfinal);
585 if (_1_prgov ) { _1_prgov -> Delete(); }
586 if (_1_mapfinal ) { _1_mapfinal -> Delete(); }
587 if (_1_stripfinal ) { _1_stripfinal -> Delete(); }
588 if (_1_isoMapperMC6 ) { _1_isoMapperMC6 -> Delete(); }
589 if (_1_isoActorMC6 ) { _1_isoActorMC6 -> Delete(); }
590 if (_1_isoMC6 ) { _1_isoMC6 -> Delete(); }
595 _1_stripfinal = NULL;
596 _1_isoMapperMC6 = NULL;
597 _1_isoActorMC6 = NULL;
601 //------------------------------------------------------------------------
602 void wxEmptyPanelWidget_2::ResetTree2_JF()
605 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
607 ren->RemoveActor(_2_isoActorMC6);
610 ren->RemoveActor(_2_stripfinal);
614 if (_2_prgov ) { _2_prgov -> Delete(); }
615 if (_2_mapfinal ) { _2_mapfinal -> Delete(); }
616 if (_2_stripfinal ) { _2_stripfinal -> Delete(); }
617 if (_2_isoMapperMC6 ) { _2_isoMapperMC6 -> Delete(); }
618 if (_2_isoActorMC6 ) { _2_isoActorMC6 -> Delete(); }
619 if (_2_isoMC6 ) { _2_isoMC6 -> Delete(); }
624 _2_stripfinal = NULL;
625 _2_isoMapperMC6 = NULL;
626 _2_isoActorMC6 = NULL;
632 //------------------------------------------------------------------------
633 void wxEmptyPanelWidget_2::ExtractTree1_JF(int x, int y, int z)
635 double opacity_Res1VolJF = ((double)_opacity_Res1VolJF->GetValue())/100;
636 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
638 double puntoactualprov[3];
642 puntoactualprov[0]=x;
643 puntoactualprov[1]=y;
644 puntoactualprov[2]=z;
646 imagedata->GetSpacing(espprin);
647 imagedata->GetExtent(extprin);
649 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
650 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
651 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
653 // Juan Francisco Carrillo Filter
654 _1_prgov= axisExtractor::New();
655 _1_prgov->SetHumbral(0.45);
656 _1_prgov->SetInput(imagedata);
657 _1_prgov->SetPoint(puntoactualprov);
660 // Visualisation - result vascular tree
661 _1_mapfinal = vtkPolyDataMapper::New();
662 _1_mapfinal->SetInput(_1_prgov->GetOutput());
664 _1_stripfinal = vtkActor::New();
665 _1_stripfinal->SetMapper(_1_mapfinal);
666 _1_stripfinal->GetProperty()->SetColor(1, 1, 1);
667 _1_stripfinal->GetProperty()->SetLineWidth(2);
668 _1_stripfinal->GetProperty()->BackfaceCullingOff();
670 // Visualisation - result volume
671 vtkImageData *imageOut = _1_prgov->GetVolumen();
674 _1_isoMC6 = vtkMarchingCubes::New();
675 _1_isoMC6->SetInput(imageOut);
676 _1_isoMC6->SetValue(0, 1);
679 _1_isoMapperMC6 = vtkPolyDataMapper::New();
680 _1_isoMapperMC6->SetInput(_1_isoMC6->GetOutput());
681 _1_isoMapperMC6->ScalarVisibilityOff();
682 _1_isoMapperMC6->ImmediateModeRenderingOn();
684 _1_isoActorMC6 = vtkActor::New();
685 _1_isoActorMC6->SetMapper(_1_isoMapperMC6);
686 _1_isoActorMC6->GetProperty()->SetColor( 0, 1, 0);
687 _1_isoActorMC6->GetProperty()->SetOpacity( opacity_Res1VolJF );
691 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
692 ren->AddActor(_1_isoActorMC6);
693 ren->AddActor(_1_stripfinal);
697 //------------------------------------------------------------------------
698 void wxEmptyPanelWidget_2::ExtractTree2_JF(int x, int y, int z)
700 double opacity_Res2VolJF = ((double)_opacity_Res2VolJF->GetValue())/100;
701 vtkImageData *imagedata = _mar->_experiment->getDynData( )->getVolume( )->castVtk();
703 double puntoactualprov[3];
707 puntoactualprov[0]=x;
708 puntoactualprov[1]=y;
709 puntoactualprov[2]=z;
711 imagedata->GetSpacing(espprin);
712 imagedata->GetExtent(extprin);
714 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
715 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
716 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
718 _2_prgov= axisExtractor02::New();
719 _2_prgov->SetParam(1);
720 _2_prgov->SetParam2(1);
721 _2_prgov->SetParam3(_sensibility_JF);
722 _2_prgov->SetMaxant(20);
723 _2_prgov->SetMinant(5);
724 _2_prgov->SetInput(imagedata);
725 _2_prgov->SetPoint(puntoactualprov);
728 // Visualisation - result vascular tree
729 _2_mapfinal = vtkPolyDataMapper::New();
730 _2_mapfinal->SetInput(_2_prgov->GetOutput());
732 _2_stripfinal = vtkActor::New();
733 _2_stripfinal->SetMapper(_2_mapfinal);
734 _2_stripfinal->GetProperty()->SetColor(0.3, 0.3, 0.3);
735 _2_stripfinal->GetProperty()->SetLineWidth(2);
736 _2_stripfinal->GetProperty()->BackfaceCullingOff();
738 // Visualisation - result volume
739 vtkImageData *imageOut = _2_prgov->GetVolumen();
742 _2_isoMC6 = vtkMarchingCubes::New();
743 _2_isoMC6->SetInput(imageOut);
744 _2_isoMC6->SetValue(0, 1);
747 _2_isoMapperMC6 = vtkPolyDataMapper::New();
748 _2_isoMapperMC6->SetInput(_2_isoMC6->GetOutput());
749 _2_isoMapperMC6->ScalarVisibilityOff();
750 _2_isoMapperMC6->ImmediateModeRenderingOn();
752 _2_isoActorMC6 = vtkActor::New();
753 _2_isoActorMC6->SetMapper(_2_isoMapperMC6);
754 _2_isoActorMC6->GetProperty()->SetColor( 1, 1, 0);
755 _2_isoActorMC6->GetProperty()->SetOpacity( opacity_Res2VolJF );
758 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
759 ren->AddActor(_2_isoActorMC6);
760 ren->AddActor(_2_stripfinal);
763 //------------------------------------------------------------------------
764 void wxEmptyPanelWidget_2::OnOpacity_OrigVol(wxScrollEvent& event)
766 double value = ((double)_opacity_OrigVol->GetValue())/100;
767 _surfActor->GetProperty( )->SetOpacity( value );
770 //------------------------------------------------------------------------
771 void wxEmptyPanelWidget_2::OnOpacity_Res1VolJF(wxScrollEvent& event)
773 if (_1_isoActorMC6!=NULL){
774 double value = ((double)_opacity_Res1VolJF->GetValue())/100;
775 _1_isoActorMC6->GetProperty( )->SetOpacity( value );
779 //------------------------------------------------------------------------
780 void wxEmptyPanelWidget_2::OnOpacity_Res2VolJF(wxScrollEvent& event)
782 if (_2_isoActorMC6!=NULL){
783 double value = ((double)_opacity_Res2VolJF->GetValue())/100;
784 _2_isoActorMC6->GetProperty( )->SetOpacity( value );
789 //------------------------------------------------------------------------
790 void wxEmptyPanelWidget_2::OnIsoValue(wxScrollEvent& event)
793 _mCubes->SetValue(0, _isoValue->GetValue());
796 //------------------------------------------------------------------------
797 void wxEmptyPanelWidget_2::OnBtnExtractTree1_JF(wxCommandEvent& event)
801 vtk3DSurfaceWidget *world3D = _maracasSurfaceWidget->GetVtk3DSurfaceWidget();
802 if( world3D->GetInitialSphere() ){
804 world3D->GetSphereCenter( point );
805 ExtractTree1_JF((int)point[0],(int)point[1],(int)point[2]);
810 //------------------------------------------------------------------------
811 void wxEmptyPanelWidget_2::OnBtnExtractTree2_JF(wxCommandEvent& event)
815 vtk3DSurfaceWidget *world3D = _maracasSurfaceWidget->GetVtk3DSurfaceWidget();
816 if( world3D->GetInitialSphere() ){
818 world3D->GetSphereCenter( point );
819 ExtractTree2_JF((int)point[0],(int)point[1],(int)point[2]);
824 //------------------------------------------------------------------------
825 void wxEmptyPanelWidget_2::OnBtnEraseTree1_JF(wxCommandEvent& event)
830 //------------------------------------------------------------------------
831 void wxEmptyPanelWidget_2::OnBtnEraseTree2_JF(wxCommandEvent& event)
837 //------------------------------------------------------------------------
838 void wxEmptyPanelWidget_2::PaintVascularTree_MH_JFC(marExperiment * newExperiment)
840 vtkActor *branchActor;
841 vtkPolyData *axisVtk;
842 vtkPolyDataMapper *branchMapper;
843 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
845 int i,maxAxis=newExperiment->getNumberOfAxes();
846 for (i=0;i<maxAxis;i++){
847 newExperiment->setAxis(i);
848 marAxis *maraxis =newExperiment->getAxis( );
850 axisVtk = maraxis->Draw();
851 branchMapper = vtkPolyDataMapper::New( );
852 branchMapper->SetInput( axisVtk );
853 branchMapper->Update();
854 branchActor = vtkActor::New( );
855 branchActor->SetMapper( branchMapper );
856 branchActor->GetProperty()->SetColor( 1, 1, 1 );
857 if (i== 0) { branchActor->GetProperty()->SetColor( 0 , 0 , 0.3 ); }
858 if (i== 1) { branchActor->GetProperty()->SetColor( 0 , 0.3 , 0.3 ); }
859 if (i== 2) { branchActor->GetProperty()->SetColor( 0.3, 0.3 , 0.3 ); }
860 if (i== 3) { branchActor->GetProperty()->SetColor( 0.0, 0.0 , 0.6 ); }
861 if (i== 4) { branchActor->GetProperty()->SetColor( 0.0, 0.6 , 0.6 ); }
862 if (i== 5) { branchActor->GetProperty()->SetColor( 0.6, 0.6 , 0.6 ); }
863 if (i== 7) { branchActor->GetProperty()->SetColor( 0.0, 0.0 , 0.9 ); }
864 if (i== 8) { branchActor->GetProperty()->SetColor( 0.0, 0.9 , 0.9 ); }
865 if (i== 9) { branchActor->GetProperty()->SetColor( 0.9, 0.9 , 0.9 ); }
866 if (i==10) { branchActor->GetProperty()->SetColor( 0.9, 0.0 , 0.0 ); }
867 if (i==11) { branchActor->GetProperty()->SetColor( 0.6, 0.0 , 0.0 ); }
868 if (i==12) { branchActor->GetProperty()->SetColor( 0.3, 0.0 , 0.0 ); }
869 if (i==13) { branchActor->GetProperty()->SetColor( 0.6, 0.6 , 0.0 ); }
870 if (i==14) { branchActor->GetProperty()->SetColor( 0.3, 0.3 , 0.0 ); }
871 if (i==15) { branchActor->GetProperty()->SetColor( 0.9, 0.9 , 0.0 ); }
872 branchActor->GetProperty()->SetLineWidth( 2.0 );
873 ren->AddActor( branchActor );
875 _lstAxisVtk.push_back( axisVtk );
876 _lstBranchActor.push_back( branchActor );
877 _lstBranchMapper.push_back( branchMapper );
883 //------------------------------------------------------------------------
884 void wxEmptyPanelWidget_2::PaintVascularVolume_MH_JFC(vtkImageData * image)
887 // Visualisation - result volume
890 _imageThresholdMC1=vtkImageThreshold::New();
891 _imageThresholdMC1->SetInput(image);
892 _imageThresholdMC1->ThresholdBetween(0,100);
893 _imageThresholdMC1->SetOutValue ( 0 );
894 _imageThresholdMC1->Update();
896 _isoMC1 = vtkMarchingCubes::New();
897 _isoMC1->SetInput(_imageThresholdMC1->GetOutput() );
898 _isoMC1->SetValue(0, 1);
901 _isoMapperMC1 = vtkPolyDataMapper::New();
902 _isoMapperMC1->SetInput(_isoMC1->GetOutput());
903 _isoMapperMC1->ScalarVisibilityOff();
904 _isoMapperMC1->ImmediateModeRenderingOn();
905 _isoMapperMC1->Update();
907 _isoActorMC1 = vtkActor::New();
908 _isoActorMC1->SetMapper(_isoMapperMC1);
909 _isoActorMC1->GetProperty()->SetColor( 1, 0, 0);
910 _isoActorMC1->GetProperty()->SetOpacity( 0.4 );
913 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
914 ren->AddActor(_isoActorMC1);
917 //------------------------------------------------------------------------
918 void wxEmptyPanelWidget_2::WriteSignals(marExperiment *newExperiment){
923 int maxAxis = newExperiment->getNumberOfAxes();
926 ff=fopen("c:/Temp/MaracasTEMP.TXT", "w");
930 for (i=0;i<maxAxis;i++){
931 newExperiment->setAxis(i);
932 marAxis *maraxis =newExperiment->getAxis( );
934 if ( j < maraxis->getNumberOfControlPoints() ){
936 value= (int)(maraxis->getSignal((uint32_t)j) );
937 fprintf(ff,"%d\t", value );
950 //------------------------------------------------------------------------
951 void wxEmptyPanelWidget_2::OnBtnExtractTree_MH_JFC(wxCommandEvent& event)
953 if ((_lstBranchActor.size()==0)
955 (_maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetInitialSphere() ) )
962 _mar->_experiment->getVOI(voiA);
964 voiB[1]=voiA[1]-voiA[0];
966 voiB[3]=voiA[3]-voiA[2];
968 voiB[5]=voiA[5]-voiA[4];
969 marExperiment *newExperiment = new marExperiment( _mar->_experiment->getParameters() );
970 newExperiment->setVOI( voiB );
971 newExperiment->initExperiment( _mar->_experiment->getDynData( )->getVolume() );
975 _mar->_experiment->getDynData( )->getVolume( )->castVtk()->GetExtent( extent );
976 _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetSphereCenter( point );
977 int x = (int)point[0] - extent[0];
978 int y = (int)point[1] - extent[2];
979 int z = (int)point[2] - extent[4];
980 newExperiment->setStartPoint( x, y, z);
982 // Vascular tree extraction
983 _treeExtraction = TreeExtraction_MH_JFC::New();
984 _treeExtraction->SetInput(newExperiment);
985 _treeExtraction->SetCleanTreeLevel( _cleanTree_MH_JFC->GetValue() );
986 _treeExtraction->SetBranchLevel( _branchLevel->GetValue() );
987 _treeExtraction->Update();
989 //Paint Vascular Tree
990 PaintVascularTree_MH_JFC(newExperiment);
991 //Paint Vascular Volume
992 PaintVascularVolume_MH_JFC( _treeExtraction->GetVolume() );
995 WriteSignals(newExperiment);
998 delete newExperiment;
1001 //------------------------------------------------------------------------
1002 void wxEmptyPanelWidget_2::OnBtnEraseTree_MH_JFC(wxCommandEvent& event)
1008 //------------------------------------------------------------------------
1009 void wxEmptyPanelWidget_2::ResetTree_MH_JFC()
1012 vtkRenderer *ren = _maracasSurfaceWidget->GetVtk3DSurfaceWidget()->GetRenderer();
1014 size=_lstAxisVtk.size();
1015 size=_lstBranchMapper.size();
1016 size=_lstBranchActor.size();
1017 for (i=0;i<size;i++){
1018 if (_lstBranchActor[i]!=NULL){
1019 ren->RemoveActor( _lstBranchActor[i] );
1022 for (i=0;i<size;i++){
1024 if (_lstAxisVtk[i] != NULL ) { _lstAxisVtk[i] -> Delete(); }
1025 // if (_lstBranchMapper[i] != NULL ) { _lstBranchMapper[i] -> Delete(); }
1026 if (_lstBranchActor[i] != NULL ) { _lstBranchActor[i] -> Delete(); }
1028 _lstAxisVtk[i] = NULL;
1029 _lstBranchActor[i] = NULL;
1030 _lstBranchMapper[i] = NULL;
1032 _lstAxisVtk.clear();
1033 _lstBranchActor.clear();
1034 _lstBranchMapper.clear();
1038 ren->RemoveActor(_isoActorMC1);
1042 if (_isoMapperMC1 ) { _isoMapperMC1 -> Delete(); }
1043 if (_isoActorMC1 ) { _isoActorMC1 -> Delete(); }
1044 if (_isoMC1 ) { _isoMC1 -> Delete(); }
1045 if (_imageThresholdMC1 ) { _imageThresholdMC1 -> Delete(); }
1049 _isoMapperMC1 = NULL;
1050 _isoActorMC1 = NULL;
1052 _imageThresholdMC1 = NULL;
1055 // if (_treeExtraction ) { _treeExtraction -> Delete(); } // EED
1056 // _treeExtraction=NULL;
1060 //------------------------------------------------------------------------
1061 void wxEmptyPanelWidget_2::OnOpacity_ResVolMHJF(wxScrollEvent& event)
1063 if (_isoActorMC1!=NULL){
1064 double value = ((double)_opacity_ResVolMHJF->GetValue())/100;
1065 _isoActorMC1->GetProperty( )->SetOpacity( value );
1069 //------------------------------------------------------------------------
1070 void wxEmptyPanelWidget_2::OnBranchLevel(wxScrollEvent& event)
1074 //------------------------------------------------------------------------
1075 void wxEmptyPanelWidget_2::OnIsoValue_MH_JFC(wxScrollEvent& event)
1077 if (_imageThresholdMC1!=NULL){
1079 double threshold = _isoValue_MH_JFC->GetValue();
1081 _imageThresholdMC1->ThresholdBetween(threshold, threshold );
1083 _imageThresholdMC1->ThresholdBetween(0, 1000 );
1088 //------------------------------------------------------------------------
1089 void wxEmptyPanelWidget_2::OnCleanTree_MH_JFC(wxScrollEvent& event)
1093 //------------------------------------------------------------------------
1094 void wxEmptyPanelWidget_2::OnSensibility(wxScrollEvent& event)
1096 _sensibility_JF = (double)(_sl_sensibility_JF->GetValue())/100;