1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "AutoControlPoints.h"
27 //------------------------------------------------------------------------------------------------------------------------------------------
28 //CLASS: AutoControlPoints -----------------------------------------------------------------------------------------------------------------
29 //------------------------------------------------------------------------------------------------------------------------------------------
31 AutoControlPoints::AutoControlPoints()
37 AutoControlPoints::~AutoControlPoints()
40 //------------------------------------------------------------------------------------------------------------------------------------------
41 int AutoControlPoints::GetSizeVector(std::vector<double>*Vector)
45 return _SizeVectorIn = Vector->size();
49 return _SizeVectorIn = -1;
52 //------------------------------------------------------------------------------------------------------------------------------------------
53 void AutoControlPoints::PointLeft ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
54 double* lex, double* ley, double* lez )
58 int size = GetSizeVector(InX);
61 for(int i=0; i< size; i++)
63 if( (*InX)[i] < LeftX )
74 //------------------------------------------------------------------------------------------------------------------------------------------
75 void AutoControlPoints::PointRight( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
76 double* rix, double* riy, double* riz )
80 int size = GetSizeVector(InX);
83 for(int i=0; i< size; i++)
85 if( (*InX)[i] > RightX )
96 //------------------------------------------------------------------------------------------------------------------------------------------
97 void AutoControlPoints::PointHigh ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
98 double* hix, double* hiy, double* hiz )
102 int size = InX->size();
105 for(int i = 1; i < size; i++){
106 if((*InY)[i] < HighY){
117 int size = GetSizeVector(InX);
120 for(int i=0; i< _SizeVectorIn; i++)
122 if( (*InY)[i] < HighY )
136 //------------------------------------------------------------------------------------------------------------------------------------------
137 void AutoControlPoints::PointLow ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
138 double *lox, double *loy, double *loz)
142 int size = GetSizeVector(InX);
145 for(int i=0; i< _SizeVectorIn; i++)
147 if( (*InY)[i] > LowY )
158 //------------------------------------------------------------------------------------------------------------------------------------------
159 void AutoControlPoints::TwoPoints ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
161 double hiX=0,hiY=0,hiZ=0;
162 PointHigh ( InX,InY,InZ,&hiX,&hiY,&hiZ );
164 double leX=0,leY=0,leZ=0;
165 PointLeft ( InX,InY,InZ,&leX,&leY,&leZ );
167 double loX=0,loY=0,loZ=0;
168 PointLow ( InX,InY,InZ,&loX,&loY,&loZ );
170 double riX=0,riY=0,riZ=0;
171 PointRight( InX,InY,InZ,&riX,&riY,&riZ );
173 double distHiLo = sqrt( pow(hiX-loX,2) + pow(hiY-loY,2) );
174 double distRiLe = sqrt( pow(riX-leX,2) + pow(riY-leY,2) );
176 _controlpointsX.clear();
177 _controlpointsY.clear();
178 _controlpointsZ.clear();
179 if(distHiLo >= distRiLe)
181 _controlpointsX.push_back(hiX);
182 _controlpointsY.push_back(hiY);
183 _controlpointsZ.push_back(hiZ);
185 _controlpointsX.push_back(loX);
186 _controlpointsY.push_back(loY);
187 _controlpointsZ.push_back(loZ);
191 _controlpointsX.push_back(riX);
192 _controlpointsY.push_back(riY);
193 _controlpointsZ.push_back(riZ);
195 _controlpointsX.push_back(leX);
196 _controlpointsY.push_back(leY);
197 _controlpointsZ.push_back(leZ);
200 //------------------------------------------------------------------------------------------------------------------------------------------
201 void AutoControlPoints::CircleCenter(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ, double *cx, double *cy, double *r)
203 double hiX=0,hiY=0,hiZ=0;
204 PointHigh ( InX,InY,InZ,&hiX,&hiY,&hiZ );
206 double leX=0,leY=0,leZ=0;
207 PointLeft ( InX,InY,InZ,&leX,&leY,&leZ );
209 double loX=0,loY=0,loZ=0;
210 PointLow ( InX,InY,InZ,&loX,&loY,&loZ );
212 double riX=0,riY=0,riZ=0;
213 PointRight( InX,InY,InZ,&riX,&riY,&riZ );
217 *r = sqrt(pow(leX-*cx,2)+pow(hiY-*cy,2)) + 7;
219 //------------------------------------------------------------------------------------------------------------------------------------------
220 void AutoControlPoints::CirclePoints(double cx, double cy, double r, double grad, double *x, double *y)
222 double alpha = (2*3.14159265*grad)/360;
224 *x = cx + (r*cos(alpha));
225 *y = cy + (r*sin(alpha));
227 //------------------------------------------------------------------------------------------------------------------------------------------
228 void AutoControlPoints::ChargeSpline( )
230 int size = _controlpointsX.size();
233 _mContourModel = new manualContourModel();
234 if( _controlpointsX.size() == 2 )
236 _mContourModel->SetCloseContour(false);
238 if( _controlpointsX.size() > 2 )
240 _mContourModel->SetCloseContour(true);
243 _mContourModel->DeleteAllPoints();
244 _mContourModel->SetNumberOfPointsSpline(_numspline);
245 for(int i=0; i<size; i++)
247 _mContourModel->AddPoint(_controlpointsX[i],_controlpointsY[i],_controlpointsZ[i]);
249 _mContourModel->UpdateSpline();
250 int numspline = _mContourModel->GetNumberOfPointsSpline();
252 _chargecontrolpointsX.clear();
253 _chargecontrolpointsY.clear();
254 _chargecontrolpointsZ.clear();
255 for(int j=0; j<numspline; j++)
257 _mContourModel->GetSpline_i_Point(j,&x,&y,&z);
258 _chargecontrolpointsX.push_back(x);
259 _chargecontrolpointsY.push_back(y);
260 _chargecontrolpointsZ.push_back(z);
264 // _pathsize = _mContourModel->GetPathSize( );
269 _pathsize = _mContourModel->GetPathSize( spc );
271 //printf("\nPATH SIZE = %f",_pathsize);
273 // std::ofstream file1;
274 // file1.open( "4_SplinePoints.txt" );
275 // for(int i = 0; i < numspline; i++)
277 // file1<<"X= "<<_chargecontrolpointsX[i] << "\tY= "<<_chargecontrolpointsY[i] << "\tZ= "<<_chargecontrolpointsZ[i]<<std::endl;
284 //Given the coordinates of two points, it calculates the slope
285 double AutoControlPoints::Slope(double x0, double y0, double x1, double y1)
287 double m = (y1-y0)/(x1-x0);
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)
296 y = ((*m)*(xi - x0)) + y0;
299 //----------------------------------------------------------------------------------------------------------------------------------------
300 void AutoControlPoints::Intersection(double x01, double y01, double x02, double y02, double mn, double m2, double* x, double* y)
302 *x = ( y02-y01-(m2*x02)+(mn*x01) )/(mn-m2);
303 *y = m2*(*x-x02)+y02;
305 //-----------------------------------------------------------------------------------------------------------------------------------------
307 **This methods finds the points where each radius of the circle intersect the contour
309 void AutoControlPoints::InterCircle(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
312 CircleCenter(InX,InY,InZ,&cx,&cy,&r);
314 //GENERATE THE CIRCLE'S POINTS
317 std::vector<double>tempX;
318 std::vector<double>tempY;
323 for(i=0; i<360/n; i++)
325 CirclePoints(cx,cy,r,grad,&x,&y);
331 //FIND THE INTERSECTIONS BETWEEN THE CIRCLE AND THE CONTOUR
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();
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");
349 //std::ofstream file1;
350 //file1.open( "Temp.txt" );
352 for(i=0; i<(int)(tempX.size()); i++)
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
359 for(j=0; j<(int)(InX->size()); j++)
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);
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]) ))
369 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
379 if((*InX)[j]<=(*InX)[jj])
381 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) ) //Intersection entre le cercle et le contour
383 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
392 if((*InX)[j]>(*InX)[jj])
394 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) ) //Intersection entre le cercle et le contour
396 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
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
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)) );
421 // file1<<i<<std::endl;
423 //JCP 26-09-08 if(min<r)
425 _intercircleX.push_back(xmin);
426 _intercircleY.push_back(ymin);
427 _intercircleDist.push_back(min);
428 // file1<<"\t"<<i<<std::endl;
435 //WHEN THERE IS RADIAL INTERSECTION
436 vectorFunctions *vecf = new vectorFunctions();
440 // fdata = fopen("C:/bbtk_JS/data/autoCPdata.txt","w");
443 std::vector<double> tempXX;
444 std::vector<double> tempYY;
445 std::vector<double> tempDD;
449 //Copy of the first points in the array until the first intersection is found
450 for(i=0; i<_interbewteencirclePos[0]; i++)
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]);
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--)
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]);
470 for(i=_interbewteencirclePos[0]; i<(int)(_intercircleX.size()); i++)
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]);
478 _intercircleX.clear();
479 _intercircleY.clear();
480 _intercircleDist.clear();
481 vecf->copyVector(&tempXX,&_intercircleX);
482 vecf->copyVector(&tempYY,&_intercircleY);
483 vecf->copyVector(&tempDD,&_intercircleDist);
490 // std::ofstream file1;
491 // file1.open( "1_Intersection.txt" );
492 // for(int i = 0; i < (int)(_intercircleX.size()); i++)
494 // file1<<"X= "<<_intercircleX[i] << "\tY= "<<_intercircleY[i] << "\tDist= "<<_intercircleDist[i]<<std::endl;
500 //-----------------------------------------------------------------------------------------------------------------------------------------
501 void AutoControlPoints::maxminLocal()
504 _posmaxlocal.clear();
505 _posminlocal.clear();
506 _posminmaxlocal.clear();
511 _minmaxlocalX.clear();
512 _minmaxlocalY.clear();
514 if(_intercircleDist.size() != 0)
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++)
523 currentdist = _intercircleDist[i];
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];
531 lastdist = _intercircleDist[i-1];
532 nextdist = _intercircleDist[i+1];
536 //JCP 26-09-08 if( (_intercircleDist[i-1]<_intercircleDist[i]) && (_intercircleDist[i]>_intercircleDist[i+1]))
537 if(lastdist < currentdist && currentdist > nextdist)
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);
547 //JCP 26-09-08 if( (_intercircleDist[i-1]>_intercircleDist[i]) && (_intercircleDist[i]<_intercircleDist[i+1]))
548 if(lastdist > currentdist && currentdist < nextdist)
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);
560 vectorFunctions *vecf = new vectorFunctions();
561 std::vector<double> tempZ;
564 vecf->copyVector(&_minlocalX,&_controlpointsX);
565 vecf->copyVector(&_minlocalY,&_controlpointsY);
566 for(i=0; i<(int)(_minlocalX.size()); i++)
568 tempZ.push_back(_controlpointsZ[0]);
570 vecf->copyVector(&tempZ,&_controlpointsZ);
574 // std::ofstream file1;
575 // file1.open( "2_MaxMin.txt" );
576 // for(int i = 0; i < (int)(_controlpointsX.size()); i++)
578 // file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
585 //-----------------------------------------------------------------------------------------------------------------------------------------
586 //ELIMINATES THE POINTS WITH A DISTANCE < val
587 void AutoControlPoints::fixBetweenPoints(double val)
589 int size = _controlpointsX.size();
593 std::vector<double> tempX;
594 std::vector<double> tempY;
595 std::vector<double> tempZ;
601 vectorFunctions *vecf = new vectorFunctions();
602 for(int i=0; i<size; i++)
605 dist = sqrt(pow(_controlpointsX[i]-_controlpointsX[ii],2)+pow(_controlpointsY[i]-_controlpointsY[ii],2));
608 tempX.push_back(_controlpointsX[i]);
609 tempY.push_back(_controlpointsY[i]);
610 tempZ.push_back(_controlpointsZ[i]);
613 _controlpointsX.clear();
614 _controlpointsY.clear();
615 _controlpointsZ.clear();
617 vecf->copyVector(&tempX,&_controlpointsX);
618 vecf->copyVector(&tempY,&_controlpointsY);
619 vecf->copyVector(&tempZ,&_controlpointsZ);
622 // std::ofstream file1;
623 // file1.open( "3_PointsFixed.txt" );
624 // for(int i = 0; i < (int)(_controlpointsX.size()); i++)
626 // file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
633 //-----------------------------------------------------------------------------------------------------------------------------------------
634 //ALL THE INTERSECTIONS
635 void AutoControlPoints::InterBetweenContours(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
637 _intervectorX.clear();
638 _intervectorY.clear();
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
647 // fd = fopen("C:/bbtk_JS/data/interBetweenContours.txt","w");
648 for(i=0; i<(int)(_chargecontrolpointsX.size()); i++)
650 ii = (i+1)%(_chargecontrolpointsX.size());
652 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
654 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
655 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
657 Vector *vecX = new Vector();
658 Vector *vecY = new Vector();
659 vecX->set_var(_chargecontrolpointsX[i]);
660 vecY->set_var(_chargecontrolpointsY[i]);
662 for(j=0; j<(int)(InX->size()); j++)
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);
668 if(((*InX)[j] <= xinter && xinter <= (*InX)[jj]) || (xinter<=(*InX)[j] && xinter>=(*InX)[jj])){
669 vecX->set_vec(xinter);
670 vecY->set_vec(yinter);
673 if( (*InX)[j]<=(*InX)[jj] )
675 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) )
677 //If the point is a CP, the intersection is itself.
678 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
680 vecX->set_vec(xinter);
681 vecY->set_vec(yinter);
682 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
686 vecX->set_vec(xinter);
687 vecY->set_vec(yinter);
688 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
692 if( (*InX)[j]>(*InX)[jj] )
694 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) )
696 //If the point is a CP, the intersection is itself.
697 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
699 vecX->set_vec(xinter);
700 vecY->set_vec(yinter);
701 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
705 vecX->set_vec(xinter);
706 vecY->set_vec(yinter);
707 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
713 _intervectorX.push_back(*vecX);
714 _intervectorY.push_back(*vecY);
722 //-----------------------------------------------------------------------------------------------------------------------------------------
723 void AutoControlPoints::GetInterBetweenContours(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
727 int size = _intervectorX.size();
731 for(i=0; i<size; i++)
733 interVX->push_back(_intervectorX[i]);
734 interVY->push_back(_intervectorY[i]);
738 //-----------------------------------------------------------------------------------------------------------------------------------------
739 //ONLY THE LOGICAL INTERSECTIONS
740 void AutoControlPoints::IntersectionPoints()
742 if(_intervectorX.size() != 0)
744 _interpointsX.clear();
745 _interpointsY.clear();
749 // fd = fopen("C:/bbtk_JS/data/IntersectionPoints.txt","w");
756 for(j=0; j<_intervectorX[0].getsize_vec(); j++)
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 ) );
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]);
774 printf("\n\n There is an invalid intersection: Must see AutoControlPoints::IntersectionPoints() method");
777 for(i=0; i<(int)(_intervectorX.size()); i++){
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 ) );
787 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
788 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
791 for(i=1; i<_intervectorX.size(); i++)
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++)
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));
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]);
817 //-----------------------------------------------------------------------------------------------------------------------------------------
818 void AutoControlPoints::GetIntersectionPoints(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
820 int size = _interpointsX.size();
824 Vector *vecX = new Vector();
825 Vector *vecY = new Vector();
828 for(i=0; i<size; i++)
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);
841 //-----------------------------------------------------------------------------------------------------------------------------------------
842 //ERROR BETWEEN THE LOGICAL INTERSECTIONS
843 void AutoControlPoints::ErrorBetweenContours()
846 if(_interpointsX.size() != 0)
848 _errorvector.clear();
853 // fd = fopen("C:/bbtk_JS/data/interErrorData.txt","w");
854 for(i=0; i<(int)(_interpointsX.size()); i++)
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]);
861 for(i=0; i<(int)(_errorvector.size()); i++)
863 if(_interpointsX[i] != -1)
865 if(_errorvector[i]>max)
867 max = _errorvector[i];
874 //-----------------------------------------------------------------------------------------------------------------------------------------
875 void AutoControlPoints::GetErrorBetweenContours( std::vector<double>*vec )
878 vectorFunctions *vf = new vectorFunctions();
879 vf->copyVector(&_errorvector,vec);
882 //-----------------------------------------------------------------------------------------------------------------------------------------
883 void AutoControlPoints::AddControlPoint(bool activate)
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);
893 int i,ii,j,posA=-1,posB=-1;
894 bool findA=false, findB=false;
896 for(i=(int)_errorpos; findA!=true; i++)
898 ii = i%_errorvector.size();
899 for(j=0; j<(int)(_controlpointsX.size()); j++)
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) )
910 for(i=(int)_errorpos; findB!=true; i--)
914 i = _errorvector.size();
916 for(j=0; j<(int)(_controlpointsX.size()); j++)
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) )
933 if( ( posB = _controlpointsX.size()-1) ) // ?!? // JPRx // ?!? EED
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]);
943 if(((posA!=-1)&&(posB!=-1)))
947 printf("\n ID = %d",id);
950 std::vector<double> tempX;
951 std::vector<double> tempY;
952 std::vector<double> tempZ;
953 for(i=0; i<(int)(_controlpointsX.size()); i++)
957 tempX.push_back(xmax);
958 tempY.push_back(ymax);
959 tempZ.push_back(_controlpointsZ[0]);
961 tempX.push_back(_controlpointsX[i]);
962 tempY.push_back(_controlpointsY[i]);
963 tempZ.push_back(_controlpointsZ[i]);
968 vectorFunctions *vf = new vectorFunctions();
969 vf->copyVector(&tempX,&_controlpointsX);
970 vf->copyVector(&tempY,&_controlpointsY);
971 vf->copyVector(&tempZ,&_controlpointsZ);
978 //-----------------------------------------------------------------------------------------------------------------------------------------
979 void AutoControlPoints::InterBetweenControl( )
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
991 // fd = fopen("C:/bbtk_JS/data/InterBetweenControl.txt","w");
992 for(i=0; i<(int)(_chargecontrolpointsX.size())-1; i++)
994 ii = (i+1)%(_chargecontrolpointsX.size());
995 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
997 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
998 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
1000 Vector *vecX = new Vector();
1001 Vector *vecY = new Vector();
1002 vecX->set_var(_chargecontrolpointsX[i]);
1003 vecY->set_var(_chargecontrolpointsY[i]);
1005 for(j=0; j<(int)(_chargecontrolpointsX.size()); j++)
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] )
1012 if( (xinter>=_chargecontrolpointsX[j]) && (xinter<=_chargecontrolpointsX[jj]) )
1014 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1019 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1020 vecX->set_vec(xinter);
1021 vecY->set_vec(yinter);
1025 if( _chargecontrolpointsX[j]>_chargecontrolpointsX[jj] )
1027 if( (xinter<=_chargecontrolpointsX[j]) && (xinter>=_chargecontrolpointsX[jj]) )
1029 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1034 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1035 vecX->set_vec(xinter);
1036 vecY->set_vec(yinter);
1041 _intervecXX.push_back(*vecX);
1042 _intervecYY.push_back(*vecY);
1052 //-----------------------------------------------------------------------------------------------------------------------------------------
1053 void AutoControlPoints::fixBetweenControl()
1055 _interitselfX.clear();
1056 _interitselfY.clear();
1058 float vecx,vecy,varx,vary;
1060 // fd = fopen("C:/bbtk_JS/data/InterBetweenControlFix.txt","w");
1061 for(i=0; i<(int)(_intervecXX.size()); i++)
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++)
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) )
1079 vx->set_vec((double)vecx);
1080 vy->set_vec((double)vecy);
1081 // fprintf(fd,"\n => x_int = %f, y_int = %f",vecx,vecy);
1084 _interitselfX.push_back(*vx);
1085 _interitselfY.push_back(*vy);
1091 //-----------------------------------------------------------------------------------------------------------------------------------------
1092 void AutoControlPoints::PossibleIntersections( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1094 InterBetweenContours(InX,InY,InZ); //_intervectorX
1095 //InterBetweenControl(); //_intervecXX
1096 //fixBetweenControl(); //_interitselfX
1098 std::vector<Vector> tempX;
1099 std::vector<Vector> tempY;
1103 //double dist1,dist2; // JPRx
1108 fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1111 for(i=0; i<_intervectorX.size(); i++)
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());
1119 for(j=0; j<_intervectorX[i].getsize_vec() ; j++)
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++)
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) );
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));
1134 tempX.push_back(*vx);
1135 tempY.push_back(*vy);
1141 _intervectorX.clear();
1142 _intervectorY.clear();
1143 Vector *vv = new Vector();
1144 vv->copyVector(&tempX,&_intervectorX);
1145 vv->copyVector(&tempY,&_intervectorY);
1147 //vv->printVector(&_intervectorX);
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)
1158 // fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1159 for(i=0; i<(int)(_intervectorX.size()); i++)
1161 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1162 if(_intervectorX[i].getsize_vec() > 1)
1166 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
1168 arrX.push_back(_intervectorX[i].get_vec(j));
1169 arrY.push_back(_intervectorY[i].get_vec(j));
1171 //printf("\n arrX Size = %d",arrX.size());
1174 itxx = arrX.begin()+1;
1175 ityy = arrY.begin()+1;
1176 for(j=0; j<(int)(arrX.size())-1; j++)
1179 if( (*itx > _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1180 (*itxx > _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
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) );
1198 else if( (*itx < _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1199 (*itxx < _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
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) );
1217 else if( (*itx < _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1218 (*itxx < _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
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) );
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()) )
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) );
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++)
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]);
1280 //-----------------------------------------------------------------------------------------------------------------------------------------
1281 void AutoControlPoints::ControlInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1284 _contIncontpos.clear();
1287 for(i=0; i<(int)(_controlpointsX.size()); i++)
1290 for(j=0; (j<(int)(InX->size())) && (find!=true); j++)
1292 if( ((*InX)[j]-range<=_controlpointsX[i]) && (_controlpointsX[i]<=(*InX)[j]+range) && ((*InY)[j]-range<=_controlpointsY[i]) && (_controlpointsY[i]<=(*InY)[j]+range) )
1294 _contIncontpos.push_back(j);
1300 //-----------------------------------------------------------------------------------------------------------------------------------------
1301 void AutoControlPoints::NearMaxError2Control()
1303 if(_interpointsX.size() != 0)
1305 AddControlPoint(false);
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) );
1319 } // if interpointsX
1321 //-----------------------------------------------------------------------------------------------------------------------------------------
1322 void AutoControlPoints::MoveControlPointInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1326 //PRINTF---------------------------------------------------------------
1327 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1328 for(i=0; i<_controlpointsX.size(); i++)
1330 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1332 //---------------------------------------------------------------------
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
1341 std::vector<double> tempX;
1342 std::vector<double> tempY;
1343 std::vector<double> tempZ;
1348 vf->copyVector(&_controlpointsX,&tempX);
1349 vf->copyVector(&_controlpointsY,&tempY);
1350 vf->copyVector(&_controlpointsZ,&tempZ);
1351 _controlpointsX.clear();
1352 _controlpointsY.clear();
1353 _controlpointsZ.clear();
1355 for(i=0; i<(int)(tempX.size()); i++)
1359 _controlpointsX.push_back( (*InX)[_contIncontpos[_posn]] );
1360 _controlpointsY.push_back( (*InY)[_contIncontpos[_posn]] );
1361 _controlpointsZ.push_back( (*InZ)[_contIncontpos[_posn]] );
1363 _controlpointsX.push_back( tempX[i] );
1364 _controlpointsY.push_back( tempY[i] );
1365 _controlpointsZ.push_back( tempZ[i] );
1369 fixBetweenPoints(5.0);
1370 PossibleIntersections(InX,InY,InZ);
1371 IntersectionPoints();
1372 ErrorBetweenContours();
1373 double promactualIn = vf->promVector(&_errorvector,false);
1379 //double prom1final; // JPRx
1387 promactual = promactualIn;
1388 _controlpointsX.clear();
1389 _controlpointsY.clear();
1390 _controlpointsZ.clear();
1391 for(i=0; promactual > prom; i++)
1394 for(i=0; i<(int)(tempX.size()); i++)
1398 _controlpointsX.push_back( (*InX)[_contIncontpos[posact]] );
1399 _controlpointsY.push_back( (*InY)[_contIncontpos[posact]] );
1400 _controlpointsZ.push_back( (*InZ)[_contIncontpos[posact]] );
1402 _controlpointsX.push_back( tempX[i] );
1403 _controlpointsY.push_back( tempY[i] );
1404 _controlpointsZ.push_back( tempZ[i] );
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);
1423 prom2final = promactual;
1427 //--------------------------------------------------------------------------------------------------------------------------------
1428 double AutoControlPoints::MoveAndAverage(int dir, std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1431 //PRINTF---------------------------------------------------------------
1433 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1434 for(i=0; i<_controlpointsX.size(); i++)
1436 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1438 for(i=0; i<_contIncontpos.size(); i++)
1440 printf("\n contIncont pos = %d",_contIncontpos[i]);
1443 //IMPLEMENTATION-------------------------------------------------------
1444 if( (_contIncontpos.size() != 0) && (_controlpointsX.size() != 0) )
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;
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
1460 if(_contIncontpos[h]>_contIncontpos[hh])
1462 itx = _controlpointsX.begin();
1463 ity = _controlpointsY.begin();
1464 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i>_contIncontpos[hh]) && (promactual1>prom1); i--)
1466 if(j == (int)(InX->size()))
1470 prom1 = promactual1;
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);
1482 if(_contIncontpos[h]<_contIncontpos[hh])
1484 itx = _controlpointsX.begin();
1485 ity = _controlpointsY.begin();
1486 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i<_contIncontpos[hh]) && (promactual1>prom1); i++)
1492 prom1 = promactual1;
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);
1508 //--------------------------------------------------------------------------------------------------------------------------------
1509 void AutoControlPoints::MoveControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1511 ControlInContour(InX,InY,InZ);
1512 NearMaxError2Control();
1513 MoveAndAverage(1,InX,InY,InZ);
1515 //-----------------------------------------------------------------------------------------------------------------------------------------
1516 void AutoControlPoints::GetNewPoints( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1518 vectorFunctions *vf = new vectorFunctions();
1519 double prom,maxerror;
1521 InterCircle(InX,InY,InZ);
1523 fixBetweenPoints(5.0);
1524 PossibleIntersections(InX,InY,InZ);
1525 IntersectionPoints();
1526 ErrorBetweenContours();
1527 prom = vf->promVector(&_errorvector,false);
1528 vf->maxVector(&_errorvector,&maxerror);
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++)
1539 _controlpointsZ.push_back( (*InZ)[0] );
1541 fixBetweenPoints(5.0);
1542 PossibleIntersections(InX,InY,InZ);
1543 IntersectionPoints();
1544 ErrorBetweenContours();
1545 prom = vf->promVector(&_errorvector,false);
1546 vf->maxVector(&_errorvector,&maxerror);
1550 std::vector<double> cpX;
1551 std::vector<double> cpY;
1552 std::vector<double> cpZ;
1556 vf->copyVector(&_controlpointsX,&cpX);
1557 vf->copyVector(&_controlpointsY,&cpY);
1558 vf->copyVector(&_controlpointsZ,&cpZ);
1561 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
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);
1575 _controlpointsX.clear();
1576 _controlpointsY.clear();
1577 _controlpointsZ.clear();
1578 int inicontrolpoints = cpX.size();
1579 double inipercentage = (inicontrolpoints*100)/InX->size();
1582 if(inicontrolpoints<10)
1584 int points = (int)((inipercentage*3*InX->size())/100);
1585 for (int i=0; i<(int)(InX->size()); i++, h++)
1589 _controlpointsX.push_back( (*InX)[i] );
1590 _controlpointsY.push_back( (*InY)[i] );
1591 _controlpointsZ.push_back( (*InZ)[i] );
1595 } // if initontrolpoints
1597 if(inicontrolpoints>=10)
1599 int points = (int)((inipercentage*2*InX->size())/100);
1600 for (int i=0; i<(int)(InX->size()); i++, h++)
1604 _controlpointsX.push_back( (*InX)[i] );
1605 _controlpointsY.push_back( (*InY)[i] );
1606 _controlpointsZ.push_back( (*InZ)[i] );
1610 } // if inicontrolpoints
1613 fixBetweenPoints(5.0);
1614 PossibleIntersections(InX,InY,InZ);
1615 IntersectionPoints();
1616 ErrorBetweenContours();
1617 prom = vf->promVector(&_errorvector,false);
1618 vf->maxVector(&_errorvector,&maxerror);
1621 printf("\n Error Average = %f",prom);
1622 printf("\n Error Max = %f",maxerror);
1623 AddControlPoint(false);
1626 //if( (prom>1) || (maxerror>2))
1629 printf("\n Error Average is grater than 1 !!");
1630 MoveControlPoints(InX,InY,InZ);
1635 //------------------------------------------------------------------------------------------------------------------------------------------
1636 void AutoControlPoints::GetInitialNewPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1638 vectorFunctions *vf = new vectorFunctions();
1639 double prom,maxerror;
1641 InterCircle(InX,InY,InZ);
1643 fixBetweenPoints(5.0);
1644 PossibleIntersections(InX,InY,InZ);
1645 IntersectionPoints();
1646 ErrorBetweenContours();
1647 prom = vf->promVector(&_errorvector,false);
1648 vf->maxVector(&_errorvector,&maxerror);
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++)
1659 _controlpointsZ.push_back( (*InZ)[0] );
1661 fixBetweenPoints(5.0);
1662 PossibleIntersections(InX,InY,InZ);
1663 IntersectionPoints();
1664 ErrorBetweenContours();
1665 prom = vf->promVector(&_errorvector,false);
1666 vf->maxVector(&_errorvector,&maxerror);
1669 std::vector<double> cpX;
1670 std::vector<double> cpY;
1671 std::vector<double> cpZ;
1675 vf->copyVector(&_controlpointsX,&cpX);
1676 vf->copyVector(&_controlpointsY,&cpY);
1677 vf->copyVector(&_controlpointsZ,&cpZ);
1679 double promini = prom;
1682 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
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);
1693 if( i==10 || prom > promini)
1695 _controlpointsX.clear();
1696 _controlpointsY.clear();
1697 _controlpointsZ.clear();
1698 vf->copyVector(&cpX,&_controlpointsX);
1699 vf->copyVector(&cpY,&_controlpointsY);
1700 vf->copyVector(&cpZ,&_controlpointsZ);
1704 //------------------------------------------------------------------------------------------------------------------------------------------
1705 void AutoControlPoints::CalculeControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1708 _controlpointsX.clear();
1709 _controlpointsY.clear();
1710 _controlpointsZ.clear();
1711 _controlpointsZ.push_back((*InZ)[0]);
1712 GetNewPoints( InX,InY,InZ );
1714 //-----------------------------------------------------------------------------------------------------------------------------------------
1715 void AutoControlPoints::CalculeInitialControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1717 _controlpointsX.clear();
1718 _controlpointsY.clear();
1719 _controlpointsZ.clear();
1720 _controlpointsZ.push_back((*InZ)[0]);
1721 GetInitialNewPoints( InX,InY,InZ );
1723 //-----------------------------------------------------------------------------------------------------------------------------------------
1724 void AutoControlPoints::GetControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1726 vectorFunctions *vf = new vectorFunctions();
1730 vf->copyVector(&_controlpointsX,OutX);
1731 vf->copyVector(&_controlpointsY,OutY);
1732 vf->copyVector(&_controlpointsZ,OutZ);
1735 //-----------------------------------------------------------------------------------------------------------------------------------------
1736 void AutoControlPoints::GetInitialControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1738 vectorFunctions *vf = new vectorFunctions();
1742 vf->copyVector(&_controlpointsX,OutX);
1743 vf->copyVector(&_controlpointsY,OutY);
1744 vf->copyVector(&_controlpointsZ,OutZ);
1748 //-----------------------------------------------------------------------------------------------------------------------------------------
1749 void AutoControlPoints::SetNumSplineInterpolation(int num)
1753 //-----------------------------------------------------------------------------------------------------------------------------------------
1754 //-----------------------------------------------------------------------------------------------------------------------------------------
1755 //-----------------------------------------------------------------------------------------------------------------------------------------