]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/AutoControlPoints.cxx
#3093 creaMaracasVisu Feature New Normal - Contour Information in pixels and image...
[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
272 //printf("\nPATH SIZE = %f",_pathsize);
273
274                  std::ofstream file1;
275                 file1.open( "4_SplinePoints.txt" );
276
277                 for(int i = 0; i < numspline; i++){
278                         file1<<"X= "<<_chargecontrolpointsX[i] << "\tY= "<<_chargecontrolpointsY[i] << "\tZ= "<<_chargecontrolpointsZ[i]<<std::endl;
279                 }
280                 file1.close();
281          }
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         std::ofstream file1;
490     file1.open( "1_Intersection.txt" );
491
492         for(int i = 0; i < (int)(_intercircleX.size()); i++){
493                 file1<<"X= "<<_intercircleX[i] << "\tY= "<<_intercircleY[i] << "\tDist= "<<_intercircleDist[i]<<std::endl;
494         }
495         file1.close();
496                 
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 //JCP 26-09-08  
573         std::ofstream file1;
574     file1.open( "2_MaxMin.txt" );
575
576         for(int i = 0; i < (int)(_controlpointsX.size()); i++){
577                 file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
578         }
579         file1.close();
580 //JCP 26-09-08
581         delete vecf;
582 }
583 //-----------------------------------------------------------------------------------------------------------------------------------------
584 //ELIMINATES THE POINTS WITH A DISTANCE < val
585 void AutoControlPoints::fixBetweenPoints(double val)
586 {
587         int size = _controlpointsX.size();
588         double dist;
589         if(size != 0)
590         {
591                 std::vector<double> tempX;
592                 std::vector<double> tempY;
593                 std::vector<double>     tempZ;
594                 tempX.clear();
595                 tempY.clear();
596                 tempZ.clear();
597
598                 int ii;
599                 vectorFunctions *vecf = new vectorFunctions();
600                 for(int i=0; i<size; i++)
601                 {
602                         ii = (i+1)%size;
603                         dist = sqrt(pow(_controlpointsX[i]-_controlpointsX[ii],2)+pow(_controlpointsY[i]-_controlpointsY[ii],2));
604                         if(dist>val)
605                         {
606                                 tempX.push_back(_controlpointsX[i]);
607                                 tempY.push_back(_controlpointsY[i]);
608                                 tempZ.push_back(_controlpointsZ[i]);
609                         }
610                 }
611                 _controlpointsX.clear();
612                 _controlpointsY.clear();
613                 _controlpointsZ.clear();
614
615                 vecf->copyVector(&tempX,&_controlpointsX);
616                 vecf->copyVector(&tempY,&_controlpointsY);
617                 vecf->copyVector(&tempZ,&_controlpointsZ);
618
619                 std::ofstream file1;
620                 file1.open( "3_PointsFixed.txt" );
621
622                 for(int i = 0; i < (int)(_controlpointsX.size()); i++){
623                         file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
624                 }
625                 file1.close();
626
627                 delete vecf;
628         }
629 }
630 //-----------------------------------------------------------------------------------------------------------------------------------------
631 //ALL THE INTERSECTIONS
632 void AutoControlPoints::InterBetweenContours(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
633 {
634         _intervectorX.clear();
635         _intervectorY.clear();
636         ChargeSpline();
637
638         int i,ii,j,jj;
639         double m1,mn,m2,xinter,yinter;
640         if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points 
641         {
642 //EED 22 Sep 2008
643 //              FILE *fd;
644 //              fd = fopen("C:/bbtk_JS/data/interBetweenContours.txt","w");
645                 for(i=0; i<(int)(_chargecontrolpointsX.size()); i++)
646                 {
647                         ii = (i+1)%(_chargecontrolpointsX.size());
648
649                         m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
650                         mn = m1;
651                         Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
652 //                      fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
653
654                         Vector *vecX = new Vector();
655                         Vector *vecY = new Vector();
656                         vecX->set_var(_chargecontrolpointsX[i]);
657                         vecY->set_var(_chargecontrolpointsY[i]);
658
659                         for(j=0; j<(int)(InX->size()); j++)
660                         {
661                                 jj = (j+1)%(InX->size());
662                                 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);
663                                 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],(*InX)[j],(*InY)[j],mn,m2,&xinter,&yinter);
664
665                                 if(((*InX)[j] <= xinter && xinter <= (*InX)[jj]) || (xinter<=(*InX)[j] && xinter>=(*InX)[jj])){
666                                         vecX->set_vec(xinter);
667                                         vecY->set_vec(yinter);
668                                 }
669 /*JCP 29-09-08
670                                 if( (*InX)[j]<=(*InX)[jj] )
671                                 {
672                                         if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) )
673                                         {
674                                                 //If the point is a CP, the intersection is itself.
675                                                 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
676                                                 {
677                                                         vecX->set_vec(xinter);
678                                                         vecY->set_vec(yinter);
679 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
680                                                 }
681                                                 else
682                                                 {
683                                                         vecX->set_vec(xinter);
684                                                         vecY->set_vec(yinter);
685 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
686                                                 }
687                                         }
688                                 }
689                                 if( (*InX)[j]>(*InX)[jj] )
690                                 {
691                                         if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) )
692                                         {
693                                                 //If the point is a CP, the intersection is itself.
694                                                 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
695                                                 {
696                                                         vecX->set_vec(xinter);
697                                                         vecY->set_vec(yinter);
698 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
699                                                 }
700                                                 else
701                                                 {
702                                                         vecX->set_vec(xinter);
703                                                         vecY->set_vec(yinter);
704 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
705                                                 }
706                                         }
707                                 }
708 JCP 29-09-08*/
709                         }//FOR2
710                         _intervectorX.push_back(*vecX);
711                         _intervectorY.push_back(*vecY);
712                         //DELETE!!
713                         delete vecX;
714                         delete vecY;
715                 }//FOR1
716 //              fclose(fd);
717         }//IF
718 }
719 //-----------------------------------------------------------------------------------------------------------------------------------------
720 void AutoControlPoints::GetInterBetweenContours(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
721 {
722         interVX->clear();
723         interVY->clear();
724         int size = _intervectorX.size();
725         int i;
726         if(size != 0)
727         {
728                 for(i=0; i<size; i++)
729                 {
730                         interVX->push_back(_intervectorX[i]);
731                         interVY->push_back(_intervectorY[i]);
732                 }
733         }
734 }
735 //-----------------------------------------------------------------------------------------------------------------------------------------
736 //ONLY THE LOGICAL INTERSECTIONS
737 void AutoControlPoints::IntersectionPoints()
738 {
739         if(_intervectorX.size() != 0)
740         {               
741                 _interpointsX.clear();
742                 _interpointsY.clear();
743
744 //EED
745 //              FILE *fd;
746 //              fd = fopen("C:/bbtk_JS/data/IntersectionPoints.txt","w");
747                 double dist,min;
748                 int i,j,posj;
749
750                 posj = -1;
751                 min = 9999;
752 /*JCP 30-08-09 
753                 for(j=0; j<_intervectorX[0].getsize_vec(); j++)
754                 {
755                         dist = sqrt( pow( _intervectorX[0].get_vec(j)-_intervectorX[0].get_var(),2 ) + pow( _intervectorY[0].get_vec(j)-_intervectorY[0].get_var(),2 ) );
756                         if( dist < min )
757                         {
758                                 min = dist;
759                                 posj = j;
760                         }
761                 }
762                 if(posj != -1)
763                 {
764                         _interpointsX.push_back(_intervectorX[0].get_vec(posj));
765                         _interpointsY.push_back(_intervectorY[0].get_vec(posj));
766 //                      fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[0].get_var(),_intervectorY[0].get_var());
767 //                      fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[0],_interpointsY[0]);
768                 }
769                 if(posj == -1)
770                 {
771                         printf("\n\n There is an invalid intersection: Must see AutoControlPoints::IntersectionPoints() method");
772                 }
773 JCP 30-08-09 */
774                 for(i=0; i<(int)(_intervectorX.size()); i++){
775                         min = 9999;
776                         posj = -1;
777                         for(j=0; j<_intervectorX[i].getsize_vec(); j++) {
778                                 dist  = sqrt( pow( _intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2 ) + pow( _intervectorY[i].get_vec(j)-_intervectorX[i].get_var(),2 ) );
779                                 if( dist < min ){
780                                         min = dist;
781                                         posj = j;
782                                 }
783                         }
784                         _interpointsX.push_back(_intervectorX[i].get_vec(posj));
785                         _interpointsY.push_back(_intervectorY[i].get_vec(posj));                
786                 }
787 /*JCP 30-09-08
788                 for(i=1; i<_intervectorX.size(); i++)
789                 {
790                         min = 9999;
791                         posj = -1;
792 //                      fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
793                         for(j=0; j<_intervectorX[i].getsize_vec(); j++)
794                         {
795                                 //TYPE: LE PLUS PRES VOISIN
796                                 dist  = sqrt( pow( _intervectorX[i].get_vec(j)-_interpointsX[i-1],2 ) + pow( _intervectorY[i].get_vec(j)-_interpointsY[i-1],2 ) );
797                                 //TYPE: LE PLUS PRES DANS LA M�ME DROITE
798                                 //dist = sqrt(pow(_intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2)+pow(_intervectorY[i].get_vec(j)-_intervectorY[i].get_var(),2));
799                                 
800                                 if( dist < min )
801                                 {
802                                         min = dist;
803                                         posj = j;
804                                 }
805                         }
806                         _interpointsX.push_back(_intervectorX[i].get_vec(posj));
807                         _interpointsY.push_back(_intervectorY[i].get_vec(posj));
808 //                      fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[i],_interpointsY[i]);
809                 }
810 JCP 30-09-08*/
811 //              fclose(fd);
812         }
813 }
814 //-----------------------------------------------------------------------------------------------------------------------------------------
815 void AutoControlPoints::GetIntersectionPoints(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
816 {
817         int size = _interpointsX.size();
818         int i;
819         if(size != 0)
820         {
821                 Vector *vecX = new Vector();
822                 Vector *vecY = new Vector();
823                 interVX->clear();
824                 interVY->clear();
825                 for(i=0; i<size; i++)
826                 {
827                         vecX->set_var(_controlpointsZ[0]);
828                         vecX->set_vec(_interpointsX[i]);
829                         vecY->set_var(_controlpointsZ[0]);
830                         vecY->set_vec(_interpointsY[i]);
831                         interVX->push_back(*vecX);
832                         interVY->push_back(*vecY);
833                 }
834                 delete vecX;
835                 delete vecY;
836         }
837 }
838 //-----------------------------------------------------------------------------------------------------------------------------------------
839 //ERROR BETWEEN THE LOGICAL INTERSECTIONS
840 void AutoControlPoints::ErrorBetweenContours()
841 {
842         _errorpos = -1;
843         if(_interpointsX.size() != 0)
844         {
845                 _errorvector.clear();
846                 int i;
847 //EED 22 Sep 2008
848
849 //              FILE *fd;
850 //              fd = fopen("C:/bbtk_JS/data/interErrorData.txt","w");
851                 for(i=0; i<(int)(_interpointsX.size()); i++)
852                 {
853                         _errorvector.push_back( (sqrt( pow( _interpointsX[i]-_intervectorX[i].get_var(),2 ) + pow( _interpointsY[i]-_intervectorY[i].get_var(),2 ) )/_pathsize)*100 );
854 //                      fprintf(fd,"\n%d        %f",i,_errorvector[i]);
855                 }
856 //              fclose(fd);
857                 double max = -1;
858                 for(i=0; i<(int)(_errorvector.size()); i++)
859                 {
860                         if(_interpointsX[i] != -1)
861                         {
862                                 if(_errorvector[i]>max)
863                                 {
864                                         max = _errorvector[i];
865                                         _errorpos = i;
866                                 }
867                         }
868                 }
869         }
870 }
871 //-----------------------------------------------------------------------------------------------------------------------------------------
872 void AutoControlPoints::GetErrorBetweenContours( std::vector<double>*vec )
873 {
874         vec->clear();
875         vectorFunctions *vf = new vectorFunctions();
876         vf->copyVector(&_errorvector,vec);
877         delete vf;
878 }
879 //-----------------------------------------------------------------------------------------------------------------------------------------
880 void AutoControlPoints::AddControlPoint(bool activate)
881 {
882         if(_errorpos != -1)
883         {
884                 double xmax = _interpointsX[(int)_errorpos];
885                 double ymax = _interpointsY[(int)_errorpos];
886                 double xx       = _intervectorX[(int)_errorpos].get_var();
887                 double yy       = _intervectorY[(int)_errorpos].get_var();
888 printf("\n XMAX = %f, YMAX = %f, XX = %f, YY = %f",xmax,ymax,xx,yy);
889
890                 int i,ii,j,posA=-1,posB=-1;
891                 bool findA=false, findB=false;
892                 //CASE A
893                 for(i=(int)_errorpos; findA!=true; i++)
894                 {
895                         ii = i%_errorvector.size();
896                         for(j=0; j<(int)(_controlpointsX.size()); j++)
897                         {
898                                 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[ii].get_var()) && ((float)_intervectorX[ii].get_var()<=(float)_controlpointsX[j]+1.5) &&
899                                         ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[ii].get_var()) && ((float)_intervectorY[ii].get_var()<=(float)_controlpointsY[j]+1.5) )
900                                 {
901                                         findA = true;
902                                         posA = j;
903                                 }
904                         }
905                 }
906                 //CASE B
907                 for(i=(int)_errorpos; findB!=true; i--)
908                 {
909                         if(_errorpos==-1)
910                         {
911                                 i = _errorvector.size();
912                         }
913                         for(j=0; j<(int)(_controlpointsX.size()); j++)
914                         {
915                                 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[i].get_var()) && ((float)_intervectorX[i].get_var()<=(float)_controlpointsX[j]+1.5) &&
916                                         ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[i].get_var()) && ((float)_intervectorY[i].get_var()<=(float)_controlpointsY[j]+1.5) )
917                                 {
918                                         findB = true;
919                                         posB = j;
920                                 }
921                         }
922                 }
923                 if(posA == posB)
924                 {
925                         posB = posA-1;
926                 }
927                 if(posA<posB)
928                 {
929                         posA = posB+1;
930                         if( ( posB = _controlpointsX.size()-1) )  // ?!? // JPRx     // ?!? EED
931                         {
932                                 posA = 0;
933                         }
934                 }
935 printf("\n POSA = %d, X = %f, Y = %f",posA,_controlpointsX[posA],_controlpointsY[posA]);
936 printf("\n POSB = %d, X = %f, Y = %f",posB,_controlpointsX[posB],_controlpointsY[posB]);
937                 _posA = posA;
938                 _posB = posB;
939                 int id = -1;
940                 if(((posA!=-1)&&(posB!=-1)))
941                 {
942                         id = posA;
943                 }
944 printf("\n ID = %d",id);
945                 if(id != -1)
946                 {
947                         std::vector<double> tempX;
948                         std::vector<double> tempY;
949                         std::vector<double> tempZ;
950                         for(i=0; i<(int)(_controlpointsX.size()); i++)
951                         {
952                                 if(i == id)
953                                 {
954                                         tempX.push_back(xmax);
955                                         tempY.push_back(ymax);
956                                         tempZ.push_back(_controlpointsZ[0]);
957                                 }
958                                 tempX.push_back(_controlpointsX[i]);
959                                 tempY.push_back(_controlpointsY[i]);
960                                 tempZ.push_back(_controlpointsZ[i]);
961                         }
962                 
963                         if(activate == true)
964                         {
965                                 vectorFunctions *vf = new vectorFunctions();
966                                 vf->copyVector(&tempX,&_controlpointsX);
967                                 vf->copyVector(&tempY,&_controlpointsY);
968                                 vf->copyVector(&tempZ,&_controlpointsZ);
969                                 delete vf;
970                         }
971                 
972                 }
973         }//IF-(principal)
974 }
975 //-----------------------------------------------------------------------------------------------------------------------------------------
976 void AutoControlPoints::InterBetweenControl( )
977 {
978         _intervecXX.clear();
979         _intervecYY.clear();
980         
981         int i,ii,j,jj;
982         double m1,mn,m2,xinter,yinter;
983         if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points 
984         {
985 //EED 22 Sep 2008
986
987 //              FILE *fd;
988 //              fd = fopen("C:/bbtk_JS/data/InterBetweenControl.txt","w");
989                 for(i=0; i<(int)(_chargecontrolpointsX.size())-1; i++)
990                 {
991                         ii = (i+1)%(_chargecontrolpointsX.size());
992                         m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
993                         mn = m1;
994                         Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
995 //                      fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
996
997                         Vector *vecX = new Vector();
998                         Vector *vecY = new Vector();
999                         vecX->set_var(_chargecontrolpointsX[i]);
1000                         vecY->set_var(_chargecontrolpointsY[i]);
1001
1002                         for(j=0; j<(int)(_chargecontrolpointsX.size()); j++)
1003                         {
1004                                 jj = (j+1)%(_chargecontrolpointsX.size());
1005                                 m2 = Slope(_chargecontrolpointsX[j],_chargecontrolpointsY[j],_chargecontrolpointsX[jj],_chargecontrolpointsY[jj]);
1006                                 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[j],_chargecontrolpointsY[j],mn,m2,&xinter,&yinter);
1007                                 if( _chargecontrolpointsX[j]<=_chargecontrolpointsX[jj] )
1008                                 {
1009                                         if( (xinter>=_chargecontrolpointsX[j]) && (xinter<=_chargecontrolpointsX[jj]) )
1010                                         {
1011                                                 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1012                                                 {
1013                                                 }
1014                                                 else
1015                                                 {
1016 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1017                                                         vecX->set_vec(xinter);
1018                                                         vecY->set_vec(yinter);
1019                                                 }
1020                                         }
1021                                 }
1022                                 if( _chargecontrolpointsX[j]>_chargecontrolpointsX[jj] )
1023                                 {
1024                                         if( (xinter<=_chargecontrolpointsX[j]) && (xinter>=_chargecontrolpointsX[jj]) )
1025                                         {
1026                                                 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1027                                                 {
1028                                                 }
1029                                                 else
1030                                                 {
1031 //                                                      fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1032                                                         vecX->set_vec(xinter);
1033                                                         vecY->set_vec(yinter);
1034                                                 }
1035                                         }
1036                                 }
1037                         }//FOR2
1038                         _intervecXX.push_back(*vecX);
1039                         _intervecYY.push_back(*vecY);
1040                         
1041                         //DELETE!!
1042                         delete vecX;
1043                         delete vecY;
1044
1045                 }//FOR1
1046 //              fclose(fd);
1047         }//IF
1048 }
1049 //-----------------------------------------------------------------------------------------------------------------------------------------
1050 void AutoControlPoints::fixBetweenControl()
1051 {
1052         _interitselfX.clear();
1053         _interitselfY.clear();
1054         int i,j;
1055         float vecx,vecy,varx,vary;
1056 //      FILE *fd;
1057 //      fd = fopen("C:/bbtk_JS/data/InterBetweenControlFix.txt","w");
1058         for(i=0; i<(int)(_intervecXX.size()); i++)
1059         {
1060                 Vector *vx = new Vector();
1061                 Vector *vy = new Vector();
1062                 vx->set_var(_intervecXX[i].get_var());
1063                 vy->set_var(_intervecYY[i].get_var());
1064 //              fprintf(fd,"\n Para X = %f, Y = %f",_intervecXX[i].get_var(),_intervecYY[i].get_var());
1065                 for(j=0; j<_intervecXX[i].getsize_vec(); j++)
1066                 {
1067                         vecx = _intervecXX[i].get_vec(j);
1068                         varx = _intervecXX[i].get_var();
1069                         vecy = _intervecYY[i].get_vec(j);
1070                         vary = _intervecYY[i].get_var();
1071                         if(  (vecx == varx) && (vecy == vary) )
1072                         {
1073                         }
1074                         else
1075                         {
1076                                 vx->set_vec((double)vecx);
1077                                 vy->set_vec((double)vecy);
1078 //                              fprintf(fd,"\n => x_int = %f, y_int = %f",vecx,vecy);
1079                         }
1080                 }
1081                 _interitselfX.push_back(*vx);
1082                 _interitselfY.push_back(*vy);
1083                 delete vx;
1084                 delete vy;
1085         }
1086 //      fclose(fd);
1087 }
1088 //-----------------------------------------------------------------------------------------------------------------------------------------
1089 void AutoControlPoints::PossibleIntersections( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1090 {
1091         InterBetweenContours(InX,InY,InZ);      //_intervectorX
1092         //InterBetweenControl();                                //_intervecXX
1093         //fixBetweenControl();                          //_interitselfX
1094         
1095         std::vector<Vector> tempX;
1096         std::vector<Vector> tempY;
1097         tempX.clear();
1098         tempY.clear();
1099         int i,j,k;
1100         //double dist1,dist2; // JPRx
1101 //EED 22 Sep 2008
1102 //      FILE *fd;
1103 /*
1104         bool ready;
1105         fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1106
1107
1108         for(i=0; i<_intervectorX.size(); i++)
1109         {
1110                 fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1111                 Vector *vx = new Vector();
1112                 Vector *vy = new Vector();
1113                 vx->set_var(_intervectorX[i].get_var());
1114                 vy->set_var(_intervectorY[i].get_var());
1115                 ready = false;
1116                 for(j=0; j<_intervectorX[i].getsize_vec() ; j++)
1117                 {
1118                         dist1 = sqrt( pow(_intervectorX[i].get_var()-_intervectorX[i].get_vec(j),2) + pow(_intervectorY[i].get_var()-_intervectorY[i].get_vec(j),2) );
1119                         for(k=0; (k<_interitselfX[i].getsize_vec()) && (ready!=true); k++)
1120                         {
1121                                 dist2 = sqrt( pow(_interitselfX[i].get_var()-_interitselfX[i].get_vec(k),2) + pow(_interitselfY[i].get_var()-_interitselfY[i].get_vec(k),2) );
1122                                 if(dist2>dist1)
1123                                 {
1124                                         fprintf(fd,"\n => x_int = %f, y_int = %f",_intervectorX[i].get_vec(j),_intervectorY[i].get_vec(j));
1125                                         vx->set_vec(_intervectorX[i].get_vec(j));
1126                                         vy->set_vec(_intervectorY[i].get_vec(j));
1127                                         ready == true;
1128                                 }
1129                         }
1130                 }
1131                 tempX.push_back(*vx);
1132                 tempY.push_back(*vy);
1133                 delete vx;
1134                 delete vy;
1135         }
1136         fclose(fd);
1137         
1138         _intervectorX.clear();
1139         _intervectorY.clear();
1140         Vector *vv = new Vector();
1141         vv->copyVector(&tempX,&_intervectorX);
1142         vv->copyVector(&tempY,&_intervectorY);
1143         
1144         //vv->printVector(&_intervectorX);
1145 */
1146         std::vector<double> arrX; 
1147         std::vector<double> arrY;
1148         std::vector<double>::iterator itx;
1149         std::vector<double>::iterator ity;
1150         std::vector<double>::iterator itxx;
1151         std::vector<double>::iterator ityy;
1152         double distA, distB;
1153         if(_intervectorX.size() != 0)
1154         {
1155 //              fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1156                 for(i=0; i<(int)(_intervectorX.size()); i++)
1157                 {
1158 //                      fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1159                         if(_intervectorX[i].getsize_vec() > 1)
1160                         {
1161                                 arrX.clear();
1162                                 arrY.clear();
1163                                 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
1164                                 {
1165                                         arrX.push_back(_intervectorX[i].get_vec(j));
1166                                         arrY.push_back(_intervectorY[i].get_vec(j));
1167                                 }
1168 //printf("\n arrX Size = %d",arrX.size());
1169                                 itx = arrX.begin();
1170                                 ity = arrY.begin();
1171                                 itxx = arrX.begin()+1;
1172                                 ityy = arrY.begin()+1;
1173                                 for(j=0; j<(int)(arrX.size())-1; j++)
1174                                 {
1175                                         // I
1176                                         if( (*itx > _intervectorX[i].get_var())  && (*ity < _intervectorY[i].get_var()) && 
1177                                                 (*itxx > _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1178                                         {
1179                                                 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1180                                                 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1181                                                 if(distA<distB)
1182                                                 {
1183                                                         arrX.erase(itxx);
1184                                                         arrY.erase(ityy);
1185                                                 }
1186                                                         if(distA>distB)
1187                                                 {
1188                                                         arrX.erase(itx);
1189                                                         arrY.erase(ity);
1190                                                         itxx++;
1191                                                         ityy++;
1192                                                 }       
1193                                         }
1194                                         // II
1195                                         else if( (*itx < _intervectorX[i].get_var())  && (*ity < _intervectorY[i].get_var()) && 
1196                                                 (*itxx < _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1197                                         {
1198                                                 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1199                                                 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1200                                                 if(distA<distB)
1201                                                 {
1202                                                         arrX.erase(itxx);
1203                                                         arrY.erase(ityy);
1204                                                 }
1205                                                 if(distA>distB)
1206                                                 {
1207                                                         arrX.erase(itx);
1208                                                         arrY.erase(ity);
1209                                                         itxx++;
1210                                                         ityy++;
1211                                                 }       
1212                                         }
1213                                         // III
1214                                         else if( (*itx < _intervectorX[i].get_var())  && (*ity > _intervectorY[i].get_var()) && 
1215                                                 (*itxx < _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1216                                         {
1217                                                 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1218                                                 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1219                                                 if(distA<distB)
1220                                                 {
1221                                                         arrX.erase(itxx);
1222                                                         arrY.erase(ityy);
1223                                                 }
1224                                                 if(distA>distB)
1225                                                 {
1226                                                         arrX.erase(itx);
1227                                                         arrY.erase(ity);
1228                                                         itxx++;
1229                                                         ityy++;
1230                                                 }       
1231                                         }
1232                                         // IV
1233                                         else if( ((double)*itx > _intervectorX[i].get_var())  && (*ity > _intervectorY[i].get_var()) && 
1234                                                 ((double)*itxx > _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1235                                         {
1236                                                 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1237                                                 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1238                                                 if(distA<distB)
1239                                                 {
1240                                                         arrX.erase(itxx);
1241                                                         arrY.erase(ityy);
1242                                                 }
1243                                                 if(distA>distB)
1244                                                 {
1245                                                         arrX.erase(itx);
1246                                                         arrY.erase(ity);
1247                                                         itxx++;
1248                                                         ityy++;
1249                                                 }       
1250                                         }
1251                                         else
1252                                         {
1253                                                 itx++;
1254                                                 ity++;
1255                                                 itxx++;
1256                                                 ityy++;
1257                                         }
1258                                 }
1259                                 _intervectorX[i].resetVec();
1260                                 _intervectorY[i].resetVec();
1261 //printf("\n _intervector(%d) Size = %d",i,_intervectorX[i].getsize_vec());
1262                                 for(k=0; k<(int)(arrX.size()); k++)
1263                                 {
1264 //printf("\n arr(%d) X = %f, Y = %f",k,arrX[k],arrY[k]);
1265 //                                      fprintf(fd,"\n => x_int = %f, y_int = %f",arrX[k],arrY[k]);
1266                                         _intervectorX[i].set_vec(arrX[k]);
1267                                         _intervectorY[i].set_vec(arrY[k]);
1268                                 }
1269                         }
1270                 }
1271         }
1272
1273         //DELETE!!
1274 //      delete vv;
1275
1276 }
1277 //-----------------------------------------------------------------------------------------------------------------------------------------
1278 void AutoControlPoints::ControlInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1279 {
1280         int i,j;
1281         _contIncontpos.clear(); 
1282         bool find = false;
1283         double range = 2;
1284         for(i=0; i<(int)(_controlpointsX.size()); i++)
1285         {
1286                 find = false;
1287                 for(j=0; (j<(int)(InX->size())) && (find!=true); j++)
1288                 {
1289                         if( ((*InX)[j]-range<=_controlpointsX[i]) && (_controlpointsX[i]<=(*InX)[j]+range) && ((*InY)[j]-range<=_controlpointsY[i]) && (_controlpointsY[i]<=(*InY)[j]+range) )
1290                         {
1291                                 _contIncontpos.push_back(j);
1292                                 find = true;
1293                         }
1294                 }
1295         }
1296 }
1297 //-----------------------------------------------------------------------------------------------------------------------------------------
1298 void AutoControlPoints::NearMaxError2Control()
1299 {
1300         if(_interpointsX.size() != 0)
1301         {
1302                 AddControlPoint(false);
1303
1304                 double distA = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posA],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posA],2) );
1305                 double distB = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posB],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posB],2) );
1306                 double nearp = -1;
1307                 if(distA<distB)
1308                 {
1309                         nearp = distA;
1310                         _posn = _posA;
1311
1312                 }
1313                 else
1314                 {
1315                         nearp = distB;
1316                         _posn = _posB;
1317                 }
1318         }
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                 }
1362                 else
1363                 {
1364                         _controlpointsX.push_back( tempX[i] );
1365                         _controlpointsY.push_back( tempY[i] );
1366                         _controlpointsZ.push_back( tempZ[i] );
1367                 }
1368         }
1369
1370         fixBetweenPoints(5.0);
1371         PossibleIntersections(InX,InY,InZ);
1372         IntersectionPoints();
1373         ErrorBetweenContours();
1374         double promactualIn = vf->promVector(&_errorvector,false);
1375         double prom;
1376         double promactual;
1377         
1378         int posact;
1379         //int pos1; // JPRx
1380         //double prom1final; // JPRx
1381         int pos2;
1382         double prom2final;
1383
1384         //DIRECTION 1
1385         int direction = 1;
1386         posact = _posn;
1387         prom = -1;
1388         promactual = promactualIn;
1389         _controlpointsX.clear();
1390         _controlpointsY.clear();
1391         _controlpointsZ.clear();
1392         for(i=0; promactual > prom; i++)
1393         {
1394                 prom = promactual;
1395                 for(i=0; i<(int)(tempX.size()); i++)
1396                 {
1397                         if(i==_posn)
1398                         {
1399                                 _controlpointsX.push_back( (*InX)[_contIncontpos[posact]] );
1400                                 _controlpointsY.push_back( (*InY)[_contIncontpos[posact]] );
1401                                 _controlpointsZ.push_back( (*InZ)[_contIncontpos[posact]] );
1402                         }
1403                         else
1404                         {
1405                                 _controlpointsX.push_back( tempX[i] );
1406                                 _controlpointsY.push_back( tempY[i] );
1407                                 _controlpointsZ.push_back( tempZ[i] );
1408                         }
1409                 }
1410                 if(direction == 1)
1411                 {
1412                         posact = posact+1;
1413                 }
1414                 if(direction == -1)
1415                 {
1416                         posact = posact-1;
1417                 }
1418                 fixBetweenPoints(5.0);
1419                 PossibleIntersections(InX,InY,InZ);
1420                 IntersectionPoints();
1421                 ErrorBetweenContours();
1422                 promactual = vf->promVector(&_errorvector,false);
1423 //printf("\n The point in the position %d, has moved %d times",_posn,i);
1424         }
1425         pos2 = posact;
1426         prom2final = promactual;
1427
1428         delete vf;
1429 }
1430 //--------------------------------------------------------------------------------------------------------------------------------
1431 double AutoControlPoints::MoveAndAverage(int dir, std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1432 {
1433         /*
1434 //PRINTF---------------------------------------------------------------
1435         int i;
1436         printf("\n CONTROL POINTS BEFORE MOVEMENT");
1437         for(i=0; i<_controlpointsX.size(); i++)
1438         {
1439                 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1440         }
1441         for(i=0; i<_contIncontpos.size(); i++)
1442         {
1443                 printf("\n contIncont pos = %d",_contIncontpos[i]);
1444         }
1445 */
1446 //IMPLEMENTATION-------------------------------------------------------
1447         if( (_contIncontpos.size() != 0) && (_controlpointsX.size() != 0) )
1448         {
1449                 vectorFunctions *vf = new vectorFunctions();
1450                 std::vector<double>::iterator itx;
1451                 std::vector<double>::iterator ity;
1452                 std::vector<double> tempX;
1453                 std::vector<double> tempY;
1454                 tempX.clear();
1455                 tempY.clear();
1456                 vf->copyVector(&_controlpointsX,&tempX);
1457                 vf->copyVector(&_controlpointsY,&tempY);
1458                 int i,j /*,pos = 0*/ ;  // JPRx
1459                 double prom1=0,promactual1=1;
1460                 //double prom2=0,promactual2=1; // JPRx
1461                 int h = 0;
1462                 int hh = 1;
1463                 if(_contIncontpos[h]>_contIncontpos[hh])
1464                 {
1465                         itx = _controlpointsX.begin();
1466                         ity = _controlpointsY.begin();
1467                         for(i=_contIncontpos[h],j=_contIncontpos[h]; (i>_contIncontpos[hh]) && (promactual1>prom1); i--)
1468                         {
1469                                 if(j == (int)(InX->size()))
1470                                 {
1471                                         j = 0;
1472                                 }
1473                                 prom1 = promactual1;
1474                                 *itx = (*InX)[j];
1475                                 *ity = (*InY)[j];
1476                                 printf("\n itx = %f, ity = %f", *itx,*ity);
1477                                 fixBetweenPoints(5.0);
1478                                 PossibleIntersections(InX,InY,InZ);
1479                                 IntersectionPoints();
1480                                 ErrorBetweenContours();
1481                                 promactual1 = vf->promVector(&_errorvector,false);
1482                                 j++;
1483                         }
1484                 }
1485                 if(_contIncontpos[h]<_contIncontpos[hh])
1486                 {
1487                         itx = _controlpointsX.begin();
1488                         ity = _controlpointsY.begin();
1489                         for(i=_contIncontpos[h],j=_contIncontpos[h]; (i<_contIncontpos[hh]) && (promactual1>prom1); i++)
1490                         {
1491                                 if(j == -1)
1492                                 {
1493                                         j = InX->size()-1;
1494                                 }
1495                                 prom1 = promactual1;
1496                                 *itx = (*InX)[j];
1497                                 *ity = (*InY)[j];
1498                                 printf("\n itx = %f, ity = %f", *itx,*ity);
1499                                 fixBetweenPoints(5.0);
1500                                 PossibleIntersections(InX,InY,InZ);
1501                                 IntersectionPoints();
1502                                 ErrorBetweenContours();
1503                                 promactual1 = vf->promVector(&_errorvector,false);
1504                                 j--;
1505                         }
1506                 }
1507                 delete vf;
1508         }
1509         return 99999;
1510 }
1511 //--------------------------------------------------------------------------------------------------------------------------------
1512 void AutoControlPoints::MoveControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1513 {
1514         ControlInContour(InX,InY,InZ);
1515         NearMaxError2Control();
1516         MoveAndAverage(1,InX,InY,InZ);
1517 }
1518 //-----------------------------------------------------------------------------------------------------------------------------------------
1519 void AutoControlPoints::GetNewPoints( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1520 {
1521         vectorFunctions *vf = new vectorFunctions();
1522         double prom,maxerror;
1523         
1524         InterCircle(InX,InY,InZ);
1525         maxminLocal();
1526         fixBetweenPoints(5.0);
1527         PossibleIntersections(InX,InY,InZ);
1528         IntersectionPoints();
1529         ErrorBetweenContours();
1530         prom = vf->promVector(&_errorvector,false);
1531         vf->maxVector(&_errorvector,&maxerror);
1532 printf("\n");
1533         if( maxerror>3.0 )
1534         {
1535                 _controlpointsX.clear();
1536                 _controlpointsY.clear();
1537                 _controlpointsZ.clear();
1538                 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1539                 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1540                 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1541                 {
1542                         _controlpointsZ.push_back( (*InZ)[0] );
1543                 }
1544                 fixBetweenPoints(5.0);
1545                 PossibleIntersections(InX,InY,InZ);
1546                 IntersectionPoints();
1547                 ErrorBetweenContours();
1548                 prom = vf->promVector(&_errorvector,false);
1549                 vf->maxVector(&_errorvector,&maxerror);
1550 printf("\n");
1551         }
1552
1553         std::vector<double> cpX;
1554         std::vector<double> cpY;
1555         std::vector<double> cpZ;
1556         cpX.clear();
1557         cpY.clear();
1558         cpZ.clear();
1559         vf->copyVector(&_controlpointsX,&cpX);
1560         vf->copyVector(&_controlpointsY,&cpY);
1561         vf->copyVector(&_controlpointsZ,&cpZ);
1562         int i;
1563
1564         for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1565         {
1566                 AddControlPoint(true);
1567                 fixBetweenPoints(5.0);
1568                 PossibleIntersections(InX,InY,InZ);
1569                 IntersectionPoints();
1570                 ErrorBetweenContours();
1571                 prom = vf->promVector(&_errorvector,false);
1572                 vf->maxVector(&_errorvector,&maxerror);
1573                 printf("\n %d ",i);
1574         }
1575
1576         if(i == 10)
1577         {
1578                 _controlpointsX.clear();
1579                 _controlpointsY.clear();
1580                 _controlpointsZ.clear();
1581                 int inicontrolpoints = cpX.size();
1582                 double inipercentage = (inicontrolpoints*100)/InX->size();
1583                 int h=0;
1584                 if(inicontrolpoints<10)
1585                 {
1586                         int points = (int)((inipercentage*3*InX->size())/100);
1587                         for (int i=0; i<(int)(InX->size()); i++, h++)
1588                         {
1589                                 if( h == points )
1590                                 {
1591                                         _controlpointsX.push_back( (*InX)[i] );
1592                                         _controlpointsY.push_back( (*InY)[i] );
1593                                         _controlpointsZ.push_back( (*InZ)[i] );
1594                                         h = 0;
1595                                 }
1596                         }
1597                 }
1598                 if(inicontrolpoints>=10)
1599                 {
1600                         int points = (int)((inipercentage*2*InX->size())/100);
1601                         for (int i=0; i<(int)(InX->size()); i++, h++)
1602                         {
1603                                 if( h == points )
1604                                 {
1605                                         _controlpointsX.push_back( (*InX)[i] );
1606                                         _controlpointsY.push_back( (*InY)[i] );
1607                                         _controlpointsZ.push_back( (*InZ)[i] );
1608                                         h = 0;
1609                                 }
1610                         }
1611                 }
1612         }
1613 /*
1614         fixBetweenPoints(5.0);
1615         PossibleIntersections(InX,InY,InZ);
1616         IntersectionPoints();
1617         ErrorBetweenContours();
1618         prom = vf->promVector(&_errorvector,false);
1619         vf->maxVector(&_errorvector,&maxerror);
1620
1621
1622 printf("\n Error Average  = %f",prom);
1623 printf("\n Error Max  = %f",maxerror);
1624         AddControlPoint(false);
1625 */
1626 /*
1627         //if( (prom>1) || (maxerror>2))
1628         if( prom>0.2 )
1629         {
1630 printf("\n Error Average is grater than 1 !!");
1631                 MoveControlPoints(InX,InY,InZ);
1632         }
1633 */
1634         delete vf;
1635 }
1636 //------------------------------------------------------------------------------------------------------------------------------------------
1637 void AutoControlPoints::GetInitialNewPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1638 {
1639         vectorFunctions *vf = new vectorFunctions();
1640         double prom,maxerror;
1641         
1642         InterCircle(InX,InY,InZ);
1643         maxminLocal();
1644         fixBetweenPoints(5.0);
1645         PossibleIntersections(InX,InY,InZ);
1646         IntersectionPoints();
1647         ErrorBetweenContours();
1648         prom = vf->promVector(&_errorvector,false);
1649         vf->maxVector(&_errorvector,&maxerror);
1650         
1651         if( maxerror>3.0 )
1652         {
1653                 _controlpointsX.clear();
1654                 _controlpointsY.clear();
1655                 _controlpointsZ.clear();
1656                 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1657                 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1658                 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1659                 {
1660                         _controlpointsZ.push_back( (*InZ)[0] );
1661                 }
1662                 fixBetweenPoints(5.0);
1663                 PossibleIntersections(InX,InY,InZ);
1664                 IntersectionPoints();
1665                 ErrorBetweenContours();
1666                 prom = vf->promVector(&_errorvector,false);
1667                 vf->maxVector(&_errorvector,&maxerror);
1668         }
1669
1670         std::vector<double> cpX;
1671         std::vector<double> cpY;
1672         std::vector<double> cpZ;
1673         cpX.clear();
1674         cpY.clear();
1675         cpZ.clear();
1676         vf->copyVector(&_controlpointsX,&cpX);
1677         vf->copyVector(&_controlpointsY,&cpY);
1678         vf->copyVector(&_controlpointsZ,&cpZ);
1679
1680         double promini = prom; 
1681
1682         int i;
1683         for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1684         {
1685                 AddControlPoint(true);
1686                 fixBetweenPoints(5.0);
1687                 PossibleIntersections(InX,InY,InZ);
1688                 IntersectionPoints();
1689                 ErrorBetweenContours();
1690                 prom = vf->promVector(&_errorvector,false);
1691                 vf->maxVector(&_errorvector,&maxerror);
1692         }
1693
1694         if( i==10 || prom > promini)
1695         {
1696                 _controlpointsX.clear();
1697                 _controlpointsY.clear();
1698                 _controlpointsZ.clear();
1699                 vf->copyVector(&cpX,&_controlpointsX);
1700                 vf->copyVector(&cpY,&_controlpointsY);
1701                 vf->copyVector(&cpZ,&_controlpointsZ);
1702         }
1703         delete vf;
1704 }
1705 //------------------------------------------------------------------------------------------------------------------------------------------
1706 void AutoControlPoints::CalculeControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1707 {
1708
1709         _controlpointsX.clear();
1710         _controlpointsY.clear();
1711         _controlpointsZ.clear();
1712         _controlpointsZ.push_back((*InZ)[0]);
1713         GetNewPoints( InX,InY,InZ );
1714 }
1715 //-----------------------------------------------------------------------------------------------------------------------------------------
1716 void AutoControlPoints::CalculeInitialControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1717 {
1718
1719         _controlpointsX.clear();
1720         _controlpointsY.clear();
1721         _controlpointsZ.clear();
1722         _controlpointsZ.push_back((*InZ)[0]);
1723         GetInitialNewPoints( InX,InY,InZ );
1724 }
1725 //-----------------------------------------------------------------------------------------------------------------------------------------
1726 void AutoControlPoints::GetControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1727 {
1728         vectorFunctions *vf = new vectorFunctions();
1729         OutX->clear();
1730         OutY->clear();
1731         OutZ->clear();
1732         vf->copyVector(&_controlpointsX,OutX);
1733         vf->copyVector(&_controlpointsY,OutY);
1734         vf->copyVector(&_controlpointsZ,OutZ);
1735         delete vf;
1736 }
1737 //-----------------------------------------------------------------------------------------------------------------------------------------
1738 void AutoControlPoints::GetInitialControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1739 {
1740         vectorFunctions *vf = new vectorFunctions();
1741         OutX->clear();
1742         OutY->clear();
1743         OutZ->clear();
1744         vf->copyVector(&_controlpointsX,OutX);
1745         vf->copyVector(&_controlpointsY,OutY);
1746         vf->copyVector(&_controlpointsZ,OutZ);
1747         delete vf;
1748 }
1749
1750 //-----------------------------------------------------------------------------------------------------------------------------------------
1751 void AutoControlPoints::SetNumSplineInterpolation(int num)
1752 {
1753         _numspline = num;
1754 }
1755 //-----------------------------------------------------------------------------------------------------------------------------------------
1756 //-----------------------------------------------------------------------------------------------------------------------------------------
1757 //-----------------------------------------------------------------------------------------------------------------------------------------
1758  
1759