From 387ace8b7a3b41defe187e150d09e5ff40a02488 Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Tue, 17 Mar 2026 12:58:15 +0100 Subject: [PATCH] Clean code --- bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx | 30 ++++- ...bbcreaVtkBifurcationsInSkeletonization.cxx | 117 ++++-------------- .../src/bbcreaVtkImageConnectivityFilter.cxx | 4 - 3 files changed, 48 insertions(+), 103 deletions(-) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx index a730292..3869759 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx @@ -23,6 +23,7 @@ void BestPoint::ProcessPoint(int x,int y, int z, std::vector *pOutPoint , d int dimY; int dimZ; double value; + double DistBack; double dx,dy,dz; double M1,M2,D2,G; double FG,FGback; @@ -63,27 +64,46 @@ void BestPoint::ProcessPoint(int x,int y, int z, std::vector *pOutPoint , d { ok = false; value=bbGetInputIn()->GetScalarComponentAsDouble(i,j,k,0); + dx = x - i; + dy = y - j; + dz = z - k; + D2 = dx*dx + dy*dy + dz*dz; + if (bbGetInputType()==1) // max { if ( value > *pOutputValue) { - ok=true; + ok = true; + DistBack= D2; } // if max + if ( value == *pOutputValue) + { + if (D2 tmpLstX = bbGetInputLstX(); std::vector tmpLstY = bbGetInputLstY(); std::vector tmpLstZ = bbGetInputLstZ(); @@ -49,9 +48,7 @@ void BifurcationsInSkeletonization::Process() long int ww; bool ok; - // ---- Step 1.1 Find start point of the segments----------- - w=2; while (tmpLstX.size()!=0) { @@ -117,7 +114,6 @@ void BifurcationsInSkeletonization::Process() } // for i - // ---- Step 2.1 Find leaves ----------- tmpLstX = leavesLstX; tmpLstY = leavesLstY; @@ -289,93 +285,26 @@ void BifurcationsInSkeletonization::Process() } // while leavesLstX.size()!=0 - - - /* - // --- Step 3.0 Find all bifurcations --- - ww=-1; - double gl=-1; - while (leavesLstX.size()!=0) - { - px = leavesLstX[0]; - py = leavesLstY[0]; - pz = leavesLstZ[0]; - leavesLstX.erase( leavesLstX.begin() ); - leavesLstY.erase( leavesLstY.begin() ); - leavesLstZ.erase( leavesLstZ.begin() ); -// w = tmpImage->GetScalarComponentAsDouble(px,py,pz,0); -// printf("EED BifurcationsInSkeletonization::Process px,py,pz %d %d %d w=%ld ww=%d \n", px,py,pz, w,ww); - ok = true; - while ( (tmpImage->GetScalarComponentAsDouble(px,py,pz,0)!=1) && (ok==true) ) - { - // w = w - 1; - w = tmpImage->GetScalarComponentAsDouble(px,py,pz,0); - ok = false; - tmpImage->SetScalarComponentFromDouble( px,py,pz,0,ww); - for ( i=px-1 ; i<=px+1 ; i++ ) - { - for ( j=py-1 ; j<=py+1 ; j++ ) - { - for ( k=pz-1 ; k<=pz+1 ; k++ ) - { - if (!((px==i) && (py==j) && (pz==k))) - { - gl = tmpImage->GetScalarComponentAsDouble(i,j,k,0); - if ((gl0) ) - { - tx = i; - ty = j; - tz = k; - ok = true; -// printf("EED BifurcationsInSkeletonization::Process tx,ty,tz %d %d %d \n", tx,ty,tz); - } // if graylevel == w - } // if px,py,pz != i,j,k - } // for k - } // for j - } // for i - px = tx; - py = ty; - pz = tz; - } // while graylevel!=1 && ok==true - - ww = ww -1; - ok = false; - w = tmpImage->GetScalarComponentAsDouble(px,py,pz,0); - for ( i=px-2 ; i<=px+2 ; i++ ) + // ---- Step 3.1 Clean possible repeated bifurcations ---- + size = outLstX.size(); + for (i=size-1; i>=0; i--) + { + for (ii=size-1; ii>i; ii--) { - for ( j=py-2 ; j<=py+2 ; j++ ) + if ( (outLstX[i]==outLstX[ii]) && (outLstY[i]==outLstY[ii]) && (outLstZ[i]==outLstZ[ii]) ) { - for ( k=pz-2 ; k<=pz+2 ; k++ ) - { - if (!((px==i) && (py==j) && (pz==k))) - { - gl = tmpImage->GetScalarComponentAsDouble(i,j,k,0); - if (gl<0) - { - if ( abs( abs(gl)-abs(w) ) >= 2 ) - { - ok=true; - } // if abs (diff w) - } // if graylevel == w - } // if px,py,pz != i,j,k - } // for k - } // for j - } // for i - - if (ok==true) - { - outLstX.push_back( px ); - outLstY.push_back( py ); - outLstZ.push_back( pz ); - } - - } // while leavesLstX.size()!=0 - - */ - bbSetOutputOutLstX(outLstX); - bbSetOutputOutLstY(outLstY); - bbSetOutputOutLstZ(outLstZ); + outLstX.erase( outLstX.begin()+ii ); + outLstY.erase( outLstY.begin()+ii ); + outLstZ.erase( outLstZ.begin()+ii ); + size--; + } // if iPoint == iiPoint + }// for ii + } // for i + + bbSetOutputOutLstX(outLstX); + bbSetOutputOutLstY(outLstY); + bbSetOutputOutLstZ(outLstZ); //bbSetOutputOutLstX(leavesLstX); //bbSetOutputOutLstY(leavesLstY); diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx index c633b6f..c4ccc93 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx @@ -41,7 +41,6 @@ void ImageConnectivityFilter::Process() if (bbGetInputScalarRange().size()==2) { imgConnfilter->SetScalarRange( bbGetInputScalarRange()[0], bbGetInputScalarRange()[1] ); - printf("EED ImageConnectivityFilter Scalar Range %f %f \n", bbGetInputScalarRange()[0], bbGetInputScalarRange()[1]); } // Range if (bbGetInputExtractionMode()==0) // LargestRegion @@ -59,14 +58,12 @@ void ImageConnectivityFilter::Process() } // ExtractionMode 1 if (bbGetInputExtractionMode()==2) // SeedRegions { - printf("EED ImageConnectivityFilter 1\n"); imgConnfilter->SetExtractionModeToSeededRegions(); std::vector lstX = bbGetInputLstX(); std::vector lstY = bbGetInputLstY(); std::vector lstZ = bbGetInputLstZ(); if ( (lstX.size()>0) && (lstX.size()==lstY.size()) && (lstX.size()==lstZ.size()) ) { - printf("EED ImageConnectivityFilter 2\n"); int i,size = lstX.size(); double p[3]; vtkPoints *points = vtkPoints::New(); @@ -75,7 +72,6 @@ void ImageConnectivityFilter::Process() p[0] = lstX[i]; p[1] = lstY[i]; p[2] = lstZ[i]; - printf("EED ImageConnectivityFilter 3 %f %f %f\n", p[0], p[1], p[2] ); points->InsertNextPoint(p); } // for i vtkPolyData *seedData = vtkPolyData::New(); -- 2.53.0