]> Creatis software - creaMaracasVisu.git/commitdiff
#3457 Clean Contour Interpolation 3D in Manual Contour Model
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Tue, 9 Feb 2021 06:55:10 +0000 (07:55 +0100)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Tue, 9 Feb 2021 06:55:10 +0000 (07:55 +0100)
bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx

index e1717ca87466bbbabbf5bc22628d5cf99ba9d442..b3e434fbb473e7cfa7c6127ccc2cbaea2856a4e0 100644 (file)
@@ -58,7 +58,7 @@ void ManualContourModel_Box::RedistributionPoints(    std::vector<double> *lstOutX,
        std::vector<double> lstRstX;
        std::vector<double> lstRstY;
        std::vector<double> lstRstZ;
-       int iLstIndexOut,sizeLstIndexOut=lstIndexsOut->size();
+       int iLstIndexOut,sizeLstIndexOut = lstIndexsOut->size();
        int ii, iGeneral=0;
        int size;
        for (iLstIndexOut=0;  iLstIndexOut<sizeLstIndexOut; iLstIndexOut++)
@@ -73,51 +73,50 @@ void ManualContourModel_Box::RedistributionPoints(  std::vector<double> *lstOutX,
                        double dist=0,dist2,distSeg,delta;
                        double dd,dx,dy,dz;
                        int i,k;
-                       for (i=iGeneral+1; i<iGeneral+size;i++)
+                       for ( i=iGeneral+1 ; i<iGeneral+size ; i++ )
                        {
-                               dx=(*lstOutX)[i]-(*lstOutX)[i-1];
-                               dy=(*lstOutY)[i]-(*lstOutY)[i-1];
-                               dz=(*lstOutZ)[i]-(*lstOutZ)[i-1];
-                               dist = dist+sqrt( dx*dx + dy*dy + dz*dz );
+                               dx      = (*lstOutX)[i]-(*lstOutX)[i-1];
+                               dy      = (*lstOutY)[i]-(*lstOutY)[i-1];
+                               dz      = (*lstOutZ)[i]-(*lstOutZ)[i-1];
+                               dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
                        } //for
-                       delta=dist/(size-1);
+                       delta = dist/(size-1);
                        lstRstX.push_back( (*lstOutX)[iGeneral] );
                        lstRstY.push_back( (*lstOutY)[iGeneral] );
                        lstRstZ.push_back( (*lstOutZ)[iGeneral] );
                        for (i=iGeneral+1; i<iGeneral+size;i++)
                        {
 //printf("EED ManualContourModel_Box::RedistributionPointsi=%d \n", i-iGeneral );
-
                                dist2 = 0;
                                for (k=iGeneral+1; k<iGeneral+size;k++)
                                {
-                                       dx=(*lstOutX)[k]-(*lstOutX)[k-1];
-                                       dy=(*lstOutY)[k]-(*lstOutY)[k-1];
-                                       dz=(*lstOutZ)[k]-(*lstOutZ)[k-1];
+                                       dx = (*lstOutX)[k]-(*lstOutX)[k-1];
+                                       dy = (*lstOutY)[k]-(*lstOutY)[k-1];
+                                       dz = (*lstOutZ)[k]-(*lstOutZ)[k-1];
                                        distSeg = sqrt( dx*dx + dy*dy + dz*dz );
-                                       ii=i-iGeneral;
-                                       if ( dist2+distSeg>=ii*delta) 
+                                       ii = i-iGeneral;
+                                       if ( dist2+distSeg >= ii*delta )
                                        {
                                                dd=(ii*delta-dist2)/distSeg;
                                                if (distSeg==0)
                                                {
-                                                       dd=0;
+                                                       dd = 0;
                                                } // if distSeg == 0
                                                lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
                                                lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
                                                lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
                                                k=iGeneral+size;
                                        } else {
-                                               if (k==iGeneral+size-1) 
+                                               if ( k==iGeneral+size-1 )
                                                {
-                                                       dd=1;
+                                                       dd = 1;
                                                        lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
                                                        lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
                                                        lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
 //                                                     printf("EED ManualContourModel_Box::RedistributionPoints iLstIndexOut=%d    i=%d k=%d  dist2+distSeg=%f    ii*delta=%f   dif=%f \n", iLstIndexOut,i-iGeneral, k-iGeneral, dist2+distSeg , ii*delta ,  (dist2+distSeg) - ii*delta);
                                                }
                                        }// if dist2 
-                                       dist2=dist2+distSeg;
+                                       dist2 = dist2+distSeg;
                                } // for k
                        } //for i   
                        if (lstRstX.size()!=size) 
@@ -217,8 +216,6 @@ void ManualContourModel_Box::ClockwisePoints(       std::vector<double> *lstInX,
                                backang=ang; 
                        } // for i 
 
-printf("EED ManualContourModel_Box::ClockwisePoints cx=%f cy=%f cz=%f    flagAng=%d   size=%d \n",cx,cy,cz,flagAng, size);
-//if (cy<=490) { flagAng = flagAng*(-1); }
 
                        // Step 3. Invert order of points
                        if (flagAng<0)
@@ -396,6 +393,8 @@ void ManualContourModel_Box::ShiftValues(   std::vector<double> *lstInX,
        if (sizeLstIndexIn>=2)
        {
        
+         
+        
                for (iLstIndexIn=0;  iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
                {
                        size  = (*lstIndexsIn)[iLstIndexIn];
@@ -404,7 +403,8 @@ void ManualContourModel_Box::ShiftValues(   std::vector<double> *lstInX,
                        distMin = 10000000;
                        iBack   = 0;
                        
-                       
+                   // Comparing distance between two contours  
+                   // Both contours need the same size 
                        for (ig=0; ig<size; ig++)
                        {
                                dist=0;
@@ -425,7 +425,7 @@ void ManualContourModel_Box::ShiftValues(   std::vector<double> *lstInX,
                        } // for ig size
 
                        
-printf("EED ManualContourModel_Box::ShiftValues px=%f py=%f pz=%f  iBack=%d/%d  size=%d  distMin=%f \n", (*lstInX)[iGeneral]  , (*lstInY)[iGeneral] , (*lstInZ)[iGeneral], iBack, size2,size, distMin);
+//printf("EED ManualContourModel_Box::ShiftValues px=%f py=%f pz=%f  iBack=%d/%d  size=%d  distMin=%f \n", (*lstInX)[iGeneral]  , (*lstInY)[iGeneral] , (*lstInZ)[iGeneral], iBack, size2,size, distMin);
                        
                        if (iBack!=0)
                        {
@@ -434,11 +434,20 @@ printf("EED ManualContourModel_Box::ShiftValues px=%f py=%f pz=%f  iBack=%d/%d
                                LstTmpZ.clear();
                                for (i=0 ; i<size2 ; i++) 
                                {
-                                       ii= (i+iBack)%size2;
-                                       LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
-                                       LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
-                                       LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
-                               } // for i                              
+                                       ii = (i+iBack)%size2;
+                                       if (ii<(size2-1)) // Skip the last item
+                                       {
+                                               LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
+                                               LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
+                                               LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
+                                       }
+                               } // for i
+                               
+                               //Repeat the first item at the end to close the contour
+                               LstTmpX.push_back( LstTmpX[0] );
+                               LstTmpY.push_back( LstTmpY[0] );
+                               LstTmpZ.push_back( LstTmpZ[0] );
+
                                for (i=0 ; i<size2 ; i++) 
                                {
                                        (*lstInX)[iGeneral+size+i] = LstTmpX[i];
@@ -519,6 +528,7 @@ void ManualContourModel_Box::Process()
                bbSetOutputLstIndexsOut(lstIndexsOut);  
        } else {
                RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
+//EED 01/2021          
                ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
                ///////////// Second Step Transpose the vectors   
                lstInX.clear();