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++)
66 //printf("EED ManualContourModel_Box::RedistributionPoints iLstIndexOut=%d \n", iLstIndexOut);
70 size=(*lstIndexsOut)[iLstIndexOut];
73 double dist=0,dist2,distSeg,delta;
76 for (i=iGeneral+1; i<iGeneral+size;i++)
78 dx=(*lstOutX)[i]-(*lstOutX)[i-1];
79 dy=(*lstOutY)[i]-(*lstOutY)[i-1];
80 dz=(*lstOutZ)[i]-(*lstOutZ)[i-1];
81 dist = dist+sqrt( dx*dx + dy*dy + dz*dz );
84 lstRstX.push_back( (*lstOutX)[iGeneral] );
85 lstRstY.push_back( (*lstOutY)[iGeneral] );
86 lstRstZ.push_back( (*lstOutZ)[iGeneral] );
87 for (i=iGeneral+1; i<iGeneral+size;i++)
89 //printf("EED ManualContourModel_Box::RedistributionPointsi=%d \n", i-iGeneral );
92 for (k=iGeneral+1; k<iGeneral+size;k++)
94 dx=(*lstOutX)[k]-(*lstOutX)[k-1];
95 dy=(*lstOutY)[k]-(*lstOutY)[k-1];
96 dz=(*lstOutZ)[k]-(*lstOutZ)[k-1];
97 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
99 if ( dist2+distSeg>=ii*delta)
101 dd=(ii*delta-dist2)/distSeg;
106 lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
107 lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
108 lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
111 if (k==iGeneral+size-1)
114 lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
115 lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
116 lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
117 // printf("EED ManualContourModel_Box::RedistributionPoints iLstIndexOut=%d i=%d k=%d dist2+distSeg=%f ii*delta=%f dif=%f \n", iLstIndexOut,i-iGeneral, k-iGeneral, dist2+distSeg , ii*delta , (dist2+distSeg) - ii*delta);
123 if (lstRstX.size()!=size)
125 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size);
127 for (i=iGeneral; i<iGeneral+size;i++)
130 (*lstOutX)[i] = lstRstX[ii];
131 (*lstOutY)[i] = lstRstY[ii];
132 (*lstOutZ)[i] = lstRstZ[ii];
135 iGeneral=iGeneral+size;
140 void ManualContourModel_Box::ClockwisePoints( std::vector<double> *lstInX,
141 std::vector<double> *lstInY,
142 std::vector<double> *lstInZ,
143 std::vector<int> *lstIndexsIn )
145 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
150 double backpx,backpy,backpz;
159 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn; iLstIndexIn++)
161 // Step 1. Find gravity center and direction
162 size = (*lstIndexsIn)[iLstIndexIn];
163 if (size>2) // for contour with more than 2 points
171 for ( i=0 ; i<size ; i++ )
173 px=(*lstInX)[iGeneral+i];
174 py=(*lstInY)[iGeneral+i];
175 pz=(*lstInZ)[iGeneral+i];
181 if (backpx!=px) { dirx=false; }
182 if (backpy!=py) { diry=false; }
183 if (backpz!=pz) { dirz=false; }
195 if (dirx==true) { dir=1; } // YZ
196 if (diry==true) { dir=2; } // XZ
197 if (dirz==true) { dir=0; } // XZ
198 // Step 2. Find angle diference find
200 for ( i=0 ; i<size ; i++ )
202 px = (*lstInX)[iGeneral+i]-cx;
203 py = (*lstInY)[iGeneral+i]-cy;
204 pz = (*lstInZ)[iGeneral+i]-cz;
205 if (dir==0) { ang=atan2( py , px ); } // XY
206 if (dir==1) { ang=atan2( pz , py ); } // YZ
207 if (dir==2) { ang=atan2( pz , px ); } // XZ
220 printf("EED ManualContourModel_Box::ClockwisePoints cx=%f cy=%f cz=%f flagAng=%d size=%d \n",cx,cy,cz,flagAng, size);
221 //if (cy<=490) { flagAng = flagAng*(-1); }
223 // Step 3. Invert order of points
227 for ( i=0 ; i<size2 ; i++ )
229 tmp = (*lstInX)[iGeneral+i];
230 (*lstInX)[iGeneral+i] = (*lstInX)[iGeneral+size-1-i];
231 (*lstInX)[iGeneral+size-1-i] = tmp;
232 tmp = (*lstInY)[iGeneral+i];
233 (*lstInY)[iGeneral+i] = (*lstInY)[iGeneral+size-1-i];
234 (*lstInY)[iGeneral+size-1-i] = tmp;
235 tmp = (*lstInZ)[iGeneral+i];
236 (*lstInZ)[iGeneral+i] = (*lstInZ)[iGeneral+size-1-i];
237 (*lstInZ)[iGeneral+size-1-i] = tmp;
241 iGeneral = iGeneral+size;
245 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
246 std::vector<double> *lstInY,
247 std::vector<double> *lstInZ,
248 std::vector<int> *lstIndexsIn )
250 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
257 std::vector<double> LstTmpX;
258 std::vector<double> LstTmpY;
259 std::vector<double> LstTmpZ;
260 if (sizeLstIndexIn>=2)
263 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
265 size = (*lstIndexsIn)[iLstIndexIn];
266 size2 = (*lstIndexsIn)[iLstIndexIn+1];
267 //find min distance and iBack
272 for (ig=0; ig<size; ig++)
274 for ( i=0 ; i<size2 ; i++ )
276 dx = (*lstInX)[iGeneral+ig]-(*lstInX)[iGeneral+size+i];
277 dy = (*lstInY)[iGeneral+ig]-(*lstInY)[iGeneral+size+i];
278 dz = (*lstInZ)[iGeneral+ig]-(*lstInZ)[iGeneral+size+i];
279 dist= sqrt( dx*dx + dy*dy + dz*dz );
291 iBack = iBack + size2;
294 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);
301 for (i=0 ; i<size2 ; i++)
304 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
305 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
306 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
308 for (i=0 ; i<size2 ; i++)
310 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
311 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
312 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
315 iGeneral=iGeneral+size;
322 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
324 size = (*lstIndexsIn)[iLstIndexIn];
325 size2 = (*lstIndexsIn)[iLstIndexIn+1];
326 //find min distance and iBack
331 // for (ig=0; ig<size; ig++)
333 for ( i=0 ; i<size2 ; i++ )
335 dx = (*lstInX)[iGeneral]-(*lstInX)[iGeneral+size+i];
336 dy = (*lstInY)[iGeneral]-(*lstInY)[iGeneral+size+i];
337 dz = (*lstInZ)[iGeneral]-(*lstInZ)[iGeneral+size+i];
338 dist= sqrt( dx*dx + dy*dy + dz*dz );
348 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);
355 for (i=0 ; i<size2 ; i++)
358 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
359 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
360 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
362 for (i=0 ; i<size2 ; i++)
364 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
365 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
366 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
369 iGeneral=iGeneral+size;
372 } // if sizeLstIndexIn
378 void ManualContourModel_Box::Process()
380 // THE MAIN PROCESSING METHOD BODY
381 // Here we simply set the input 'In' value to the output 'Out'
382 // And print out the output value
383 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
384 // void bbSet{Input|Output}NAME(const TYPE&)
385 // const TYPE& bbGet{Input|Output}NAME() const
387 // * NAME is the name of the input/output
388 // (the one provided in the attribute 'name' of the tag 'input')
389 // * TYPE is the C++ type of the input/output
390 // (the one provided in the attribute 'type' of the tag 'input')
392 // bbSetOutputOut( bbGetInputIn() );
393 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
395 // First Step Spline Interpolation
396 std::vector<double> lstInX=bbGetInputLstControlPointsX();
397 std::vector<double> lstInY=bbGetInputLstControlPointsY();
398 std::vector<double> lstInZ=bbGetInputLstControlPointsZ();
399 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
401 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
404 std::vector<int> lstIndexsIn=bbGetInputLstIndexsIn();
405 std::vector<int> lstIndexsOut;
406 std::vector<double> lstOutX;
407 std::vector<double> lstOutY;
408 std::vector<double> lstOutZ;
409 if (bbGetInputLstIndexsIn().size()==0)
411 lstIndexsIn.push_back( lstInX.size() );
413 if (bbGetInputDoubleContour()==1)
415 ClockwisePoints( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
416 ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
418 int i,size=lstIndexsIn.size();
422 ProcessBySegment( bbGetInputType() ,
423 iGeneral, lstIndexsIn[i] ,
424 &lstInX , &lstInY , &lstInZ,
425 &lstOutX , &lstOutY , &lstOutZ,
426 &lstIndexsOut,bbGetInputOpenClose() );
429 if (bbGetInputDoubleContour()==0)
431 //////////////////// Set Out DoubleContour = 0
432 bbSetOutputLstContourPointsX(lstOutX);
433 bbSetOutputLstContourPointsY(lstOutY);
434 bbSetOutputLstContourPointsZ(lstOutZ);
435 bbSetOutputLstIndexsOut(lstIndexsOut);
437 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
438 ///////////// Second Step Transpose the vectors
443 size = bbGetInputNbPoints();
444 int j,size2 = lstIndexsOut.size();
447 for (j=0;j<size2;j++)
449 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
450 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
451 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
453 lstIndexsIn.push_back( size2 );
458 lstIndexsOut.clear();
459 ///////////////////// Third step Interponation 2
460 size=lstIndexsIn.size();
464 ProcessBySegment( bbGetInputType() ,
465 iGeneral, lstIndexsIn[i] ,
466 &lstInX,&lstInY,&lstInZ,
467 &lstOutX,&lstOutY,&lstOutZ,
468 &lstIndexsOut,bbGetInputOpenClose2());
470 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
471 //////////////////// Forth step Transpose the vectors
476 size = bbGetInputNbPoints();
477 size2 = lstIndexsOut.size();
480 for (j=0;j<size2;j++)
482 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
483 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
484 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
486 lstIndexsIn.push_back( size2 );
491 lstIndexsOut.clear();
492 //////////////////// Set Out DoubleContour = 1
493 bbSetOutputLstContourPointsX(lstInX);
494 bbSetOutputLstContourPointsY(lstInY);
495 bbSetOutputLstContourPointsZ(lstInZ);
496 bbSetOutputLstIndexsOut(lstIndexsIn);
498 } // if DoubleContour
502 // 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)
504 void ManualContourModel_Box::bbUserSetDefaultValues()
507 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
508 // Here we initialize the input 'In' to 0
510 bbSetInputDoubleContour(0);
511 bbSetInputOpenClose(false);
512 bbSetInputOpenClose2(false);
513 bbSetInputNbPoints(100);
517 // 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)
519 void ManualContourModel_Box::bbUserInitializeProcessing()
522 // THE INITIALIZATION METHOD BODY :
524 // but this is where you should allocate the internal/output pointers
530 // 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)
532 void ManualContourModel_Box::bbUserFinalizeProcessing()
535 // THE FINALIZATION METHOD BODY :
537 // but this is where you should desallocate the internal/output pointers
542 // EO namespace bbcreaMaracasVisu