2 // 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)
4 #include "bbcreaMaracasVisuManualContourModel_Box.h"
5 #include "bbcreaMaracasVisuPackage.h"
7 #include <creaContoursFactory.h>
10 namespace bbcreaMaracasVisu
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ManualContourModel_Box)
14 BBTK_BLACK_BOX_IMPLEMENTATION(ManualContourModel_Box,bbtk::AtomicBlackBox);
16 // 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)
20 void ManualContourModel_Box::ProcessBySegment(
22 int &iGeneral, int sizeSegment,
23 std::vector<double> *lstInX,std::vector<double> *lstInY, std::vector<double> *lstInZ,
24 std::vector<double> *lstOutX,std::vector<double> *lstOutY, std::vector<double> *lstOutZ,
25 std::vector<int> *lstIndexsOut, bool open )
27 creaContoursFactory f;
28 manualContourModel *m;
29 int i,size=iGeneral+sizeSegment;
31 m = (manualContourModel*)f.getContourModel( bbGetInputType() );
32 m->SetNumberOfPointsSpline( bbGetInputNbPoints() );
33 m->SetCloseContour( open );
34 for (i=iGeneral;i<size;i++)
36 m->AddPoint( (*lstInX)[i] , (*lstInY)[i] , (*lstInZ)[i] );
39 int sizeContour = bbGetInputNbPoints();
40 for (i=0;i<sizeContour;i++)
42 m->GetSpline_i_Point(i,&x,&y,&z);
43 lstOutX->push_back(x);
44 lstOutY->push_back(y);
45 lstOutZ->push_back(z);
47 iGeneral=iGeneral+sizeSegment;
48 lstIndexsOut->push_back( sizeContour );
53 void ManualContourModel_Box::RedistributionPoints( std::vector<double> *lstOutX,
54 std::vector<double> *lstOutY,
55 std::vector<double> *lstOutZ,
56 std::vector<int> *lstIndexsOut )
58 std::vector<double> lstRstX;
59 std::vector<double> lstRstY;
60 std::vector<double> lstRstZ;
61 int iLstIndexOut,sizeLstIndexOut = lstIndexsOut->size();
64 for (iLstIndexOut=0; iLstIndexOut<sizeLstIndexOut; iLstIndexOut++)
69 size=(*lstIndexsOut)[iLstIndexOut];
72 double dist=0,dist2,distSeg,delta;
75 for ( i=iGeneral+1 ; i<iGeneral+size ; i++ )
77 dx = (*lstOutX)[i]-(*lstOutX)[i-1];
78 dy = (*lstOutY)[i]-(*lstOutY)[i-1];
79 dz = (*lstOutZ)[i]-(*lstOutZ)[i-1];
80 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
82 delta = dist/(size-1);
83 lstRstX.push_back( (*lstOutX)[iGeneral] );
84 lstRstY.push_back( (*lstOutY)[iGeneral] );
85 lstRstZ.push_back( (*lstOutZ)[iGeneral] );
86 for (i=iGeneral+1; i<iGeneral+size;i++)
89 for (k=iGeneral+1; k<iGeneral+size;k++)
91 dx = (*lstOutX)[k]-(*lstOutX)[k-1];
92 dy = (*lstOutY)[k]-(*lstOutY)[k-1];
93 dz = (*lstOutZ)[k]-(*lstOutZ)[k-1];
94 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
96 if ( dist2+distSeg >= ii*delta )
98 dd=(ii*delta-dist2)/distSeg;
103 lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
104 lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
105 lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
108 if ( k==iGeneral+size-1 )
111 lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
112 lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
113 lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
116 dist2 = dist2+distSeg;
119 if (lstRstX.size()!=size)
121 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size);
123 for (i=iGeneral; i<iGeneral+size;i++)
126 (*lstOutX)[i] = lstRstX[ii];
127 (*lstOutY)[i] = lstRstY[ii];
128 (*lstOutZ)[i] = lstRstZ[ii];
131 iGeneral=iGeneral+size;
136 //-------------------------------------------------------------------------------------------------------------
139 void ManualContourModel_Box::ExtractContour( std::vector<double> *lstX,
140 std::vector<double> *lstY,
141 std::vector<double> *lstZ,
142 std::vector<int> *lstIndexs,
144 std::vector<double> *lstOutX,
145 std::vector<double> *lstOutY,
146 std::vector<double> *lstOutZ )
151 int sizeLstIndexslstIndexs;
153 int iGeneralPlusSize;
154 if ( (lstX!=NULL) && (lstY!=NULL) && (lstZ!=NULL) && (lstIndexs!=NULL) && (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) )
156 sizeLstIndexslstIndexs = (*lstIndexs).size();
157 if ( sizeLstIndexslstIndexs!=0 )
163 iGeneralPlusSize = (*lstIndexs)[0];
164 for ( iContour=1 ; iContour<=contour ; iContour++ )
166 iGeneral = iGeneral+(*lstIndexs)[iContour-1];
167 iGeneralPlusSize = iGeneral+(*lstIndexs)[iContour];
169 for ( i=iGeneral ; i<iGeneralPlusSize ; i++ )
171 (*lstOutX).push_back( (*lstX)[i] );
172 (*lstOutY).push_back( (*lstY)[i] );
173 (*lstOutZ).push_back( (*lstZ)[i] );
179 void ManualContourModel_Box::PutPointsInContour(std::vector<double> *lstTmpX,
180 std::vector<double> *lstTmpY,
181 std::vector<double> *lstTmpZ,
183 std::vector<double> *lstOutX,
184 std::vector<double> *lstOutY,
185 std::vector<double> *lstOutZ,
186 std::vector<int> *lstOutIndexs )
191 int sizeLstIndexslstIndexs;
193 int iGeneralPlusSize;
196 if ( (lstTmpX!=NULL) && (lstTmpY!=NULL) && (lstTmpZ!=NULL) && (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) && (lstOutIndexs!=NULL) )
198 sizeLstIndexslstIndexs = (*lstOutIndexs).size();
199 if ( sizeLstIndexslstIndexs!=0 )
202 SizeContour = (*lstOutIndexs)[0];
203 iGeneralPlusSize = iGeneral + SizeContour;
204 for ( iContour=1 ; iContour<=contour ; iContour++ )
206 iGeneral = iGeneral + (*lstOutIndexs)[iContour-1];
207 SizeContour = (*lstOutIndexs)[iContour];
208 iGeneralPlusSize = iGeneral + SizeContour;
211 if(SizeContour==(*lstTmpX).size() )
214 for ( i=iGeneral ; i<iGeneralPlusSize ; i++ )
216 (*lstOutX)[i] = (*lstTmpX)[iSize] ;
217 (*lstOutY)[i] = (*lstTmpY)[iSize] ;
218 (*lstOutZ)[i] = (*lstTmpZ)[iSize] ;
222 printf("EED Warnning!! ManualContourModel_Box::PutPointsInContour the lstTmp vector is not of the correct size. SizeContour=%d lstTmp.size=%d\n"
223 ,SizeContour, (*lstTmpX).size() );
224 for ( i=iGeneral ; i<iGeneralPlusSize ; i++ )
226 (*lstOutX)[i] = -9999 ;
227 (*lstOutY)[i] = -9999 ;
228 (*lstOutZ)[i] = -9999 ;
236 void ManualContourModel_Box::Redistribution_SIN( double alpha,
238 std::vector<double> *lstC1X,
239 std::vector<double> *lstC1Y,
240 std::vector<double> *lstC1Z,
241 double sizeOfContour,
242 std::vector<double> *lstC2X,
243 std::vector<double> *lstC2Y,
244 std::vector<double> *lstC2Z )
246 std::vector<double> lstRstX;
247 std::vector<double> lstRstY;
248 std::vector<double> lstRstZ;
250 int size,iGeneralPlusSize;
251 int iGeneralPlusSizeMoisUn;
252 int iGeneralPlusSizeMoisDeux;
256 double dist2,distSeg;
261 dist = sizeOfContour;
265 size = (*lstC1X).size();
266 iGeneralPlusSize = iGeneral+size;
267 iGeneralPlusSizeMoisUn = iGeneralPlusSize-1;
268 iGeneralPlusSizeMoisDeux = iGeneralPlusSize-2;
272 for (i=iGeneral; i<iGeneralPlusSize;i++) // For each point of one contour
277 t = ((double)ii) / ((double)(size-1));
278 tt = t + 0.70710678182*sin(t*TwoPI)*beta + alpha;
279 if (tt>1) { tt=tt-1; }
280 if (tt<0) { tt=tt+1; }
281 iiByDelta = tt * dist;
283 for ( k=iGeneral ; k<iGeneralPlusSizeMoisUn ; k++ ) // Search inside
285 dx = (*lstC1X)[k+1]-(*lstC1X)[k];
286 dy = (*lstC1Y)[k+1]-(*lstC1Y)[k];
287 dz = (*lstC1Z)[k+1]-(*lstC1Z)[k];
288 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
289 if ( dist2+distSeg >= iiByDelta )
295 dd=(iiByDelta-dist2)/distSeg;
297 lstRstX.push_back( (*lstC1X)[k] + dd*dx );
298 lstRstY.push_back( (*lstC1Y)[k] + dd*dy );
299 lstRstZ.push_back( (*lstC1Z)[k] + dd*dz );
300 if (ii==0) { firstK=k; }
301 k = iGeneralPlusSize-1;
303 if ( k==iGeneralPlusSizeMoisDeux )
306 lstRstX.push_back( (*lstC1X)[k] + dd*dx );
307 lstRstY.push_back( (*lstC1Y)[k] + dd*dy );
308 lstRstZ.push_back( (*lstC1Z)[k] + dd*dz );
311 dist2 = dist2 + distSeg;
314 if (lstRstX.size()!=size)
316 printf("EED Warnning! ManualContourModel_Box::Redistribution_SIN >> This list is not coherent lstRstX.size()=%d size=%d\n", lstRstX.size(), size);
321 for (i=iGeneral; i<iGeneralPlusSize;i++)
323 (*lstC2X).push_back(-1);
324 (*lstC2Y).push_back(-1);
325 (*lstC2Z).push_back(-1);
328 for (i=iGeneral; i<iGeneralPlusSize;i++)
331 iii = iGeneral+ ( (i-iGeneral) + firstK) % size ;
332 (*lstC2X)[iii] = lstRstX[ii];
333 (*lstC2Y)[iii] = lstRstY[ii];
334 (*lstC2Z)[iii] = lstRstZ[ii];
336 (*lstC2X)[iGeneralPlusSize-1]=(*lstC2X)[iGeneral];
337 (*lstC2Y)[iGeneralPlusSize-1]=(*lstC2Y)[iGeneral];
338 (*lstC2Z)[iGeneralPlusSize-1]=(*lstC2Z)[iGeneral];
340 for (i=0; i<size ; i++)
342 (*lstC2X)[i] = (*lstC1X)[i];
343 (*lstC2Y)[i] = (*lstC1Y)[i];
344 (*lstC2Z)[i] = (*lstC1Z)[i];
349 void ManualContourModel_Box::CopyContour2InContour1(
350 std::vector<double> *lstInX,
351 std::vector<double> *lstInY,
352 std::vector<double> *lstInZ,
353 std::vector<double> *lstOutX,
354 std::vector<double> *lstOutY,
355 std::vector<double> *lstOutZ )
357 int i,sizeLstInX=(*lstInX).size();
361 for ( i=0 ; i<sizeLstInX ; i++ )
363 (*lstOutX).push_back( (*lstInX)[i] );
364 (*lstOutY).push_back( (*lstInY)[i] );
365 (*lstOutZ).push_back( (*lstInZ)[i] );
369 double ManualContourModel_Box::IntegralDistanceTwoContours(std::vector<double> *lstTmpAX,
370 std::vector<double> *lstTmpAY,
371 std::vector<double> *lstTmpAZ,
372 std::vector<double> *lstTmpBX,
373 std::vector<double> *lstTmpBY,
374 std::vector<double> *lstTmpBZ )
381 int iSize = (*lstTmpAX).size();
382 for ( i=0 ; i<iSize ; i++ )
384 dx = (*lstTmpAX)[i]-(*lstTmpBX)[i];
385 dy = (*lstTmpAY)[i]-(*lstTmpBY)[i];
386 dz = (*lstTmpAZ)[i]-(*lstTmpBZ)[i];
387 // dist = dist + sqrt( dx*dx + dy*dy + dz*dz );
388 dist = dist + (dx*dx + dy*dy + dz*dz) ;
393 void ManualContourModel_Box::findAlphaBetaSinDistribution( std::vector<double> *ptrLstTmp2X,
394 std::vector<double> *ptrLstTmp2Y,
395 std::vector<double> *ptrLstTmp2Z ,
397 std::vector<double> *ptrLstTmp1X,
398 std::vector<double> *ptrLstTmp1Y,
399 std::vector<double> *ptrLstTmp1Z,
403 std::vector<double> lstTmp2aX;
404 std::vector<double> lstTmp2aY;
405 std::vector<double> lstTmp2aZ;
406 double alpha,iAlpha,deltaAlpha;
407 double beta,iBeta,deltaBeta;
410 deltaAlpha = 0.1 / 2;
411 deltaBeta = 0.01 / 2;
414 minDistAcum = 999999999999;
415 for (iAlpha=0 ; iAlpha<1; iAlpha=iAlpha+deltaAlpha )
417 Redistribution_SIN( iAlpha,beta, ptrLstTmp2X,ptrLstTmp2Y,ptrLstTmp2Z ,sizeContour, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
418 distAcum = IntegralDistanceTwoContours( ptrLstTmp1X,ptrLstTmp1Y,ptrLstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
419 if (distAcum<minDistAcum)
422 minDistAcum = distAcum;
426 minDistAcum = 999999999999;
427 for (iBeta=0.0 ; iBeta<0.2; iBeta=iBeta+deltaBeta)
429 Redistribution_SIN( alpha,iBeta, ptrLstTmp2X,ptrLstTmp2Y,ptrLstTmp2Z ,sizeContour, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
430 distAcum = IntegralDistanceTwoContours( ptrLstTmp1X,ptrLstTmp1Y,ptrLstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
431 if (distAcum<minDistAcum)
434 minDistAcum = distAcum;
443 double ManualContourModel_Box::SizeContour( std::vector<double> *lstX,
444 std::vector<double> *lstY,
445 std::vector<double> *lstZ)
452 int iSize = (*lstX).size() - 1;
453 for ( i=0 ; i<iSize ; i++ )
455 dx = (*lstX)[i+1]-(*lstX)[i];
456 dy = (*lstY)[i+1]-(*lstY)[i];
457 dz = (*lstZ)[i+1]-(*lstZ)[i];
458 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
465 void ManualContourModel_Box::CalculeLstSizeContours( std::vector<double> *lstOutX,
466 std::vector<double> *lstOutY,
467 std::vector<double> *lstOutZ,
468 std::vector<int> *lstIndexsOut,
469 std::vector<double> *lstSizeContours )
476 int iGeneralPlusSize;
479 (*lstSizeContours).clear();
480 if ( (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) && (lstIndexsOut!=NULL) )
482 sizeLstIndexs = (*lstIndexsOut).size();
483 if ( sizeLstIndexs!=0 )
486 for ( iContour=0 ; iContour<sizeLstIndexs ; iContour++ )
489 iGeneralPlusSize = iGeneral + (*lstIndexsOut)[iContour];
490 for ( i=iGeneral+1 ; i<iGeneralPlusSize ; i++ )
492 dx = (*lstOutX)[i]-(*lstOutX)[i-1] ;
493 dy = (*lstOutY)[i]-(*lstOutY)[i-1] ;
494 dz = (*lstOutZ)[i]-(*lstOutZ)[i-1] ;
495 dist= dist + sqrt( dx*dx +dy*dy + dz*dz );
497 (*lstSizeContours).push_back( dist );
498 iGeneral = iGeneralPlusSize;
505 void ManualContourModel_Box::RedistributionPointsAllContours_SIN( std::vector<double> *lstOutX,
506 std::vector<double> *lstOutY,
507 std::vector<double> *lstOutZ,
508 std::vector<int> *lstIndexsOut )
510 std::vector<double> lstTmp1X;
511 std::vector<double> lstTmp1Y;
512 std::vector<double> lstTmp1Z;
513 std::vector<double> lstTmp2X;
514 std::vector<double> lstTmp2Y;
515 std::vector<double> lstTmp2Z;
516 std::vector<double> lstTmp2aX;
517 std::vector<double> lstTmp2aY;
518 std::vector<double> lstTmp2aZ;
519 std::vector<double> lstTmp3X;
520 std::vector<double> lstTmp3Y;
521 std::vector<double> lstTmp3Z;
522 std::vector<int> lstContourExeption;
523 std::vector<double> lstSizeContours;
525 double nbContours = (*lstIndexsOut).size();
531 CalculeLstSizeContours(lstOutX,lstOutY,lstOutZ,lstIndexsOut, &lstSizeContours);
533 // ------------ Wave 1 Back to Fordward (redistribution for the little one)-----------------
534 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,0,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
535 // sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
536 sizeContour1 = lstSizeContours[0];
539 for ( iContour=0; iContour<nbContours-1 ; iContour++ ) // Back to Fordward
541 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
542 // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
543 sizeContour2 = lstSizeContours[ iContour+1 ];
545 if (iContour+2<nbContours)
547 // ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+2 ,&lstTmp3X,&lstTmp3Y,&lstTmp3Z );
548 // sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z );
549 sizeContour3 = lstSizeContours[ iContour+2 ];
553 if ( (sizeContour1>sizeContour2) && (sizeContour2>sizeContour3) )
555 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha,&beta);
556 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
557 sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
558 lstSizeContours[ iContour+1 ] = sizeContour2;
559 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour+1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
560 CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
562 if ( (sizeContour1>sizeContour2) && (sizeContour2<sizeContour3) ) // Warning for a minimum local
564 lstContourExeption.push_back( iContour-1 );
565 } // if minimum local
566 if ( (sizeContour1<sizeContour2) && (sizeContour2>sizeContour3) ) // Warning for a maximum local
568 lstInconsistentContourY.push_back( lstTmp2Y[0] );
569 lstInconsistentContourID.push_back( iContour+1 );
570 } // if maximum local
571 CopyContour2InContour1( &lstTmp2aX,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
572 } //if sizeContour1>sizeContour2>sizeContour3
573 sizeContour1 = sizeContour2;
577 // ------------ Wave 2 fordward to back (redistribute the litle one)-----------------
578 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,nbContours-1,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
579 // sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
580 sizeContour1 = lstSizeContours[ nbContours-1 ];
583 for ( iContour=nbContours-1; iContour>0 ; iContour-- ) // Fordward to Back
585 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
586 // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
587 sizeContour2 = lstSizeContours[ iContour-1 ];
590 // ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-2 ,&lstTmp3X,&lstTmp3Y,&lstTmp3Z );
591 // sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z );
592 sizeContour3 = lstSizeContours[ iContour-2 ];
596 if ( (sizeContour1>sizeContour2) && (sizeContour2>sizeContour3) )
598 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha,&beta);
599 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
600 sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
601 lstSizeContours[ iContour-1 ] = sizeContour2;
602 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour-1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
603 CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
605 if ( (sizeContour1>sizeContour2) && (sizeContour2<sizeContour3) ) // Warning for a minim local
607 lstContourExeption.push_back( iContour-1 );
608 } // if minimum local
609 if ( (sizeContour1<sizeContour2) && (sizeContour2>sizeContour3) ) // Warning for a maximum local
611 lstInconsistentContourY.push_back( lstTmp2Y[0] );
612 lstInconsistentContourID.push_back( iContour-1 );
613 } // if Maximum local
614 CopyContour2InContour1( &lstTmp2X,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
615 } //if sizeContour1>sizeContour2>sizeContour3
616 sizeContour1 = sizeContour2;
619 // ------------ Wave 3 redistribution for the minimun detected in Wave 1 -----------------
620 double alpha1,alpha2;
622 double iExtra,sizeExtra=lstContourExeption.size();
623 for ( iExtra=0 ; iExtra<sizeExtra ; iExtra++ )
625 iContour = lstContourExeption[iExtra];
626 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-1 , &lstTmp1X,&lstTmp1Y,&lstTmp1Z);
627 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour , &lstTmp2X,&lstTmp2Y,&lstTmp2Z);
628 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+1 , &lstTmp3X,&lstTmp3Y,&lstTmp3Z);
629 // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
630 sizeContour2 = lstSizeContours[ iContour ];
631 printf("EED Warnning! ManualContourModel_Box::RedistributionPointsAllContours_SIN wave3 posible inconsistent contour y=%f iContour=%d\n", lstTmp2Y[0], iContour );
632 lstInconsistentContourY.push_back( lstTmp2Y[0] );
633 lstInconsistentContourID.push_back( iContour );
634 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha1,&beta1);
635 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp3X,&lstTmp3Y,&lstTmp3Z, &alpha2,&beta2);
642 beta = ( beta1 + beta2 ) / 2;
643 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
644 sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
645 lstSizeContours[ iContour ] = sizeContour2;
646 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
652 void ManualContourModel_Box::ClockwisePoints( std::vector<double> *lstInX,
653 std::vector<double> *lstInY,
654 std::vector<double> *lstInZ,
655 std::vector<int> *lstIndexsIn )
657 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
662 double backpx,backpy,backpz;
671 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn; iLstIndexIn++)
673 // Step 1. Find gravity center and direction
674 size = (*lstIndexsIn)[iLstIndexIn];
675 if (size>2) // for contour with more than 2 points
683 for ( i=0 ; i<size ; i++ )
685 px=(*lstInX)[iGeneral+i];
686 py=(*lstInY)[iGeneral+i];
687 pz=(*lstInZ)[iGeneral+i];
693 if (backpx!=px) { dirx=false; }
694 if (backpy!=py) { diry=false; }
695 if (backpz!=pz) { dirz=false; }
707 if (dirx==true) { dir=1; } // YZ
708 if (diry==true) { dir=2; } // XZ
709 if (dirz==true) { dir=0; } // XZ
710 // Step 2. Find angle diference find
712 for ( i=0 ; i<size ; i++ )
714 px = (*lstInX)[iGeneral+i]-cx;
715 py = (*lstInY)[iGeneral+i]-cy;
716 pz = (*lstInZ)[iGeneral+i]-cz;
717 if (dir==0) { ang=atan2( py , px ); } // XY
718 if (dir==1) { ang=atan2( pz , py ); } // YZ
719 if (dir==2) { ang=atan2( pz , px ); } // XZ
733 // Step 3. Invert order of points
737 for ( i=0 ; i<size2 ; i++ )
739 tmp = (*lstInX)[iGeneral+i];
740 (*lstInX)[iGeneral+i] = (*lstInX)[iGeneral+size-1-i];
741 (*lstInX)[iGeneral+size-1-i] = tmp;
742 tmp = (*lstInY)[iGeneral+i];
743 (*lstInY)[iGeneral+i] = (*lstInY)[iGeneral+size-1-i];
744 (*lstInY)[iGeneral+size-1-i] = tmp;
745 tmp = (*lstInZ)[iGeneral+i];
746 (*lstInZ)[iGeneral+i] = (*lstInZ)[iGeneral+size-1-i];
747 (*lstInZ)[iGeneral+size-1-i] = tmp;
751 iGeneral = iGeneral+size;
756 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
757 std::vector<double> *lstInY,
758 std::vector<double> *lstInZ,
759 std::vector<int> *lstIndexsIn )
761 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
768 std::vector<double> LstTmpX;
769 std::vector<double> LstTmpY;
770 std::vector<double> LstTmpZ;
771 if (sizeLstIndexIn>=2)
773 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
775 size = (*lstIndexsIn)[iLstIndexIn];
776 size2 = (*lstIndexsIn)[iLstIndexIn+1];
777 //find min distance and iBack
780 // Comparing distance between two contours
781 // Both contours need the same size
782 for (ig=0; ig<size; ig++)
785 for ( i=0 ; i<size2 ; i++ )
787 dx = (*lstInX)[iGeneral+i]-(*lstInX)[iGeneral+size+(i+ig)%size];
788 dy = (*lstInY)[iGeneral+i]-(*lstInY)[iGeneral+size+(i+ig)%size];
789 dz = (*lstInZ)[iGeneral+i]-(*lstInZ)[iGeneral+size+(i+ig)%size];
790 dist= dist + sqrt( dx*dx + dy*dy + dz*dz );
803 for (i=0 ; i<size2 ; i++)
805 ii = (i+iBack)%size2;
806 if (ii<(size2-1)) // Skip the last item
808 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
809 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
810 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
813 //Repeat the first item at the end to close the contour
814 LstTmpX.push_back( LstTmpX[0] );
815 LstTmpY.push_back( LstTmpY[0] );
816 LstTmpZ.push_back( LstTmpZ[0] );
817 for (i=0 ; i<size2 ; i++)
819 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
820 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
821 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
824 iGeneral=iGeneral+size;
826 } // if sizeLstIndexIn
831 void ManualContourModel_Box::Process()
833 // THE MAIN PROCESSING METHOD BODY
834 // Here we simply set the input 'In' value to the output 'Out'
835 // And print out the output value
836 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
837 // void bbSet{Input|Output}NAME(const TYPE&)
838 // const TYPE& bbGet{Input|Output}NAME() const
840 // * NAME is the name of the input/output
841 // (the one provided in the attribute 'name' of the tag 'input')
842 // * TYPE is the C++ type of the input/output
843 // (the one provided in the attribute 'type' of the tag 'input')
845 // bbSetOutputOut( bbGetInputIn() );
846 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
848 if (bbGetInputActive()==true)
850 lstInconsistentContourY.clear();
851 lstInconsistentContourID.clear();
853 // First Step Spline Interpolation
854 std::vector<double> lstInX=bbGetInputLstControlPointsX();
855 std::vector<double> lstInY=bbGetInputLstControlPointsY();
856 std::vector<double> lstInZ=bbGetInputLstControlPointsZ();
857 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
859 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
862 std::vector<int> lstIndexsIn=bbGetInputLstIndexsIn();
863 std::vector<int> lstIndexsOut;
864 std::vector<double> lstOutX;
865 std::vector<double> lstOutY;
866 std::vector<double> lstOutZ;
867 if (bbGetInputLstIndexsIn().size()==0)
869 lstIndexsIn.push_back( lstInX.size() );
872 // Step 1. All contours the same clockwise direction (Control Points)
873 if (bbGetInputDoubleContour()==1)
875 ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
876 // ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
878 int i,size = lstIndexsIn.size();
881 // Step 2. Spline interpolation of control points
884 ProcessBySegment( bbGetInputType() ,
885 iGeneral, lstIndexsIn[i] ,
886 &lstInX , &lstInY , &lstInZ,
887 &lstOutX , &lstOutY , &lstOutZ,
888 &lstIndexsOut,bbGetInputOpenClose() );
891 if (bbGetInputDoubleContour()==0)
893 // Finish if Simple contours
894 //////////////////// Set Out DoubleContour = 0
895 bbSetOutputLstContourPointsX(lstOutX);
896 bbSetOutputLstContourPointsY(lstOutY);
897 bbSetOutputLstContourPointsZ(lstOutZ);
898 bbSetOutputLstIndexsOut(lstIndexsOut);
900 // Step 3. Interpolation in the other direction
901 // Step 3.1 Linear Normalice points around contours
902 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
904 // Step 3.2 Shift points to find minimun acumulate distance
905 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
906 // Step 3.3. SIN Normalice points around contours
907 if (bbGetInputParam().size()>=1)
909 if (bbGetInputParam()[0]==1)
911 RedistributionPointsAllContours_SIN( &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
912 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
915 // Step 3.4 Transpose the vectors
920 size = bbGetInputNbPoints();
921 int j,size2 = lstIndexsOut.size();
924 for (j=0;j<size2;j++)
926 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
927 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
928 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
930 lstIndexsIn.push_back( size2 );
935 lstIndexsOut.clear();
936 // Step 3.5 Interponation 2
937 size=lstIndexsIn.size();
941 ProcessBySegment( bbGetInputType() ,
942 iGeneral, lstIndexsIn[i] ,
943 &lstInX,&lstInY,&lstInZ,
944 &lstOutX,&lstOutY,&lstOutZ,
945 &lstIndexsOut,bbGetInputOpenClose2());
947 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
948 // Step 3.6 Transpose the vectors
953 size = bbGetInputNbPoints();
954 size2 = lstIndexsOut.size();
957 for (j=0;j<size2;j++)
959 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
960 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
961 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
963 lstIndexsIn.push_back( size2 );
968 lstIndexsOut.clear();
969 //////////////////// Set Out DoubleContour = 1
970 bbSetOutputLstContourPointsX( lstInX );
971 bbSetOutputLstContourPointsY( lstInY );
972 bbSetOutputLstContourPointsZ( lstInZ );
973 bbSetOutputLstIndexsOut( lstIndexsIn );
974 bbSetOutputLstPssblIncnsnstntCntrY( lstInconsistentContourY );
975 bbSetOutputLstPssblIncnsnstntCntrID( lstInconsistentContourID );
976 } // if DoubleContour
980 // 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)
982 void ManualContourModel_Box::bbUserSetDefaultValues()
984 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
985 // Here we initialize the input 'In' to 0
986 bbSetInputActive(true);
988 bbSetInputDoubleContour(0);
989 bbSetInputOpenClose(false);
990 bbSetInputOpenClose2(false);
991 bbSetInputNbPoints(100);
994 // 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)
996 void ManualContourModel_Box::bbUserInitializeProcessing()
998 // THE INITIALIZATION METHOD BODY :
1000 // but this is where you should allocate the internal/output pointers
1004 // 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)
1006 void ManualContourModel_Box::bbUserFinalizeProcessing()
1008 // THE FINALIZATION METHOD BODY :
1009 // Here does nothing
1010 // but this is where you should desallocate the internal/output pointers
1013 } // EO namespace bbcreaMaracasVisu