]> Creatis software - creaVtk.git/commitdiff
#3537 Bifurcations In Skeletonization vtk9itk5wx3-macos
authoreduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Sun, 1 Mar 2026 13:56:43 +0000 (14:56 +0100)
committereduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Sun, 1 Mar 2026 13:56:43 +0000 (14:56 +0100)
bbtk_creaVtk_PKG/.DS_Store
bbtk_creaVtk_PKG/src/bbcreaVtkBifurcationsInSkeletonization.cxx

index 9e9655d8fd9a5157af96d9e6d516da62ad3f1647..8fd3482ce295b13412c4a47a718c628794e1ca1a 100644 (file)
Binary files a/bbtk_creaVtk_PKG/.DS_Store and b/bbtk_creaVtk_PKG/.DS_Store differ
index 477f9e31546a33b7ede1500b858d157aaddf756b..2a67de153de681865e52a081490a353236c188d4 100644 (file)
@@ -15,9 +15,17 @@ BBTK_BLACK_BOX_IMPLEMENTATION(BifurcationsInSkeletonization,bbtk::AtomicBlackBox
 void BifurcationsInSkeletonization::Process()
 {
     printf("EED BifurcationsInSkeletonization::Process  start  \n");
-    std::vector<int> tmpLstX=bbGetInputLstX();
-    std::vector<int> tmpLstY=bbGetInputLstY();
-    std::vector<int> tmpLstZ=bbGetInputLstZ();
+    
+    // ---- 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              ----
+
+    
+    std::vector<int> tmpLstX = bbGetInputLstX();
+    std::vector<int> tmpLstY = bbGetInputLstY();
+    std::vector<int> tmpLstZ = bbGetInputLstZ();
     std::vector<int> leavesLstX;
     std::vector<int> leavesLstY;
     std::vector<int> leavesLstZ;
@@ -37,9 +45,14 @@ void BifurcationsInSkeletonization::Process()
         tmpImage->DeepCopy( bbGetInputIn() );
         int px,py,pz, i,j,k,  tx,ty,tz,  ii,size;
         // Find all leaves
-        long int    w=1;
-        int         ww;
+        long int    w;
+        long int    ww;
         bool        ok;
+
+        
+        // ---- Step 1.1 Find start point of the segments-----------
+        
+        w=2;
         while (tmpLstX.size()!=0)
         {
             px  = tmpLstX[0];
@@ -50,7 +63,7 @@ void BifurcationsInSkeletonization::Process()
             tmpLstZ.erase( tmpLstZ.begin() );
             if (tmpImage->GetScalarComponentAsDouble(px,py,pz,0)<=1)
             {
-                w   = w + 1;
+//                w   = w + 1;
                 tmpImage->SetScalarComponentFromDouble( px,py,pz,0, w );
                 ok=false;
                 for ( i=px-1 ; i<=px+1 ; i++)
@@ -63,15 +76,15 @@ void BifurcationsInSkeletonization::Process()
                             {
                                 if ((i>=0) &&(j>=0) &&(k>=0) &&(i<dim[0]) &&(j<dim[1]) &&(k<dim[2]) )
                                 {
-                                    if (1==tmpImage->GetScalarComponentAsDouble(i,j,k,0))
+                                    if ( 1 == tmpImage->GetScalarComponentAsDouble(i,j,k,0))
                                     {
                                         ok=true;
-//                                        tmpLstX.push_back(i);
-//                                        tmpLstY.push_back(j);
-//                                        tmpLstZ.push_back(k);
-                                                                                tmpLstX.insert(tmpLstX.begin() , i);
-                                                                                tmpLstY.insert(tmpLstY.begin() , j);
-                                                                                tmpLstZ.insert(tmpLstZ.begin() , k);
+//                                      tmpLstX.push_back(i);
+//                                      tmpLstY.push_back(j);
+//                                      tmpLstZ.push_back(k);
+                                        tmpLstX.insert(tmpLstX.begin() , i);
+                                        tmpLstY.insert(tmpLstY.begin() , j);
+                                        tmpLstZ.insert(tmpLstZ.begin() , k);
                                     } // if graylevel == 1
                                 } // if ijk>0  &&  ijk<dim
                             } // if px,py,pz != i,j,k
@@ -84,11 +97,11 @@ void BifurcationsInSkeletonization::Process()
                     leavesLstY.push_back(py);
                     leavesLstZ.push_back(pz);
                 } //
-            }// if value > 1
+            }// if value <= 1
         } // while tmpLstX.size()!=0
         
