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;
33 m = (manualContourModel*)f.getContourModel( bbGetInputType() );
34 m->SetNumberOfPointsSpline( bbGetInputNbPoints() );
35 m->SetCloseContour( open );
36 for (i=iGeneral;i<size;i++)
38 m->AddPoint( (*lstInX)[i] , (*lstInY)[i] , (*lstInZ)[i] );
41 int sizeContour = bbGetInputNbPoints();
42 for (i=0;i<sizeContour;i++)
44 m->GetSpline_i_Point(i,&x,&y,&z);
45 lstOutX->push_back(x);
46 lstOutY->push_back(y);
47 lstOutZ->push_back(z);
49 iGeneral=iGeneral+sizeSegment;
50 lstIndexsOut->push_back( sizeContour );
55 void ManualContourModel_Box::RedistributionPoints( std::vector<double> *lstOutX,
56 std::vector<double> *lstOutY,
57 std::vector<double> *lstOutZ,
58 std::vector<int> *lstIndexsOut )
60 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints Start\n");
62 std::vector<double> lstRstX;
63 std::vector<double> lstRstY;
64 std::vector<double> lstRstZ;
66 int iLstIndexOut,sizeLstIndexOut=lstIndexsOut->size();
70 for (iLstIndexOut=0; iLstIndexOut<sizeLstIndexOut; iLstIndexOut++)
72 //printf("EED ManualContourModel_Box::RedistributionPoints iLstIndexOut=%d \n", iLstIndexOut);
78 size=(*lstIndexsOut)[iLstIndexOut];
81 double dist=0,dist2,distSeg,delta;
84 for (i=iGeneral+1; i<iGeneral+size;i++)
86 dx=(*lstOutX)[i]-(*lstOutX)[i-1];
87 dy=(*lstOutY)[i]-(*lstOutY)[i-1];
88 dz=(*lstOutZ)[i]-(*lstOutZ)[i-1];
89 dist = dist+sqrt( dx*dx + dy*dy + dz*dz );
93 lstRstX.push_back( (*lstOutX)[iGeneral] );
94 lstRstY.push_back( (*lstOutY)[iGeneral] );
95 lstRstZ.push_back( (*lstOutZ)[iGeneral] );
96 for (i=iGeneral+1; i<iGeneral+size;i++)
98 //printf("EED ManualContourModel_Box::RedistributionPointsi=%d \n", i-iGeneral );
101 for (k=iGeneral+1; k<iGeneral+size;k++)
103 dx=(*lstOutX)[k]-(*lstOutX)[k-1];
104 dy=(*lstOutY)[k]-(*lstOutY)[k-1];
105 dz=(*lstOutZ)[k]-(*lstOutZ)[k-1];
106 distSeg = sqrt( dx*dx + dy*dy + dz*dz );
108 if ( dist2+distSeg>=ii*delta)
110 dd=(ii*delta-dist2)/distSeg;
115 lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
116 lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
117 lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
120 if (k==iGeneral+size-1)
123 lstRstX.push_back( (*lstOutX)[k-1] + dd*dx );
124 lstRstY.push_back( (*lstOutY)[k-1] + dd*dy );
125 lstRstZ.push_back( (*lstOutZ)[k-1] + dd*dz );
126 // 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);
134 if (lstRstX.size()!=size)
136 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints >> This list is not coherent iLstIndexOut=%d lstRstX.size()=%d size=%d\n",iLstIndexOut, lstRstX.size(), size);
139 for (i=iGeneral; i<iGeneral+size;i++)
142 (*lstOutX)[i] = lstRstX[ii];
143 (*lstOutY)[i] = lstRstY[ii];
144 (*lstOutZ)[i] = lstRstZ[ii];
149 iGeneral=iGeneral+size;
153 printf("EED Warnning! ManualContourModel_Box::RedistributionPoints End\n");
159 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
160 std::vector<double> *lstInY,
161 std::vector<double> *lstInZ,
162 std::vector<int> *lstIndexsIn )
164 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
171 std::vector<double> LstTmpX;
172 std::vector<double> LstTmpY;
173 std::vector<double> LstTmpZ;
175 if (sizeLstIndexIn>=2)
177 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
179 size = (*lstIndexsIn)[iLstIndexIn];
180 size2 = (*lstIndexsIn)[iLstIndexIn+1];
182 //find min distance and iBack
185 for ( i=0 ; i<size2 ; i++ )
187 dx = (*lstInX)[iGeneral]-(*lstInX)[iGeneral+size+i];
188 dy = (*lstInY)[iGeneral]-(*lstInY)[iGeneral+size+i];
189 dz = (*lstInZ)[iGeneral]-(*lstInZ)[iGeneral+size+i];
190 dist= sqrt( dx*dx + dy*dy + dz*dz );
204 for (i=0 ; i<size2 ; i++)
207 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
208 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
209 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
211 for (i=0 ; i<size2 ; i++)
213 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
214 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
215 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
219 iGeneral=iGeneral+size;
226 void ManualContourModel_Box::Process()
228 // THE MAIN PROCESSING METHOD BODY
229 // Here we simply set the input 'In' value to the output 'Out'
230 // And print out the output value
231 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
232 // void bbSet{Input|Output}NAME(const TYPE&)
233 // const TYPE& bbGet{Input|Output}NAME() const
235 // * NAME is the name of the input/output
236 // (the one provided in the attribute 'name' of the tag 'input')
237 // * TYPE is the C++ type of the input/output
238 // (the one provided in the attribute 'type' of the tag 'input')
240 // bbSetOutputOut( bbGetInputIn() );
241 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
244 // First Step Spline Interpolation
245 std::vector<double> lstInX=bbGetInputLstControlPointsX();
246 std::vector<double> lstInY=bbGetInputLstControlPointsY();
247 std::vector<double> lstInZ=bbGetInputLstControlPointsZ();
249 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
251 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
255 std::vector<int> lstIndexsIn=bbGetInputLstIndexsIn();
256 std::vector<int> lstIndexsOut;
257 std::vector<double> lstOutX;
258 std::vector<double> lstOutY;
259 std::vector<double> lstOutZ;
261 if (bbGetInputLstIndexsIn().size()==0)
263 lstIndexsIn.push_back( lstInX.size() );
267 if (bbGetInputDoubleContour()==1)
269 ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
272 int i,size=lstIndexsIn.size();
276 ProcessBySegment( bbGetInputType() ,
277 iGeneral, lstIndexsIn[i] ,
278 &lstInX , &lstInY , &lstInZ,
279 &lstOutX , &lstOutY , &lstOutZ,
280 &lstIndexsOut,bbGetInputOpenClose() );
283 if (bbGetInputDoubleContour()==0)
285 //////////////////// Set Out DoubleContour = 0
286 bbSetOutputLstContourPointsX(lstOutX);
287 bbSetOutputLstContourPointsY(lstOutY);
288 bbSetOutputLstContourPointsZ(lstOutZ);
289 bbSetOutputLstIndexsOut(lstIndexsOut);
291 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
292 ///////////// Second Step Transpose the vectors
297 size = bbGetInputNbPoints();
298 int j,size2 = lstIndexsOut.size();
301 for (j=0;j<size2;j++)
303 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
304 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
305 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
307 lstIndexsIn.push_back( size2 );
312 lstIndexsOut.clear();
313 ///////////////////// Third step Interponation 2
314 size=lstIndexsIn.size();
318 ProcessBySegment( bbGetInputType() ,
319 iGeneral, lstIndexsIn[i] ,
320 &lstInX,&lstInY,&lstInZ,
321 &lstOutX,&lstOutY,&lstOutZ,
322 &lstIndexsOut,bbGetInputOpenClose2());
324 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
325 //////////////////// Forth step Transpose the vectors
330 size = bbGetInputNbPoints();
331 size2 = lstIndexsOut.size();
334 for (j=0;j<size2;j++)
336 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
337 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
338 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
340 lstIndexsIn.push_back( size2 );
345 lstIndexsOut.clear();
347 //////////////////// Set Out DoubleContour = 1
348 bbSetOutputLstContourPointsX(lstInX);
349 bbSetOutputLstContourPointsY(lstInY);
350 bbSetOutputLstContourPointsZ(lstInZ);
351 bbSetOutputLstIndexsOut(lstIndexsIn);
353 } // if DoubleContour
357 // 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)
359 void ManualContourModel_Box::bbUserSetDefaultValues()
362 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
363 // Here we initialize the input 'In' to 0
365 bbSetInputDoubleContour(0);
366 bbSetInputOpenClose(false);
367 bbSetInputOpenClose2(false);
368 bbSetInputNbPoints(100);
372 // 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)
374 void ManualContourModel_Box::bbUserInitializeProcessing()
377 // THE INITIALIZATION METHOD BODY :
379 // but this is where you should allocate the internal/output pointers
385 // 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)
387 void ManualContourModel_Box::bbUserFinalizeProcessing()
390 // THE FINALIZATION METHOD BODY :
392 // but this is where you should desallocate the internal/output pointers
397 // EO namespace bbcreaMaracasVisu