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 ( (sizeContour3!=-1) && (sizeContour1<sizeContour2) && (sizeContour2>sizeContour3) ) // Warning for a maximum local
564 lstInconsistentContourY.push_back( lstTmp2Y[0] );
565 lstInconsistentContourID.push_back( iContour+1 );
566 } // if maximum local
567 CopyContour2InContour1( &lstTmp2aX,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
568 } //if sizeContour1>sizeContour2>sizeContour3
569 sizeContour1 = sizeContour2;
573 // ------------ Wave 2 fordward to back (redistribute the litle one)-----------------
574 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,nbContours-1,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
575 // sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
576 sizeContour1 = lstSizeContours[ nbContours-1 ];
579 for ( iContour=nbContours-1; iContour>0 ; iContour-- ) // Fordward to Back
581 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
582 // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
583 sizeContour2 = lstSizeContours[ iContour-1 ];
586 // ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-2 ,&lstTmp3X,&lstTmp3Y,&lstTmp3Z );
587 // sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z );
588 sizeContour3 = lstSizeContours[ iContour-2 ];
592 if ( (sizeContour1>sizeContour2) && (sizeContour2>sizeContour3) )
594 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha,&beta);
595 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
596 sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
597 lstSizeContours[ iContour-1 ] = sizeContour2;
598 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour-1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
599 CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
601 if ( (sizeContour1>sizeContour2) && (sizeContour2<sizeContour3) ) // Warning for a minim local
603 lstContourExeption.push_back( iContour-1 );
604 } // if minimum local
605 if ( (sizeContour3!=-1) && (sizeContour1<sizeContour2) && (sizeContour2>sizeContour3) ) // Warning for a maximum local
607 lstInconsistentContourY.push_back( lstTmp2Y[0] );
608 lstInconsistentContourID.push_back( iContour-1 );
609 } // if Maximum local
610 CopyContour2InContour1( &lstTmp2X,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
611 } //if sizeContour1>sizeContour2>sizeContour3
612 sizeContour1 = sizeContour2;
615 // ------------ Wave 3 redistribution for the minimun detected in Wave 1 -----------------
616 double alpha1,alpha2;
618 double iExtra,sizeExtra=lstContourExeption.size();
619 for ( iExtra=0 ; iExtra<sizeExtra ; iExtra++ )
621 iContour = lstContourExeption[iExtra];
622 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-1 , &lstTmp1X,&lstTmp1Y,&lstTmp1Z);
623 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour , &lstTmp2X,&lstTmp2Y,&lstTmp2Z);
624 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+1 , &lstTmp3X,&lstTmp3Y,&lstTmp3Z);
625 // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
626 sizeContour2 = lstSizeContours[ iContour ];
627 printf("EED Warnning! ManualContourModel_Box::RedistributionPointsAllContours_SIN wave3 posible inconsistent contour y=%f iContour=%d\n", lstTmp2Y[0], iContour );
628 lstInconsistentContourY.push_back( lstTmp2Y[0] );
629 lstInconsistentContourID.push_back( iContour );
630 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha1,&beta1);
631 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp3X,&lstTmp3Y,&lstTmp3Z, &alpha2,&beta2);
638 beta = ( beta1 + beta2 ) / 2;
639 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
640 sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
641 lstSizeContours[ iContour ] = sizeContour2;
642 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
648 void ManualContourModel_Box::ClockwisePoints( std::vector<double> *lstInX,
649 std::vector<double> *lstInY,
650 std::vector<double> *lstInZ,
651 std::vector<int> *lstIndexsIn )
653 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
658 double backpx,backpy,backpz;
667 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn; iLstIndexIn++)
669 // Step 1. Find gravity center and direction
670 size = (*lstIndexsIn)[iLstIndexIn];
671 if (size>2) // for contour with more than 2 points
679 for ( i=0 ; i<size ; i++ )
681 px=(*lstInX)[iGeneral+i];
682 py=(*lstInY)[iGeneral+i];
683 pz=(*lstInZ)[iGeneral+i];
689 if (backpx!=px) { dirx=false; }
690 if (backpy!=py) { diry=false; }
691 if (backpz!=pz) { dirz=false; }
703 if (dirx==true) { dir=1; } // YZ
704 if (diry==true) { dir=2; } // XZ
705 if (dirz==true) { dir=0; } // XZ
706 // Step 2. Find angle diference find
708 for ( i=0 ; i<size ; i++ )
710 px = (*lstInX)[iGeneral+i]-cx;
711 py = (*lstInY)[iGeneral+i]-cy;
712 pz = (*lstInZ)[iGeneral+i]-cz;
713 if (dir==0) { ang=atan2( py , px ); } // XY
714 if (dir==1) { ang=atan2( pz , py ); } // YZ
715 if (dir==2) { ang=atan2( pz , px ); } // XZ
729 // Step 3. Invert order of points
733 for ( i=0 ; i<size2 ; i++ )
735 tmp = (*lstInX)[iGeneral+i];
736 (*lstInX)[iGeneral+i] = (*lstInX)[iGeneral+size-1-i];
737 (*lstInX)[iGeneral+size-1-i] = tmp;
738 tmp = (*lstInY)[iGeneral+i];
739 (*lstInY)[iGeneral+i] = (*lstInY)[iGeneral+size-1-i];
740 (*lstInY)[iGeneral+size-1-i] = tmp;
741 tmp = (*lstInZ)[iGeneral+i];
742 (*lstInZ)[iGeneral+i] = (*lstInZ)[iGeneral+size-1-i];
743 (*lstInZ)[iGeneral+size-1-i] = tmp;
747 iGeneral = iGeneral+size;
752 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
753 std::vector<double> *lstInY,
754 std::vector<double> *lstInZ,
755 std::vector<int> *lstIndexsIn )
757 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
764 std::vector<double> LstTmpX;
765 std::vector<double> LstTmpY;
766 std::vector<double> LstTmpZ;
767 if (sizeLstIndexIn>=2)
769 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
771 size = (*lstIndexsIn)[iLstIndexIn];
772 size2 = (*lstIndexsIn)[iLstIndexIn+1];
773 //find min distance and iBack
776 // Comparing distance between two contours
777 // Both contours need the same size
778 for (ig=0; ig<size; ig++)
781 for ( i=0 ; i<size2 ; i++ )
783 dx = (*lstInX)[iGeneral+i]-(*lstInX)[iGeneral+size+(i+ig)%size];
784 dy = (*lstInY)[iGeneral+i]-(*lstInY)[iGeneral+size+(i+ig)%size];
785 dz = (*lstInZ)[iGeneral+i]-(*lstInZ)[iGeneral+size+(i+ig)%size];
786 dist= dist + sqrt( dx*dx + dy*dy + dz*dz );
799 for (i=0 ; i<size2 ; i++)
801 ii = (i+iBack)%size2;
802 if (ii<(size2-1)) // Skip the last item
804 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
805 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
806 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
809 //Repeat the first item at the end to close the contour
810 LstTmpX.push_back( LstTmpX[0] );
811 LstTmpY.push_back( LstTmpY[0] );
812 LstTmpZ.push_back( LstTmpZ[0] );
813 for (i=0 ; i<size2 ; i++)
815 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
816 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
817 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
820 iGeneral=iGeneral+size;
822 } // if sizeLstIndexIn
827 void ManualContourModel_Box::Process()
829 // THE MAIN PROCESSING METHOD BODY
830 // Here we simply set the input 'In' value to the output 'Out'
831 // And print out the output value
832 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
833 // void bbSet{Input|Output}NAME(const TYPE&)
834 // const TYPE& bbGet{Input|Output}NAME() const
836 // * NAME is the name of the input/output
837 // (the one provided in the attribute 'name' of the tag 'input')
838 // * TYPE is the C++ type of the input/output
839 // (the one provided in the attribute 'type' of the tag 'input')
841 // bbSetOutputOut( bbGetInputIn() );
842 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
844 if (bbGetInputActive()==true)
846 lstInconsistentContourY.clear();
847 lstInconsistentContourID.clear();
849 // First Step Spline Interpolation
851 std::vector<int> lstIndexsIn = bbGetInputLstIndexsIn();
852 std::vector<int> lstIndexsOut;
853 std::vector<double> lstOutX;
854 std::vector<double> lstOutY;
855 std::vector<double> lstOutZ;
857 std::vector<double> lstInX = bbGetInputLstControlPointsX();
858 std::vector<double> lstInY = bbGetInputLstControlPointsY();
859 std::vector<double> lstInZ = bbGetInputLstControlPointsZ();
861 bool ok_abortMethod = false;
862 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
865 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
868 if ( (lstInX.size()==0) && (lstInY.size()==0) && (lstInZ.size()==0) )
871 printf("Warnning !! .. ManualContourModel_Box: The lists X Y Z, are empty \n");
874 if (ok_abortMethod==true)
876 bbSetOutputLstContourPointsX( lstOutX );
877 bbSetOutputLstContourPointsY( lstOutY );
878 bbSetOutputLstContourPointsZ( lstOutZ );
879 bbSetOutputLstIndexsOut( lstIndexsOut );
885 if (bbGetInputLstIndexsIn().size()==0)
887 lstIndexsIn.push_back( lstInX.size() );
890 // Step 0. Clean lstIndexIn
891 int i,size = lstIndexsIn.size();
892 for (i=size-1 ; i>=0; i--)
894 if (lstIndexsIn[i]==0)
896 lstIndexsIn.erase( lstIndexsIn.begin()+i );
900 // Step 1. All contours the same clockwise direction (Control Points)
901 if ((bbGetInputDoubleContour()==1) && (bbGetInputOpenClose()==true))
903 ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn ); // wich is the plane base XY? XZ ZY ??????
904 // ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
906 size = lstIndexsIn.size();
909 // Step 2. Spline interpolation of control points
912 ProcessBySegment( bbGetInputType() ,
913 iGeneral, lstIndexsIn[i] ,
914 &lstInX , &lstInY , &lstInZ,
915 &lstOutX , &lstOutY , &lstOutZ,
916 &lstIndexsOut,bbGetInputOpenClose() );
919 if (bbGetInputDoubleContour()==0 || size == 1)
921 // Finish if Simple contours
922 //////////////////// Set Out DoubleContour = 0
923 bbSetOutputLstContourPointsX(lstOutX);
924 bbSetOutputLstContourPointsY(lstOutY);
925 bbSetOutputLstContourPointsZ(lstOutZ);
926 bbSetOutputLstIndexsOut(lstIndexsOut);
928 // Step 3. Interpolation in the other direction
929 // Step 3.1 Linear Normalice points around contours
930 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
932 // Step 3.2 Shift points to find minimun acumulate distance
933 if (bbGetInputOpenClose()==true)
935 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
937 // Step 3.3. SIN Normalice points around contours
938 if (bbGetInputParam().size()==2)
940 if (bbGetInputParam()[0]==1) // type param 1
942 if (bbGetInputOpenClose()==true)
944 RedistributionPointsAllContours_SIN( &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
945 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
947 } // if type param = 1
949 // Step 3.4 Transpose the vectors
954 size = bbGetInputNbPoints();
955 int j,size2 = lstIndexsOut.size();
958 for (j=0;j<size2;j++)
960 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
961 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
962 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
964 lstIndexsIn.push_back( size2 );
969 lstIndexsOut.clear();
970 // Step 3.5 Interponation 2
971 size=lstIndexsIn.size();
975 ProcessBySegment( bbGetInputType() ,
976 iGeneral, lstIndexsIn[i] ,
977 &lstInX,&lstInY,&lstInZ,
978 &lstOutX,&lstOutY,&lstOutZ,
979 &lstIndexsOut,bbGetInputOpenClose2());
981 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
982 // Step 3.6 Transpose the vectors
987 size = bbGetInputNbPoints();
988 size2 = lstIndexsOut.size();
991 for (j=0;j<size2;j++)
993 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
994 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
995 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
997 lstIndexsIn.push_back( size2 );
1002 lstIndexsOut.clear();
1003 //////////////////// Set Out DoubleContour = 1
1004 bbSetOutputLstContourPointsX( lstInX );
1005 bbSetOutputLstContourPointsY( lstInY );
1006 bbSetOutputLstContourPointsZ( lstInZ );
1007 bbSetOutputLstIndexsOut( lstIndexsIn );
1008 bbSetOutputLstPssblIncnsnstntCntrY( lstInconsistentContourY );
1009 bbSetOutputLstPssblIncnsnstntCntrID( lstInconsistentContourID );
1010 } // if DoubleContour
1015 // 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)
1017 void ManualContourModel_Box::bbUserSetDefaultValues()
1019 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
1020 // Here we initialize the input 'In' to 0
1021 bbSetInputActive(true);
1023 bbSetInputDoubleContour(0);
1024 bbSetInputOpenClose(false);
1025 bbSetInputOpenClose2(false);
1026 bbSetInputNbPoints(100);
1030 // 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)
1032 void ManualContourModel_Box::bbUserInitializeProcessing()
1034 // THE INITIALIZATION METHOD BODY :
1035 // Here does nothing
1036 // but this is where you should allocate the internal/output pointers
1041 // 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)
1043 void ManualContourModel_Box::bbUserFinalizeProcessing()
1045 // THE FINALIZATION METHOD BODY :
1046 // Here does nothing
1047 // but this is where you should desallocate the internal/output pointers
1051 } // EO namespace bbcreaMaracasVisu