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>
9 namespace bbcreaMaracasVisu
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ManualContourModel_Box)
13 BBTK_BLACK_BOX_IMPLEMENTATION(ManualContourModel_Box,bbtk::AtomicBlackBox);
15 // 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)
19 void ManualContourModel_Box::ProcessBySegment(
21 int &iGeneral, int sizeSegment,
22 std::vector<double> *lstInX,std::vector<double> *lstInY, std::vector<double> *lstInZ,
23 std::vector<double> *lstOutX,std::vector<double> *lstOutY, std::vector<double> *lstOutZ,
24 std::vector<int> *lstIndexsOut, bool open )
26 creaContoursFactory f;
27 manualContourModel *m;
28 int i,size=iGeneral+sizeSegment;
30 m = (manualContourModel*)f.getContourModel( bbGetInputType() );
31 m->SetNumberOfPointsSpline( bbGetInputNbPoints() );
32 m->SetCloseContour( open );
33 for (i=iGeneral;i<size;i++)
35 m->AddPoint( (*lstInX)[i] , (*lstInY)[i] , (*lstInZ)[i] );
38 int sizeContour = bbGetInputNbPoints();
39 for (i=0;i<sizeContour;i++)
41 m->GetSpline_i_Point(i,&x,&y,&z);
42 lstOutX->push_back(x);
43 lstOutY->push_back(y);
44 lstOutZ->push_back(z);
46 iGeneral=iGeneral+sizeSegment;
47 lstIndexsOut->push_back( sizeContour );
52 void ManualContourModel_Box::RedistributionPoints( std::vector<double> *lstOutX,
53 std::vector<double> *lstOutY,
54 std::vector<double> *lstOutZ,
55 std::vector<int> *lstIndexsOut )
57 std::vector<double> lstRstX;
58 std::vector<double> lstRstY;
59 std::vector<double> lstRstZ;
60 int iLstIndexOut,sizeLstIndexOut = lstIndexsOut->size();
63 for (iLstIndexOut=0; iLstIndexOut<sizeLstIndexOut; iLstIndexOut++)
68 size=(*lstIndexsOut)[iLstIndexOut];
71 double dist=0,dist2,distSeg,delta;
74 for ( i=iGeneral+1 ; i<iGeneral+size ; i++ )
76 dx = (*lstOutX)[i]-(*lstOutX)[i-1];
77 dy = (*lstOutY)[i]-(*lstOutY)[i-1];
78 dz = (*lstOutZ)[i]-(*lstOutZ)[i-1];
79 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
81 delta = dist/(size-1);
82 lstRstX.push_back( (*lstOutX)[iGeneral] );
83 lstRstY.push_back( (*lstOutY)[iGeneral] );
84 lstRstZ.push_back( (*lstOutZ)[iGeneral] );
85 for (i=iGeneral+1; i<iGeneral+size;i++)
88 for (k=iGeneral+1; k<iGeneral+size;k++)
90 dx = (*lstOutX)[k]-(*lstOutX)[k-1];
91 dy = (*lstOutY)[k]-(*lstOutY)[k-1];
92 dz = (*lstOutZ)[k]-(*lstOutZ)[k-1];
93 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
95 if ( dist2+distSeg >= ii*delta )
97 dd=(ii*delta-dist2)/distSeg;
102 lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
103 lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
104 lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
107 if ( k==iGeneral+size-1 )
110 lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
111 lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
112 lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
115 dist2 = dist2+distSeg;
118 if (lstRstX.size()!=size)
120 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size);
122 for (i=iGeneral; i<iGeneral+size;i++)
125 (*lstOutX)[i] = lstRstX[ii];
126 (*lstOutY)[i] = lstRstY[ii];
127 (*lstOutZ)[i] = lstRstZ[ii];
130 iGeneral=iGeneral+size;
135 //-------------------------------------------------------------------------------------------------------------
138 void ManualContourModel_Box::ExtractContour( std::vector<double> *lstX,
139 std::vector<double> *lstY,
140 std::vector<double> *lstZ,
141 std::vector<int> *lstIndexs,
143 std::vector<double> *lstOutX,
144 std::vector<double> *lstOutY,
145 std::vector<double> *lstOutZ )
150 int sizeLstIndexslstIndexs;
152 int iGeneralPlusSize;
153 if ( (lstX!=NULL) && (lstY!=NULL) && (lstZ!=NULL) && (lstIndexs!=NULL) && (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) )
155 sizeLstIndexslstIndexs = (*lstIndexs).size();
156 if ( sizeLstIndexslstIndexs!=0 )
162 iGeneralPlusSize = (*lstIndexs)[0];
163 for ( iContour=1 ; iContour<=contour ; iContour++ )
165 iGeneral = iGeneral+(*lstIndexs)[iContour-1];
166 iGeneralPlusSize = iGeneral+(*lstIndexs)[iContour];
168 for ( i=iGeneral ; i<iGeneralPlusSize ; i++ )
170 (*lstOutX).push_back( (*lstX)[i] );
171 (*lstOutY).push_back( (*lstY)[i] );
172 (*lstOutZ).push_back( (*lstZ)[i] );
178 void ManualContourModel_Box::PutPointsInContour(std::vector<double> *lstTmpX,
179 std::vector<double> *lstTmpY,
180 std::vector<double> *lstTmpZ,
182 std::vector<double> *lstOutX,
183 std::vector<double> *lstOutY,
184 std::vector<double> *lstOutZ,
185 std::vector<int> *lstOutIndexs )
190 int sizeLstIndexslstIndexs;
192 int iGeneralPlusSize;
195 if ( (lstTmpX!=NULL) && (lstTmpY!=NULL) && (lstTmpZ!=NULL) && (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) && (lstOutIndexs!=NULL) )
197 sizeLstIndexslstIndexs = (*lstOutIndexs).size();
198 if ( sizeLstIndexslstIndexs!=0 )
201 SizeContour = (*lstOutIndexs)[0];
202 iGeneralPlusSize = iGeneral + SizeContour;
203 for ( iContour=1 ; iContour<=contour ; iContour++ )
205 iGeneral = iGeneral + (*lstOutIndexs)[iContour-1];
206 SizeContour = (*lstOutIndexs)[iContour];
207 iGeneralPlusSize = iGeneral + SizeContour;
210 if(SizeContour==(*lstTmpX).size() )
213 for ( i=iGeneral ; i<iGeneralPlusSize ; i++ )
215 (*lstOutX)[i] = (*lstTmpX)[iSize] ;
216 (*lstOutY)[i] = (*lstTmpY)[iSize] ;
217 (*lstOutZ)[i] = (*lstTmpZ)[iSize] ;
221 printf("EED Warnning!! ManualContourModel_Box::PutPointsInContour the lstTmp vector is not of the correct size. SizeContour=%d lstTmp.size=%d\n"
222 ,SizeContour, (*lstTmpX).size() );
223 for ( i=iGeneral ; i<iGeneralPlusSize ; i++ )
225 (*lstOutX)[i] = -9999 ;
226 (*lstOutY)[i] = -9999 ;
227 (*lstOutZ)[i] = -9999 ;
235 void ManualContourModel_Box::Redistribution_SIN( double alpha,
237 std::vector<double> *lstC1X,
238 std::vector<double> *lstC1Y,
239 std::vector<double> *lstC1Z,
240 double sizeOfContour,
241 std::vector<double> *lstC2X,
242 std::vector<double> *lstC2Y,
243 std::vector<double> *lstC2Z )
245 std::vector<double> lstRstX;
246 std::vector<double> lstRstY;
247 std::vector<double> lstRstZ;
249 int size,iGeneralPlusSize;
250 int iGeneralPlusSizeMoisUn;
251 int iGeneralPlusSizeMoisDeux;
255 double dist2,distSeg;
260 dist = sizeOfContour;
264 size = (*lstC1X).size();
265 iGeneralPlusSize = iGeneral+size;
266 iGeneralPlusSizeMoisUn = iGeneralPlusSize-1;
267 iGeneralPlusSizeMoisDeux = iGeneralPlusSize-2;
271 for (i=iGeneral; i<iGeneralPlusSize;i++) // For each point of one contour
276 t = ((double)ii) / ((double)(size-1));
277 tt = t + 0.70710678182*sin(t*TwoPI)*beta + alpha;
278 if (tt>1) { tt=tt-1; }
279 if (tt<0) { tt=tt+1; }
280 iiByDelta = tt * dist;
282 for ( k=iGeneral ; k<iGeneralPlusSizeMoisUn ; k++ ) // Search inside
284 dx = (*lstC1X)[k+1]-(*lstC1X)[k];
285 dy = (*lstC1Y)[k+1]-(*lstC1Y)[k];
286 dz = (*lstC1Z)[k+1]-(*lstC1Z)[k];
287 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
288 if ( dist2+distSeg >= iiByDelta )
294 dd=(iiByDelta-dist2)/distSeg;
296 lstRstX.push_back( (*lstC1X)[k] + dd*dx );
297 lstRstY.push_back( (*lstC1Y)[k] + dd*dy );
298 lstRstZ.push_back( (*lstC1Z)[k] + dd*dz );
299 if (ii==0) { firstK=k; }
300 k = iGeneralPlusSize-1;
302 if ( k==iGeneralPlusSizeMoisDeux )
305 lstRstX.push_back( (*lstC1X)[k] + dd*dx );
306 lstRstY.push_back( (*lstC1Y)[k] + dd*dy );
307 lstRstZ.push_back( (*lstC1Z)[k] + dd*dz );
310 dist2 = dist2 + distSeg;
313 if (lstRstX.size()!=size)
315 printf("EED Warnning! ManualContourModel_Box::Redistribution_SIN >> This list is not coherent lstRstX.size()=%d size=%d\n", lstRstX.size(), size);
320 for (i=iGeneral; i<iGeneralPlusSize;i++)
322 (*lstC2X).push_back(-1);
323 (*lstC2Y).push_back(-1);
324 (*lstC2Z).push_back(-1);
327 for (i=iGeneral; i<iGeneralPlusSize;i++)
330 iii = iGeneral+ ( (i-iGeneral) + firstK) % size ;
331 (*lstC2X)[iii] = lstRstX[ii];
332 (*lstC2Y)[iii] = lstRstY[ii];
333 (*lstC2Z)[iii] = lstRstZ[ii];
335 (*lstC2X)[iGeneralPlusSize-1]=(*lstC2X)[iGeneral];
336 (*lstC2Y)[iGeneralPlusSize-1]=(*lstC2Y)[iGeneral];
337 (*lstC2Z)[iGeneralPlusSize-1]=(*lstC2Z)[iGeneral];
339 for (i=0; i<size ; i++)
341 (*lstC2X)[i] = (*lstC1X)[i];
342 (*lstC2Y)[i] = (*lstC1Y)[i];
343 (*lstC2Z)[i] = (*lstC1Z)[i];
348 void ManualContourModel_Box::CopyContour2InContour1(
349 std::vector<double> *lstInX,
350 std::vector<double> *lstInY,
351 std::vector<double> *lstInZ,
352 std::vector<double> *lstOutX,
353 std::vector<double> *lstOutY,
354 std::vector<double> *lstOutZ )
356 int i,sizeLstInX=(*lstInX).size();
360 for ( i=0 ; i<sizeLstInX ; i++ )
362 (*lstOutX).push_back( (*lstInX)[i] );
363 (*lstOutY).push_back( (*lstInY)[i] );
364 (*lstOutZ).push_back( (*lstInZ)[i] );
368 double ManualContourModel_Box::IntegralDistanceTwoContours(std::vector<double> *lstTmpAX,
369 std::vector<double> *lstTmpAY,
370 std::vector<double> *lstTmpAZ,
371 std::vector<double> *lstTmpBX,
372 std::vector<double> *lstTmpBY,
373 std::vector<double> *lstTmpBZ )
380 int iSize = (*lstTmpAX).size();
381 for ( i=0 ; i<iSize ; i++ )
383 dx = (*lstTmpAX)[i]-(*lstTmpBX)[i];
384 dy = (*lstTmpAY)[i]-(*lstTmpBY)[i];
385 dz = (*lstTmpAZ)[i]-(*lstTmpBZ)[i];
386 // dist = dist + sqrt( dx*dx + dy*dy + dz*dz );
387 dist = dist + (dx*dx + dy*dy + dz*dz) ;
392 void ManualContourModel_Box::findAlphaBetaSinDistribution( std::vector<double> *ptrLstTmp2X,
393 std::vector<double> *ptrLstTmp2Y,
394 std::vector<double> *ptrLstTmp2Z ,
396 std::vector<double> *ptrLstTmp1X,
397 std::vector<double> *ptrLstTmp1Y,
398 std::vector<double> *ptrLstTmp1Z,
402 std::vector<double> lstTmp2aX;
403 std::vector<double> lstTmp2aY;
404 std::vector<double> lstTmp2aZ;
405 double alpha,iAlpha,deltaAlpha;
406 double beta,iBeta,deltaBeta;
409 deltaAlpha = 0.1 / 2;
410 deltaBeta = 0.01 / 2;
413 minDistAcum = 999999999999;
414 for (iAlpha=0 ; iAlpha<1; iAlpha=iAlpha+deltaAlpha )
416 Redistribution_SIN( iAlpha,beta, ptrLstTmp2X,ptrLstTmp2Y,ptrLstTmp2Z ,sizeContour, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
417 distAcum = IntegralDistanceTwoContours( ptrLstTmp1X,ptrLstTmp1Y,ptrLstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
418 if (distAcum<minDistAcum)
421 minDistAcum = distAcum;
425 minDistAcum = 999999999999;
426 for (iBeta=0.0 ; iBeta<0.2; iBeta=iBeta+deltaBeta)
428 Redistribution_SIN( alpha,iBeta, ptrLstTmp2X,ptrLstTmp2Y,ptrLstTmp2Z ,sizeContour, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
429 distAcum = IntegralDistanceTwoContours( ptrLstTmp1X,ptrLstTmp1Y,ptrLstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
430 if (distAcum<minDistAcum)
433 minDistAcum = distAcum;
442 double ManualContourModel_Box::SizeContour( std::vector<double> *lstX,
443 std::vector<double> *lstY,
444 std::vector<double> *lstZ)
451 int iSize = (*lstX).size() - 1;
452 for ( i=0 ; i<iSize ; i++ )
454 dx = (*lstX)[i+1]-(*lstX)[i];
455 dy = (*lstY)[i+1]-(*lstY)[i];
456 dz = (*lstZ)[i+1]-(*lstZ)[i];
457 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
464 void ManualContourModel_Box::CalculeLstSizeContours( std::vector<double> *lstOutX,
465 std::vector<double> *lstOutY,
466 std::vector<double> *lstOutZ,
467 std::vector<int> *lstIndexsOut,
468 std::vector<double> *lstSizeContours )
475 int iGeneralPlusSize;
478 (*lstSizeContours).clear();
479 if ( (lstOutX!=NULL) && (lstOutY!=NULL) && (lstOutZ!=NULL) && (lstIndexsOut!=NULL) )
481 sizeLstIndexs = (*lstIndexsOut).size();
482 if ( sizeLstIndexs!=0 )
485 for ( iContour=0 ; iContour<sizeLstIndexs ; iContour++ )
488 iGeneralPlusSize = iGeneral + (*lstIndexsOut)[iContour];
489 for ( i=iGeneral+1 ; i<iGeneralPlusSize ; i++ )
491 dx = (*lstOutX)[i]-(*lstOutX)[i-1] ;
492 dy = (*lstOutY)[i]-(*lstOutY)[i-1] ;
493 dz = (*lstOutZ)[i]-(*lstOutZ)[i-1] ;
494 dist= dist + sqrt( dx*dx +dy*dy + dz*dz );
496 (*lstSizeContours).push_back( dist );
497 iGeneral = iGeneralPlusSize;
504 void ManualContourModel_Box::RedistributionPointsAllContours_SIN( std::vector<double> *lstOutX,
505 std::vector<double> *lstOutY,
506 std::vector<double> *lstOutZ,
507 std::vector<int> *lstIndexsOut )
509 std::vector<double> lstTmp1X;
510 std::vector<double> lstTmp1Y;
511 std::vector<double> lstTmp1Z;
512 std::vector<double> lstTmp2X;
513 std::vector<double> lstTmp2Y;
514 std::vector<double> lstTmp2Z;
515 std::vector<double> lstTmp2aX;
516 std::vector<double> lstTmp2aY;
517 std::vector<double> lstTmp2aZ;
518 std::vector<double> lstTmp3X;
519 std::vector<double> lstTmp3Y;
520 std::vector<double> lstTmp3Z;
521 std::vector<int> lstContourExeption;
522 std::vector<double> lstSizeContours;
524 double nbContours = (*lstIndexsOut).size();
530 CalculeLstSizeContours(lstOutX,lstOutY,lstOutZ,lstIndexsOut, &lstSizeContours);
532 // ------------ Wave 1 Back to Fordward (redistribution for the little one)-----------------
533 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,0,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
534 // sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
535 sizeContour1 = lstSizeContours[0];
538 for ( iContour=0; iContour<nbContours-1 ; iContour++ ) // Back to Fordward
540 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
541 // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
542 sizeContour2 = lstSizeContours[ iContour+1 ];
544 if (iContour+2<nbContours)
546 // ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+2 ,&lstTmp3X,&lstTmp3Y,&lstTmp3Z );
547 // sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z );
548 sizeContour3 = lstSizeContours[ iContour+2 ];
552 if ( (sizeContour1>=sizeContour2) && (sizeContour2>sizeContour3) )
554 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha,&beta);
555 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
556 sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
557 lstSizeContours[ iContour+1 ] = sizeContour2;
558 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour+1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
559 CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
561 if ( (sizeContour3!=-1) && (sizeContour1<sizeContour2) && (sizeContour2>sizeContour3) ) // Warning for a maximum local
563 lstInconsistentContourY.push_back( lstTmp2Y[0] );
564 lstInconsistentContourID.push_back( iContour+1 );
565 } // if maximum local
566 CopyContour2InContour1( &lstTmp2aX,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
567 } //if sizeContour1>sizeContour2>sizeContour3
568 sizeContour1 = sizeContour2;
572 // ------------ Wave 2 fordward to back (redistribute the litle one)-----------------
573 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,nbContours-1,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
574 // sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
575 sizeContour1 = lstSizeContours[ nbContours-1 ];
578 for ( iContour=nbContours-1; iContour>0 ; iContour-- ) // Fordward to Back
580 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
581 // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
582 sizeContour2 = lstSizeContours[ iContour-1 ];
585 // ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-2 ,&lstTmp3X,&lstTmp3Y,&lstTmp3Z );
586 // sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z );
587 sizeContour3 = lstSizeContours[ iContour-2 ];
591 if ( (sizeContour1>sizeContour2) && (sizeContour2>sizeContour3) )
593 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha,&beta);
594 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
595 sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
596 lstSizeContours[ iContour-1 ] = sizeContour2;
597 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour-1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
598 CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
600 if ( (sizeContour1>sizeContour2) && (sizeContour2<sizeContour3) ) // Warning for a minim local
602 lstContourExeption.push_back( iContour-1 );
603 } // if minimum local
604 if ( (sizeContour3!=-1) && (sizeContour1<sizeContour2) && (sizeContour2>sizeContour3) ) // Warning for a maximum local
606 lstInconsistentContourY.push_back( lstTmp2Y[0] );
607 lstInconsistentContourID.push_back( iContour-1 );
608 } // if Maximum local
609 CopyContour2InContour1( &lstTmp2X,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
610 } //if sizeContour1>sizeContour2>sizeContour3
611 sizeContour1 = sizeContour2;
614 // ------------ Wave 3 redistribution for the minimun detected in Wave 1 -----------------
615 double alpha1,alpha2;
617 double iExtra,sizeExtra=lstContourExeption.size();
618 for ( iExtra=0 ; iExtra<sizeExtra ; iExtra++ )
620 iContour = lstContourExeption[iExtra];
621 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-1 , &lstTmp1X,&lstTmp1Y,&lstTmp1Z);
622 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour , &lstTmp2X,&lstTmp2Y,&lstTmp2Z);
623 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+1 , &lstTmp3X,&lstTmp3Y,&lstTmp3Z);
624 // sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
625 sizeContour2 = lstSizeContours[ iContour ];
626 printf("EED Warnning! ManualContourModel_Box::RedistributionPointsAllContours_SIN wave3 posible inconsistent contour y=%f iContour=%d\n", lstTmp2Y[0], iContour );
627 lstInconsistentContourY.push_back( lstTmp2Y[0] );
628 lstInconsistentContourID.push_back( iContour );
629 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp1X,&lstTmp1Y,&lstTmp1Z, &alpha1,&beta1);
630 findAlphaBetaSinDistribution( &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp3X,&lstTmp3Y,&lstTmp3Z, &alpha2,&beta2);
637 beta = ( beta1 + beta2 ) / 2;
638 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
639 sizeContour2 = SizeContour( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
640 lstSizeContours[ iContour ] = sizeContour2;
641 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
647 void ManualContourModel_Box::ClockwisePoints( std::vector<double> *lstInX,
648 std::vector<double> *lstInY,
649 std::vector<double> *lstInZ,
650 std::vector<int> *lstIndexsIn )
652 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
657 double backpx,backpy,backpz;
666 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn; iLstIndexIn++)
668 // Step 1. Find gravity center and direction
669 size = (*lstIndexsIn)[iLstIndexIn];
670 if (size>2) // for contour with more than 2 points
678 for ( i=0 ; i<size ; i++ )
680 px=(*lstInX)[iGeneral+i];
681 py=(*lstInY)[iGeneral+i];
682 pz=(*lstInZ)[iGeneral+i];
688 if (backpx!=px) { dirx=false; }
689 if (backpy!=py) { diry=false; }
690 if (backpz!=pz) { dirz=false; }
702 if (dirx==true) { dir=1; } // YZ
703 if (diry==true) { dir=2; } // XZ
704 if (dirz==true) { dir=0; } // XZ
705 // Step 2. Find angle diference find
707 for ( i=0 ; i<size ; i++ )
709 px = (*lstInX)[iGeneral+i]-cx;
710 py = (*lstInY)[iGeneral+i]-cy;
711 pz = (*lstInZ)[iGeneral+i]-cz;
712 if (dir==0) { ang=atan2( py , px ); } // XY
713 if (dir==1) { ang=atan2( pz , py ); } // YZ
714 if (dir==2) { ang=atan2( pz , px ); } // XZ
728 // Step 3. Invert order of points
732 for ( i=0 ; i<size2 ; i++ )
734 tmp = (*lstInX)[iGeneral+i];
735 (*lstInX)[iGeneral+i] = (*lstInX)[iGeneral+size-1-i];
736 (*lstInX)[iGeneral+size-1-i] = tmp;
737 tmp = (*lstInY)[iGeneral+i];
738 (*lstInY)[iGeneral+i] = (*lstInY)[iGeneral+size-1-i];
739 (*lstInY)[iGeneral+size-1-i] = tmp;
740 tmp = (*lstInZ)[iGeneral+i];
741 (*lstInZ)[iGeneral+i] = (*lstInZ)[iGeneral+size-1-i];
742 (*lstInZ)[iGeneral+size-1-i] = tmp;
746 iGeneral = iGeneral+size;
751 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
752 std::vector<double> *lstInY,
753 std::vector<double> *lstInZ,
754 std::vector<int> *lstIndexsIn )
756 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
763 std::vector<double> LstTmpX;
764 std::vector<double> LstTmpY;
765 std::vector<double> LstTmpZ;
766 if (sizeLstIndexIn>=2)
768 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
770 size = (*lstIndexsIn)[iLstIndexIn];
771 size2 = (*lstIndexsIn)[iLstIndexIn+1];
772 //find min distance and iBack
775 // Comparing distance between two contours
776 // Both contours need the same size
777 for (ig=0; ig<size; ig++)
780 for ( i=0 ; i<size2 ; i++ )
782 dx = (*lstInX)[iGeneral+i]-(*lstInX)[iGeneral+size+(i+ig)%size];
783 dy = (*lstInY)[iGeneral+i]-(*lstInY)[iGeneral+size+(i+ig)%size];
784 dz = (*lstInZ)[iGeneral+i]-(*lstInZ)[iGeneral+size+(i+ig)%size];
785 dist= dist + sqrt( dx*dx + dy*dy + dz*dz );
798 for (i=0 ; i<size2 ; i++)
800 ii = (i+iBack)%size2;
801 if (ii<(size2-1)) // Skip the last item
803 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
804 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
805 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
808 //Repeat the first item at the end to close the contour
809 LstTmpX.push_back( LstTmpX[0] );
810 LstTmpY.push_back( LstTmpY[0] );
811 LstTmpZ.push_back( LstTmpZ[0] );
812 for (i=0 ; i<size2 ; i++)
814 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
815 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
816 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
819 iGeneral=iGeneral+size;
821 } // if sizeLstIndexIn
826 void ManualContourModel_Box::Process()
828 // THE MAIN PROCESSING METHOD BODY
829 // Here we simply set the input 'In' value to the output 'Out'
830 // And print out the output value
831 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
832 // void bbSet{Input|Output}NAME(const TYPE&)
833 // const TYPE& bbGet{Input|Output}NAME() const
835 // * NAME is the name of the input/output
836 // (the one provided in the attribute 'name' of the tag 'input')
837 // * TYPE is the C++ type of the input/output
838 // (the one provided in the attribute 'type' of the tag 'input')
840 // bbSetOutputOut( bbGetInputIn() );
841 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
843 if (bbGetInputActive()==true)
845 lstInconsistentContourY.clear();
846 lstInconsistentContourID.clear();
848 // First Step Spline Interpolation
850 std::vector<int> lstIndexsIn = bbGetInputLstIndexsIn();
851 std::vector<int> lstIndexsOut;
852 std::vector<double> lstOutX;
853 std::vector<double> lstOutY;
854 std::vector<double> lstOutZ;
856 std::vector<double> lstInX = bbGetInputLstControlPointsX();
857 std::vector<double> lstInY = bbGetInputLstControlPointsY();
858 std::vector<double> lstInZ = bbGetInputLstControlPointsZ();
860 bool ok_abortMethod = false;
861 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
864 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
867 if ( (lstInX.size()==0) && (lstInY.size()==0) && (lstInZ.size()==0) )
870 printf("Warnning !! .. ManualContourModel_Box: The lists X Y Z, are empty \n");
873 if (ok_abortMethod==true)
875 bbSetOutputLstContourPointsX( lstOutX );
876 bbSetOutputLstContourPointsY( lstOutY );
877 bbSetOutputLstContourPointsZ( lstOutZ );
878 bbSetOutputLstIndexsOut( lstIndexsOut );
884 if (bbGetInputLstIndexsIn().size()==0)
886 lstIndexsIn.push_back( lstInX.size() );
889 // Step 0. Clean lstIndexIn
890 int i,size = lstIndexsIn.size();
891 for (i=size-1 ; i>=0; i--)
893 if (lstIndexsIn[i]==0)
895 lstIndexsIn.erase( lstIndexsIn.begin()+i );
899 // Step 1. All contours the same clockwise direction (Control Points)
900 if ((bbGetInputDoubleContour()==1) && (bbGetInputOpenClose()==true))
902 ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn ); // wich is the plane base XY? XZ ZY ??????
903 // ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
905 size = lstIndexsIn.size();
908 // Step 2. Spline interpolation of control points
911 ProcessBySegment( bbGetInputType() ,
912 iGeneral, lstIndexsIn[i] ,
913 &lstInX , &lstInY , &lstInZ,
914 &lstOutX , &lstOutY , &lstOutZ,
915 &lstIndexsOut,bbGetInputOpenClose() );
918 if (bbGetInputDoubleContour()==0 || size == 1)
920 // Finish if Simple contours
921 //////////////////// Set Out DoubleContour = 0
922 bbSetOutputLstContourPointsX(lstOutX);
923 bbSetOutputLstContourPointsY(lstOutY);
924 bbSetOutputLstContourPointsZ(lstOutZ);
925 bbSetOutputLstIndexsOut(lstIndexsOut);
927 // Step 3. Interpolation in the other direction
928 // Step 3.1 Linear Normalice points around contours
929 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
931 // Step 3.2 Shift points to find minimun acumulate distance
932 if (bbGetInputOpenClose()==true)
934 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
936 // Step 3.3. SIN Normalice points around contours
937 if (bbGetInputParam().size()==2)
939 if (bbGetInputParam()[0]==1) // type param 1
941 if (bbGetInputOpenClose()==true)
943 RedistributionPointsAllContours_SIN( &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
944 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
946 } // if type param = 1
948 // Step 3.4 Transpose the vectors
953 size = bbGetInputNbPoints();
954 int j,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 // Step 3.5 Interponation 2
970 size=lstIndexsIn.size();
974 ProcessBySegment( bbGetInputType() ,
975 iGeneral, lstIndexsIn[i] ,
976 &lstInX,&lstInY,&lstInZ,
977 &lstOutX,&lstOutY,&lstOutZ,
978 &lstIndexsOut,bbGetInputOpenClose2());
980 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
981 // Step 3.6 Transpose the vectors
986 size = bbGetInputNbPoints();
987 size2 = lstIndexsOut.size();
990 for (j=0;j<size2;j++)
992 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
993 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
994 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
996 lstIndexsIn.push_back( size2 );
1001 lstIndexsOut.clear();
1002 //////////////////// Set Out DoubleContour = 1
1003 bbSetOutputLstContourPointsX( lstInX );
1004 bbSetOutputLstContourPointsY( lstInY );
1005 bbSetOutputLstContourPointsZ( lstInZ );
1006 bbSetOutputLstIndexsOut( lstIndexsIn );
1007 bbSetOutputLstPssblIncnsnstntCntrY( lstInconsistentContourY );
1008 bbSetOutputLstPssblIncnsnstntCntrID( lstInconsistentContourID );
1009 } // if DoubleContour
1014 // 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)
1016 void ManualContourModel_Box::bbUserSetDefaultValues()
1018 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
1019 // Here we initialize the input 'In' to 0
1020 bbSetInputActive(true);
1022 bbSetInputDoubleContour(0);
1023 bbSetInputOpenClose(false);
1024 bbSetInputOpenClose2(false);
1025 bbSetInputNbPoints(100);
1029 // 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)
1031 void ManualContourModel_Box::bbUserInitializeProcessing()
1033 // THE INITIALIZATION METHOD BODY :
1034 // Here does nothing
1035 // but this is where you should allocate the internal/output pointers
1040 // 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)
1042 void ManualContourModel_Box::bbUserFinalizeProcessing()
1044 // THE FINALIZATION METHOD BODY :
1045 // Here does nothing
1046 // but this is where you should desallocate the internal/output pointers
1050 } // EO namespace bbcreaMaracasVisu