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];
208 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 );
253 void ManualContourModel_Box::Redistribution_SIN( double alpha,
255 std::vector<double> *lstInX,
256 std::vector<double> *lstInY,
257 std::vector<double> *lstInZ,
258 std::vector<double> *lstOutX,
259 std::vector<double> *lstOutY,
260 std::vector<double> *lstOutZ )
262 int i,sizeLstInX=(*lstInX).size();
266 for ( i=0 ; i<sizeLstInX ; i++ )
268 (*lstOutX).push_back( (*lstInX)[i] );
269 (*lstOutY).push_back( (*lstInY)[i] );
270 (*lstOutZ).push_back( (*lstInZ)[i] );
274 void ManualContourModel_Box::CopyContour2InContour1(
275 std::vector<double> *lstInX,
276 std::vector<double> *lstInY,
277 std::vector<double> *lstInZ,
278 std::vector<double> *lstOutX,
279 std::vector<double> *lstOutY,
280 std::vector<double> *lstOutZ )
282 int i,sizeLstInX=(*lstInX).size();
286 for ( i=0 ; i<sizeLstInX ; i++ )
288 (*lstOutX).push_back( (*lstInX)[i] );
289 (*lstOutY).push_back( (*lstInY)[i] );
290 (*lstOutZ).push_back( (*lstInZ)[i] );
294 double ManualContourModel_Box::IntegralDistanceTwoContours(std::vector<double> *lstTmpAX,
295 std::vector<double> *lstTmpAY,
296 std::vector<double> *lstTmpAZ,
297 std::vector<double> *lstTmpBX,
298 std::vector<double> *lstTmpBY,
299 std::vector<double> *lstTmpBZ )
306 int iSize = (*lstTmpAX).size();
307 for ( i=0 ; i<iSize ; i++ )
309 dx = (*lstTmpAX)[i]-(*lstTmpBX)[i];
310 dy = (*lstTmpAY)[i]-(*lstTmpBY)[i];
311 dz = (*lstTmpAZ)[i]-(*lstTmpBZ)[i];
312 dist= dist+ sqrt( dx*dx + dy*dy + dz*dz );
318 void ManualContourModel_Box::RedistributionPointsAllContours_SIN( std::vector<double> *lstOutX,
319 std::vector<double> *lstOutY,
320 std::vector<double> *lstOutZ,
321 std::vector<int> *lstIndexsOut )
323 std::vector<double> lstTmp1X;
324 std::vector<double> lstTmp1Y;
325 std::vector<double> lstTmp1Z;
326 std::vector<double> lstTmp2X;
327 std::vector<double> lstTmp2Y;
328 std::vector<double> lstTmp2Z;
329 std::vector<double> lstTmp1aX;
330 std::vector<double> lstTmp1aY;
331 std::vector<double> lstTmp1aZ;
333 double nbContours = (*lstIndexsOut).size()-1;
341 ExtractContour(lstOutX,lstOutY,lstOutZ,lstIndexsOut,0,&lstTmp1X,&lstTmp1Y,&lstTmp1Z);
342 sizeContour1 = SizeContour( &lstTmp1X, &lstTmp1Y, &lstTmp1Z );
345 for ( iContour=0; iContour<nbContours ; iContour++ )
349 ExtractContour( lstOutX,lstOutY,lstOutZ,lstIndexsOut, iContour+1 ,&lstTmp2X,&lstTmp2Y,&lstTmp2Z );
350 sizeContour2 = SizeContour( &lstTmp2X, &lstTmp2Y, &lstTmp2Z );
351 if (sizeContour1<sizeContour2){
353 minDistAcum=-999999999;
354 for (iAlpha=0.1 ; iAlpha<1; iAlpha=iAlpha+0.1)
356 Redistribution_SIN( alpha,beta, &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ );
357 distAcum = IntegralDistanceTwoContours( &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ , &lstTmp2X,&lstTmp2Y,&lstTmp2Z );
358 if (distAcum<minDistAcum)
361 minDistAcum = distAcum;
365 for (iBeta=0.0 ; iBeta<0.2; iBeta=iBeta+0.01)
367 minDistAcum=-999999999;
368 Redistribution_SIN( alpha,beta, &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ );
369 distAcum = IntegralDistanceTwoContours( &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ , &lstTmp2X,&lstTmp2Y,&lstTmp2Z );
370 if (distAcum<minDistAcum)
373 minDistAcum = distAcum;
377 } //if sizeContour2<sizeContour1
379 Redistribution_SIN( alpha,beta, &lstTmp1X,&lstTmp1Y,&lstTmp1Z , &lstTmp1aX,&lstTmp1aY,&lstTmp1aZ );
380 double nn = SizeContour( &lstTmp1aX, &lstTmp1aY, &lstTmp1aZ );
381 PutPointsInContour(&lstTmp1aX,&lstTmp1aY,&lstTmp1aZ, iContour ,lstOutX,lstOutY,lstOutZ,lstIndexsOut);
382 sizeContour1 = sizeContour2;
383 CopyContour2InContour1( &lstTmp2X,&lstTmp2Y,&lstTmp2Z , &lstTmp1X,&lstTmp1Y,&lstTmp1Z );
389 void ManualContourModel_Box::RedistributionPoints_SIN_iContour(int iContour, std::vector<double> *lstOutX,
390 std::vector<double> *lstOutY,
391 std::vector<double> *lstOutZ,
392 std::vector<int> *lstIndexsOut,double alpha, double beta )
394 printf("EED ManualContourModel_Box::RedistributionPoints_SIN_iContour Start \n");
395 std::vector<double> lstRstX;
396 std::vector<double> lstRstY;
397 std::vector<double> lstRstZ;
398 int iLstIndexOut,sizeLstIndexOut = lstIndexsOut->size();
401 int size,iGeneralPlusSize;
402 double Alpha,Beta,t,tt, PI=3.14159265;
404 double dist=0,dist2,distSeg,delta;
408 double tmpX,tmpY,tmpZ;
410 for (iLstIndexOut=0; iLstIndexOut<sizeLstIndexOut; iLstIndexOut++) // For each contour
415 size = (*lstIndexsOut)[iLstIndexOut];
416 iGeneralPlusSize = iGeneral+size;
420 for ( i=iGeneral ; i<iGeneralPlusSize-1 ; i++ )
422 dx = (*lstOutX)[i]-(*lstOutX)[i+1];
423 dy = (*lstOutY)[i]-(*lstOutY)[i+1];
424 dz = (*lstOutZ)[i]-(*lstOutZ)[i+1];
425 dist= dist+sqrt( dx*dx + dy*dy + dz*dz );
427 delta = dist/(size-1);
430 for (i=iGeneral; i<iGeneralPlusSize;i++) // For each point of one contour
434 for (k=iGeneral; k<iGeneralPlusSize-1;k++) // Search inside
436 if ( 385==(*lstOutY)[k] )
438 t = ((double)ii) / ((double)(size-1));
439 Beta = 0.20; // [0..1]
440 Alpha = 0.0; // [0..1]
441 Beta = bbGetInputParam()[0];
442 Alpha = bbGetInputParam()[1];
443 tt = t + 0.70710678182*sin(t*TwoPI)*Beta + Alpha;
444 if (tt>1) { tt=tt-1; }
445 if (tt<0) { tt=tt+1; }
446 iiByDelta = tt * dist;
448 iiByDelta = ii*delta;
450 dx = (*lstOutX)[k+1]-(*lstOutX)[k];
451 dy = (*lstOutY)[k+1]-(*lstOutY)[k];
452 dz = (*lstOutZ)[k+1]-(*lstOutZ)[k];
453 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
454 if ( dist2+distSeg >= iiByDelta )
460 dd=(iiByDelta-dist2)/distSeg;
462 lstRstX.push_back( (*lstOutX)[k] + dd*dx );
463 lstRstY.push_back( (*lstOutY)[k] + dd*dy );
464 lstRstZ.push_back( (*lstOutZ)[k] + dd*dz );
465 if (ii==0) { firstK=k; }
466 k = iGeneralPlusSize-1;
468 if ( k==iGeneral+size-2 )
471 lstRstX.push_back( (*lstOutX)[k] + dd*dx );
472 lstRstY.push_back( (*lstOutY)[k] + dd*dy );
473 lstRstZ.push_back( (*lstOutZ)[k] + dd*dz );
476 dist2 = dist2+distSeg;
481 if (lstRstX.size()!=size)
483 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size);
484 tmpX = lstRstX[iGeneral];
485 tmpY = lstRstY[iGeneral];
486 tmpZ = lstRstZ[iGeneral];
487 lstRstX.push_back( tmpX );
488 lstRstY.push_back( tmpY );
489 lstRstZ.push_back( tmpZ );
492 for (i=iGeneral; i<iGeneralPlusSize;i++)
494 // ii=( (i-iGeneral) + firstK) % size ;
496 iii=iGeneral+ ( (i-iGeneral) + firstK) % size ;
497 (*lstOutX)[iii] = lstRstX[ii];
498 (*lstOutY)[iii] = lstRstY[ii];
499 (*lstOutZ)[iii] = lstRstZ[ii];
502 iGeneral=iGeneral+size;
505 printf("EED ManualContourModel_Box::RedistributionPoints_SIN_iContour End \n");
512 void ManualContourModel_Box::ClockwisePoints( std::vector<double> *lstInX,
513 std::vector<double> *lstInY,
514 std::vector<double> *lstInZ,
515 std::vector<int> *lstIndexsIn )
517 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
522 double backpx,backpy,backpz;
531 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn; iLstIndexIn++)
533 // Step 1. Find gravity center and direction
534 size = (*lstIndexsIn)[iLstIndexIn];
535 if (size>2) // for contour with more than 2 points
543 for ( i=0 ; i<size ; i++ )
545 px=(*lstInX)[iGeneral+i];
546 py=(*lstInY)[iGeneral+i];
547 pz=(*lstInZ)[iGeneral+i];
553 if (backpx!=px) { dirx=false; }
554 if (backpy!=py) { diry=false; }
555 if (backpz!=pz) { dirz=false; }
567 if (dirx==true) { dir=1; } // YZ
568 if (diry==true) { dir=2; } // XZ
569 if (dirz==true) { dir=0; } // XZ
570 // Step 2. Find angle diference find
572 for ( i=0 ; i<size ; i++ )
574 px = (*lstInX)[iGeneral+i]-cx;
575 py = (*lstInY)[iGeneral+i]-cy;
576 pz = (*lstInZ)[iGeneral+i]-cz;
577 if (dir==0) { ang=atan2( py , px ); } // XY
578 if (dir==1) { ang=atan2( pz , py ); } // YZ
579 if (dir==2) { ang=atan2( pz , px ); } // XZ
593 // Step 3. Invert order of points
597 for ( i=0 ; i<size2 ; i++ )
599 tmp = (*lstInX)[iGeneral+i];
600 (*lstInX)[iGeneral+i] = (*lstInX)[iGeneral+size-1-i];
601 (*lstInX)[iGeneral+size-1-i] = tmp;
602 tmp = (*lstInY)[iGeneral+i];
603 (*lstInY)[iGeneral+i] = (*lstInY)[iGeneral+size-1-i];
604 (*lstInY)[iGeneral+size-1-i] = tmp;
605 tmp = (*lstInZ)[iGeneral+i];
606 (*lstInZ)[iGeneral+i] = (*lstInZ)[iGeneral+size-1-i];
607 (*lstInZ)[iGeneral+size-1-i] = tmp;
611 iGeneral = iGeneral+size;
617 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
618 std::vector<double> *lstInY,
619 std::vector<double> *lstInZ,
620 std::vector<int> *lstIndexsIn )
622 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
629 std::vector<double> LstTmpX;
630 std::vector<double> LstTmpY;
631 std::vector<double> LstTmpZ;
632 if (sizeLstIndexIn>=2)
635 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
637 size = (*lstIndexsIn)[iLstIndexIn];
638 size2 = (*lstIndexsIn)[iLstIndexIn+1];
639 //find min distance and iBack
644 for (ig=0; ig<size; ig++)
646 for ( i=0 ; i<size2 ; i++ )
648 dx = (*lstInX)[iGeneral+ig]-(*lstInX)[iGeneral+size+i];
649 dy = (*lstInY)[iGeneral+ig]-(*lstInY)[iGeneral+size+i];
650 dz = (*lstInZ)[iGeneral+ig]-(*lstInZ)[iGeneral+size+i];
651 dist= sqrt( dx*dx + dy*dy + dz*dz );
663 iBack = iBack + size2;
666 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);
673 for (i=0 ; i<size2 ; i++)
676 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
677 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
678 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
680 for (i=0 ; i<size2 ; i++)
682 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
683 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
684 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
687 iGeneral=iGeneral+size;
694 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
696 size = (*lstIndexsIn)[iLstIndexIn];
697 size2 = (*lstIndexsIn)[iLstIndexIn+1];
698 //find min distance and iBack
703 // for (ig=0; ig<size; ig++)
705 for ( i=0 ; i<size2 ; i++ )
707 dx = (*lstInX)[iGeneral]-(*lstInX)[iGeneral+size+i];
708 dy = (*lstInY)[iGeneral]-(*lstInY)[iGeneral+size+i];
709 dz = (*lstInZ)[iGeneral]-(*lstInZ)[iGeneral+size+i];
710 dist= sqrt( dx*dx + dy*dy + dz*dz );
720 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);
727 for (i=0 ; i<size2 ; i++)
730 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
731 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
732 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
734 for (i=0 ; i<size2 ; i++)
736 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
737 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
738 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
741 iGeneral=iGeneral+size;
744 } // if sizeLstIndexIn
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)
771 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
773 size = (*lstIndexsIn)[iLstIndexIn];
774 size2 = (*lstIndexsIn)[iLstIndexIn+1];
775 //find min distance and iBack
779 // Comparing distance between two contours
780 // Both contours need the same size
781 for (ig=0; ig<size; ig++)
784 for ( i=0 ; i<size2 ; i++ )
786 dx = (*lstInX)[iGeneral+i]-(*lstInX)[iGeneral+size+(i+ig)%size];
787 dy = (*lstInY)[iGeneral+i]-(*lstInY)[iGeneral+size+(i+ig)%size];
788 dz = (*lstInZ)[iGeneral+i]-(*lstInZ)[iGeneral+size+(i+ig)%size];
789 dist= dist + sqrt( dx*dx + dy*dy + dz*dz );
801 //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);
808 for (i=0 ; i<size2 ; i++)
810 ii = (i+iBack)%size2;
811 if (ii<(size2-1)) // Skip the last item
813 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
814 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
815 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
819 //Repeat the first item at the end to close the contour
820 LstTmpX.push_back( LstTmpX[0] );
821 LstTmpY.push_back( LstTmpY[0] );
822 LstTmpZ.push_back( LstTmpZ[0] );
824 for (i=0 ; i<size2 ; i++)
826 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
827 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
828 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
831 iGeneral=iGeneral+size;
835 } // if sizeLstIndexIn
844 void ManualContourModel_Box::Process()
846 // THE MAIN PROCESSING METHOD BODY
847 // Here we simply set the input 'In' value to the output 'Out'
848 // And print out the output value
849 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
850 // void bbSet{Input|Output}NAME(const TYPE&)
851 // const TYPE& bbGet{Input|Output}NAME() const
853 // * NAME is the name of the input/output
854 // (the one provided in the attribute 'name' of the tag 'input')
855 // * TYPE is the C++ type of the input/output
856 // (the one provided in the attribute 'type' of the tag 'input')
858 // bbSetOutputOut( bbGetInputIn() );
859 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
861 // First Step Spline Interpolation
862 std::vector<double> lstInX=bbGetInputLstControlPointsX();
863 std::vector<double> lstInY=bbGetInputLstControlPointsY();
864 std::vector<double> lstInZ=bbGetInputLstControlPointsZ();
865 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
867 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
870 std::vector<int> lstIndexsIn=bbGetInputLstIndexsIn();
871 std::vector<int> lstIndexsOut;
872 std::vector<double> lstOutX;
873 std::vector<double> lstOutY;
874 std::vector<double> lstOutZ;
875 if (bbGetInputLstIndexsIn().size()==0)
877 lstIndexsIn.push_back( lstInX.size() );
880 // Step 1. All contours the same clockwise direction (Control Points)
881 if (bbGetInputDoubleContour()==1)
883 ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
884 // ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
886 int i,size=lstIndexsIn.size();
889 // Step 2. Spline interpolation of control points
892 ProcessBySegment( bbGetInputType() ,
893 iGeneral, lstIndexsIn[i] ,
894 &lstInX , &lstInY , &lstInZ,
895 &lstOutX , &lstOutY , &lstOutZ,
896 &lstIndexsOut,bbGetInputOpenClose() );
899 if (bbGetInputDoubleContour()==0)
901 // Finish if Simple contours
902 //////////////////// Set Out DoubleContour = 0
903 bbSetOutputLstContourPointsX(lstOutX);
904 bbSetOutputLstContourPointsY(lstOutY);
905 bbSetOutputLstContourPointsZ(lstOutZ);
906 bbSetOutputLstIndexsOut(lstIndexsOut);
908 // Step 3. Interpolation in the other direction
909 // Step 3.1 Linear Normalice points around contours
910 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
912 // Step 3.2 Shift points to find minimun acumulate distance
913 ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
914 // Step 3.3. SIN Normalice points around contours
915 // RedistributionPoints_SIN_iContour(-1, &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut,-1,-1);
916 RedistributionPointsAllContours_SIN( &lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
917 // ShiftValues( &lstOutX, &lstOutY, &lstOutZ, &lstIndexsOut );
918 // Step 3.4 Transpose the vectors
923 size = bbGetInputNbPoints();
924 int j,size2 = lstIndexsOut.size();
927 for (j=0;j<size2;j++)
929 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
930 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
931 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
933 lstIndexsIn.push_back( size2 );
938 lstIndexsOut.clear();
939 // Step 3.5 Interponation 2
940 size=lstIndexsIn.size();
944 ProcessBySegment( bbGetInputType() ,
945 iGeneral, lstIndexsIn[i] ,
946 &lstInX,&lstInY,&lstInZ,
947 &lstOutX,&lstOutY,&lstOutZ,
948 &lstIndexsOut,bbGetInputOpenClose2());
950 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
951 // Step 3.6 Transpose the vectors
956 size = bbGetInputNbPoints();
957 size2 = lstIndexsOut.size();
960 for (j=0;j<size2;j++)
962 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
963 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
964 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
966 lstIndexsIn.push_back( size2 );
971 lstIndexsOut.clear();
972 //////////////////// Set Out DoubleContour = 1
973 bbSetOutputLstContourPointsX(lstInX);
974 bbSetOutputLstContourPointsY(lstInY);
975 bbSetOutputLstContourPointsZ(lstInZ);
976 bbSetOutputLstIndexsOut(lstIndexsIn);
978 } // if DoubleContour
982 // 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)
984 void ManualContourModel_Box::bbUserSetDefaultValues()
987 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
988 // Here we initialize the input 'In' to 0
990 bbSetInputDoubleContour(0);
991 bbSetInputOpenClose(false);
992 bbSetInputOpenClose2(false);
993 bbSetInputNbPoints(100);
997 // 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)
999 void ManualContourModel_Box::bbUserInitializeProcessing()
1002 // THE INITIALIZATION METHOD BODY :
1003 // Here does nothing
1004 // but this is where you should allocate the internal/output pointers
1010 // 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)
1012 void ManualContourModel_Box::bbUserFinalizeProcessing()
1015 // THE FINALIZATION METHOD BODY :
1016 // Here does nothing
1017 // but this is where you should desallocate the internal/output pointers
1022 // EO namespace bbcreaMaracasVisu