+        // ---- step 1.2  Cleaning repeated start points----
         size = leavesLstX.size();
-        // Cleaning repeated leaves
         for (i=size-1; i>=0; i--)
         {
             for (ii=size-1; ii>i; ii--)
@@ -103,9 +116,185 @@ void BifurcationsInSkeletonization::Process()
             }// for ii
         } // for i
 
+        
+        
+        // ---- Step 2.1 Find leaves -----------
+        tmpLstX = leavesLstX;
+        tmpLstY = leavesLstY;
+        tmpLstZ = leavesLstZ;
+        leavesLstX.clear();
+        leavesLstY.clear();
+        leavesLstZ.clear();
+        w=2;
+        while (tmpLstX.size()!=0)
+        {
+            px  = tmpLstX[0];
+            py  = tmpLstY[0];
+            pz  = tmpLstZ[0];
+            tmpLstX.erase( tmpLstX.begin() );
+            tmpLstY.erase( tmpLstY.begin() );
+            tmpLstZ.erase( tmpLstZ.begin() );
+            if (tmpImage->GetScalarComponentAsDouble(px,py,pz,0)<=2)
+            {
+                w   = w + 1;
+                tmpImage->SetScalarComponentFromDouble( px,py,pz,0, w );
+                ok=false;
+                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)))
+                            {
+                                if ((i>=0) &&(j>=0) &&(k>=0) &&(i<dim[0]) &&(j<dim[1]) &&(k<dim[2]) )
+                                {
+                                    if ( 2 == tmpImage->GetScalarComponentAsDouble(i,j,k,0))
+                                    {
+                                        ok=true;
+//                                      tmpLstX.push_back(i);
+//                                      tmpLstY.push_back(j);
+//                                      tmpLstZ.push_back(k);
+                                        tmpLstX.insert(tmpLstX.begin() , i);
+                                        tmpLstY.insert(tmpLstY.begin() , j);
+                                        tmpLstZ.insert(tmpLstZ.begin() , k);
+                                    } // if graylevel == 2
+                                } // if ijk>0  &&  ijk<dim
+                            } // if px,py,pz != i,j,k
+                        } // for k
+                    } // for j
+                } // for i
+                if (ok==false)
+                {
+                    leavesLstX.push_back(px);
+                    leavesLstY.push_back(py);
+                    leavesLstZ.push_back(pz);
+                } //
+            }// if value < 2
+        } // while tmpLstX.size()!=0
+        
+        // ---- Step 2.2 Cleaning repeated leaves----
+        size = leavesLstX.size();
+        for (i=size-1; i>=0; i--)
+        {
+            for (ii=size-1; ii>i; ii--)
+            {
+                if ( (leavesLstX[i]==leavesLstX[ii]) && (leavesLstY[i]==leavesLstY[ii]) && (leavesLstZ[i]==leavesLstZ[ii]) )
+                {
+                    leavesLstX.erase( leavesLstX.begin()+ii );
+                    leavesLstY.erase( leavesLstY.begin()+ii );
+                    leavesLstZ.erase( leavesLstZ.begin()+ii );
+                    size--;
+                } // if iPoint == iiPoint
+            }// for ii
+        } // for i
+
+        
+        // --- Step 3.0  Find all bifurcations ---
         ww=-1;
