//===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== #include "bbcreaMaracasVisuManualContourModel_Box.h" #include "bbcreaMaracasVisuPackage.h" #include namespace bbcreaMaracasVisu { BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ManualContourModel_Box) BBTK_BLACK_BOX_IMPLEMENTATION(ManualContourModel_Box,bbtk::AtomicBlackBox); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ManualContourModel_Box::ProcessBySegment( int Type, int &iGeneral, int sizeSegment, std::vector *lstInX,std::vector *lstInY, std::vector *lstInZ, std::vector *lstOutX,std::vector *lstOutY, std::vector *lstOutZ, std::vector *lstIndexsOut, bool open ) { creaContoursFactory f; manualContourModel *m; int i,size=iGeneral+sizeSegment; double x,y,z; m = (manualContourModel*)f.getContourModel( bbGetInputType() ); m->SetNumberOfPointsSpline( bbGetInputNbPoints() ); m->SetCloseContour( open ); for (i=iGeneral;iAddPoint( (*lstInX)[i] , (*lstInY)[i] , (*lstInZ)[i] ); } // for m->UpdateSpline(); int sizeContour = bbGetInputNbPoints(); for (i=0;iGetSpline_i_Point(i,&x,&y,&z); lstOutX->push_back(x); lstOutY->push_back(y); lstOutZ->push_back(z); } // for iGeneral=iGeneral+sizeSegment; lstIndexsOut->push_back( sizeContour ); delete m; } void ManualContourModel_Box::RedistributionPoints( std::vector *lstOutX, std::vector *lstOutY, std::vector *lstOutZ, std::vector *lstIndexsOut ) { std::vector lstRstX; std::vector lstRstY; std::vector lstRstZ; int iLstIndexOut,sizeLstIndexOut = lstIndexsOut->size(); int ii, iGeneral=0; int size; for (iLstIndexOut=0; iLstIndexOut2) { double dist=0,dist2,distSeg,delta; double dd,dx,dy,dz; int i,k; for ( i=iGeneral+1 ; i= ii*delta ) { dd=(ii*delta-dist2)/distSeg; if (distSeg==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 ) { 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 ); } }// if dist2 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; i2 iGeneral=iGeneral+size; }// for iLstIndexOut } //------------------------------------------------------------------------------------------------------------- void ManualContourModel_Box::ExtractContour( std::vector *lstX, std::vector *lstY, std::vector *lstZ, std::vector *lstIndexs, int contour, std::vector *lstOutX, std::vector *lstOutY, std::vector *lstOutZ ) { int i; // int iLstIndex; int iContour; int sizeLstIndexslstIndexs; int iGeneral; int iGeneralPlusSize; if ( (lstX!=NULL) && (lstY!=NULL) && (lstZ!=NULL) && (lstIndexs!=NULL) && (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) ) { sizeLstIndexslstIndexs = (*lstIndexs).size(); if ( sizeLstIndexslstIndexs!=0 ) { (*lstOutX).clear(); (*lstOutY).clear(); (*lstOutZ).clear(); iGeneral = 0; iGeneralPlusSize = (*lstIndexs)[0]; for ( iContour=1 ; iContour<=contour ; iContour++ ) { iGeneral = iGeneral+(*lstIndexs)[iContour-1]; iGeneralPlusSize = iGeneral+(*lstIndexs)[iContour]; } // for iContour for ( i=iGeneral ; i *lstTmpX, std::vector *lstTmpY, std::vector *lstTmpZ, int contour, std::vector *lstOutX, std::vector *lstOutY, std::vector *lstOutZ, std::vector *lstOutIndexs ) { int i; // int iLstIndex; int iContour; int sizeLstIndexslstIndexs; int iGeneral; int iGeneralPlusSize; int iSize; int SizeContour; if ( (lstTmpX!=NULL) && (lstTmpY!=NULL) && (lstTmpZ!=NULL) && (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) && (lstOutIndexs!=NULL) ) { sizeLstIndexslstIndexs = (*lstOutIndexs).size(); if ( sizeLstIndexslstIndexs!=0 ) { iGeneral = 0; SizeContour = (*lstOutIndexs)[0]; iGeneralPlusSize = iGeneral + SizeContour; for ( iContour=1 ; iContour<=contour ; iContour++ ) { iGeneral = iGeneral + (*lstOutIndexs)[iContour-1]; SizeContour = (*lstOutIndexs)[iContour]; iGeneralPlusSize = iGeneral + SizeContour; } // for iContour if(SizeContour==(*lstTmpX).size() ) { int iSize=0; for ( i=iGeneral ; i *lstC1X, std::vector *lstC1Y, std::vector *lstC1Z, double sizeOfContour, std::vector *lstC2X, std::vector *lstC2Y, std::vector *lstC2Z ) { std::vector lstRstX; std::vector lstRstY; std::vector lstRstZ; int ii,iGeneral; int size,iGeneralPlusSize; int iGeneralPlusSizeMoisUn; int iGeneralPlusSizeMoisDeux; int i,k; int firstK; double iiByDelta; double dist2,distSeg; double dd,dx,dy,dz; double t,tt, PI; double TwoPI; double dist; dist = sizeOfContour; PI = 3.14159265; TwoPI = 2*PI; iGeneral = 0; size = (*lstC1X).size(); iGeneralPlusSize = iGeneral+size; iGeneralPlusSizeMoisUn = iGeneralPlusSize-1; iGeneralPlusSizeMoisDeux = iGeneralPlusSize-2; if (size>2) { firstK = 0; for (i=iGeneral; i1) { tt=tt-1; } if (tt<0) { tt=tt+1; } iiByDelta = tt * dist; for ( k=iGeneral ; k= iiByDelta ) { if (distSeg==0) { dd = 0; } else { dd=(iiByDelta-dist2)/distSeg; }// if distSeg == 0 lstRstX.push_back( (*lstC1X)[k] + dd*dx ); lstRstY.push_back( (*lstC1Y)[k] + dd*dy ); lstRstZ.push_back( (*lstC1Z)[k] + dd*dz ); if (ii==0) { firstK=k; } k = iGeneralPlusSize-1; } else { if ( k==iGeneralPlusSizeMoisDeux ) { dd = 1; lstRstX.push_back( (*lstC1X)[k] + dd*dx ); lstRstY.push_back( (*lstC1Y)[k] + dd*dy ); lstRstZ.push_back( (*lstC1Z)[k] + dd*dz ); } // if k }// if dist2 dist2 = dist2 + distSeg; } // for k } //for i if (lstRstX.size()!=size) { printf("EED Warnning! ManualContourModel_Box::Redistribution_SIN >> This list is not coherent lstRstX.size()=%d size=%d\n", lstRstX.size(), size); } (*lstC2X).clear(); (*lstC2Y).clear(); (*lstC2Z).clear(); for (i=iGeneral; i2 } void ManualContourModel_Box::CopyContour2InContour1( std::vector *lstInX, std::vector *lstInY, std::vector *lstInZ, std::vector *lstOutX, std::vector *lstOutY, std::vector *lstOutZ ) { int i,sizeLstInX=(*lstInX).size(); (*lstOutX).clear(); (*lstOutY).clear(); (*lstOutZ).clear(); for ( i=0 ; i *lstTmpAX, std::vector *lstTmpAY, std::vector *lstTmpAZ, std::vector *lstTmpBX, std::vector *lstTmpBY, std::vector *lstTmpBZ ) { int i; double dx; double dy; double dz; double dist = 0; int iSize = (*lstTmpAX).size(); for ( i=0 ; i *ptrLstTmp2X, std::vector *ptrLstTmp2Y, std::vector *ptrLstTmp2Z , int sizeContour, std::vector *ptrLstTmp1X, std::vector *ptrLstTmp1Y, std::vector *ptrLstTmp1Z, double *alphaOut, double *betaOut) { std::vector lstTmp2aX; std::vector lstTmp2aY; std::vector lstTmp2aZ; double alpha,iAlpha,deltaAlpha; double beta,iBeta,deltaBeta; double distAcum; double minDistAcum; deltaAlpha = 0.1 / 2; deltaBeta = 0.01 / 2; beta = 0.05; alpha = 0; minDistAcum = 999999999999; for (iAlpha=0 ; iAlpha<1; iAlpha=iAlpha+deltaAlpha ) { Redistribution_SIN( iAlpha,beta, ptrLstTmp2X,ptrLstTmp2Y,ptrLstTmp2Z ,sizeContour, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ ); distAcum = IntegralDistanceTwoContours( ptrLstTmp1X,ptrLstTmp1Y,ptrLstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ ); if (distAcum *lstX, std::vector *lstY, std::vector *lstZ) { int i; double dx; double dy; double dz; double dist = 0; int iSize = (*lstX).size() - 1; for ( i=0 ; i *lstOutX, std::vector *lstOutY, std::vector *lstOutZ, std::vector *lstIndexsOut, std::vector *lstSizeContours ) { int i; // int iLstIndex; int iContour; int sizeLstIndexs; int iGeneral; int iGeneralPlusSize; double dx,dy,dz; double dist; (*lstSizeContours).clear(); if ( (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) && (lstIndexsOut!=NULL) ) { sizeLstIndexs = (*lstIndexsOut).size(); if ( sizeLstIndexs!=0 ) { iGeneral = 0; for ( iContour=0 ; iContour *lstOutX, std::vector *lstOutY, std::vector *lstOutZ, std::vector *lstIndexsOut ) { std::vector lstTmp1X; std::vector lstTmp1Y; std::vector lstTmp1Z; std::vector lstTmp2X; std::vector lstTmp2Y; std::vector lstTmp2Z; std::vector lstTmp2aX; std::vector lstTmp2aY; std::vector lstTmp2aZ; std::vector lstTmp3X; std::vector lstTmp3Y; std::vector lstTmp3Z; std::vector lstContourExeption; std::vector lstSizeContours; int iContour; double nbContours = (*lstIndexsOut).size(); double alpha,beta; double sizeContour1; double sizeContour2; double sizeContour3; CalculeLstSizeContours(lstOutX,lstOutY,lstOutZ,lstIndexsOut, &lstSizeContours); // ------------ Wave 1 Back to Fordward (redistribution for the little one)----------------- ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,0,&lstTmp1X,&lstTmp1Y,&lstTmp1Z); // sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z ); sizeContour1 = lstSizeContours[0]; // Increment for ( iContour=0; iContour=sizeContour2) && (sizeContour2>sizeContour3) ) { findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha,&beta); Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ ); sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ ); lstSizeContours[ iContour+1 ] = sizeContour2; PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour+1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut); CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z ); } else { if ( (sizeContour3!=-1) && (sizeContour1sizeContour3) ) // Warning for a maximum local { lstInconsistentContourY.push_back( lstTmp2Y[0] ); lstInconsistentContourID.push_back( iContour+1 ); } // if maximum local CopyContour2InContour1( &lstTmp2aX,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z ); } //if sizeContour1>sizeContour2>sizeContour3 sizeContour1 = sizeContour2; } // for iContour // ------------ Wave 2 fordward to back (redistribute the litle one)----------------- ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,nbContours-1,&lstTmp1X,&lstTmp1Y,&lstTmp1Z); // sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z ); sizeContour1 = lstSizeContours[ nbContours-1 ]; // Increment for ( iContour=nbContours-1; iContour>0 ; iContour-- ) // Fordward to Back { ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z ); // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z ); sizeContour2 = lstSizeContours[ iContour-1 ]; if (iContour-2>=0) { // ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-2 ,&lstTmp3X,&lstTmp3Y,&lstTmp3Z ); // sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z ); sizeContour3 = lstSizeContours[ iContour-2 ]; } else { sizeContour3=-1; } if ( (sizeContour1>sizeContour2) && (sizeContour2>sizeContour3) ) { findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha,&beta); Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ ); sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ ); lstSizeContours[ iContour-1 ] = sizeContour2; PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour-1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut); CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z ); } else { if ( (sizeContour1>sizeContour2) && (sizeContour2sizeContour3) ) // Warning for a maximum local { lstInconsistentContourY.push_back( lstTmp2Y[0] ); lstInconsistentContourID.push_back( iContour-1 ); } // if Maximum local CopyContour2InContour1( &lstTmp2X,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z ); } //if sizeContour1>sizeContour2>sizeContour3 sizeContour1 = sizeContour2; } // for iContour // ------------ Wave 3 redistribution for the minimun detected in Wave 1 ----------------- double alpha1,alpha2; double beta1,beta2; double iExtra,sizeExtra=lstContourExeption.size(); for ( iExtra=0 ; iExtrabeta1) { alpha = alpha2; } else { alpha = alpha1; } beta = ( beta1 + beta2 ) / 2; Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ ); sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ ); lstSizeContours[ iContour ] = sizeContour2; PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour ,lstOutX,lstOutY,lstOutZ,lstIndexsOut); } // for iExtra } void ManualContourModel_Box::ClockwisePoints( std::vector *lstInX, std::vector *lstInY, std::vector *lstInZ, std::vector *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; iLstIndexIn2) // for contour with more than 2 points { cx = 0; cy = 0; cz = 0; dirx = true; diry = true; dirz = true; for ( i=0 ; i0) { if (backang2 iGeneral = iGeneral+size; } // for iLstIndexIn } void ManualContourModel_Box::ShiftValues( std::vector *lstInX, std::vector *lstInY, std::vector *lstInZ, std::vector *lstIndexsIn ) { int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size(); int ii, iGeneral=0; int size,size2; double dist,distMin; int i,iBack; int ig; double dx,dy,dz; std::vector LstTmpX; std::vector LstTmpY; std::vector LstTmpZ; if (sizeLstIndexIn>=2) { for (iLstIndexIn=0; iLstIndexIn lstIndexsIn=bbGetInputLstIndexsIn(); std::vector lstIndexsOut; std::vector lstOutX; std::vector lstOutY; std::vector lstOutZ; if (bbGetInputLstIndexsIn().size()==0) { lstIndexsIn.push_back( lstInX.size() ); } // Step 1. All contours the same clockwise direction (Control Points) if (bbGetInputDoubleContour()==1) { ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn ); // ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn ); } // DoubleContour int i,size = lstIndexsIn.size(); int iGeneral= 0; // Step 2. Spline interpolation of control points for (i=0;i=1) { if (bbGetInputParam()[0]==1) { RedistributionPointsAllContours_SIN( &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut); ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut ); } // if 1 } // if size // Step 3.4 Transpose the vectors lstInX.clear(); lstInY.clear(); lstInZ.clear(); lstIndexsIn.clear(); size = bbGetInputNbPoints(); int j,size2 = lstIndexsOut.size(); for (i=0;i