]> Creatis software - creaVtk.git/commitdiff
Clean code vtk9itk5wx3-macos
authoreduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Tue, 17 Mar 2026 11:58:15 +0000 (12:58 +0100)
committereduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Tue, 17 Mar 2026 11:58:15 +0000 (12:58 +0100)
bbtk_creaVtk_PKG/src/bbcreaVtkBestPoint.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkBifurcationsInSkeletonization.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkImageConnectivityFilter.cxx

index a73029247f5f97fabb1296d7bb113c17c27ffa35..3869759d340ccbbe8dcb343e1cec7edd40dfa526 100644 (file)
@@ -23,6 +23,7 @@ void BestPoint::ProcessPoint(int x,int y, int z, std::vector<int> *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<int> *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<DistBack)
+                        {
+                            ok      = true;
+                            DistBack= D2;
+                        }
+                    }
                 } // if Type == 1
                 if (bbGetInputType()==2) // min
                 {
                     if ( value < *pOutputValue)
                     {
                         ok=true;
+                        DistBack= D2;
                     } // if max
+                    if ( value == *pOutputValue)
+                    {
+                        if (D2<DistBack)
+                        {
+                            ok      = true;
+                            DistBack= D2;
+                        }
+                    }
                 } // if Type == 2
                 if ((bbGetInputType()==3) ||  (bbGetInputType()==4) ) // FG
                 {
                     M2 = value;
-                    dx = x - i;
-                    dy = y - j;
-                    dz = z - k;
-                    D2 = dx*dx + dy*dy + dz*dz;
                     if (D2==0) {D2=0.000000001;}
                     FG = G * M1 * M2 / D2;
                 } // if Type == 3 or 4
index 2a67de153de681865e52a081490a353236c188d4..7f28e777f19fd7e3182e28a31e8d067c8dd2e41f 100644 (file)
@@ -15,14 +15,13 @@ BBTK_BLACK_BOX_IMPLEMENTATION(BifurcationsInSkeletonization,bbtk::AtomicBlackBox
 void BifurcationsInSkeletonization::Process()
 {
     printf("EED BifurcationsInSkeletonization::Process  start  \n");
-    
-    // ---- Step 1.1 Find start point of the segments   ----
-    // ---- step 1.2 Cleaning repeated start points     ----
-    // ---- Step 2.1 Find leaves                        ----
-    // ---- Step 2.2 Cleaning repeated leaves           ----
-    // ---- Step 3.0 Find all bifurcations              ----
+    // ---- Step 1.1 Find start point of the segments       ----
+    // ---- step 1.2 Cleaning repeated start points         ----
+    // ---- Step 2.1 Find leaves                            ----
+    // ---- Step 2.2 Cleaning repeated leaves               ----
+    // ---- Step 3.0 Find all bifurcations                  ----
+    // ---- Step 3.1 Clean possible repeated bifurcations   ----
 
-    
     std::vector<int> tmpLstX = bbGetInputLstX();
     std::vector<int> tmpLstY = bbGetInputLstY();
     std::vector<int> 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 ((gl<w) && (gl>0) )
-                                {
-                                    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);
index c633b6fd89d60d320fb6102c8907e6f32e8a769d..c4ccc93110782f5dab347a1da106117164f6aa11 100644 (file)
@@ -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<double> lstX = bbGetInputLstX();
             std::vector<double> lstY = bbGetInputLstY();
             std::vector<double> 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();