}
+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
+
+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)
+ {
+ 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,
int size,size2;
double dist,distMin;
int i,iBack;
+ int ig;
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];
//find min distance and iBack
distMin = 10000000;
iBack = 0;
- for ( i=0 ; i<size2 ; i++ )
+
+
+ for (ig=0; ig<size; ig++)
{
- dx = (*lstInX)[iGeneral]-(*lstInX)[iGeneral+size+i];
- dy = (*lstInY)[iGeneral]-(*lstInY)[iGeneral+size+i];
- dz = (*lstInZ)[iGeneral]-(*lstInZ)[iGeneral+size+i];
- dist= sqrt( dx*dx + dy*dy + dz*dz );
- if ( dist<distMin )
+ for ( i=0 ; i<size2 ; i++ )
+ {
+ dx = (*lstInX)[iGeneral+ig]-(*lstInX)[iGeneral+size+i];
+ dy = (*lstInY)[iGeneral+ig]-(*lstInY)[iGeneral+size+i];
+ dz = (*lstInZ)[iGeneral+ig]-(*lstInZ)[iGeneral+size+i];
+ dist= sqrt( dx*dx + dy*dy + dz*dz );
+ if ( dist<distMin )
+ {
+ iBack = i-ig;
+ distMin = dist;
+ }
+ } // for i size2
+ } // for ig size
+
+if (iBack<0)
+{
+ printf("- ");
+ iBack = iBack + size2;
+}
+
+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)
+ {
+ LstTmpX.clear();
+ LstTmpY.clear();
+ LstTmpZ.clear();
+ for (i=0 ; i<size2 ; i++)
{
- iBack = i;
- distMin = dist;
- }
- } // for dist
+ 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
+ for (i=0 ; i<size2 ; i++)
+ {
+ (*lstInX)[iGeneral+size+i] = LstTmpX[i];
+ (*lstInY)[iGeneral+size+i] = LstTmpY[i];
+ (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
+ } // for i
+ }
+ iGeneral=iGeneral+size;
+ } // for iLstIndexIn
+
+//------------
+
+ iGeneral=0;
+
+ for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
+ {
+ size = (*lstIndexsIn)[iLstIndexIn];
+ size2 = (*lstIndexsIn)[iLstIndexIn+1];
+ //find min distance and iBack
+ distMin = 10000000;
+ iBack = 0;
+
+
+// for (ig=0; ig<size; ig++)
+// {
+ for ( i=0 ; i<size2 ; i++ )
+ {
+ dx = (*lstInX)[iGeneral]-(*lstInX)[iGeneral+size+i];
+ dy = (*lstInY)[iGeneral]-(*lstInY)[iGeneral+size+i];
+ dz = (*lstInZ)[iGeneral]-(*lstInZ)[iGeneral+size+i];
+ dist= sqrt( dx*dx + dy*dy + dz*dz );
+ if ( dist<distMin )
+ {
+ iBack = i;
+ distMin = dist;
+ }
+ } // for i size2
+// } // 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);
+
if (iBack!=0)
{
LstTmpX.clear();
}
iGeneral=iGeneral+size;
} // for iLstIndexIn
- } // sizeLstIndexIn
+
+ } // if sizeLstIndexIn
+
}
}
if (bbGetInputDoubleContour()==1)
{
+ ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
} // DoubleContour
int i,size=lstIndexsIn.size();