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