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 ;
235 double ManualContourModel_Box::SizeContour( std::vector<double> *lstX,
236 std::vector<double> *lstY,
237 std::vector<double> *lstZ)
244 int iSize = (*lstX).size() - 1;
245 for ( i=0 ; i<iSize ; i++ )
247 dx = (*lstX)[i+1]-(*lstX)[i];
248 dy = (*lstY)[i+1]-(*lstY)[i];
249 dz = (*lstZ)[i+1]-(*lstZ)[i];
250 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
256 void ManualContourModel_Box::Redistribution_SIN( double alpha,
258 std::vector<double> *lstC1X,
259 std::vector<double> *lstC1Y,
260 std::vector<double> *lstC1Z,
261 double sizeOfContour,
262 std::vector<double> *lstC2X,
263 std::vector<double> *lstC2Y,
264 std::vector<double> *lstC2Z )
266 std::vector<double> lstRstX;
267 std::vector<double> lstRstY;
268 std::vector<double> lstRstZ;
270 int size,iGeneralPlusSize;
274 double dist2,distSeg;
280 dist = sizeOfContour;
284 // for (iLstIndexOut=0; iLstIndexOut<sizeLstIndexOut; iLstIndexOut++) // For each contour
289 // size = (*lstIndexsOut)[iLstIndexOut];
290 size = (*lstC1X).size();
291 iGeneralPlusSize = iGeneral+size;
295 // for ( i=iGeneral ; i<iGeneralPlusSize-1 ; i++ )
297 // dx = (*lstOutX)[i]-(*lstOutX)[i+1];
298 // dy = (*lstOutY)[i]-(*lstOutY)[i+1];
299 // dz = (*lstOutZ)[i]-(*lstOutZ)[i+1];
300 // dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
304 // delta = dist/(size-1);
306 for (i=iGeneral; i<iGeneralPlusSize;i++) // For each point of one contour
310 for (k=iGeneral; k<iGeneralPlusSize;k++) // Search inside
312 //if ( 385==(*lstOutY)[k] )
314 t = ((double)ii) / ((double)(size-1));
315 // Beta = 0.20; // [0..1]
316 // Alpha = 0.0; // [0..1]
317 // Beta = bbGetInputParam()[0];
318 // Alpha = bbGetInputParam()[1];
319 tt = t + 0.70710678182*sin(t*TwoPI)*beta + alpha;
320 if (tt>1) { tt=tt-1; }
321 if (tt<0) { tt=tt+1; }
322 iiByDelta = tt * dist;
324 // iiByDelta = ii*delta;
327 // dx = (*lstOutX)[k+1]-(*lstOutX)[k];
328 // dy = (*lstOutY)[k+1]-(*lstOutY)[k];
329 // dz = (*lstOutZ)[k+1]-(*lstOutZ)[k];
330 dx = (*lstC1X)[k+1]-(*lstC1X)[k];
331 dy = (*lstC1Y)[k+1]-(*lstC1Y)[k];
332 dz = (*lstC1Z)[k+1]-(*lstC1Z)[k];
333 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
334 if ( dist2+distSeg >= iiByDelta )
340 dd=(iiByDelta-dist2)/distSeg;
342 lstRstX.push_back( (*lstC1X)[k] + dd*dx );
343 lstRstY.push_back( (*lstC1Y)[k] + dd*dy );
344 lstRstZ.push_back( (*lstC1Z)[k] + dd*dz );
345 if (ii==0) { firstK=k; }
346 k = iGeneralPlusSize-1;
348 if ( k==iGeneral+size-2 )
351 lstRstX.push_back( (*lstC1X)[k] + dd*dx );
352 lstRstY.push_back( (*lstC1Y)[k] + dd*dy );
353 lstRstZ.push_back( (*lstC1Z)[k] + dd*dz );
356 dist2 = dist2 + distSeg;
359 if (lstRstX.size()!=size)
361 printf("EED Warnning! ManualContourModel_Box::Redistribution_SIN >> This list is not coherent lstRstX.size()=%d size=%d\n", lstRstX.size(), size);
366 for (i=iGeneral; i<iGeneralPlusSize;i++)
368 (*lstC2X).push_back(-1);
369 (*lstC2Y).push_back(-1);
370 (*lstC2Z).push_back(-1);
373 for (i=iGeneral; i<iGeneralPlusSize;i++)
376 iii = iGeneral+ ( (i-iGeneral) + firstK) % size ;
377 // (*lstOutX)[iii] = lstRstX[ii];
378 // (*lstOutY)[iii] = lstRstY[ii];
379 // (*lstOutZ)[iii] = lstRstZ[ii];
380 (*lstC2X)[iii] = lstRstX[ii];
381 (*lstC2Y)[iii] = lstRstY[ii];
382 (*lstC2Z)[iii] = lstRstZ[ii];
385 for (i=0; i<size ; i++)
387 (*lstC2X)[i] = (*lstC1X)[i];
388 (*lstC2Y)[i] = (*lstC1Y)[i];
389 (*lstC2Z)[i] = (*lstC1Z)[i];
392 // iGeneral=iGeneral+size;
393 // }// for iLstIndexOut
396 void ManualContourModel_Box::CopyContour2InContour1(
397 std::vector<double> *lstInX,
398 std::vector<double> *lstInY,
399 std::vector<double> *lstInZ,
400 std::vector<double> *lstOutX,
401 std::vector<double> *lstOutY,
402 std::vector<double> *lstOutZ )
404 int i,sizeLstInX=(*lstInX).size();
408 for ( i=0 ; i<sizeLstInX ; i++ )
410 (*lstOutX).push_back( (*lstInX)[i] );
411 (*lstOutY).push_back( (*lstInY)[i] );
412 (*lstOutZ).push_back( (*lstInZ)[i] );
416 double ManualContourModel_Box::IntegralDistanceTwoContours(std::vector<double> *lstTmpAX,
417 std::vector<double> *lstTmpAY,
418 std::vector<double> *lstTmpAZ,
419 std::vector<double> *lstTmpBX,
420 std::vector<double> *lstTmpBY,
421 std::vector<double> *lstTmpBZ )
428 int iSize = (*lstTmpAX).size();
429 for ( i=0 ; i<iSize ; i++ )
431 dx = (*lstTmpAX)[i]-(*lstTmpBX)[i];
432 dy = (*lstTmpAY)[i]-(*lstTmpBY)[i];
433 dz = (*lstTmpAZ)[i]-(*lstTmpBZ)[i];
434 dist = dist + sqrt( dx*dx + dy*dy + dz*dz );
440 void ManualContourModel_Box::RedistributionPointsAllContours_SIN( std::vector<double> *lstOutX,
441 std::vector<double> *lstOutY,
442 std::vector<double> *lstOutZ,
443 std::vector<int> *lstIndexsOut )
445 printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN start\n");
446 std::vector<double> lstTmp1X;
447 std::vector<double> lstTmp1Y;
448 std::vector<double> lstTmp1Z;
449 std::vector<double> lstTmp2X;
450 std::vector<double> lstTmp2Y;
451 std::vector<double> lstTmp2Z;
452 std::vector<double> lstTmp2aX;
453 std::vector<double> lstTmp2aY;
454 std::vector<double> lstTmp2aZ;
455 std::vector<double> lstTmp2bX;
456 std::vector<double> lstTmp2bY;
457 std::vector<double> lstTmp2bZ;
458 std::vector<double> lstTmp2cX;
459 std::vector<double> lstTmp2cY;
460 std::vector<double> lstTmp2cZ;
461 std::vector<double> lstTmp3X;
462 std::vector<double> lstTmp3Y;
463 std::vector<double> lstTmp3Z;
464 std::vector<int> lstContourExeption;
466 double nbContours = (*lstIndexsOut).size();
476 // ------------ Wave 1 -----------------
478 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,0,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
479 sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
482 for ( iContour=0; iContour<nbContours-1 ; iContour++ )
484 printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN iContour=%d\n",iContour);
488 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
489 sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
491 if (iContour+2<nbContours)
493 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+2 ,&lstTmp3X,&lstTmp3Y,&lstTmp3Z );
494 sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z );
499 if ( (sizeContour1>sizeContour2) && (sizeContour2>sizeContour3) )
503 minDistAcum = 999999999;
504 for (iAlpha=0 ; iAlpha<1; iAlpha=iAlpha+0.1 )
506 Redistribution_SIN( iAlpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
507 distAcum = IntegralDistanceTwoContours( &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
508 if (distAcum<minDistAcum)
511 minDistAcum = distAcum;
515 minDistAcum = 999999999;
516 for (iBeta=0.0 ; iBeta<0.2; iBeta=iBeta+0.01)
518 Redistribution_SIN( alpha,iBeta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
519 distAcum = IntegralDistanceTwoContours( &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
520 if (distAcum<minDistAcum)
523 minDistAcum = distAcum;
527 } //if sizeContour1>sizeContour2>sizeContour3
529 if ( (sizeContour1>sizeContour2) && (sizeContour2<sizeContour3) )
531 lstContourExeption.push_back( iContour+1 );
538 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
540 // if(lstTmp2Y[0]==385) { alpha=bbGetInputParam()[1]; beta=bbGetInputParam()[2]; printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN ---385-- \n"); }
541 printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN wve 1 alpha=%f beta=%f z=%f sc1=%f sc2=%f\n",alpha,beta,lstTmp2Y[0], sizeContour1,sizeContour2 );
543 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour+1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
544 sizeContour1 = sizeContour2;
545 CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
553 // ------------ Wave 2 -----------------
555 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,nbContours-1,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
556 sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
559 for ( iContour=nbContours-1; iContour>=0 ; iContour-- )
561 printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN iContour=%d\n",iContour);
565 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
566 sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
571 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour-2 ,&lstTmp3X,&lstTmp3Y,&lstTmp3Z );
572 sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z );
577 if ( (sizeContour1>sizeContour2) && (sizeContour2>sizeContour3) ){
580 minDistAcum = 999999999;
581 for (iAlpha=0 ; iAlpha<1; iAlpha=iAlpha+0.1 )
583 Redistribution_SIN( iAlpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
584 distAcum = IntegralDistanceTwoContours( &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
585 if (distAcum<minDistAcum)
588 minDistAcum = distAcum;
592 minDistAcum = 999999999;
593 for (iBeta=0.0 ; iBeta<0.2; iBeta=iBeta+0.01)
595 Redistribution_SIN( alpha,iBeta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
596 distAcum = IntegralDistanceTwoContours( &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
597 if (distAcum<minDistAcum)
600 minDistAcum = distAcum;
604 } //if sizeContour1>sizeContour2>sizeContour3
608 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
610 // if(lstTmp2Y[0]==385) { alpha=bbGetInputParam()[1]; beta=bbGetInputParam()[2]; printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN ---385-- \n"); }
611 printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN wave 2 alpha=%f beta=%f z=%f sc1=%f sc2=%f\n",alpha,beta,lstTmp2Y[0], sizeContour1,sizeContour2 );
613 PutPointsInContour(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ, iContour-1 ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
614 sizeContour1 = sizeContour2;
615 CopyContour2InContour1( &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
621 // ------------ Wave 3 -----------------
623 printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN wave3 los que faltan");
624 double iExtra,sizeExtra=lstContourExeption.size();
625 for ( iExtra=0 ; iExtra<sizeExtra ; iExtra++ )
627 printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN wave3 los que faltan %d \n", lstContourExeption[iExtra] );
629 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, lstContourExeption[iExtra]-1 , &lstTmp1X,&lstTmp1Y,&lstTmp1Z);
630 sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
631 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, lstContourExeption[iExtra] , &lstTmp2X,&lstTmp2Y,&lstTmp2Z);
632 sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
633 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut, lstContourExeption[iExtra]+1 , &lstTmp3X,&lstTmp3Y,&lstTmp3Z);
634 sizeContour3 = SizeContour( &lstTmp3X, &lstTmp3Y, &lstTmp3Z );
638 minDistAcum = 999999999;
639 for (iAlpha=0 ; iAlpha<1; iAlpha=iAlpha+0.1 )
641 Redistribution_SIN( iAlpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
642 distAcum = IntegralDistanceTwoContours( &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
643 if (distAcum<minDistAcum)
646 minDistAcum = distAcum;
650 minDistAcum = 999999999;
651 for (iBeta=0.0 ; iBeta<0.2; iBeta=iBeta+0.01)
653 Redistribution_SIN( alpha,iBeta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
654 distAcum = IntegralDistanceTwoContours( &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
655 if (distAcum<minDistAcum)
658 minDistAcum = distAcum;
661 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2aX,&lstTmp2aY,&lstTmp2aZ );
666 minDistAcum = 999999999;
667 for (iAlpha=0 ; iAlpha<1; iAlpha=iAlpha+0.1 )
669 Redistribution_SIN( iAlpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2bX,&lstTmp2bY,&lstTmp2bZ );
670 distAcum = IntegralDistanceTwoContours( &lstTmp3X,&lstTmp3Y,&lstTmp3Z , &lstTmp2bX,&lstTmp2bY,&lstTmp2bZ );
671 if (distAcum<minDistAcum)
674 minDistAcum = distAcum;
678 minDistAcum = 999999999;
679 for (iBeta=0.0 ; iBeta<0.2; iBeta=iBeta+0.01)
681 Redistribution_SIN( alpha,iBeta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2bX,&lstTmp2bY,&lstTmp2bZ );
682 distAcum = IntegralDistanceTwoContours( &lstTmp3X,&lstTmp3Y,&lstTmp3Z , &lstTmp2bX,&lstTmp2bY,&lstTmp2bZ );
683 if (distAcum<minDistAcum)
686 minDistAcum = distAcum;
689 Redistribution_SIN( alpha,beta, &lstTmp2X,&lstTmp2Y,&lstTmp2Z ,sizeContour2, &lstTmp2bX,&lstTmp2bY,&lstTmp2bZ );
691 // Mixing2DistributionVectors(&lstTmp2aX,&lstTmp2aY,&lstTmp2aZ,&lstTmp2bX,&lstTmp2bY,&lstTmp2bZ, &lstTmp2cX,&lstTmp2cY,&lstTmp2cZ );
692 PutPointsInContour(&lstTmp2cX,&lstTmp2cY,&lstTmp2cZ, lstContourExeption[iExtra] ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
702 printf("ManualContourModel_Box::RedistributionPointsAllContours_SIN End\n");
708 void ManualContourModel_Box::RedistributionPoints_SIN_iContour(int iContour, std::vector<double> *lstOutX,
709 std::vector<double> *lstOutY,
710 std::vector<double> *lstOutZ,
711 std::vector<int> *lstIndexsOut,double alpha, double beta )
713 printf("EED ManualContourModel_Box::RedistributionPoints_SIN_iContour Start \n");
714 std::vector<double> lstRstX;
715 std::vector<double> lstRstY;
716 std::vector<double> lstRstZ;
717 int iLstIndexOut,sizeLstIndexOut = lstIndexsOut->size();
720 int size,iGeneralPlusSize;
721 double Alpha,Beta,t,tt, PI=3.14159265;
723 double dist=0,dist2,distSeg,delta;
727 double tmpX,tmpY,tmpZ;
729 for (iLstIndexOut=0; iLstIndexOut<sizeLstIndexOut; iLstIndexOut++) // For each contour
734 size = (*lstIndexsOut)[iLstIndexOut];
735 iGeneralPlusSize = iGeneral+size;
739 for ( i=iGeneral ; i<iGeneralPlusSize-1 ; i++ )
741 dx = (*lstOutX)[i]-(*lstOutX)[i+1];
742 dy = (*lstOutY)[i]-(*lstOutY)[i+1];
743 dz = (*lstOutZ)[i]-(*lstOutZ)[i+1];
744 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
746 delta = dist/(size-1);
749 for (i=iGeneral; i<iGeneralPlusSize;i++) // For each point of one contour
753 for (k=iGeneral; k<iGeneralPlusSize-1;k++) // Search inside
755 if ( 385==(*lstOutY)[k] )
757 t = ((double)ii) / ((double)(size-1));
758 Beta = 0.20; // [0..1]
759 Alpha = 0.0; // [0..1]
760 Beta = bbGetInputParam()[0];
761 Alpha = bbGetInputParam()[1];
762 tt = t + 0.70710678182*sin(t*TwoPI)*Beta + Alpha;
763 if (tt>1) { tt=tt-1; }
764 if (tt<0) { tt=tt+1; }
765 iiByDelta = tt * dist;
767 iiByDelta = ii*delta;
769 dx = (*lstOutX)[k+1]-(*lstOutX)[k];
770 dy = (*lstOutY)[k+1]-(*lstOutY)[k];
771 dz = (*lstOutZ)[k+1]-(*lstOutZ)[k];
772 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
773 if ( dist2+distSeg >= iiByDelta )
779 dd=(iiByDelta-dist2)/distSeg;
781 lstRstX.push_back( (*lstOutX)[k] + dd*dx );
782 lstRstY.push_back( (*lstOutY)[k] + dd*dy );
783 lstRstZ.push_back( (*lstOutZ)[k] + dd*dz );
784 if (ii==0) { firstK=k; }
785 k = iGeneralPlusSize-1;
787 if ( k==iGeneral+size-2 )
790 lstRstX.push_back( (*lstOutX)[k] + dd*dx );
791 lstRstY.push_back( (*lstOutY)[k] + dd*dy );
792 lstRstZ.push_back( (*lstOutZ)[k] + dd*dz );
795 dist2 = dist2+distSeg;
800 if (lstRstX.size()!=size)
802 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size);
803 tmpX = lstRstX[iGeneral];
804 tmpY = lstRstY[iGeneral];
805 tmpZ = lstRstZ[iGeneral];
806 lstRstX.push_back( tmpX );
807 lstRstY.push_back( tmpY );
808 lstRstZ.push_back( tmpZ );
811 for (i=iGeneral; i<iGeneralPlusSize;i++)
813 // ii=( (i-iGeneral) + firstK) % size ;
815 iii=iGeneral+ ( (i-iGeneral) + firstK) % size ;
816 (*lstOutX)[iii] = lstRstX[ii];
817 (*lstOutY)[iii] = lstRstY[ii];
818 (*lstOutZ)[iii] = lstRstZ[ii];
821 iGeneral=iGeneral+size;
824 printf("EED ManualContourModel_Box::RedistributionPoints_SIN_iContour End \n");
830 void ManualContourModel_Box::ClockwisePoints( std::vector<double> *lstInX,
831 std::vector<double> *lstInY,
832 std::vector<double> *lstInZ,
833 std::vector<int> *lstIndexsIn )
835 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
840 double backpx,backpy,backpz;
849 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn; iLstIndexIn++)
851 // Step 1. Find gravity center and direction
852 size = (*lstIndexsIn)[iLstIndexIn];
853 if (size>2) // for contour with more than 2 points
861 for ( i=0 ; i<size ; i++ )
863 px=(*lstInX)[iGeneral+i];
864 py=(*lstInY)[iGeneral+i];
865 pz=(*lstInZ)[iGeneral+i];
871 if (backpx!=px) { dirx=false; }
872 if (backpy!=py) { diry=false; }
873 if (backpz!=pz) { dirz=false; }
885 if (dirx==true) { dir=1; } // YZ
886 if (diry==true) { dir=2; } // XZ
887 if (dirz==true) { dir=0; } // XZ
888 // Step 2. Find angle diference find
890 for ( i=0 ; i<size ; i++ )
892 px = (*lstInX)[iGeneral+i]-cx;
893 py = (*lstInY)[iGeneral+i]-cy;
894 pz = (*lstInZ)[iGeneral+i]-cz;
895 if (dir==0) { ang=atan2( py , px ); } // XY
896 if (dir==1) { ang=atan2( pz , py ); } // YZ
897 if (dir==2) { ang=atan2( pz , px ); } // XZ
911 // Step 3. Invert order of points
915 for ( i=0 ; i<size2 ; i++ )
917 tmp = (*lstInX)[iGeneral+i];
918 (*lstInX)[iGeneral+i] = (*lstInX)[iGeneral+size-1-i];
919 (*lstInX)[iGeneral+size-1-i] = tmp;
920 tmp = (*lstInY)[iGeneral+i];
921 (*lstInY)[iGeneral+i] = (*lstInY)[iGeneral+size-1-i];
922 (*lstInY)[iGeneral+size-1-i] = tmp;
923 tmp = (*lstInZ)[iGeneral+i];
924 (*lstInZ)[iGeneral+i] = (*lstInZ)[iGeneral+size-1-i];
925 (*lstInZ)[iGeneral+size-1-i] = tmp;
929 iGeneral = iGeneral+size;
935 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
936 std::vector<double> *lstInY,
937 std::vector<double> *lstInZ,
938 std::vector<int> *lstIndexsIn )
940 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
947 std::vector<double> LstTmpX;
948 std::vector<double> LstTmpY;
949 std::vector<double> LstTmpZ;
950 if (sizeLstIndexIn>=2)
953 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
955 size = (*lstIndexsIn)[iLstIndexIn];
956 size2 = (*lstIndexsIn)[iLstIndexIn+1];
957 //find min distance and iBack
962 for (ig=0; ig<size; ig++)
964 for ( i=0 ; i<size2 ; i++ )
966 dx = (*lstInX)[iGeneral+ig]-(*lstInX)[iGeneral+size+i];
967 dy = (*lstInY)[iGeneral+ig]-(*lstInY)[iGeneral+size+i];
968 dz = (*lstInZ)[iGeneral+ig]-(*lstInZ)[iGeneral+size+i];
969 dist= sqrt( dx*dx + dy*dy + dz*dz );
981 iBack = iBack + size2;
984 printf("EED ManualContourModel_Box::ShiftValues px=%f py=%f pz=%f iBack=%d/%d size=%d distMin=%f \n", (*lstInX)[iGeneral] , (*lstInY)[iGeneral] , (*lstInZ)[iGeneral], iBack, size2,size, distMin);
991 for (i=0 ; i<size2 ; i++)
994 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
995 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
996 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
998 for (i=0 ; i<size2 ; i++)
1000 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
1001 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
1002 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
1005 iGeneral=iGeneral+size;
1006 } // for iLstIndexIn
1012 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
1014 size = (*lstIndexsIn)[iLstIndexIn];
1015 size2 = (*lstIndexsIn)[iLstIndexIn+1];
1016 //find min distance and iBack
1021 // for (ig=0; ig<size; ig++)
1023 for ( i=0 ; i<size2 ; i++ )
1025 dx = (*lstInX)[iGeneral]-(*lstInX)[iGeneral+size+i];
1026 dy = (*lstInY)[iGeneral]-(*lstInY)[iGeneral+size+i];
1027 dz = (*lstInZ)[iGeneral]-(*lstInZ)[iGeneral+size+i];
1028 dist= sqrt( dx*dx + dy*dy + dz*dz );
1038 printf("EED ManualContourModel_Box::ShiftValues px=%f py=%f pz=%f iBack=%d/%d size=%d distMin=%f \n", (*lstInX)[iGeneral] , (*lstInY)[iGeneral] , (*lstInZ)[iGeneral], iBack, size2,size, distMin);
1045 for (i=0 ; i<size2 ; i++)
1047 ii= (i+iBack)%size2;
1048 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
1049 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
1050 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
1052 for (i=0 ; i<size2 ; i++)
1054 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
1055 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
1056 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
1059 iGeneral=iGeneral+size;
1060 } // for iLstIndexIn
1062 } // if sizeLstIndexIn
1069 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
1070 std::vector<double> *lstInY,
1071 std::vector<double> *lstInZ,
1072 std::vector<int> *lstIndexsIn )
1074 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
1077 double dist,distMin;
1081 std::vector<double> LstTmpX;
1082 std::vector<double> LstTmpY;
1083 std::vector<double> LstTmpZ;
1084 if (sizeLstIndexIn>=2)
1089 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
1091 size = (*lstIndexsIn)[iLstIndexIn];
1092 size2 = (*lstIndexsIn)[iLstIndexIn+1];
1093 //find min distance and iBack
1097 // Comparing distance between two contours
1098 // Both contours need the same size
1099 for (ig=0; ig<size; ig++)
1102 for ( i=0 ; i<size2 ; i++ )
1104 dx = (*lstInX)[iGeneral+i]-(*lstInX)[iGeneral+size+(i+ig)%size];
1105 dy = (*lstInY)[iGeneral+i]-(*lstInY)[iGeneral+size+(i+ig)%size];
1106 dz = (*lstInZ)[iGeneral+i]-(*lstInZ)[iGeneral+size+(i+ig)%size];
1107 dist= dist + sqrt( dx*dx + dy*dy + dz*dz );
1119 //printf("EED ManualContourModel_Box::ShiftValues px=%f py=%f pz=%f iBack=%d/%d size=%d distMin=%f \n", (*lstInX)[iGeneral] , (*lstInY)[iGeneral] , (*lstInZ)[iGeneral], iBack, size2,size, distMin);
1126 for (i=0 ; i<size2 ; i++)
1128 ii = (i+iBack)%size2;
1129 if (ii<(size2-1)) // Skip the last item
1131 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
1132 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
1133 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
1137 //Repeat the first item at the end to close the contour
1138 LstTmpX.push_back( LstTmpX[0] );
1139 LstTmpY.push_back( LstTmpY[0] );
1140 LstTmpZ.push_back( LstTmpZ[0] );
1142 for (i=0 ; i<size2 ; i++)
1144 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
1145 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
1146 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
1149 iGeneral=iGeneral+size;
1150 } // for iLstIndexIn
1153 } // if sizeLstIndexIn
1162 void ManualContourModel_Box::Process()
1164 // THE MAIN PROCESSING METHOD BODY
1165 // Here we simply set the input 'In' value to the output 'Out'
1166 // And print out the output value
1167 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
1168 // void bbSet{Input|Output}NAME(const TYPE&)
1169 // const TYPE& bbGet{Input|Output}NAME() const
1171 // * NAME is the name of the input/output
1172 // (the one provided in the attribute 'name' of the tag 'input')
1173 // * TYPE is the C++ type of the input/output
1174 // (the one provided in the attribute 'type' of the tag 'input')
1176 // bbSetOutputOut( bbGetInputIn() );
1177 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
1179 // First Step Spline Interpolation
1180 std::vector<double> lstInX=bbGetInputLstControlPointsX();
1181 std::vector<double> lstInY=bbGetInputLstControlPointsY();
1182 std::vector<double> lstInZ=bbGetInputLstControlPointsZ();
1183 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
1185 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
1188 std::vector<int> lstIndexsIn=bbGetInputLstIndexsIn();
1189 std::vector<int> lstIndexsOut;
1190 std::vector<double> lstOutX;
1191 std::vector<double> lstOutY;
1192 std::vector<double> lstOutZ;
1193 if (bbGetInputLstIndexsIn().size()==0)
1195 lstIndexsIn.push_back( lstInX.size() );
1198 // Step 1. All contours the same clockwise direction (Control Points)
1199 if (bbGetInputDoubleContour()==1)
1201 ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
1202 // ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
1204 int i,size=lstIndexsIn.size();
1207 // Step 2. Spline interpolation of control points
1208 for (i=0;i<size;i++)
1210 ProcessBySegment( bbGetInputType() ,
1211 iGeneral, lstIndexsIn[i] ,
1212 &lstInX , &lstInY , &lstInZ,
1213 &lstOutX , &lstOutY , &lstOutZ,
1214 &lstIndexsOut,bbGetInputOpenClose() );
1217 if (bbGetInputDoubleContour()==0)
1219 // Finish if Simple contours
1220 //////////////////// Set Out DoubleContour = 0
1221 bbSetOutputLstContourPointsX(lstOutX);
1222 bbSetOutputLstContourPointsY(lstOutY);
1223 bbSetOutputLstContourPointsZ(lstOutZ);
1224 bbSetOutputLstIndexsOut(lstIndexsOut);
1226 // Step 3. Interpolation in the other direction
1227 // Step 3.1 Linear Normalice points around contours
1228 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
1230 // Step 3.2 Shift points to find minimun acumulate distance
1231 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
1232 // Step 3.3. SIN Normalice points around contours
1233 // RedistributionPoints_SIN_iContour(-1, &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut,-1,-1);
1235 if (bbGetInputParam()[0]==1)
1237 RedistributionPointsAllContours_SIN( &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
1239 // Step 3.4 Transpose the vectors
1243 lstIndexsIn.clear();
1244 size = bbGetInputNbPoints();
1245 int j,size2 = lstIndexsOut.size();
1246 for (i=0;i<size;i++)
1248 for (j=0;j<size2;j++)
1250 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
1251 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
1252 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
1254 lstIndexsIn.push_back( size2 );
1259 lstIndexsOut.clear();
1260 // Step 3.5 Interponation 2
1261 size=lstIndexsIn.size();
1263 for (i=0;i<size;i++)
1265 ProcessBySegment( bbGetInputType() ,
1266 iGeneral, lstIndexsIn[i] ,
1267 &lstInX,&lstInY,&lstInZ,
1268 &lstOutX,&lstOutY,&lstOutZ,
1269 &lstIndexsOut,bbGetInputOpenClose2());
1271 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
1272 // Step 3.6 Transpose the vectors
1276 lstIndexsIn.clear();
1277 size = bbGetInputNbPoints();
1278 size2 = lstIndexsOut.size();
1279 for (i=0;i<size;i++)
1281 for (j=0;j<size2;j++)
1283 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
1284 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
1285 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
1287 lstIndexsIn.push_back( size2 );
1292 lstIndexsOut.clear();
1293 //////////////////// Set Out DoubleContour = 1
1294 bbSetOutputLstContourPointsX(lstInX);
1295 bbSetOutputLstContourPointsY(lstInY);
1296 bbSetOutputLstContourPointsZ(lstInZ);
1297 bbSetOutputLstIndexsOut(lstIndexsIn);
1299 } // if DoubleContour
1303 // 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)
1305 void ManualContourModel_Box::bbUserSetDefaultValues()
1308 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
1309 // Here we initialize the input 'In' to 0
1311 bbSetInputDoubleContour(0);
1312 bbSetInputOpenClose(false);
1313 bbSetInputOpenClose2(false);
1314 bbSetInputNbPoints(100);
1318 // 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)
1320 void ManualContourModel_Box::bbUserInitializeProcessing()
1323 // THE INITIALIZATION METHOD BODY :
1324 // Here does nothing
1325 // but this is where you should allocate the internal/output pointers
1331 // 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)
1333 void ManualContourModel_Box::bbUserFinalizeProcessing()
1336 // THE FINALIZATION METHOD BODY :
1337 // Here does nothing
1338 // but this is where you should desallocate the internal/output pointers
1343 // EO namespace bbcreaMaracasVisu