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 iGeneralPlusSize = (*lstOutIndexs)[0];
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. \n");
222 for ( i=iGeneral ; i<iGeneralPlusSize ; i++ )
224 (*lstOutX)[i] = -9999 ;
225 (*lstOutY)[i] = -9999 ;
226 (*lstOutZ)[i] = -9999 ;
233 double ManualContourModel_Box::SizeContour( std::vector<double> *lstX,
234 std::vector<double> *lstY,
235 std::vector<double> *lstZ)
242 int iSize = (*lstX).size() - 1;
243 for ( i=0 ; i<iSize ; i++ )
245 dx = (*lstX)[i+1]-(*lstX)[i];
246 dy = (*lstY)[i+1]-(*lstY)[i];
247 dz = (*lstZ)[i+1]-(*lstZ)[i];
248 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
254 void ManualContourModel_Box::Redistribution_SIN( double alpha,
256 std::vector<double> *lstC1X,
257 std::vector<double> *lstC1Y,
258 std::vector<double> *lstC1Z,
259 double sizeOfContour,
260 std::vector<double> *lstC2X,
261 std::vector<double> *lstC2Y,
262 std::vector<double> *lstC2Z )
264 printf("EED ManualContourModel_Box::Redistribution_SIN Start \n");
265 std::vector<double> lstRstX;
266 std::vector<double> lstRstY;
267 std::vector<double> lstRstZ;
270 int size,iGeneralPlusSize;
271 double Alpha,Beta,t,tt, PI=3.14159265;
273 double dist=sizeOfContour;
274 double dist2,distSeg,delta;
278 double tmpX,tmpY,tmpZ;
280 // for (iLstIndexOut=0; iLstIndexOut<sizeLstIndexOut; iLstIndexOut++) // For each contour
285 // size = (*lstIndexsOut)[iLstIndexOut];
286 size = (*lstInX).size();
287 iGeneralPlusSize = iGeneral+size;
291 // for ( i=iGeneral ; i<iGeneralPlusSize-1 ; i++ )
293 // dx = (*lstOutX)[i]-(*lstOutX)[i+1];
294 // dy = (*lstOutY)[i]-(*lstOutY)[i+1];
295 // dz = (*lstOutZ)[i]-(*lstOutZ)[i+1];
296 // dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
298 delta = dist/(size-1);
301 for (i=iGeneral; i<iGeneralPlusSize;i++) // For each point of one contour
305 for (k=iGeneral; k<iGeneralPlusSize-1;k++) // Search inside
307 //if ( 385==(*lstOutY)[k] )
309 t = ((double)ii) / ((double)(size-1));
310 // Beta = 0.20; // [0..1]
311 // Alpha = 0.0; // [0..1]
312 // Beta = bbGetInputParam()[0];
313 // Alpha = bbGetInputParam()[1];
314 tt = t + 0.70710678182*sin(t*TwoPI)*beta + alpha;
315 if (tt>1) { tt=tt-1; }
316 if (tt<0) { tt=tt+1; }
317 iiByDelta = tt * dist;
319 // iiByDelta = ii*delta;
322 // dx = (*lstOutX)[k+1]-(*lstOutX)[k];
323 // dy = (*lstOutY)[k+1]-(*lstOutY)[k];
324 // dz = (*lstOutZ)[k+1]-(*lstOutZ)[k];
325 dx = (*lstC1X)[k+1]-(*lstC1X)[k];
326 dy = (*lstC1Y)[k+1]-(*lstC1Y)[k];
327 dz = (*lstC1Z)[k+1]-(*lstC1Z)[k];
328 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
329 if ( dist2+distSeg >= iiByDelta )
335 dd=(iiByDelta-dist2)/distSeg;
337 lstRstX.push_back( (*lstC1X)[k] + dd*dx );
338 lstRstY.push_back( (*lstC1Y)[k] + dd*dy );
339 lstRstZ.push_back( (*lstC1Z)[k] + dd*dz );
340 if (ii==0) { firstK=k; }
341 k = iGeneralPlusSize-1;
343 if ( k==iGeneral+size-2 )
346 lstRstX.push_back( (*lstC1X)[k] + dd*dx );
347 lstRstY.push_back( (*lstC1Y)[k] + dd*dy );
348 lstRstZ.push_back( (*lstC1Z)[k] + dd*dz );
351 dist2 = dist2+distSeg;
356 if (lstRstX.size()!=size)
358 printf("EED Warnning! ManualContourModel_Box::Redistribution_SIN >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size);
359 tmpX = lstRstX[iGeneral];
360 tmpY = lstRstY[iGeneral];
361 tmpZ = lstRstZ[iGeneral];
362 lstRstX.push_back( tmpX );
363 lstRstY.push_back( tmpY );
364 lstRstZ.push_back( tmpZ );
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 // iGeneral=iGeneral+size;
386 // }// for iLstIndexOut
387 printf("EED ManualContourModel_Box::Redistribution_SIN End \n");
391 void ManualContourModel_Box::CopyContour2InContour1(
392 std::vector<double> *lstInX,
393 std::vector<double> *lstInY,
394 std::vector<double> *lstInZ,
395 std::vector<double> *lstOutX,
396 std::vector<double> *lstOutY,
397 std::vector<double> *lstOutZ )
399 int i,sizeLstInX=(*lstInX).size();
403 for ( i=0 ; i<sizeLstInX ; i++ )
405 (*lstOutX).push_back( (*lstInX)[i] );
406 (*lstOutY).push_back( (*lstInY)[i] );
407 (*lstOutZ).push_back( (*lstInZ)[i] );
411 double ManualContourModel_Box::IntegralDistanceTwoContours(std::vector<double> *lstTmpAX,
412 std::vector<double> *lstTmpAY,
413 std::vector<double> *lstTmpAZ,
414 std::vector<double> *lstTmpBX,
415 std::vector<double> *lstTmpBY,
416 std::vector<double> *lstTmpBZ )
423 int iSize = (*lstTmpAX).size();
424 for ( i=0 ; i<iSize ; i++ )
426 dx = (*lstTmpAX)[i]-(*lstTmpBX)[i];
427 dy = (*lstTmpAY)[i]-(*lstTmpBY)[i];
428 dz = (*lstTmpAZ)[i]-(*lstTmpBZ)[i];
429 dist = dist + sqrt( dx*dx + dy*dy + dz*dz );
435 void ManualContourModel_Box::RedistributionPointsAllContours_SIN( std::vector<double> *lstOutX,
436 std::vector<double> *lstOutY,
437 std::vector<double> *lstOutZ,
438 std::vector<int> *lstIndexsOut )
440 std::vector<double> lstTmp1X;
441 std::vector<double> lstTmp1Y;
442 std::vector<double> lstTmp1Z;
443 std::vector<double> lstTmp2X;
444 std::vector<double> lstTmp2Y;
445 std::vector<double> lstTmp2Z;
446 std::vector<double> lstTmp1aX;
447 std::vector<double> lstTmp1aY;
448 std::vector<double> lstTmp1aZ;
450 double nbContours = (*lstIndexsOut).size()-1;
458 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,0,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
459 sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
462 for ( iContour=0; iContour<nbContours ; iContour++ )
466 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
467 sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
468 if (sizeContour1<sizeContour2){
470 minDistAcum=-999999999;
471 for (iAlpha=0.1 ; iAlpha<1; iAlpha=iAlpha+0.1)
473 Redistribution_SIN( alpha,beta, &lstTmp1X,&lstTmp1Y,&lstTmp1Z ,sizeContour1, &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ );
474 distAcum = IntegralDistanceTwoContours( &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ , &lstTmp2X,&lstTmp2Y,&lstTmp2Z );
475 if (distAcum<minDistAcum)
478 minDistAcum = distAcum;
482 for (iBeta=0.0 ; iBeta<0.2; iBeta=iBeta+0.01)
484 minDistAcum=-999999999;
485 Redistribution_SIN( alpha,beta, &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ );
486 distAcum = IntegralDistanceTwoContours( &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ , &lstTmp2X,&lstTmp2Y,&lstTmp2Z );
487 if (distAcum<minDistAcum)
490 minDistAcum = distAcum;
494 } //if sizeContour2<sizeContour1
496 Redistribution_SIN( alpha,beta, &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ );
497 double nn = SizeContour( &lstTmp1aX, &lstTmp1aY, &lstTmp1aZ );
498 PutPointsInContour(&lstTmp1aX,&lstTmp1aY,&lstTmp1aZ, iContour ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
499 sizeContour1 = sizeContour2;
500 CopyContour2InContour1( &lstTmp2X,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
506 void ManualContourModel_Box::RedistributionPoints_SIN_iContour(int iContour, std::vector<double> *lstOutX,
507 std::vector<double> *lstOutY,
508 std::vector<double> *lstOutZ,
509 std::vector<int> *lstIndexsOut,double alpha, double beta )
511 printf("EED ManualContourModel_Box::RedistributionPoints_SIN_iContour Start \n");
512 std::vector<double> lstRstX;
513 std::vector<double> lstRstY;
514 std::vector<double> lstRstZ;
515 int iLstIndexOut,sizeLstIndexOut = lstIndexsOut->size();
518 int size,iGeneralPlusSize;
519 double Alpha,Beta,t,tt, PI=3.14159265;
521 double dist=0,dist2,distSeg,delta;
525 double tmpX,tmpY,tmpZ;
527 for (iLstIndexOut=0; iLstIndexOut<sizeLstIndexOut; iLstIndexOut++) // For each contour
532 size = (*lstIndexsOut)[iLstIndexOut];
533 iGeneralPlusSize = iGeneral+size;
537 for ( i=iGeneral ; i<iGeneralPlusSize-1 ; i++ )
539 dx = (*lstOutX)[i]-(*lstOutX)[i+1];
540 dy = (*lstOutY)[i]-(*lstOutY)[i+1];
541 dz = (*lstOutZ)[i]-(*lstOutZ)[i+1];
542 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
544 delta = dist/(size-1);
547 for (i=iGeneral; i<iGeneralPlusSize;i++) // For each point of one contour
551 for (k=iGeneral; k<iGeneralPlusSize-1;k++) // Search inside
553 if ( 385==(*lstOutY)[k] )
555 t = ((double)ii) / ((double)(size-1));
556 Beta = 0.20; // [0..1]
557 Alpha = 0.0; // [0..1]
558 Beta = bbGetInputParam()[0];
559 Alpha = bbGetInputParam()[1];
560 tt = t + 0.70710678182*sin(t*TwoPI)*Beta + Alpha;
561 if (tt>1) { tt=tt-1; }
562 if (tt<0) { tt=tt+1; }
563 iiByDelta = tt * dist;
565 iiByDelta = ii*delta;
567 dx = (*lstOutX)[k+1]-(*lstOutX)[k];
568 dy = (*lstOutY)[k+1]-(*lstOutY)[k];
569 dz = (*lstOutZ)[k+1]-(*lstOutZ)[k];
570 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
571 if ( dist2+distSeg >= iiByDelta )
577 dd=(iiByDelta-dist2)/distSeg;
579 lstRstX.push_back( (*lstOutX)[k] + dd*dx );
580 lstRstY.push_back( (*lstOutY)[k] + dd*dy );
581 lstRstZ.push_back( (*lstOutZ)[k] + dd*dz );
582 if (ii==0) { firstK=k; }
583 k = iGeneralPlusSize-1;
585 if ( k==iGeneral+size-2 )
588 lstRstX.push_back( (*lstOutX)[k] + dd*dx );
589 lstRstY.push_back( (*lstOutY)[k] + dd*dy );
590 lstRstZ.push_back( (*lstOutZ)[k] + dd*dz );
593 dist2 = dist2+distSeg;
598 if (lstRstX.size()!=size)
600 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size);
601 tmpX = lstRstX[iGeneral];
602 tmpY = lstRstY[iGeneral];
603 tmpZ = lstRstZ[iGeneral];
604 lstRstX.push_back( tmpX );
605 lstRstY.push_back( tmpY );
606 lstRstZ.push_back( tmpZ );
609 for (i=iGeneral; i<iGeneralPlusSize;i++)
611 // ii=( (i-iGeneral) + firstK) % size ;
613 iii=iGeneral+ ( (i-iGeneral) + firstK) % size ;
614 (*lstOutX)[iii] = lstRstX[ii];
615 (*lstOutY)[iii] = lstRstY[ii];
616 (*lstOutZ)[iii] = lstRstZ[ii];
619 iGeneral=iGeneral+size;
622 printf("EED ManualContourModel_Box::RedistributionPoints_SIN_iContour End \n");
628 void ManualContourModel_Box::ClockwisePoints( std::vector<double> *lstInX,
629 std::vector<double> *lstInY,
630 std::vector<double> *lstInZ,
631 std::vector<int> *lstIndexsIn )
633 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
638 double backpx,backpy,backpz;
647 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn; iLstIndexIn++)
649 // Step 1. Find gravity center and direction
650 size = (*lstIndexsIn)[iLstIndexIn];
651 if (size>2) // for contour with more than 2 points
659 for ( i=0 ; i<size ; i++ )
661 px=(*lstInX)[iGeneral+i];
662 py=(*lstInY)[iGeneral+i];
663 pz=(*lstInZ)[iGeneral+i];
669 if (backpx!=px) { dirx=false; }
670 if (backpy!=py) { diry=false; }
671 if (backpz!=pz) { dirz=false; }
683 if (dirx==true) { dir=1; } // YZ
684 if (diry==true) { dir=2; } // XZ
685 if (dirz==true) { dir=0; } // XZ
686 // Step 2. Find angle diference find
688 for ( i=0 ; i<size ; i++ )
690 px = (*lstInX)[iGeneral+i]-cx;
691 py = (*lstInY)[iGeneral+i]-cy;
692 pz = (*lstInZ)[iGeneral+i]-cz;
693 if (dir==0) { ang=atan2( py , px ); } // XY
694 if (dir==1) { ang=atan2( pz , py ); } // YZ
695 if (dir==2) { ang=atan2( pz , px ); } // XZ
709 // Step 3. Invert order of points
713 for ( i=0 ; i<size2 ; i++ )
715 tmp = (*lstInX)[iGeneral+i];
716 (*lstInX)[iGeneral+i] = (*lstInX)[iGeneral+size-1-i];
717 (*lstInX)[iGeneral+size-1-i] = tmp;
718 tmp = (*lstInY)[iGeneral+i];
719 (*lstInY)[iGeneral+i] = (*lstInY)[iGeneral+size-1-i];
720 (*lstInY)[iGeneral+size-1-i] = tmp;
721 tmp = (*lstInZ)[iGeneral+i];
722 (*lstInZ)[iGeneral+i] = (*lstInZ)[iGeneral+size-1-i];
723 (*lstInZ)[iGeneral+size-1-i] = tmp;
727 iGeneral = iGeneral+size;
733 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
734 std::vector<double> *lstInY,
735 std::vector<double> *lstInZ,
736 std::vector<int> *lstIndexsIn )
738 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
745 std::vector<double> LstTmpX;
746 std::vector<double> LstTmpY;
747 std::vector<double> LstTmpZ;
748 if (sizeLstIndexIn>=2)
751 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
753 size = (*lstIndexsIn)[iLstIndexIn];
754 size2 = (*lstIndexsIn)[iLstIndexIn+1];
755 //find min distance and iBack
760 for (ig=0; ig<size; ig++)
762 for ( i=0 ; i<size2 ; i++ )
764 dx = (*lstInX)[iGeneral+ig]-(*lstInX)[iGeneral+size+i];
765 dy = (*lstInY)[iGeneral+ig]-(*lstInY)[iGeneral+size+i];
766 dz = (*lstInZ)[iGeneral+ig]-(*lstInZ)[iGeneral+size+i];
767 dist= sqrt( dx*dx + dy*dy + dz*dz );
779 iBack = iBack + size2;
782 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);
789 for (i=0 ; i<size2 ; i++)
792 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
793 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
794 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
796 for (i=0 ; i<size2 ; i++)
798 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
799 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
800 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
803 iGeneral=iGeneral+size;
810 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
812 size = (*lstIndexsIn)[iLstIndexIn];
813 size2 = (*lstIndexsIn)[iLstIndexIn+1];
814 //find min distance and iBack
819 // for (ig=0; ig<size; ig++)
821 for ( i=0 ; i<size2 ; i++ )
823 dx = (*lstInX)[iGeneral]-(*lstInX)[iGeneral+size+i];
824 dy = (*lstInY)[iGeneral]-(*lstInY)[iGeneral+size+i];
825 dz = (*lstInZ)[iGeneral]-(*lstInZ)[iGeneral+size+i];
826 dist= sqrt( dx*dx + dy*dy + dz*dz );
836 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);
843 for (i=0 ; i<size2 ; i++)
846 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
847 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
848 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
850 for (i=0 ; i<size2 ; i++)
852 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
853 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
854 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
857 iGeneral=iGeneral+size;
860 } // if sizeLstIndexIn
867 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
868 std::vector<double> *lstInY,
869 std::vector<double> *lstInZ,
870 std::vector<int> *lstIndexsIn )
872 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
879 std::vector<double> LstTmpX;
880 std::vector<double> LstTmpY;
881 std::vector<double> LstTmpZ;
882 if (sizeLstIndexIn>=2)
887 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
889 size = (*lstIndexsIn)[iLstIndexIn];
890 size2 = (*lstIndexsIn)[iLstIndexIn+1];
891 //find min distance and iBack
895 // Comparing distance between two contours
896 // Both contours need the same size
897 for (ig=0; ig<size; ig++)
900 for ( i=0 ; i<size2 ; i++ )
902 dx = (*lstInX)[iGeneral+i]-(*lstInX)[iGeneral+size+(i+ig)%size];
903 dy = (*lstInY)[iGeneral+i]-(*lstInY)[iGeneral+size+(i+ig)%size];
904 dz = (*lstInZ)[iGeneral+i]-(*lstInZ)[iGeneral+size+(i+ig)%size];
905 dist= dist + sqrt( dx*dx + dy*dy + dz*dz );
917 //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);
924 for (i=0 ; i<size2 ; i++)
926 ii = (i+iBack)%size2;
927 if (ii<(size2-1)) // Skip the last item
929 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
930 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
931 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
935 //Repeat the first item at the end to close the contour
936 LstTmpX.push_back( LstTmpX[0] );
937 LstTmpY.push_back( LstTmpY[0] );
938 LstTmpZ.push_back( LstTmpZ[0] );
940 for (i=0 ; i<size2 ; i++)
942 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
943 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
944 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
947 iGeneral=iGeneral+size;
951 } // if sizeLstIndexIn
960 void ManualContourModel_Box::Process()
962 // THE MAIN PROCESSING METHOD BODY
963 // Here we simply set the input 'In' value to the output 'Out'
964 // And print out the output value
965 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
966 // void bbSet{Input|Output}NAME(const TYPE&)
967 // const TYPE& bbGet{Input|Output}NAME() const
969 // * NAME is the name of the input/output
970 // (the one provided in the attribute 'name' of the tag 'input')
971 // * TYPE is the C++ type of the input/output
972 // (the one provided in the attribute 'type' of the tag 'input')
974 // bbSetOutputOut( bbGetInputIn() );
975 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
977 // First Step Spline Interpolation
978 std::vector<double> lstInX=bbGetInputLstControlPointsX();
979 std::vector<double> lstInY=bbGetInputLstControlPointsY();
980 std::vector<double> lstInZ=bbGetInputLstControlPointsZ();
981 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
983 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
986 std::vector<int> lstIndexsIn=bbGetInputLstIndexsIn();
987 std::vector<int> lstIndexsOut;
988 std::vector<double> lstOutX;
989 std::vector<double> lstOutY;
990 std::vector<double> lstOutZ;
991 if (bbGetInputLstIndexsIn().size()==0)
993 lstIndexsIn.push_back( lstInX.size() );
996 // Step 1. All contours the same clockwise direction (Control Points)
997 if (bbGetInputDoubleContour()==1)
999 ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
1000 // ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
1002 int i,size=lstIndexsIn.size();
1005 // Step 2. Spline interpolation of control points
1006 for (i=0;i<size;i++)
1008 ProcessBySegment( bbGetInputType() ,
1009 iGeneral, lstIndexsIn[i] ,
1010 &lstInX , &lstInY , &lstInZ,
1011 &lstOutX , &lstOutY , &lstOutZ,
1012 &lstIndexsOut,bbGetInputOpenClose() );
1015 if (bbGetInputDoubleContour()==0)
1017 // Finish if Simple contours
1018 //////////////////// Set Out DoubleContour = 0
1019 bbSetOutputLstContourPointsX(lstOutX);
1020 bbSetOutputLstContourPointsY(lstOutY);
1021 bbSetOutputLstContourPointsZ(lstOutZ);
1022 bbSetOutputLstIndexsOut(lstIndexsOut);
1024 // Step 3. Interpolation in the other direction
1025 // Step 3.1 Linear Normalice points around contours
1026 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
1028 // Step 3.2 Shift points to find minimun acumulate distance
1029 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
1030 // Step 3.3. SIN Normalice points around contours
1031 // RedistributionPoints_SIN_iContour(-1, &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut,-1,-1);
1033 if (bbGetInputParam()[0]==1)
1035 RedistributionPointsAllContours_SIN( &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
1037 // Step 3.4 Transpose the vectors
1041 lstIndexsIn.clear();
1042 size = bbGetInputNbPoints();
1043 int j,size2 = lstIndexsOut.size();
1044 for (i=0;i<size;i++)
1046 for (j=0;j<size2;j++)
1048 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
1049 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
1050 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
1052 lstIndexsIn.push_back( size2 );
1057 lstIndexsOut.clear();
1058 // Step 3.5 Interponation 2
1059 size=lstIndexsIn.size();
1061 for (i=0;i<size;i++)
1063 ProcessBySegment( bbGetInputType() ,
1064 iGeneral, lstIndexsIn[i] ,
1065 &lstInX,&lstInY,&lstInZ,
1066 &lstOutX,&lstOutY,&lstOutZ,
1067 &lstIndexsOut,bbGetInputOpenClose2());
1069 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
1070 // Step 3.6 Transpose the vectors
1074 lstIndexsIn.clear();
1075 size = bbGetInputNbPoints();
1076 size2 = lstIndexsOut.size();
1077 for (i=0;i<size;i++)
1079 for (j=0;j<size2;j++)
1081 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
1082 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
1083 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
1085 lstIndexsIn.push_back( size2 );
1090 lstIndexsOut.clear();
1091 //////////////////// Set Out DoubleContour = 1
1092 bbSetOutputLstContourPointsX(lstInX);
1093 bbSetOutputLstContourPointsY(lstInY);
1094 bbSetOutputLstContourPointsZ(lstInZ);
1095 bbSetOutputLstIndexsOut(lstIndexsIn);
1097 } // if DoubleContour
1101 // 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)
1103 void ManualContourModel_Box::bbUserSetDefaultValues()
1106 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
1107 // Here we initialize the input 'In' to 0
1109 bbSetInputDoubleContour(0);
1110 bbSetInputOpenClose(false);
1111 bbSetInputOpenClose2(false);
1112 bbSetInputNbPoints(100);
1116 // 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)
1118 void ManualContourModel_Box::bbUserInitializeProcessing()
1121 // THE INITIALIZATION METHOD BODY :
1122 // Here does nothing
1123 // but this is where you should allocate the internal/output pointers
1129 // 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)
1131 void ManualContourModel_Box::bbUserFinalizeProcessing()
1134 // THE FINALIZATION METHOD BODY :
1135 // Here does nothing
1136 // but this is where you should desallocate the internal/output pointers
1141 // EO namespace bbcreaMaracasVisu