]> Creatis software - creaMaracasVisu.git/blobdiff - bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx
#3393 creaMaracas Visu Bug New Normal - ViewerNV update point selection event box
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuManualContourModel_Box.cxx
index eee2c1958b6b44cca78c413eb5b588cceb343279..8ad078e6d20b6ae2669f8a5a6975edc9ae60e0da 100644 (file)
@@ -27,9 +27,7 @@ void ManualContourModel_Box::ProcessBySegment(
        creaContoursFactory f;
        manualContourModel      *m;
        int i,size=iGeneral+sizeSegment;
-
        double x,y,z;
-
        m = (manualContourModel*)f.getContourModel( bbGetInputType() );
        m->SetNumberOfPointsSpline( bbGetInputNbPoints() );
        m->SetCloseContour( open );
@@ -57,24 +55,18 @@ void ManualContourModel_Box::RedistributionPoints(  std::vector<double> *lstOutX,
                                                                                                        std::vector<double> *lstOutZ,
                                                                                                        std::vector<int> *lstIndexsOut )
 {
-       printf("EED Warnning!   ManualContourModel_Box::RedistributionPoints  Start\n");
-
        std::vector<double> lstRstX;
        std::vector<double> lstRstY;
        std::vector<double> lstRstZ;
-
        int iLstIndexOut,sizeLstIndexOut=lstIndexsOut->size();
        int ii, iGeneral=0;
        int size;
-
        for (iLstIndexOut=0;  iLstIndexOut<sizeLstIndexOut; iLstIndexOut++)
        {
 //printf("EED ManualContourModel_Box::RedistributionPoints iLstIndexOut=%d   \n", iLstIndexOut);
-
                lstRstX.clear();
                lstRstY.clear();
                lstRstZ.clear();
-
                size=(*lstIndexsOut)[iLstIndexOut];
                if (size>2)
                {
@@ -89,7 +81,6 @@ void ManualContourModel_Box::RedistributionPoints(    std::vector<double> *lstOutX,
                                dist = dist+sqrt( dx*dx + dy*dy + dz*dz );
                        } //for
                        delta=dist/(size-1);
-                       
                        lstRstX.push_back( (*lstOutX)[iGeneral] );
                        lstRstY.push_back( (*lstOutY)[iGeneral] );
                        lstRstZ.push_back( (*lstOutZ)[iGeneral] );
@@ -129,13 +120,10 @@ void ManualContourModel_Box::RedistributionPoints(        std::vector<double> *lstOutX,
                                        dist2=dist2+distSeg;
                                } // for k
                        } //for i   
-
-                       
                        if (lstRstX.size()!=size) 
                        {
                                printf("EED Warnning!   ManualContourModel_Box::RedistributionPoints  >> This list is not coherent  iLstIndexOut=%d  lstRstX.size()=%d  size=%d\n",iLstIndexOut, lstRstX.size(), size);
                        }
-
                        for (i=iGeneral; i<iGeneral+size;i++)
                        {
                                ii=i-iGeneral;
@@ -143,18 +131,113 @@ void ManualContourModel_Box::RedistributionPoints(       std::vector<double> *lstOutX,
                                (*lstOutY)[i] = lstRstY[ii];
                                (*lstOutZ)[i] = lstRstZ[ii];
                        } // for i
-                                       
                } // if size>2
-               
                iGeneral=iGeneral+size;
-
        }// for iLstIndexOut
-
-       printf("EED Warnning!   ManualContourModel_Box::RedistributionPoints  End\n");
-
 }
 
 
+void ManualContourModel_Box::ClockwisePoints(  std::vector<double> *lstInX,
+                                                                                       std::vector<double> *lstInY, 
+                                                                                       std::vector<double> *lstInZ,
+                                                                                       std::vector<int> *lstIndexsIn )
+{
+       int     iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
+       int     i,iGeneral=0;
+       int     size,size2;
+       double  cx,cy,cz;
+       double  px,py,pz;
+       double  backpx,backpy,backpz;
+       double  ang;
+       char    dir=-1;
+       bool    dirx,diry,dirz;
+       int     flagAng=0;
+       float   backang;
+       double  tmp;
+
+       // For each contour
+       for (iLstIndexIn=0;  iLstIndexIn<sizeLstIndexIn; iLstIndexIn++)
+       {
+               // Step 1. Find gravity center and direction
+               size    = (*lstIndexsIn)[iLstIndexIn];
+               if (size>2)  // for contour with more than 2 points
+               {
+                       cx              = 0;
+                       cy              = 0;
+                       cz              = 0;
+                       dirx    = true;
+                       diry    = true;
+                       dirz    = true;
+                       for ( i=0 ; i<size ; i++ )
+                       {
+                               px=(*lstInX)[iGeneral+i];
+                               py=(*lstInY)[iGeneral+i];
+                               pz=(*lstInZ)[iGeneral+i];
+                               cx      = px + cx;
+                               cy      = py + cy;
+                               cz      = pz + cz;
+                               if (i!=0) 
+                               { 
+                                       if (backpx!=px) { dirx=false; } 
+                                       if (backpy!=py) { diry=false; } 
+                                       if (backpz!=pz) { dirz=false; } 
+                                       backpx=px;
+                                       backpy=py;
+                                       backpz=pz;
+                               } // if i!=0
+                               backpx=px; 
+                               backpy=py; 
+                               backpz=pz; 
+                       } // for i 
+                       cx=cx/size;
+                       cy=cy/size;
+                       cz=cz/size;
+                       if (dirx==true) { dir=1; }  // YZ 
+                       if (diry==true) { dir=2; }  // XZ 
+                       if (dirz==true) { dir=0; }  // XZ 
+                       // Step 2. Find angle diference find 
+                       flagAng=0;
+                       for ( i=0 ; i<size ; i++ )
+                       {
+                               px = (*lstInX)[iGeneral+i]-cx;
+                               py = (*lstInY)[iGeneral+i]-cy;
+                               pz = (*lstInZ)[iGeneral+i]-cz;
+                               if (dir==0) { ang=atan2( py , px ); } // XY
+                               if (dir==1) { ang=atan2( pz , py ); } // YZ
+                               if (dir==2) { ang=atan2( pz , px ); } // XZ
+                               if (i>0) 
+                               { 
+                                       if (backang<ang) 
+                                       {
+                                               flagAng++;
+                                       } else {
+                                               flagAng--;
+                                       }// if backang<ang
+                               } // if i
+                               backang=ang; 
+                       } // for i 
+
+                       // Step 3. Invert order of points
+                       if (flagAng<0)
+                       {
+                               size2 = size/2;
+                               for ( i=0 ; i<size2 ; i++ )
+                               {
+                                       tmp                                                     = (*lstInX)[iGeneral+i];
+                                       (*lstInX)[iGeneral+i]                   = (*lstInX)[iGeneral+size-1-i];
+                                       (*lstInX)[iGeneral+size-1-i]    = tmp;
+                                       tmp                                                     = (*lstInY)[iGeneral+i];
+                                       (*lstInY)[iGeneral+i]                   = (*lstInY)[iGeneral+size-1-i];
+                                       (*lstInY)[iGeneral+size-1-i]    = tmp;
+                                       tmp                                                     = (*lstInZ)[iGeneral+i];
+                                       (*lstInZ)[iGeneral+i]                   = (*lstInZ)[iGeneral+size-1-i];
+                                       (*lstInZ)[iGeneral+size-1-i]    = tmp;
+                               } // for i
+                       } // flagAng
+               } // size>2
+               iGeneral = iGeneral+size;
+       } // for iLstIndexIn
+}
 
 void ManualContourModel_Box::ShiftValues(      std::vector<double> *lstInX,
                                                                                        std::vector<double> *lstInY, 
@@ -167,18 +250,15 @@ void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
        double dist,distMin;
        int i,iBack;
        double dx,dy,dz;
-
        std::vector<double> LstTmpX;
        std::vector<double> LstTmpY;
        std::vector<double> LstTmpZ;
-
        if (sizeLstIndexIn>=2)
        {
                for (iLstIndexIn=0;  iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
                {
                        size  = (*lstIndexsIn)[iLstIndexIn];
                        size2 = (*lstIndexsIn)[iLstIndexIn+1];
-
                        //find min distance and  iBack
                        distMin = 10000000;
                        iBack   = 0;
@@ -194,8 +274,6 @@ void ManualContourModel_Box::ShiftValues(   std::vector<double> *lstInX,
                                        distMin = dist;
                                }
                        } // for dist
-
-
                        if (iBack!=0)
                        {
                                LstTmpX.clear();
@@ -215,7 +293,6 @@ void ManualContourModel_Box::ShiftValues(   std::vector<double> *lstInX,
                                        (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
                                } // for i                              
                        }
-
                        iGeneral=iGeneral+size;
                } // for iLstIndexIn
        } // sizeLstIndexIn
@@ -240,35 +317,29 @@ void ManualContourModel_Box::Process()
 //    bbSetOutputOut( bbGetInputIn() );
 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
 
-
        // First Step  Spline Interpolation
        std::vector<double> lstInX=bbGetInputLstControlPointsX();
        std::vector<double> lstInY=bbGetInputLstControlPointsY();
        std::vector<double> lstInZ=bbGetInputLstControlPointsZ();
-
        if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) ) 
        { 
                printf("Warnning !!  .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
                return;
        }
-
        std::vector<int>        lstIndexsIn=bbGetInputLstIndexsIn();
        std::vector<int>        lstIndexsOut;
        std::vector<double> lstOutX;
        std::vector<double> lstOutY;
        std::vector<double> lstOutZ;
-
        if (bbGetInputLstIndexsIn().size()==0)
        {
                lstIndexsIn.push_back( lstInX.size() );
        }
-
-       
        if (bbGetInputDoubleContour()==1)
        {
+               ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
                ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
        } // DoubleContour
-
        int i,size=lstIndexsIn.size();
        int iGeneral=0;
        for (i=0;i<size;i++)
@@ -343,7 +414,6 @@ void ManualContourModel_Box::Process()
                lstOutY.clear();
                lstOutZ.clear();
                lstIndexsOut.clear();
-
                //////////////////// Set Out   DoubleContour = 1
                bbSetOutputLstContourPointsX(lstInX);   
                bbSetOutputLstContourPointsY(lstInY);