]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/AutoControlPoints.cxx
e84079974529508e41bf338882ff63c65da9ada5
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / Contour / AutoControlPoints.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "AutoControlPoints.h"
27 //------------------------------------------------------------------------------------------------------------------------------------------
28 //CLASS: AutoControlPoints -----------------------------------------------------------------------------------------------------------------
29 //------------------------------------------------------------------------------------------------------------------------------------------
30 //Constructor
31 AutoControlPoints::AutoControlPoints()
32 {
33          _pathsize = 0;
34          _numspline = 100;
35 }
36 //Destructor
37 AutoControlPoints::~AutoControlPoints()
38 {
39 }
40 //------------------------------------------------------------------------------------------------------------------------------------------
41 int AutoControlPoints::GetSizeVector(std::vector<double>*Vector)
42    {
43            if(Vector != NULL)
44            {
45                         return _SizeVectorIn = Vector->size();
46            }
47            else
48            {
49                         return _SizeVectorIn = -1;
50            }
51    }
52 //------------------------------------------------------------------------------------------------------------------------------------------
53 void AutoControlPoints::PointLeft ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
54                                                                 double* lex, double* ley, double* lez )
55 {
56         double LeftX = 1000;
57         int pos = 0;
58         int size = GetSizeVector(InX);
59         if(size != -1)
60         {
61                 for(int i=0; i< size; i++)
62                 {
63                         if(  (*InX)[i] < LeftX  )
64                         {
65                                 LeftX = (*InX)[i];
66                                 pos = i;
67                         }
68                 }
69                 *lex = (*InX)[pos];
70                 *ley = (*InY)[pos];
71                 *lez = (*InZ)[pos];
72         }
73 }
74 //------------------------------------------------------------------------------------------------------------------------------------------
75 void AutoControlPoints::PointRight( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
76                                                                 double* rix, double* riy, double* riz )
77 {
78           double RightX = 0;
79           int pos = 0;
80           int size = GetSizeVector(InX);
81           if(size != -1)
82           {
83                 for(int i=0; i< size; i++)
84                 {
85                   if(  (*InX)[i] > RightX  )
86                   {
87                           RightX = (*InX)[i];
88                           pos = i;      
89                   }
90                 }
91                 *rix = (*InX)[pos];
92                 *riy = (*InY)[pos];
93                 *riz = (*InZ)[pos];
94           }
95 }
96 //------------------------------------------------------------------------------------------------------------------------------------------
97 void AutoControlPoints::PointHigh ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
98                                                                 double* hix, double* hiy, double* hiz )
99 {
100         double HighY=-1;
101         int pos = 0;
102         int size = InX->size();
103         if(size > 0){
104                 HighY = (*InY)[0];
105                 for(int i = 1; i < size; i++){
106                         if((*InY)[i] < HighY){
107                                 HighY = (*InY)[i];
108                                 pos = i;
109                         }
110                 }
111                 *hix = (*InX)[pos];
112                 *hiy = (*InY)[pos];
113                 *hiz = (*InZ)[pos];
114         }
115         
116 /*JCP 29-09-08
117         int size = GetSizeVector(InX);
118         if(size != -1)
119         {
120                 for(int i=0; i< _SizeVectorIn; i++)
121                 {
122                         if(  (*InY)[i] < HighY  )
123                         {
124                                 HighY = (*InY)[i];
125                                 pos = i;
126                         }
127                 }
128                 *hix = (*InX)[pos];
129                 *hiy = (*InY)[pos];
130                 *hiz = (*InZ)[pos];
131         }
132 JCP 29-09-08*/
133         
134 }
135
136 //------------------------------------------------------------------------------------------------------------------------------------------
137 void AutoControlPoints::PointLow (      std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
138                                                                         double *lox, double *loy, double *loz)
139 {
140         double LowY = 0;
141         int pos = 0;
142         int size = GetSizeVector(InX);
143         if(size != 0)
144         {
145                 for(int i=0; i< _SizeVectorIn; i++)
146                 {
147                         if(  (*InY)[i] > LowY  )
148                         {
149                                 LowY = (*InY)[i];
150                                 pos = i;
151                         }
152                 } 
153                 *lox = (*InX)[pos];
154                 *loy = (*InY)[pos];
155                 *loz = (*InZ)[pos];
156         }
157 }
158 //------------------------------------------------------------------------------------------------------------------------------------------
159 void AutoControlPoints::TwoPoints ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
160 {
161         double hiX=0,hiY=0,hiZ=0;
162         PointHigh ( InX,InY,InZ,&hiX,&hiY,&hiZ );
163         
164         double leX=0,leY=0,leZ=0;
165         PointLeft ( InX,InY,InZ,&leX,&leY,&leZ );
166         
167         double loX=0,loY=0,loZ=0;
168         PointLow  ( InX,InY,InZ,&loX,&loY,&loZ );
169
170         double riX=0,riY=0,riZ=0;
171         PointRight( InX,InY,InZ,&riX,&riY,&riZ );
172
173         double distHiLo = sqrt( pow(hiX-loX,2) + pow(hiY-loY,2) );
174         double distRiLe = sqrt( pow(riX-leX,2) + pow(riY-leY,2) );
175                 
176         _controlpointsX.clear();
177         _controlpointsY.clear();
178         _controlpointsZ.clear();
179         if(distHiLo >= distRiLe)
180         {
181                 _controlpointsX.push_back(hiX);
182                 _controlpointsY.push_back(hiY);
183                 _controlpointsZ.push_back(hiZ);
184                         
185                 _controlpointsX.push_back(loX);
186                 _controlpointsY.push_back(loY);
187                 _controlpointsZ.push_back(loZ);
188         }
189         else
190         {
191                 _controlpointsX.push_back(riX);
192                 _controlpointsY.push_back(riY);
193                 _controlpointsZ.push_back(riZ);
194
195                 _controlpointsX.push_back(leX);
196                 _controlpointsY.push_back(leY);
197                 _controlpointsZ.push_back(leZ);
198         }
199 }
200 //------------------------------------------------------------------------------------------------------------------------------------------
201 void AutoControlPoints::CircleCenter(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ, double *cx, double *cy, double *r)
202 {
203         double hiX=0,hiY=0,hiZ=0;
204         PointHigh ( InX,InY,InZ,&hiX,&hiY,&hiZ );
205
206         double leX=0,leY=0,leZ=0;
207         PointLeft ( InX,InY,InZ,&leX,&leY,&leZ );
208                 
209         double loX=0,loY=0,loZ=0;
210         PointLow  ( InX,InY,InZ,&loX,&loY,&loZ );
211
212         double riX=0,riY=0,riZ=0;
213         PointRight( InX,InY,InZ,&riX,&riY,&riZ );
214
215         *cx = (riX+leX)/2;
216         *cy = (hiY+loY)/2;
217         *r = sqrt(pow(leX-*cx,2)+pow(hiY-*cy,2)) + 7;
218 }
219 //------------------------------------------------------------------------------------------------------------------------------------------
220 void AutoControlPoints::CirclePoints(double cx, double cy, double r, double grad, double *x, double *y)
221 {
222         double alpha = (2*3.14159265*grad)/360;
223
224         *x = cx + (r*cos(alpha));
225         *y = cy + (r*sin(alpha));
226 }
227 //------------------------------------------------------------------------------------------------------------------------------------------
228  void AutoControlPoints::ChargeSpline( )
229  {
230          int size = _controlpointsX.size();
231          if(size != 0)
232          {
233                 _mContourModel = new manualContourModel();
234                 if( _controlpointsX.size() == 2 )
235                 {
236                         _mContourModel->SetCloseContour(false);
237                 }
238                 if( _controlpointsX.size() > 2 )
239                 {
240                         _mContourModel->SetCloseContour(true);
241                 }
242
243                 _mContourModel->DeleteAllPoints();
244                 _mContourModel->SetNumberOfPointsSpline(_numspline);
245                 for(int i=0; i<size; i++)
246                 {
247                         _mContourModel->AddPoint(_controlpointsX[i],_controlpointsY[i],_controlpointsZ[i]);
248                 }
249                 _mContourModel->UpdateSpline();
250                 int numspline = _mContourModel->GetNumberOfPointsSpline();
251                 double x,y,z;
252                 _chargecontrolpointsX.clear();
253                 _chargecontrolpointsY.clear();
254                 _chargecontrolpointsZ.clear();
255                 for(int j=0; j<numspline; j++)
256                 {
257                         _mContourModel->GetSpline_i_Point(j,&x,&y,&z);
258                         _chargecontrolpointsX.push_back(x);
259                         _chargecontrolpointsY.push_back(y);
260                         _chargecontrolpointsZ.push_back(z);
261                 }
262                 _pathsize = _mContourModel->GetPathSize();
263 //printf("\nPATH SIZE = %f",_pathsize);
264
265                  std::ofstream file1;
266                 file1.open( "4_SplinePoints.txt" );
267
268                 for(int i = 0; i < numspline; i++){
269                         file1<<"X= "<<_chargecontrolpointsX[i] << "\tY= "<<_chargecontrolpointsY[i] << "\tZ= "<<_chargecontrolpointsZ[i]<<std::endl;
270                 }
271                 file1.close();
272          }
273         
274  }
275  //Given the coordinates of two points, it calculates the slope
276 double AutoControlPoints::Slope(double x0, double y0, double x1, double y1)
277 {
278         double m = (y1-y0)/(x1-x0);
279         return m;
280 }
281 //----------------------------------------------------------------------------------------------------------------------------------------
282 //Given the coordinates of two points, it calculates the normal and it's slope 
283 double AutoControlPoints::Normal(double x0, double y0, double* m, double xi)
284 {
285         double y;
286         *m = -(1/(*m));
287         y = ((*m)*(xi - x0)) + y0;
288         return y;
289 }
290 //----------------------------------------------------------------------------------------------------------------------------------------
291 void AutoControlPoints::Intersection(double x01, double y01, double x02, double y02, double mn, double m2, double* x, double* y)
292 {
293         *x = ( y02-y01-(m2*x02)+(mn*x01) )/(mn-m2);
294         *y = m2*(*x-x02)+y02;
295 }
296 //-----------------------------------------------------------------------------------------------------------------------------------------
297 /**
298 **This methods finds the points where each radius of the circle intersect the contour
299 **/
300 void AutoControlPoints::InterCircle(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
301 {
302         double cx,cy,r;
303         CircleCenter(InX,InY,InZ,&cx,&cy,&r);
304
305         //GENERATE THE CIRCLE'S POINTS
306         int i;
307         double grad,x,y,n;
308         std::vector<double>tempX;
309         std::vector<double>tempY;
310         tempX.clear();
311         tempY.clear();
312         n = 1;
313         grad = 0;
314         for(i=0; i<360/n; i++)
315         {
316                 CirclePoints(cx,cy,r,grad,&x,&y);
317                 tempX.push_back(x);
318                 tempY.push_back(y);
319                 grad = grad + n;
320         }
321
322         //FIND THE INTERSECTIONS BETWEEN THE CIRCLE AND THE CONTOUR
323         int j,jj;
324         bool interRad = false;
325         double m1, /*mn=0,*/ m2,xinter,yinter,xmin,ymin,min,dist; // JPRx
326         _intercircleX.clear();
327         _intercircleY.clear();
328         _intercircleDist.clear();
329         _interbewteencircleX.clear();
330         _interbewteencircleY.clear();
331         _interbewteencircleDist.clear();
332         _interbewteencirclePos.clear();
333
334 //EED 22 Sep 2008
335 //      FILE *fd, *fexp;
336 //      fd = fopen("C:/bbtk_JS/data/tempCircle.txt","w");
337 //      fexp = fopen("C:/bbtk_JS/data/InterCircle.txt","w");
338 //      fprintf(fexp,"\npos     min             xmin    ymin    xcir    ycir");
339
340         //std::ofstream file1;
341     //file1.open( "Temp.txt" ); 
342         
343         for(i=0; i<(int)(tempX.size()); i++)
344         {
345 //              fprintf(fd,"\n Para X = %f, Y = %f",tempX[i],tempY[i]);
346                 _circleX.push_back(tempX[i]);
347                 _circleY.push_back(tempY[i]);
348                 m1 = Slope(tempX[i],tempY[i],cx,cy);//slope of the radius
349                 min = 9999;
350                 for(j=0; j<(int)(InX->size()); j++)
351                 {
352                         jj = (j+1)%(InX->size());
353                         m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);//Slope of the vector between the adjacent points
354                         Intersection(tempX[i],tempY[i],(*InX)[j],(*InY)[j],m1,m2,&xinter,&yinter);
355
356 //JCP 26-09-2008
357                         //If the point of intersection is between two points of the contour
358                         if( ((xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]))||((xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) ))
359                         {
360                                 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
361                                 if(dist<min)
362                                 {
363                                         min = dist;
364                                         xmin = xinter;
365                                         ymin = yinter;
366                                 }
367                         }
368 //JCP 26-09-2008
369 /*JCP 26-09-2008
370                         if((*InX)[j]<=(*InX)[jj])
371                         {
372                                 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) )               //Intersection entre le cercle et le contour
373                                 {
374                                         dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
375                                         if(dist<min)
376                                         {
377                                                 min = dist;
378                                                 xmin = xinter;
379                                                 ymin = yinter;
380                                         }
381                                 }
382                         }
383                         if((*InX)[j]>(*InX)[jj])
384                         {
385                                 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) )               //Intersection entre le cercle et le contour
386                                 {
387                                         dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
388                                         if(dist<min)
389                                         {
390                                                 min = dist;
391                                                 xmin = xinter;
392                                                 ymin = yinter;
393                                         }
394                                 }
395                         }
396 JCP 26-09-2008*/
397                 }
398
399
400
401 //              fprintf(fd,"\n => x_int = %f, y_int = %f, dist_int = %f",xmin,ymin,min);
402 //              fprintf(fexp,"\n%d      %f      %f      %f      %f      %f",i,min,xmin,ymin,tempX[i],tempY[i]);
403 //JCP 26-09-08 If the distance of the intersection is bigger than the radio we have to invert the segment
404                 if(min>=r)
405                 {
406                         interRad = true;
407                         _interbewteencirclePos.push_back(i);
408                         _interbewteencircleX.push_back(xmin);
409                         _interbewteencircleY.push_back(ymin);
410                         _interbewteencircleDist.push_back( sqrt(pow(cx-xmin,2)+pow(cy-ymin,2)) );
411
412                         //      file1<<i<<std::endl;
413                 }else{
414 //JCP 26-09-08          if(min<r)
415 //JCP 26-09-08          {
416                         _intercircleX.push_back(xmin);
417                         _intercircleY.push_back(ymin);
418                         _intercircleDist.push_back(min);
419                 //      file1<<"\t"<<i<<std::endl;
420                 }
421         }
422         //file1.close();
423 //      fclose(fd);
424 //      fclose(fexp);
425
426         //WHEN THERE IS RADIAL INTERSECTION
427         vectorFunctions *vecf = new vectorFunctions();
428
429 //EED 22 Sep 2008
430 //      FILE *fdata;
431 //      fdata = fopen("C:/bbtk_JS/data/autoCPdata.txt","w");
432         if(interRad == true)
433         {
434                 std::vector<double> tempXX;
435                 std::vector<double> tempYY;
436                 std::vector<double> tempDD;
437                 tempXX.clear();
438                 tempYY.clear();
439                 tempDD.clear();
440 //Copy of the first points in the array until the first intersection is found           
441                 for(i=0; i<_interbewteencirclePos[0]; i++)
442                 {
443                         tempXX.push_back(_intercircleX[i]);
444                         tempYY.push_back(_intercircleY[i]);
445                         tempDD.push_back(_intercircleDist[i]);
446 //                      fprintf(fdata,"\n%f     %f      %f",_intercircleDist[i],_intercircleX[i],_intercircleY[i]);
447                 }
448                 int sizep = _interbewteencirclePos.size();
449 //Copy all the points where there is an intersection with the center but inverted
450 //JCP 26-09-08          for(i=_interbewteencirclePos[sizep-1],j=sizep-1; i>=_interbewteencirclePos[0]; i--,j--)
451                 for(i=sizep-1; i >= 0;i--)
452                 {
453 //JCP 26-09-08                  tempXX.push_back(_interbewteencircleX[j]);
454 //JCP 26-09-08                  tempYY.push_back(_interbewteencircleY[j]);
455 //JCP 26-09-08                  tempDD.push_back(_interbewteencircleDist[j]);
456                         tempXX.push_back(_interbewteencircleX[i]);
457                         tempYY.push_back(_interbewteencircleY[i]);
458                         tempDD.push_back(_interbewteencircleDist[i]);
459 //                      fprintf(fdata,"\n%f     %f      %f",_interbewteencircleDist[j],_interbewteencircleX[j],_interbewteencircleY[j]);
460                 }
461                 for(i=_interbewteencirclePos[0]; i<(int)(_intercircleX.size()); i++)
462                 {
463                         tempXX.push_back(_intercircleX[i]);
464                         tempYY.push_back(_intercircleY[i]);
465                         tempDD.push_back(_intercircleDist[i]);
466 //                      fprintf(fdata,"\n%f     %f      %f",_intercircleDist[i],_intercircleX[i],_intercircleY[i]);
467                 }
468                 
469                 _intercircleX.clear();
470                 _intercircleY.clear();
471                 _intercircleDist.clear();
472                 vecf->copyVector(&tempXX,&_intercircleX);
473                 vecf->copyVector(&tempYY,&_intercircleY);
474                 vecf->copyVector(&tempDD,&_intercircleDist);
475         }       
476 //      fclose(fdata);
477
478         //DELETE!!
479
480         std::ofstream file1;
481     file1.open( "1_Intersection.txt" );
482
483         for(int i = 0; i < (int)(_intercircleX.size()); i++){
484                 file1<<"X= "<<_intercircleX[i] << "\tY= "<<_intercircleY[i] << "\tDist= "<<_intercircleDist[i]<<std::endl;
485         }
486         file1.close();
487                 
488
489         delete vecf;
490 }
491 //-----------------------------------------------------------------------------------------------------------------------------------------
492 void AutoControlPoints::maxminLocal()
493 {
494         int i;
495         _posmaxlocal.clear();
496         _posminlocal.clear();
497         _posminmaxlocal.clear();
498         _maxlocalX.clear();
499         _maxlocalY.clear();
500         _minlocalX.clear();
501         _minlocalY.clear();
502         _minmaxlocalX.clear();
503         _minmaxlocalY.clear();
504         
505         if(_intercircleDist.size() != 0)
506         {
507 //JCP 26 - 09 - 08 This change was du to the posibility of having a maximum or a minimum value in the limits of 
508 //JCP 26 - 09 - 08 the array
509                 double lastdist, currentdist, nextdist;
510                 for(i=0; i < (int)(_intercircleDist.size()); i++)
511                 {
512                         //FOR MAXIMUM LOCAL
513 //JCP 26-09-08
514                         currentdist = _intercircleDist[i];
515                         if(i == 0){
516                                 lastdist = _intercircleDist[_intercircleDist.size()-1];
517                                 nextdist = _intercircleDist[i+1];
518                         }else if (i == (int)(_intercircleDist.size())-1){
519                                 lastdist = _intercircleDist[i-1];
520                                 nextdist = _intercircleDist[0];
521                         }else{
522                                 lastdist = _intercircleDist[i-1];                               
523                                 nextdist = _intercircleDist[i+1];
524                         }
525                         
526
527 //JCP 26-09-08                  if( (_intercircleDist[i-1]<_intercircleDist[i]) && (_intercircleDist[i]>_intercircleDist[i+1]))
528                         if(lastdist < currentdist && currentdist > nextdist)
529                         {
530                                 _posmaxlocal.push_back(i);
531                                 _maxlocalX.push_back(_intercircleX[i]);
532                                 _maxlocalY.push_back(_intercircleY[i]);
533                                 _minmaxlocalX.push_back(_intercircleX[i]);
534                                 _minmaxlocalY.push_back(_intercircleY[i]);
535                                 _posminmaxlocal.push_back(i);
536                         }
537                         //FOR MINIMUM LOCAL
538 //JCP 26-09-08                  if( (_intercircleDist[i-1]>_intercircleDist[i]) && (_intercircleDist[i]<_intercircleDist[i+1]))
539                         if(lastdist > currentdist && currentdist < nextdist)
540                         {
541                                 _posminlocal.push_back(i);
542                                 _minlocalX.push_back(_intercircleX[i]);
543                                 _minlocalY.push_back(_intercircleY[i]);
544                                 _minmaxlocalX.push_back(_intercircleX[i]);
545                                 _minmaxlocalY.push_back(_intercircleY[i]);
546                                 _posminmaxlocal.push_back(i);
547                         }
548                 }
549         }
550
551         vectorFunctions *vecf   = new vectorFunctions();
552         std::vector<double> tempZ;
553         tempZ.clear();
554         
555         vecf->copyVector(&_minlocalX,&_controlpointsX); 
556         vecf->copyVector(&_minlocalY,&_controlpointsY);
557         for(i=0; i<(int)(_minlocalX.size()); i++)
558         {
559                 tempZ.push_back(_controlpointsZ[0]);
560         }
561         vecf->copyVector(&tempZ,&_controlpointsZ);
562
563 //JCP 26-09-08  
564         std::ofstream file1;
565     file1.open( "2_MaxMin.txt" );
566
567         for(int i = 0; i < (int)(_controlpointsX.size()); i++){
568                 file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
569         }
570         file1.close();
571 //JCP 26-09-08
572         delete vecf;
573 }
574 //-----------------------------------------------------------------------------------------------------------------------------------------
575 //ELIMINATES THE POINTS WITH A DISTANCE < val
576 void AutoControlPoints::fixBetweenPoints(double val)
577 {
578         int size = _controlpointsX.size();
579         double dist;
580         if(size != 0)
581         {
582                 std::vector<double> tempX;
583                 std::vector<double> tempY;
584                 std::vector<double>     tempZ;
585                 tempX.clear();
586                 tempY.clear();
587                 tempZ.clear();
588
589                 int ii;
590                 vectorFunctions *vecf = new vectorFunctions();
591                 for(int i=0; i<size; i++)
592                 {
593                         ii = (i+1)%size;
594                         dist = sqrt(pow(_controlpointsX[i]-_controlpointsX[ii],2)+pow(_controlpointsY[i]-_controlpointsY[ii],2));
595                         if(dist>val)
596                         {
597                                 tempX.push_back(_controlpointsX[i]);
598                                 tempY.push_back(_controlpointsY[i]);
599                                 tempZ.push_back(_controlpointsZ[i]);
600                         }
601                 }
602                 _controlpointsX.clear();
603                 _controlpointsY.clear();
604                 _controlpointsZ.clear();
605
606                 vecf->copyVector(&tempX,&_controlpointsX);
607                 vecf->copyVector(&tempY,&_controlpointsY);
608                 vecf->copyVector(&tempZ,&_controlpointsZ);
609
610                 std::ofstream file1;
611                 file1.open( "3_PointsFixed.txt" );
612
613                 for(int i = 0; i < (int)(_controlpointsX.size()); i++){
614                         file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
615                 }
616                 file1.close();
617
618                 delete vecf;
619         }
620 }
621 //-----------------------------------------------------------------------------------------------------------------------------------------
622 //ALL THE INTERSECTIONS
623 void AutoControlPoints::InterBetweenContours(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
624 {
625         _intervectorX.clear();
626         _intervectorY.clear();
627         ChargeSpline();
628
629         int i,ii,j,jj;
630         double m1,mn,m2,xinter,yinter;
631         if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points 
632         {
633 //EED 22 Sep 2008
634 //              FILE *fd;
635 //              fd = fopen("C:/bbtk_JS/data/interBetweenContours.txt","w");
636                 for(i=0; i<(int)(_chargecontrolpointsX.size()); i++)
637                 {
638                         ii = (i+1)%(_chargecontrolpointsX.size());
639
640                         m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
641                         mn = m1;
642                         Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
643 //                      fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
644
645                         Vector *vecX = new Vector();
646                         Vector *vecY = new Vector();
647                         vecX->set_var(_chargecontrolpointsX[i]);
648                         vecY->set_var(_chargecontrolpointsY[i]);
649
650                         for(j=0; j<(int)(InX->size()); j++)
651                         {
652                                 jj = (j+1)%(InX->size());
653                                 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);
654                                 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],(*InX)[j],(*InY)[j],mn,m2,&xinter,&yinter);
655
656                                 if(((*InX)[j] <= xinter && xinter <= (*InX)[jj]) || (xinter<=(*InX)[j] && xinter>=(*InX)[jj])){
657                                         vecX->set_vec(xinter);
658                                         vecY->set_vec(yinter);
659                                 }
660 /*JCP 29-09-08
661                                 if( (*InX)[j]<=(*InX)[jj] )
662                                 {
663                                         if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) )
664                                         {
665                                                 //If the point is a CP, the intersection is itself.
666                                                 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
667                                                 {
668                                                         vecX->set_vec(xinter);
669                                                         vecY->set_vec(yinter);
670 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
671                                                 }
672                                                 else
673                                                 {
674                                                         vecX->set_vec(xinter);
675                                                         vecY->set_vec(yinter);
676 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
677                                                 }
678                                         }
679                                 }
680                                 if( (*InX)[j]>(*InX)[jj] )
681                                 {
682                                         if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) )
683                                         {
684                                                 //If the point is a CP, the intersection is itself.
685                                                 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
686                                                 {
687                                                         vecX->set_vec(xinter);
688                                                         vecY->set_vec(yinter);
689 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
690                                                 }
691                                                 else
692                                                 {
693                                                         vecX->set_vec(xinter);
694                                                         vecY->set_vec(yinter);
695 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
696                                                 }
697                                         }
698                                 }
699 JCP 29-09-08*/
700                         }//FOR2
701                         _intervectorX.push_back(*vecX);
702                         _intervectorY.push_back(*vecY);
703                         //DELETE!!
704                         delete vecX;
705                         delete vecY;
706                 }//FOR1
707 //              fclose(fd);
708         }//IF
709 }
710 //-----------------------------------------------------------------------------------------------------------------------------------------
711 void AutoControlPoints::GetInterBetweenContours(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
712 {
713         interVX->clear();
714         interVY->clear();
715         int size = _intervectorX.size();
716         int i;
717         if(size != 0)
718         {
719                 for(i=0; i<size; i++)
720                 {
721                         interVX->push_back(_intervectorX[i]);
722                         interVY->push_back(_intervectorY[i]);
723                 }
724         }
725 }
726 //-----------------------------------------------------------------------------------------------------------------------------------------
727 //ONLY THE LOGICAL INTERSECTIONS
728 void AutoControlPoints::IntersectionPoints()
729 {
730         if(_intervectorX.size() != 0)
731         {               
732                 _interpointsX.clear();
733                 _interpointsY.clear();
734
735 //EED
736 //              FILE *fd;
737 //              fd = fopen("C:/bbtk_JS/data/IntersectionPoints.txt","w");
738                 double dist,min;
739                 int i,j,posj;
740
741                 posj = -1;
742                 min = 9999;
743 /*JCP 30-08-09 
744                 for(j=0; j<_intervectorX[0].getsize_vec(); j++)
745                 {
746                         dist = sqrt( pow( _intervectorX[0].get_vec(j)-_intervectorX[0].get_var(),2 ) + pow( _intervectorY[0].get_vec(j)-_intervectorY[0].get_var(),2 ) );
747                         if( dist < min )
748                         {
749                                 min = dist;
750                                 posj = j;
751                         }
752                 }
753                 if(posj != -1)
754                 {
755                         _interpointsX.push_back(_intervectorX[0].get_vec(posj));
756                         _interpointsY.push_back(_intervectorY[0].get_vec(posj));
757 //                      fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[0].get_var(),_intervectorY[0].get_var());
758 //                      fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[0],_interpointsY[0]);
759                 }
760                 if(posj == -1)
761                 {
762                         printf("\n\n There is an invalid intersection: Must see AutoControlPoints::IntersectionPoints() method");
763                 }
764 JCP 30-08-09 */
765                 for(i=0; i<(int)(_intervectorX.size()); i++){
766                         min = 9999;
767                         posj = -1;
768                         for(j=0; j<_intervectorX[i].getsize_vec(); j++) {
769                                 dist  = sqrt( pow( _intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2 ) + pow( _intervectorY[i].get_vec(j)-_intervectorX[i].get_var(),2 ) );
770                                 if( dist < min ){
771                                         min = dist;
772                                         posj = j;
773                                 }
774                         }
775                         _interpointsX.push_back(_intervectorX[i].get_vec(posj));
776                         _interpointsY.push_back(_intervectorY[i].get_vec(posj));                
777                 }
778 /*JCP 30-09-08
779                 for(i=1; i<_intervectorX.size(); i++)
780                 {
781                         min = 9999;
782                         posj = -1;
783 //                      fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
784                         for(j=0; j<_intervectorX[i].getsize_vec(); j++)
785                         {
786                                 //TYPE: LE PLUS PRES VOISIN
787                                 dist  = sqrt( pow( _intervectorX[i].get_vec(j)-_interpointsX[i-1],2 ) + pow( _intervectorY[i].get_vec(j)-_interpointsY[i-1],2 ) );
788                                 //TYPE: LE PLUS PRES DANS LA M�ME DROITE
789                                 //dist = sqrt(pow(_intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2)+pow(_intervectorY[i].get_vec(j)-_intervectorY[i].get_var(),2));
790                                 
791                                 if( dist < min )
792                                 {
793                                         min = dist;
794                                         posj = j;
795                                 }
796                         }
797                         _interpointsX.push_back(_intervectorX[i].get_vec(posj));
798                         _interpointsY.push_back(_intervectorY[i].get_vec(posj));
799 //                      fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[i],_interpointsY[i]);
800                 }
801 JCP 30-09-08*/
802 //              fclose(fd);
803         }
804 }
805 //-----------------------------------------------------------------------------------------------------------------------------------------
806 void AutoControlPoints::GetIntersectionPoints(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
807 {
808         int size = _interpointsX.size();
809         int i;
810         if(size != 0)
811         {
812                 Vector *vecX = new Vector();
813                 Vector *vecY = new Vector();
814                 interVX->clear();
815                 interVY->clear();
816                 for(i=0; i<size; i++)
817                 {
818                         vecX->set_var(_controlpointsZ[0]);
819                         vecX->set_vec(_interpointsX[i]);
820                         vecY->set_var(_controlpointsZ[0]);
821                         vecY->set_vec(_interpointsY[i]);
822                         interVX->push_back(*vecX);
823                         interVY->push_back(*vecY);
824                 }
825                 delete vecX;
826                 delete vecY;
827         }
828 }
829 //-----------------------------------------------------------------------------------------------------------------------------------------
830 //ERROR BETWEEN THE LOGICAL INTERSECTIONS
831 void AutoControlPoints::ErrorBetweenContours()
832 {
833         _errorpos = -1;
834         if(_interpointsX.size() != 0)
835         {
836                 _errorvector.clear();
837                 int i;
838 //EED 22 Sep 2008
839
840 //              FILE *fd;
841 //              fd = fopen("C:/bbtk_JS/data/interErrorData.txt","w");
842                 for(i=0; i<(int)(_interpointsX.size()); i++)
843                 {
844                         _errorvector.push_back( (sqrt( pow( _interpointsX[i]-_intervectorX[i].get_var(),2 ) + pow( _interpointsY[i]-_intervectorY[i].get_var(),2 ) )/_pathsize)*100 );
845 //                      fprintf(fd,"\n%d        %f",i,_errorvector[i]);
846                 }
847 //              fclose(fd);
848                 double max = -1;
849                 for(i=0; i<(int)(_errorvector.size()); i++)
850                 {
851                         if(_interpointsX[i] != -1)
852                         {
853                                 if(_errorvector[i]>max)
854                                 {
855                                         max = _errorvector[i];
856                                         _errorpos = i;
857                                 }
858                         }
859                 }
860         }
861 }
862 //-----------------------------------------------------------------------------------------------------------------------------------------
863 void AutoControlPoints::GetErrorBetweenContours( std::vector<double>*vec )
864 {
865         vec->clear();
866         vectorFunctions *vf = new vectorFunctions();
867         vf->copyVector(&_errorvector,vec);
868         delete vf;
869 }
870 //-----------------------------------------------------------------------------------------------------------------------------------------
871 void AutoControlPoints::AddControlPoint(bool activate)
872 {
873         if(_errorpos != -1)
874         {
875                 double xmax = _interpointsX[(int)_errorpos];
876                 double ymax = _interpointsY[(int)_errorpos];
877                 double xx       = _intervectorX[(int)_errorpos].get_var();
878                 double yy       = _intervectorY[(int)_errorpos].get_var();
879 printf("\n XMAX = %f, YMAX = %f, XX = %f, YY = %f",xmax,ymax,xx,yy);
880
881                 int i,ii,j,posA=-1,posB=-1;
882                 bool findA=false, findB=false;
883                 //CASE A
884                 for(i=(int)_errorpos; findA!=true; i++)
885                 {
886                         ii = i%_errorvector.size();
887                         for(j=0; j<(int)(_controlpointsX.size()); j++)
888                         {
889                                 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[ii].get_var()) && ((float)_intervectorX[ii].get_var()<=(float)_controlpointsX[j]+1.5) &&
890                                         ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[ii].get_var()) && ((float)_intervectorY[ii].get_var()<=(float)_controlpointsY[j]+1.5) )
891                                 {
892                                         findA = true;
893                                         posA = j;
894                                 }
895                         }
896                 }
897                 //CASE B
898                 for(i=(int)_errorpos; findB!=true; i--)
899                 {
900                         if(_errorpos==-1)
901                         {
902                                 i = _errorvector.size();
903                         }
904                         for(j=0; j<(int)(_controlpointsX.size()); j++)
905                         {
906                                 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[i].get_var()) && ((float)_intervectorX[i].get_var()<=(float)_controlpointsX[j]+1.5) &&
907                                         ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[i].get_var()) && ((float)_intervectorY[i].get_var()<=(float)_controlpointsY[j]+1.5) )
908                                 {
909                                         findB = true;
910                                         posB = j;
911                                 }
912                         }
913                 }
914                 if(posA == posB)
915                 {
916                         posB = posA-1;
917                 }
918                 if(posA<posB)
919                 {
920                         posA = posB+1;
921                         if( ( posB = _controlpointsX.size()-1) )  // ?!? // JPRx     // ?!? EED
922                         {
923                                 posA = 0;
924                         }
925                 }
926 printf("\n POSA = %d, X = %f, Y = %f",posA,_controlpointsX[posA],_controlpointsY[posA]);
927 printf("\n POSB = %d, X = %f, Y = %f",posB,_controlpointsX[posB],_controlpointsY[posB]);
928                 _posA = posA;
929                 _posB = posB;
930                 int id = -1;
931                 if(((posA!=-1)&&(posB!=-1)))
932                 {
933                         id = posA;
934                 }
935 printf("\n ID = %d",id);
936                 if(id != -1)
937                 {
938                         std::vector<double> tempX;
939                         std::vector<double> tempY;
940                         std::vector<double> tempZ;
941                         for(i=0; i<(int)(_controlpointsX.size()); i++)
942                         {
943                                 if(i == id)
944                                 {
945                                         tempX.push_back(xmax);
946                                         tempY.push_back(ymax);
947                                         tempZ.push_back(_controlpointsZ[0]);
948                                 }
949                                 tempX.push_back(_controlpointsX[i]);
950                                 tempY.push_back(_controlpointsY[i]);
951                                 tempZ.push_back(_controlpointsZ[i]);
952                         }
953                 
954                         if(activate == true)
955                         {
956                                 vectorFunctions *vf = new vectorFunctions();
957                                 vf->copyVector(&tempX,&_controlpointsX);
958                                 vf->copyVector(&tempY,&_controlpointsY);
959                                 vf->copyVector(&tempZ,&_controlpointsZ);
960                                 delete vf;
961                         }
962                 
963                 }
964         }//IF-(principal)
965 }
966 //-----------------------------------------------------------------------------------------------------------------------------------------
967 void AutoControlPoints::InterBetweenControl( )
968 {
969         _intervecXX.clear();
970         _intervecYY.clear();
971         
972         int i,ii,j,jj;
973         double m1,mn,m2,xinter,yinter;
974         if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points 
975         {
976 //EED 22 Sep 2008
977
978 //              FILE *fd;
979 //              fd = fopen("C:/bbtk_JS/data/InterBetweenControl.txt","w");
980                 for(i=0; i<(int)(_chargecontrolpointsX.size())-1; i++)
981                 {
982                         ii = (i+1)%(_chargecontrolpointsX.size());
983                         m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
984                         mn = m1;
985                         Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
986 //                      fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
987
988                         Vector *vecX = new Vector();
989                         Vector *vecY = new Vector();
990                         vecX->set_var(_chargecontrolpointsX[i]);
991                         vecY->set_var(_chargecontrolpointsY[i]);
992
993                         for(j=0; j<(int)(_chargecontrolpointsX.size()); j++)
994                         {
995                                 jj = (j+1)%(_chargecontrolpointsX.size());
996                                 m2 = Slope(_chargecontrolpointsX[j],_chargecontrolpointsY[j],_chargecontrolpointsX[jj],_chargecontrolpointsY[jj]);
997                                 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[j],_chargecontrolpointsY[j],mn,m2,&xinter,&yinter);
998                                 if( _chargecontrolpointsX[j]<=_chargecontrolpointsX[jj] )
999                                 {
1000                                         if( (xinter>=_chargecontrolpointsX[j]) && (xinter<=_chargecontrolpointsX[jj]) )
1001                                         {
1002                                                 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1003                                                 {
1004                                                 }
1005                                                 else
1006                                                 {
1007 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1008                                                         vecX->set_vec(xinter);
1009                                                         vecY->set_vec(yinter);
1010                                                 }
1011                                         }
1012                                 }
1013                                 if( _chargecontrolpointsX[j]>_chargecontrolpointsX[jj] )
1014                                 {
1015                                         if( (xinter<=_chargecontrolpointsX[j]) && (xinter>=_chargecontrolpointsX[jj]) )
1016                                         {
1017                                                 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1018                                                 {
1019                                                 }
1020                                                 else
1021                                                 {
1022 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1023                                                         vecX->set_vec(xinter);
1024                                                         vecY->set_vec(yinter);
1025                                                 }
1026                                         }
1027                                 }
1028                         }//FOR2
1029                         _intervecXX.push_back(*vecX);
1030                         _intervecYY.push_back(*vecY);
1031                         
1032                         //DELETE!!
1033                         delete vecX;
1034                         delete vecY;
1035
1036                 }//FOR1
1037 //              fclose(fd);
1038         }//IF
1039 }
1040 //-----------------------------------------------------------------------------------------------------------------------------------------
1041 void AutoControlPoints::fixBetweenControl()
1042 {
1043         _interitselfX.clear();
1044         _interitselfY.clear();
1045         int i,j;
1046         float vecx,vecy,varx,vary;
1047 //      FILE *fd;
1048 //      fd = fopen("C:/bbtk_JS/data/InterBetweenControlFix.txt","w");
1049         for(i=0; i<(int)(_intervecXX.size()); i++)
1050         {
1051                 Vector *vx = new Vector();
1052                 Vector *vy = new Vector();
1053                 vx->set_var(_intervecXX[i].get_var());
1054                 vy->set_var(_intervecYY[i].get_var());
1055 //              fprintf(fd,"\n Para X = %f, Y = %f",_intervecXX[i].get_var(),_intervecYY[i].get_var());
1056                 for(j=0; j<_intervecXX[i].getsize_vec(); j++)
1057                 {
1058                         vecx = _intervecXX[i].get_vec(j);
1059                         varx = _intervecXX[i].get_var();
1060                         vecy = _intervecYY[i].get_vec(j);
1061                         vary = _intervecYY[i].get_var();
1062                         if(  (vecx == varx) && (vecy == vary) )
1063                         {
1064                         }
1065                         else
1066                         {
1067                                 vx->set_vec((double)vecx);
1068                                 vy->set_vec((double)vecy);
1069 //                              fprintf(fd,"\n => x_int = %f, y_int = %f",vecx,vecy);
1070                         }
1071                 }
1072                 _interitselfX.push_back(*vx);
1073                 _interitselfY.push_back(*vy);
1074                 delete vx;
1075                 delete vy;
1076         }
1077 //      fclose(fd);
1078 }
1079 //-----------------------------------------------------------------------------------------------------------------------------------------
1080 void AutoControlPoints::PossibleIntersections( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1081 {
1082         InterBetweenContours(InX,InY,InZ);      //_intervectorX
1083         //InterBetweenControl();                                //_intervecXX
1084         //fixBetweenControl();                          //_interitselfX
1085         
1086         std::vector<Vector> tempX;
1087         std::vector<Vector> tempY;
1088         tempX.clear();
1089         tempY.clear();
1090         int i,j,k;
1091         //double dist1,dist2; // JPRx
1092 //EED 22 Sep 2008
1093 //      FILE *fd;
1094 /*
1095         bool ready;
1096         fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1097
1098
1099         for(i=0; i<_intervectorX.size(); i++)
1100         {
1101                 fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1102                 Vector *vx = new Vector();
1103                 Vector *vy = new Vector();
1104                 vx->set_var(_intervectorX[i].get_var());
1105                 vy->set_var(_intervectorY[i].get_var());
1106                 ready = false;
1107                 for(j=0; j<_intervectorX[i].getsize_vec() ; j++)
1108                 {
1109                         dist1 = sqrt( pow(_intervectorX[i].get_var()-_intervectorX[i].get_vec(j),2) + pow(_intervectorY[i].get_var()-_intervectorY[i].get_vec(j),2) );
1110                         for(k=0; (k<_interitselfX[i].getsize_vec()) && (ready!=true); k++)
1111                         {
1112                                 dist2 = sqrt( pow(_interitselfX[i].get_var()-_interitselfX[i].get_vec(k),2) + pow(_interitselfY[i].get_var()-_interitselfY[i].get_vec(k),2) );
1113                                 if(dist2>dist1)
1114                                 {
1115                                         fprintf(fd,"\n => x_int = %f, y_int = %f",_intervectorX[i].get_vec(j),_intervectorY[i].get_vec(j));
1116                                         vx->set_vec(_intervectorX[i].get_vec(j));
1117                                         vy->set_vec(_intervectorY[i].get_vec(j));
1118                                         ready == true;
1119                                 }
1120                         }
1121                 }
1122                 tempX.push_back(*vx);
1123                 tempY.push_back(*vy);
1124                 delete vx;
1125                 delete vy;
1126         }
1127         fclose(fd);
1128         
1129         _intervectorX.clear();
1130         _intervectorY.clear();
1131         Vector *vv = new Vector();
1132         vv->copyVector(&tempX,&_intervectorX);
1133         vv->copyVector(&tempY,&_intervectorY);
1134         
1135         //vv->printVector(&_intervectorX);
1136 */
1137         std::vector<double> arrX; 
1138         std::vector<double> arrY;
1139         std::vector<double>::iterator itx;
1140         std::vector<double>::iterator ity;
1141         std::vector<double>::iterator itxx;
1142         std::vector<double>::iterator ityy;
1143         double distA, distB;
1144         if(_intervectorX.size() != 0)
1145         {
1146 //              fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1147                 for(i=0; i<(int)(_intervectorX.size()); i++)
1148                 {
1149 //                      fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1150                         if(_intervectorX[i].getsize_vec() > 1)
1151                         {
1152                                 arrX.clear();
1153                                 arrY.clear();
1154                                 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
1155                                 {
1156                                         arrX.push_back(_intervectorX[i].get_vec(j));
1157                                         arrY.push_back(_intervectorY[i].get_vec(j));
1158                                 }
1159 //printf("\n arrX Size = %d",arrX.size());
1160                                 itx = arrX.begin();
1161                                 ity = arrY.begin();
1162                                 itxx = arrX.begin()+1;
1163                                 ityy = arrY.begin()+1;
1164                                 for(j=0; j<(int)(arrX.size())-1; j++)
1165                                 {
1166                                         // I
1167                                         if( (*itx > _intervectorX[i].get_var())  && (*ity < _intervectorY[i].get_var()) && 
1168                                                 (*itxx > _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1169                                         {
1170                                                 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1171                                                 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1172                                                 if(distA<distB)
1173                                                 {
1174                                                         arrX.erase(itxx);
1175                                                         arrY.erase(ityy);
1176                                                 }
1177                                                         if(distA>distB)
1178                                                 {
1179                                                         arrX.erase(itx);
1180                                                         arrY.erase(ity);
1181                                                         itxx++;
1182                                                         ityy++;
1183                                                 }       
1184                                         }
1185                                         // II
1186                                         else if( (*itx < _intervectorX[i].get_var())  && (*ity < _intervectorY[i].get_var()) && 
1187                                                 (*itxx < _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1188                                         {
1189                                                 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1190                                                 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1191                                                 if(distA<distB)
1192                                                 {
1193                                                         arrX.erase(itxx);
1194                                                         arrY.erase(ityy);
1195                                                 }
1196                                                 if(distA>distB)
1197                                                 {
1198                                                         arrX.erase(itx);
1199                                                         arrY.erase(ity);
1200                                                         itxx++;
1201                                                         ityy++;
1202                                                 }       
1203                                         }
1204                                         // III
1205                                         else if( (*itx < _intervectorX[i].get_var())  && (*ity > _intervectorY[i].get_var()) && 
1206                                                 (*itxx < _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1207                                         {
1208                                                 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1209                                                 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1210                                                 if(distA<distB)
1211                                                 {
1212                                                         arrX.erase(itxx);
1213                                                         arrY.erase(ityy);
1214                                                 }
1215                                                 if(distA>distB)
1216                                                 {
1217                                                         arrX.erase(itx);
1218                                                         arrY.erase(ity);
1219                                                         itxx++;
1220                                                         ityy++;
1221                                                 }       
1222                                         }
1223                                         // IV
1224                                         else if( ((double)*itx > _intervectorX[i].get_var())  && (*ity > _intervectorY[i].get_var()) && 
1225                                                 ((double)*itxx > _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1226                                         {
1227                                                 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1228                                                 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1229                                                 if(distA<distB)
1230                                                 {
1231                                                         arrX.erase(itxx);
1232                                                         arrY.erase(ityy);
1233                                                 }
1234                                                 if(distA>distB)
1235                                                 {
1236                                                         arrX.erase(itx);
1237                                                         arrY.erase(ity);
1238                                                         itxx++;
1239                                                         ityy++;
1240                                                 }       
1241                                         }
1242                                         else
1243                                         {
1244                                                 itx++;
1245                                                 ity++;
1246                                                 itxx++;
1247                                                 ityy++;
1248                                         }
1249                                 }
1250                                 _intervectorX[i].resetVec();
1251                                 _intervectorY[i].resetVec();
1252 //printf("\n _intervector(%d) Size = %d",i,_intervectorX[i].getsize_vec());
1253                                 for(k=0; k<(int)(arrX.size()); k++)
1254                                 {
1255 //printf("\n arr(%d) X = %f, Y = %f",k,arrX[k],arrY[k]);
1256 //                                      fprintf(fd,"\n => x_int = %f, y_int = %f",arrX[k],arrY[k]);
1257                                         _intervectorX[i].set_vec(arrX[k]);
1258                                         _intervectorY[i].set_vec(arrY[k]);
1259                                 }
1260                         }
1261                 }
1262         }
1263
1264         //DELETE!!
1265 //      delete vv;
1266
1267 }
1268 //-----------------------------------------------------------------------------------------------------------------------------------------
1269 void AutoControlPoints::ControlInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1270 {
1271         int i,j;
1272         _contIncontpos.clear(); 
1273         bool find = false;
1274         double range = 2;
1275         for(i=0; i<(int)(_controlpointsX.size()); i++)
1276         {
1277                 find = false;
1278                 for(j=0; (j<(int)(InX->size())) && (find!=true); j++)
1279                 {
1280                         if( ((*InX)[j]-range<=_controlpointsX[i]) && (_controlpointsX[i]<=(*InX)[j]+range) && ((*InY)[j]-range<=_controlpointsY[i]) && (_controlpointsY[i]<=(*InY)[j]+range) )
1281                         {
1282                                 _contIncontpos.push_back(j);
1283                                 find = true;
1284                         }
1285                 }
1286         }
1287 }
1288 //-----------------------------------------------------------------------------------------------------------------------------------------
1289 void AutoControlPoints::NearMaxError2Control()
1290 {
1291         if(_interpointsX.size() != 0)
1292         {
1293                 AddControlPoint(false);
1294
1295                 double distA = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posA],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posA],2) );
1296                 double distB = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posB],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posB],2) );
1297                 double nearp = -1;
1298                 if(distA<distB)
1299                 {
1300                         nearp = distA;
1301                         _posn = _posA;
1302
1303                 }
1304                 else
1305                 {
1306                         nearp = distB;
1307                         _posn = _posB;
1308                 }
1309         }
1310 }
1311 //-----------------------------------------------------------------------------------------------------------------------------------------
1312 void AutoControlPoints::MoveControlPointInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1313 {
1314 int i;
1315 /*
1316 //PRINTF---------------------------------------------------------------
1317 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1318 for(i=0; i<_controlpointsX.size(); i++)
1319 {
1320         printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1321 }
1322 //---------------------------------------------------------------------
1323 */
1324         vectorFunctions *vf = new vectorFunctions();
1325         fixBetweenPoints(5.0);
1326         PossibleIntersections(InX,InY,InZ);
1327         IntersectionPoints();
1328         ErrorBetweenContours();
1329         //double promIn = vf->promVector(&_errorvector,false); // JPRx
1330
1331         std::vector<double> tempX;
1332         std::vector<double> tempY;
1333         std::vector<double> tempZ;
1334         tempX.clear();
1335         tempY.clear();
1336         tempZ.clear();
1337         
1338         vf->copyVector(&_controlpointsX,&tempX);
1339         vf->copyVector(&_controlpointsY,&tempY);
1340         vf->copyVector(&_controlpointsZ,&tempZ);
1341         _controlpointsX.clear();
1342         _controlpointsY.clear();
1343         _controlpointsZ.clear();
1344
1345         for(i=0; i<(int)(tempX.size()); i++)
1346         {
1347                 if(i==_posn)
1348                 {
1349                         _controlpointsX.push_back( (*InX)[_contIncontpos[_posn]] );
1350                         _controlpointsY.push_back( (*InY)[_contIncontpos[_posn]] );
1351                         _controlpointsZ.push_back( (*InZ)[_contIncontpos[_posn]] );
1352                 }
1353                 else
1354                 {
1355                         _controlpointsX.push_back( tempX[i] );
1356                         _controlpointsY.push_back( tempY[i] );
1357                         _controlpointsZ.push_back( tempZ[i] );
1358                 }
1359         }
1360
1361         fixBetweenPoints(5.0);
1362         PossibleIntersections(InX,InY,InZ);
1363         IntersectionPoints();
1364         ErrorBetweenContours();
1365         double promactualIn = vf->promVector(&_errorvector,false);
1366         double prom;
1367         double promactual;
1368         
1369         int posact;
1370         //int pos1; // JPRx
1371         //double prom1final; // JPRx
1372         int pos2;
1373         double prom2final;
1374
1375         //DIRECTION 1
1376         int direction = 1;
1377         posact = _posn;
1378         prom = -1;
1379         promactual = promactualIn;
1380         _controlpointsX.clear();
1381         _controlpointsY.clear();
1382         _controlpointsZ.clear();
1383         for(i=0; promactual > prom; i++)
1384         {
1385                 prom = promactual;
1386                 for(i=0; i<(int)(tempX.size()); i++)
1387                 {
1388                         if(i==_posn)
1389                         {
1390                                 _controlpointsX.push_back( (*InX)[_contIncontpos[posact]] );
1391                                 _controlpointsY.push_back( (*InY)[_contIncontpos[posact]] );
1392                                 _controlpointsZ.push_back( (*InZ)[_contIncontpos[posact]] );
1393                         }
1394                         else
1395                         {
1396                                 _controlpointsX.push_back( tempX[i] );
1397                                 _controlpointsY.push_back( tempY[i] );
1398                                 _controlpointsZ.push_back( tempZ[i] );
1399                         }
1400                 }
1401                 if(direction == 1)
1402                 {
1403                         posact = posact+1;
1404                 }
1405                 if(direction == -1)
1406                 {
1407                         posact = posact-1;
1408                 }
1409                 fixBetweenPoints(5.0);
1410                 PossibleIntersections(InX,InY,InZ);
1411                 IntersectionPoints();
1412                 ErrorBetweenContours();
1413                 promactual = vf->promVector(&_errorvector,false);
1414 //printf("\n The point in the position %d, has moved %d times",_posn,i);
1415         }
1416         pos2 = posact;
1417         prom2final = promactual;
1418
1419         delete vf;
1420 }
1421 //--------------------------------------------------------------------------------------------------------------------------------
1422 double AutoControlPoints::MoveAndAverage(int dir, std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1423 {
1424         /*
1425 //PRINTF---------------------------------------------------------------
1426         int i;
1427         printf("\n CONTROL POINTS BEFORE MOVEMENT");
1428         for(i=0; i<_controlpointsX.size(); i++)
1429         {
1430                 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1431         }
1432         for(i=0; i<_contIncontpos.size(); i++)
1433         {
1434                 printf("\n contIncont pos = %d",_contIncontpos[i]);
1435         }
1436 */
1437 //IMPLEMENTATION-------------------------------------------------------
1438         if( (_contIncontpos.size() != 0) && (_controlpointsX.size() != 0) )
1439         {
1440                 vectorFunctions *vf = new vectorFunctions();
1441                 std::vector<double>::iterator itx;
1442                 std::vector<double>::iterator ity;
1443                 std::vector<double> tempX;
1444                 std::vector<double> tempY;
1445                 tempX.clear();
1446                 tempY.clear();
1447                 vf->copyVector(&_controlpointsX,&tempX);
1448                 vf->copyVector(&_controlpointsY,&tempY);
1449                 int i,j /*,pos = 0*/ ;  // JPRx
1450                 double prom1=0,promactual1=1;
1451                 //double prom2=0,promactual2=1; // JPRx
1452                 int h = 0;
1453                 int hh = 1;
1454                 if(_contIncontpos[h]>_contIncontpos[hh])
1455                 {
1456                         itx = _controlpointsX.begin();
1457                         ity = _controlpointsY.begin();
1458                         for(i=_contIncontpos[h],j=_contIncontpos[h]; (i>_contIncontpos[hh]) && (promactual1>prom1); i--)
1459                         {
1460                                 if(j == (int)(InX->size()))
1461                                 {
1462                                         j = 0;
1463                                 }
1464                                 prom1 = promactual1;
1465                                 *itx = (*InX)[j];
1466                                 *ity = (*InY)[j];
1467                                 printf("\n itx = %f, ity = %f", *itx,*ity);
1468                                 fixBetweenPoints(5.0);
1469                                 PossibleIntersections(InX,InY,InZ);
1470                                 IntersectionPoints();
1471                                 ErrorBetweenContours();
1472                                 promactual1 = vf->promVector(&_errorvector,false);
1473                                 j++;
1474                         }
1475                 }
1476                 if(_contIncontpos[h]<_contIncontpos[hh])
1477                 {
1478                         itx = _controlpointsX.begin();
1479                         ity = _controlpointsY.begin();
1480                         for(i=_contIncontpos[h],j=_contIncontpos[h]; (i<_contIncontpos[hh]) && (promactual1>prom1); i++)
1481                         {
1482                                 if(j == -1)
1483                                 {
1484                                         j = InX->size()-1;
1485                                 }
1486                                 prom1 = promactual1;
1487                                 *itx = (*InX)[j];
1488                                 *ity = (*InY)[j];
1489                                 printf("\n itx = %f, ity = %f", *itx,*ity);
1490                                 fixBetweenPoints(5.0);
1491                                 PossibleIntersections(InX,InY,InZ);
1492                                 IntersectionPoints();
1493                                 ErrorBetweenContours();
1494                                 promactual1 = vf->promVector(&_errorvector,false);
1495                                 j--;
1496                         }
1497                 }
1498                 delete vf;
1499         }
1500         return 99999;
1501 }
1502 //--------------------------------------------------------------------------------------------------------------------------------
1503 void AutoControlPoints::MoveControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1504 {
1505         ControlInContour(InX,InY,InZ);
1506         NearMaxError2Control();
1507         MoveAndAverage(1,InX,InY,InZ);
1508 }
1509 //-----------------------------------------------------------------------------------------------------------------------------------------
1510 void AutoControlPoints::GetNewPoints( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1511 {
1512         vectorFunctions *vf = new vectorFunctions();
1513         double prom,maxerror;
1514         
1515         InterCircle(InX,InY,InZ);
1516         maxminLocal();
1517         fixBetweenPoints(5.0);
1518         PossibleIntersections(InX,InY,InZ);
1519         IntersectionPoints();
1520         ErrorBetweenContours();
1521         prom = vf->promVector(&_errorvector,false);
1522         vf->maxVector(&_errorvector,&maxerror);
1523 printf("\n");
1524         if( maxerror>3.0 )
1525         {
1526                 _controlpointsX.clear();
1527                 _controlpointsY.clear();
1528                 _controlpointsZ.clear();
1529                 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1530                 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1531                 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1532                 {
1533                         _controlpointsZ.push_back( (*InZ)[0] );
1534                 }
1535                 fixBetweenPoints(5.0);
1536                 PossibleIntersections(InX,InY,InZ);
1537                 IntersectionPoints();
1538                 ErrorBetweenContours();
1539                 prom = vf->promVector(&_errorvector,false);
1540                 vf->maxVector(&_errorvector,&maxerror);
1541 printf("\n");
1542         }
1543
1544         std::vector<double> cpX;
1545         std::vector<double> cpY;
1546         std::vector<double> cpZ;
1547         cpX.clear();
1548         cpY.clear();
1549         cpZ.clear();
1550         vf->copyVector(&_controlpointsX,&cpX);
1551         vf->copyVector(&_controlpointsY,&cpY);
1552         vf->copyVector(&_controlpointsZ,&cpZ);
1553         int i;
1554
1555         for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1556         {
1557                 AddControlPoint(true);
1558                 fixBetweenPoints(5.0);
1559                 PossibleIntersections(InX,InY,InZ);
1560                 IntersectionPoints();
1561                 ErrorBetweenContours();
1562                 prom = vf->promVector(&_errorvector,false);
1563                 vf->maxVector(&_errorvector,&maxerror);
1564                 printf("\n %d ",i);
1565         }
1566
1567         if(i == 10)
1568         {
1569                 _controlpointsX.clear();
1570                 _controlpointsY.clear();
1571                 _controlpointsZ.clear();
1572                 int inicontrolpoints = cpX.size();
1573                 double inipercentage = (inicontrolpoints*100)/InX->size();
1574                 int h=0;
1575                 if(inicontrolpoints<10)
1576                 {
1577                         int points = (int)((inipercentage*3*InX->size())/100);
1578                         for (int i=0; i<(int)(InX->size()); i++, h++)
1579                         {
1580                                 if( h == points )
1581                                 {
1582                                         _controlpointsX.push_back( (*InX)[i] );
1583                                         _controlpointsY.push_back( (*InY)[i] );
1584                                         _controlpointsZ.push_back( (*InZ)[i] );
1585                                         h = 0;
1586                                 }
1587                         }
1588                 }
1589                 if(inicontrolpoints>=10)
1590                 {
1591                         int points = (int)((inipercentage*2*InX->size())/100);
1592                         for (int i=0; i<(int)(InX->size()); i++, h++)
1593                         {
1594                                 if( h == points )
1595                                 {
1596                                         _controlpointsX.push_back( (*InX)[i] );
1597                                         _controlpointsY.push_back( (*InY)[i] );
1598                                         _controlpointsZ.push_back( (*InZ)[i] );
1599                                         h = 0;
1600                                 }
1601                         }
1602                 }
1603         }
1604 /*
1605         fixBetweenPoints(5.0);
1606         PossibleIntersections(InX,InY,InZ);
1607         IntersectionPoints();
1608         ErrorBetweenContours();
1609         prom = vf->promVector(&_errorvector,false);
1610         vf->maxVector(&_errorvector,&maxerror);
1611
1612
1613 printf("\n Error Average  = %f",prom);
1614 printf("\n Error Max  = %f",maxerror);
1615         AddControlPoint(false);
1616 */
1617 /*
1618         //if( (prom>1) || (maxerror>2))
1619         if( prom>0.2 )
1620         {
1621 printf("\n Error Average is grater than 1 !!");
1622                 MoveControlPoints(InX,InY,InZ);
1623         }
1624 */
1625         delete vf;
1626 }
1627 //------------------------------------------------------------------------------------------------------------------------------------------
1628 void AutoControlPoints::GetInitialNewPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1629 {
1630         vectorFunctions *vf = new vectorFunctions();
1631         double prom,maxerror;
1632         
1633         InterCircle(InX,InY,InZ);
1634         maxminLocal();
1635         fixBetweenPoints(5.0);
1636         PossibleIntersections(InX,InY,InZ);
1637         IntersectionPoints();
1638         ErrorBetweenContours();
1639         prom = vf->promVector(&_errorvector,false);
1640         vf->maxVector(&_errorvector,&maxerror);
1641         
1642         if( maxerror>3.0 )
1643         {
1644                 _controlpointsX.clear();
1645                 _controlpointsY.clear();
1646                 _controlpointsZ.clear();
1647                 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1648                 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1649                 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1650                 {
1651                         _controlpointsZ.push_back( (*InZ)[0] );
1652                 }
1653                 fixBetweenPoints(5.0);
1654                 PossibleIntersections(InX,InY,InZ);
1655                 IntersectionPoints();
1656                 ErrorBetweenContours();
1657                 prom = vf->promVector(&_errorvector,false);
1658                 vf->maxVector(&_errorvector,&maxerror);
1659         }
1660
1661         std::vector<double> cpX;
1662         std::vector<double> cpY;
1663         std::vector<double> cpZ;
1664         cpX.clear();
1665         cpY.clear();
1666         cpZ.clear();
1667         vf->copyVector(&_controlpointsX,&cpX);
1668         vf->copyVector(&_controlpointsY,&cpY);
1669         vf->copyVector(&_controlpointsZ,&cpZ);
1670
1671         double promini = prom; 
1672
1673         int i;
1674         for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1675         {
1676                 AddControlPoint(true);
1677                 fixBetweenPoints(5.0);
1678                 PossibleIntersections(InX,InY,InZ);
1679                 IntersectionPoints();
1680                 ErrorBetweenContours();
1681                 prom = vf->promVector(&_errorvector,false);
1682                 vf->maxVector(&_errorvector,&maxerror);
1683         }
1684
1685         if( i==10 || prom > promini)
1686         {
1687                 _controlpointsX.clear();
1688                 _controlpointsY.clear();
1689                 _controlpointsZ.clear();
1690                 vf->copyVector(&cpX,&_controlpointsX);
1691                 vf->copyVector(&cpY,&_controlpointsY);
1692                 vf->copyVector(&cpZ,&_controlpointsZ);
1693         }
1694         delete vf;
1695 }
1696 //------------------------------------------------------------------------------------------------------------------------------------------
1697 void AutoControlPoints::CalculeControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1698 {
1699
1700         _controlpointsX.clear();
1701         _controlpointsY.clear();
1702         _controlpointsZ.clear();
1703         _controlpointsZ.push_back((*InZ)[0]);
1704         GetNewPoints( InX,InY,InZ );
1705 }
1706 //-----------------------------------------------------------------------------------------------------------------------------------------
1707 void AutoControlPoints::CalculeInitialControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1708 {
1709
1710         _controlpointsX.clear();
1711         _controlpointsY.clear();
1712         _controlpointsZ.clear();
1713         _controlpointsZ.push_back((*InZ)[0]);
1714         GetInitialNewPoints( InX,InY,InZ );
1715 }
1716 //-----------------------------------------------------------------------------------------------------------------------------------------
1717 void AutoControlPoints::GetControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1718 {
1719         vectorFunctions *vf = new vectorFunctions();
1720         OutX->clear();
1721         OutY->clear();
1722         OutZ->clear();
1723         vf->copyVector(&_controlpointsX,OutX);
1724         vf->copyVector(&_controlpointsY,OutY);
1725         vf->copyVector(&_controlpointsZ,OutZ);
1726         delete vf;
1727 }
1728 //-----------------------------------------------------------------------------------------------------------------------------------------
1729 void AutoControlPoints::GetInitialControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1730 {
1731         vectorFunctions *vf = new vectorFunctions();
1732         OutX->clear();
1733         OutY->clear();
1734         OutZ->clear();
1735         vf->copyVector(&_controlpointsX,OutX);
1736         vf->copyVector(&_controlpointsY,OutY);
1737         vf->copyVector(&_controlpointsZ,OutZ);
1738         delete vf;
1739 }
1740
1741 //-----------------------------------------------------------------------------------------------------------------------------------------
1742 void AutoControlPoints::SetNumSplineInterpolation(int num)
1743 {
1744         _numspline = num;
1745 }
1746 //-----------------------------------------------------------------------------------------------------------------------------------------
1747 //-----------------------------------------------------------------------------------------------------------------------------------------
1748 //-----------------------------------------------------------------------------------------------------------------------------------------
1749  
1750