-        double gl;
-        // Find all bifurcations
+        double gl=-1;
+        while (leavesLstX.size()!=0)
+        {
+            tmpLstX.clear();
+            tmpLstY.clear();
+            tmpLstZ.clear();
+            tmpLstX.push_back( leavesLstX[0] );
+            tmpLstY.push_back( leavesLstY[0] );
+            tmpLstZ.push_back( leavesLstZ[0] );
+
+            leavesLstX.erase( leavesLstX.begin() );
+            leavesLstY.erase( leavesLstY.begin() );
+            leavesLstZ.erase( leavesLstZ.begin() );
+            
+            ok  = false;
+            while (( tmpLstX.size()!=0 )  && (ok==false))
+            {
+                px = tmpLstX[0];
+                py = tmpLstY[0];
+                pz = tmpLstZ[0];
+                tmpLstX.erase( tmpLstX.begin() );
+                tmpLstY.erase( tmpLstY.begin() );
+                tmpLstZ.erase( tmpLstZ.begin() );
+
+                w   = tmpImage->GetScalarComponentAsDouble(px,py,pz,0);
+//                ok  = false;
+//                tmpImage->SetScalarComponentFromDouble( px,py,pz,0, 0 );
+              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) )
+                                {
+                                    tmpLstX.push_back( i );
+                                    tmpLstY.push_back( j );
+                                    tmpLstZ.push_back( k );
+//                                    tx  = i;
+//                                    ty  = j;
+//                                    tz  = k;
+//                                    ok  = true;
+                                } // if graylevel == w
+                                if ((gl>ww) && (gl<0))
+                                {
+                                    ok = true;
+                                    tx = i;
+                                    ty = j;
+                                    tz = k;
+                                }
+                                
+                            } // if px,py,pz != i,j,k
+                        } // for k
+                    } // for j
+                } // for i
+//                px = tx;
+//                py = ty;
+//                pz = tz;
+            } // while tmpLstX.size   && ok==true
+            
+            ww = ww -1;
+//            ok = false;
+//            w  = tmpImage->GetScalarComponentAsDouble(px,py,pz,0);
+//            for ( i=px-2 ; i<=px+2 ; i++ )
+//            {
+//                for ( j=py-2 ; j<=py+2 ; j++ )
+//                {
+//                    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( tx );
+                outLstY.push_back( ty );
+                outLstZ.push_back( tz );
+            }
+            
+        } // while leavesLstX.size()!=0
+        
+        
+        /*
+        // --- Step 3.0  Find all bifurcations ---
+        ww=-1;
+        double gl=-1;
         while (leavesLstX.size()!=0)
         {
             px  = leavesLstX[0];
@@ -114,7 +303,7 @@ void BifurcationsInSkeletonization::Process()
             leavesLstX.erase( leavesLstX.begin() );
             leavesLstY.erase( leavesLstY.begin() );
             leavesLstZ.erase( leavesLstZ.begin() );
-            w   = tmpImage->GetScalarComponentAsDouble(px,py,pz,0);
+//            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) )
@@ -150,14 +339,48 @@ void BifurcationsInSkeletonization::Process()
             } // while graylevel!=1  && ok==true
             
             ww = ww -1;
-            outLstX.push_back( px );
-            outLstY.push_back( py );
-            outLstZ.push_back( pz );
+
+            ok = false;
+            w  = tmpImage->GetScalarComponentAsDouble(px,py,pz,0);
+            for ( i=px-2 ; i<=px+2 ; i++ )
+            {
+                for ( j=py-2 ; j<=py+2 ; j++ )
+                {
+                    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);
+         
+         */
+         bbSetOutputOutLstX(outLstX);
+         bbSetOutputOutLstY(outLstY);
+         bbSetOutputOutLstZ(outLstZ);
+                
+        //bbSetOutputOutLstX(leavesLstX);
+        //bbSetOutputOutLstY(leavesLstY);
+        //bbSetOutputOutLstZ(leavesLstZ);
+
         bbSetOutputOut(tmpImage);
     } else {
         bbSetOutputOutLstX(outLstX);