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;
141 void ManualContourModel_Box::ShiftValues( std::vector<double> *lstInX,
142 std::vector<double> *lstInY,
143 std::vector<double> *lstInZ,
144 std::vector<int> *lstIndexsIn )
146 int iLstIndexIn,sizeLstIndexIn=lstIndexsIn->size();
152 std::vector<double> LstTmpX;
153 std::vector<double> LstTmpY;
154 std::vector<double> LstTmpZ;
155 if (sizeLstIndexIn>=2)
157 for (iLstIndexIn=0; iLstIndexIn<sizeLstIndexIn-1; iLstIndexIn++)
159 size = (*lstIndexsIn)[iLstIndexIn];
160 size2 = (*lstIndexsIn)[iLstIndexIn+1];
161 //find min distance and iBack
164 for ( i=0 ; i<size2 ; i++ )
166 dx = (*lstInX)[iGeneral]-(*lstInX)[iGeneral+size+i];
167 dy = (*lstInY)[iGeneral]-(*lstInY)[iGeneral+size+i];
168 dz = (*lstInZ)[iGeneral]-(*lstInZ)[iGeneral+size+i];
169 dist= sqrt( dx*dx + dy*dy + dz*dz );
181 for (i=0 ; i<size2 ; i++)
184 LstTmpX.push_back( (*lstInX)[iGeneral+size+ii] );
185 LstTmpY.push_back( (*lstInY)[iGeneral+size+ii] );
186 LstTmpZ.push_back( (*lstInZ)[iGeneral+size+ii] );
188 for (i=0 ; i<size2 ; i++)
190 (*lstInX)[iGeneral+size+i] = LstTmpX[i];
191 (*lstInY)[iGeneral+size+i] = LstTmpY[i];
192 (*lstInZ)[iGeneral+size+i] = LstTmpZ[i];
195 iGeneral=iGeneral+size;
202 void ManualContourModel_Box::Process()
204 // THE MAIN PROCESSING METHOD BODY
205 // Here we simply set the input 'In' value to the output 'Out'
206 // And print out the output value
207 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
208 // void bbSet{Input|Output}NAME(const TYPE&)
209 // const TYPE& bbGet{Input|Output}NAME() const
211 // * NAME is the name of the input/output
212 // (the one provided in the attribute 'name' of the tag 'input')
213 // * TYPE is the C++ type of the input/output
214 // (the one provided in the attribute 'type' of the tag 'input')
216 // bbSetOutputOut( bbGetInputIn() );
217 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
219 // First Step Spline Interpolation
220 std::vector<double> lstInX=bbGetInputLstControlPointsX();
221 std::vector<double> lstInY=bbGetInputLstControlPointsY();
222 std::vector<double> lstInZ=bbGetInputLstControlPointsZ();
223 if ( (lstInX.size()!=lstInY.size()) || (lstInY.size()!=lstInZ.size()) )
225 printf("Warnning !! .. ManualContourModel_Box: The list X Y Z, no have the same number of elements \n");
228 std::vector<int> lstIndexsIn=bbGetInputLstIndexsIn();
229 std::vector<int> lstIndexsOut;
230 std::vector<double> lstOutX;
231 std::vector<double> lstOutY;
232 std::vector<double> lstOutZ;
233 if (bbGetInputLstIndexsIn().size()==0)
235 lstIndexsIn.push_back( lstInX.size() );
237 if (bbGetInputDoubleContour()==1)
239 ShiftValues( &lstInX , &lstInY , &lstInZ , &lstIndexsIn );
241 int i,size=lstIndexsIn.size();
245 ProcessBySegment( bbGetInputType() ,
246 iGeneral, lstIndexsIn[i] ,
247 &lstInX , &lstInY , &lstInZ,
248 &lstOutX , &lstOutY , &lstOutZ,
249 &lstIndexsOut,bbGetInputOpenClose() );
252 if (bbGetInputDoubleContour()==0)
254 //////////////////// Set Out DoubleContour = 0
255 bbSetOutputLstContourPointsX(lstOutX);
256 bbSetOutputLstContourPointsY(lstOutY);
257 bbSetOutputLstContourPointsZ(lstOutZ);
258 bbSetOutputLstIndexsOut(lstIndexsOut);
260 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
261 ///////////// Second Step Transpose the vectors
266 size = bbGetInputNbPoints();
267 int j,size2 = lstIndexsOut.size();
270 for (j=0;j<size2;j++)
272 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
273 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
274 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
276 lstIndexsIn.push_back( size2 );
281 lstIndexsOut.clear();
282 ///////////////////// Third step Interponation 2
283 size=lstIndexsIn.size();
287 ProcessBySegment( bbGetInputType() ,
288 iGeneral, lstIndexsIn[i] ,
289 &lstInX,&lstInY,&lstInZ,
290 &lstOutX,&lstOutY,&lstOutZ,
291 &lstIndexsOut,bbGetInputOpenClose2());
293 RedistributionPoints(&lstOutX,&lstOutY,&lstOutZ,&lstIndexsOut);
294 //////////////////// Forth step Transpose the vectors
299 size = bbGetInputNbPoints();
300 size2 = lstIndexsOut.size();
303 for (j=0;j<size2;j++)
305 lstInX.push_back( lstOutX[ j*lstIndexsOut[j] + i ] );
306 lstInY.push_back( lstOutY[ j*lstIndexsOut[j] + i ] );
307 lstInZ.push_back( lstOutZ[ j*lstIndexsOut[j] + i ] );
309 lstIndexsIn.push_back( size2 );
314 lstIndexsOut.clear();
315 //////////////////// Set Out DoubleContour = 1
316 bbSetOutputLstContourPointsX(lstInX);
317 bbSetOutputLstContourPointsY(lstInY);
318 bbSetOutputLstContourPointsZ(lstInZ);
319 bbSetOutputLstIndexsOut(lstIndexsIn);
321 } // if DoubleContour
325 // 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)
327 void ManualContourModel_Box::bbUserSetDefaultValues()
330 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
331 // Here we initialize the input 'In' to 0
333 bbSetInputDoubleContour(0);
334 bbSetInputOpenClose(false);
335 bbSetInputOpenClose2(false);
336 bbSetInputNbPoints(100);
340 // 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)
342 void ManualContourModel_Box::bbUserInitializeProcessing()
345 // THE INITIALIZATION METHOD BODY :
347 // but this is where you should allocate the internal/output pointers
353 // 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)
355 void ManualContourModel_Box::bbUserFinalizeProcessing()
358 // THE FINALIZATION METHOD BODY :
360 // but this is where you should desallocate the internal/output pointers
365 // EO namespace bbcreaMaracasVisu