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