From bb31a386bbf8352d80d3531db1d96cc8ea7091f9 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Mon, 3 May 2021 17:55:18 +0200 Subject: [PATCH] #3463 box ManualContourModel optimisation of SIN() distribution by contour --- ...bcreaMaracasVisuManualContourModel_Box.cxx | 397 +++++++++++++++++- .../bbcreaMaracasVisuManualContourModel_Box.h | 68 ++- 2 files changed, 455 insertions(+), 10 deletions(-) diff --git a/bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx b/bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx index b3e434f..a6b2a7e 100644 --- a/bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx +++ b/bbtk/src/bbcreaMaracasVisuManualContourModel_Box.cxx @@ -63,7 +63,6 @@ void ManualContourModel_Box::RedistributionPoints( std::vector *lstOutX, int size; for (iLstIndexOut=0; iLstIndexOut *lstOutX, lstRstZ.push_back( (*lstOutZ)[iGeneral] ); for (i=iGeneral+1; i *lstOutX, 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; @@ -136,6 +133,382 @@ void ManualContourModel_Box::RedistributionPoints( std::vector *lstOutX, } +//------------------------------------------------------------------------------------------------------------- + + +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; + iGeneralPlusSize = (*lstOutIndexs)[0]; + for ( iContour=1 ; iContour<=contour ; iContour++ ) + { + iGeneral = iGeneral + (*lstOutIndexs)[iContour-1]; + SizeContour = (*lstOutIndexs)[iContour]; + } // for iContour + iGeneralPlusSize = iGeneral + SizeContour; + + if(SizeContour==(*lstTmpX).size() ) + { + int iSize=0; + for ( i=iGeneral ; i *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 *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 *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 *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 lstTmp1aX; + std::vector lstTmp1aY; + std::vector lstTmp1aZ; + int iContour; + double nbContours = (*lstIndexsOut).size()-1; + double alpha,iAlpha; + double beta,iBeta; + double sizeContour1; + double sizeContour2; + double distAcum; + double minDistAcum; + + ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,0,&lstTmp1X,&lstTmp1Y,&lstTmp1Z); + sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z ); + +// Increment + for ( iContour=0; iContour *lstOutX, + std::vector *lstOutY, + std::vector *lstOutZ, + std::vector *lstIndexsOut,double alpha, double beta ) +{ +printf("EED ManualContourModel_Box::RedistributionPoints_SIN_iContour Start \n"); + std::vector lstRstX; + std::vector lstRstY; + std::vector lstRstZ; + int iLstIndexOut,sizeLstIndexOut = lstIndexsOut->size(); + int ii,iGeneral; + double iiByDelta; + int size,iGeneralPlusSize; + double Alpha,Beta,t,tt, PI=3.14159265; + double TwoPI=2*PI; + double dist=0,dist2,distSeg,delta; + double dd,dx,dy,dz; + int i,k; + int firstK; + double tmpX,tmpY,tmpZ; + iGeneral=0; + for (iLstIndexOut=0; iLstIndexOut2) + { + dist=0; + for ( i=iGeneral ; i1) { tt=tt-1; } + if (tt<0) { tt=tt+1; } + iiByDelta = tt * dist; +} else { + iiByDelta = ii*delta; +} + dx = (*lstOutX)[k+1]-(*lstOutX)[k]; + dy = (*lstOutY)[k+1]-(*lstOutY)[k]; + dz = (*lstOutZ)[k+1]-(*lstOutZ)[k]; + distSeg = sqrt( dx*dx + dy*dy + dz*dz ); + if ( dist2+distSeg >= iiByDelta ) + { + if (distSeg==0) + { + dd = 0; + } else { + dd=(iiByDelta-dist2)/distSeg; + }// if distSeg == 0 + lstRstX.push_back( (*lstOutX)[k] + dd*dx ); + lstRstY.push_back( (*lstOutY)[k] + dd*dy ); + lstRstZ.push_back( (*lstOutZ)[k] + dd*dz ); + if (ii==0) { firstK=k; } + k = iGeneralPlusSize-1; + } else { + if ( k==iGeneral+size-2 ) + { + dd = 1; + lstRstX.push_back( (*lstOutX)[k] + dd*dx ); + lstRstY.push_back( (*lstOutY)[k] + dd*dy ); + lstRstZ.push_back( (*lstOutZ)[k] + 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); + tmpX = lstRstX[iGeneral]; + tmpY = lstRstY[iGeneral]; + tmpZ = lstRstZ[iGeneral]; + lstRstX.push_back( tmpX ); + lstRstY.push_back( tmpY ); + lstRstZ.push_back( tmpZ ); + } + int iii; + for (i=iGeneral; i2 + iGeneral=iGeneral+size; + }// for iLstIndexOut + +printf("EED ManualContourModel_Box::RedistributionPoints_SIN_iContour End \n"); + +} + + + + void ManualContourModel_Box::ClockwisePoints( std::vector *lstInX, std::vector *lstInY, std::vector *lstInZ, @@ -503,6 +876,8 @@ void ManualContourModel_Box::Process() { lstIndexsIn.push_back( lstInX.size() ); } + +// Step 1. All contours the same clockwise direction (Control Points) if (bbGetInputDoubleContour()==1) { ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn ); @@ -510,6 +885,8 @@ void ManualContourModel_Box::Process() } // DoubleContour int i,size=lstIndexsIn.size(); int iGeneral=0; + +// Step 2. Spline interpolation of control points for (i=0;i); - BBTK_DECLARE_INPUT(LstControlPointsX,std::vector); BBTK_DECLARE_INPUT(LstControlPointsY,std::vector); BBTK_DECLARE_INPUT(LstControlPointsZ,std::vector); + BBTK_DECLARE_INPUT(Param,std::vector); BBTK_DECLARE_OUTPUT(LstContourPointsX,std::vector); @@ -58,6 +57,8 @@ void ShiftValues( std::vector *lstInX, std::vector *lstIndexsOut, bool open ); + +// Linear Distribution void RedistributionPoints( std::vector *lstOutX, std::vector *lstOutY, std::vector *lstOutZ, @@ -65,6 +66,66 @@ void RedistributionPoints( std::vector *lstOutX, +// sin distribution +void RedistributionPoints_SIN_iContour(int iContour, + std::vector *lstOutX, + std::vector *lstOutY, + std::vector *lstOutZ, + std::vector *lstIndexsOut,double alpha,double beta ); +// find best sin distribution +void RedistributionPointsAllContours_SIN( std::vector *lstOutX, + std::vector *lstOutY, + std::vector *lstOutZ, + std::vector *lstIndexsOut ); + +void Redistribution_SIN( double alpha, + double beta, + std::vector *lstC1X, + std::vector *lstC1Y, + std::vector *lstC1Z, + std::vector *lstC2X, + std::vector *lstC2Y, + std::vector *lstC2Z ); + +double SizeContour( std::vector *lstX, + std::vector *lstY, + std::vector *lstZ ); + +void ExtractContour(std::vector *lstX, + std::vector *lstY, + std::vector *lstZ, + std::vector *lstIndexs, + int contour, + std::vector *lstOutX, + std::vector *lstOutY, + std::vector *lstOutZ ); + +void PutPointsInContour( std::vector *lstTmpX, + std::vector *lstTmpY, + std::vector *lstTmpZ, + int iContour, + std::vector *lstOutX, + std::vector *lstOutY, + std::vector *lstOutZ, + std::vector *lstOutIndexs ); + +double IntegralDistanceTwoContours( std::vector *lstTmpAX, + std::vector *lstTmpAY, + std::vector *lstTmpAZ, + std::vector *lstTmpBX, + std::vector *lstTmpBY, + std::vector *lstTmpBZ ); + +void CopyContour2InContour1( std::vector *lstInX, + std::vector *lstInY, + std::vector *lstInZ, + std::vector *lstOutX, + std::vector *lstOutY, + std::vector *lstOutZ ); + + + + //===== // 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) //===== @@ -82,11 +143,10 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(ManualContourModel_Box,bbtk::AtomicBlackBox); BBTK_INPUT(ManualContourModel_Box,OpenClose2,"(false default) false=open, true=close. Used with the DoubleContour option.",bool,""); BBTK_INPUT(ManualContourModel_Box,NbPoints,"(100 default) Number of points int the spline",int,""); BBTK_INPUT(ManualContourModel_Box,LstIndexsIn,"Lst number of points by segment",std::vector,""); - BBTK_INPUT(ManualContourModel_Box,LstControlPointsX,"List of control points",std::vector,""); BBTK_INPUT(ManualContourModel_Box,LstControlPointsY,"List of control points",std::vector,""); BBTK_INPUT(ManualContourModel_Box,LstControlPointsZ,"List of control points",std::vector,""); - + BBTK_INPUT(ManualContourModel_Box,Param,"Param",std::vector,""); BBTK_OUTPUT(ManualContourModel_Box,LstContourPointsX,"List of points in the contour",std::vector,""); BBTK_OUTPUT(ManualContourModel_Box,LstContourPointsY,"List of points in the contour",std::vector,""); BBTK_OUTPUT(ManualContourModel_Box,LstContourPointsZ,"List of points in the contour",std::vector,""); -- 2.47.1