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);
242 _mContourModel->DeleteAllPoints();
243 _mContourModel->SetNumberOfPointsSpline(_numspline);
244 for(int i=0; i<size; i++)
246 _mContourModel->AddPoint(_controlpointsX[i],_controlpointsY[i],_controlpointsZ[i]);
248 _mContourModel->UpdateSpline();
249 int numspline = _mContourModel->GetNumberOfPointsSpline();
251 _chargecontrolpointsX.clear();
252 _chargecontrolpointsY.clear();
253 _chargecontrolpointsZ.clear();
254 for(int j=0; j<numspline; j++)
256 _mContourModel->GetSpline_i_Point(j,&x,&y,&z);
257 _chargecontrolpointsX.push_back(x);
258 _chargecontrolpointsY.push_back(y);
259 _chargecontrolpointsZ.push_back(z);
263 // _pathsize = _mContourModel->GetPathSize( );
268 _pathsize = _mContourModel->GetPathSize( spc );
270 //printf("\nPATH SIZE = %f",_pathsize);
272 // std::ofstream file1;
273 // file1.open( "4_SplinePoints.txt" );
274 // for(int i = 0; i < numspline; i++)
276 // file1<<"X= "<<_chargecontrolpointsX[i] << "\tY= "<<_chargecontrolpointsY[i] << "\tZ= "<<_chargecontrolpointsZ[i]<<std::endl;
283 //Given the coordinates of two points, it calculates the slope
284 double AutoControlPoints::Slope(double x0, double y0, double x1, double y1)
286 double m = (y1-y0)/(x1-x0);
289 //----------------------------------------------------------------------------------------------------------------------------------------
290 //Given the coordinates of two points, it calculates the normal and it's slope
291 double AutoControlPoints::Normal(double x0, double y0, double* m, double xi)
295 y = ((*m)*(xi - x0)) + y0;
298 //----------------------------------------------------------------------------------------------------------------------------------------
299 void AutoControlPoints::Intersection(double x01, double y01, double x02, double y02, double mn, double m2, double* x, double* y)
301 *x = ( y02-y01-(m2*x02)+(mn*x01) )/(mn-m2);
302 *y = m2*(*x-x02)+y02;
304 //-----------------------------------------------------------------------------------------------------------------------------------------
306 **This methods finds the points where each radius of the circle intersect the contour
308 void AutoControlPoints::InterCircle(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
311 CircleCenter(InX,InY,InZ,&cx,&cy,&r);
313 //GENERATE THE CIRCLE'S POINTS
316 std::vector<double>tempX;
317 std::vector<double>tempY;
322 for(i=0; i<360/n; i++)
324 CirclePoints(cx,cy,r,grad,&x,&y);
330 //FIND THE INTERSECTIONS BETWEEN THE CIRCLE AND THE CONTOUR
332 bool interRad = false;
333 double m1, /*mn=0,*/ m2,xinter,yinter,xmin,ymin,min,dist; // JPRx
334 _intercircleX.clear();
335 _intercircleY.clear();
336 _intercircleDist.clear();
337 _interbewteencircleX.clear();
338 _interbewteencircleY.clear();
339 _interbewteencircleDist.clear();
340 _interbewteencirclePos.clear();
344 // fd = fopen("C:/bbtk_JS/data/tempCircle.txt","w");
345 // fexp = fopen("C:/bbtk_JS/data/InterCircle.txt","w");
346 // fprintf(fexp,"\npos min xmin ymin xcir ycir");
348 //std::ofstream file1;
349 //file1.open( "Temp.txt" );
351 for(i=0; i<(int)(tempX.size()); i++)
353 // fprintf(fd,"\n Para X = %f, Y = %f",tempX[i],tempY[i]);
354 _circleX.push_back(tempX[i]);
355 _circleY.push_back(tempY[i]);
356 m1 = Slope(tempX[i],tempY[i],cx,cy);//slope of the radius
358 for(j=0; j<(int)(InX->size()); j++)
360 jj = (j+1)%(InX->size());
361 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);//Slope of the vector between the adjacent points
362 Intersection(tempX[i],tempY[i],(*InX)[j],(*InY)[j],m1,m2,&xinter,&yinter);
365 //If the point of intersection is between two points of the contour
366 if( ((xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]))||((xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) ))
368 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
378 if((*InX)[j]<=(*InX)[jj])
380 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) ) //Intersection entre le cercle et le contour
382 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
391 if((*InX)[j]>(*InX)[jj])
393 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) ) //Intersection entre le cercle et le contour
395 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
409 // fprintf(fd,"\n => x_int = %f, y_int = %f, dist_int = %f",xmin,ymin,min);
410 // fprintf(fexp,"\n%d %f %f %f %f %f",i,min,xmin,ymin,tempX[i],tempY[i]);
411 //JCP 26-09-08 If the distance of the intersection is bigger than the radio we have to invert the segment
415 _interbewteencirclePos.push_back(i);
416 _interbewteencircleX.push_back(xmin);
417 _interbewteencircleY.push_back(ymin);
418 _interbewteencircleDist.push_back( sqrt(pow(cx-xmin,2)+pow(cy-ymin,2)) );
420 // file1<<i<<std::endl;
422 //JCP 26-09-08 if(min<r)
424 _intercircleX.push_back(xmin);
425 _intercircleY.push_back(ymin);
426 _intercircleDist.push_back(min);
427 // file1<<"\t"<<i<<std::endl;
434 //WHEN THERE IS RADIAL INTERSECTION
435 vectorFunctions *vecf = new vectorFunctions();
439 // fdata = fopen("C:/bbtk_JS/data/autoCPdata.txt","w");
442 std::vector<double> tempXX;
443 std::vector<double> tempYY;
444 std::vector<double> tempDD;
448 //Copy of the first points in the array until the first intersection is found
449 for(i=0; i<_interbewteencirclePos[0]; i++)
451 tempXX.push_back(_intercircleX[i]);
452 tempYY.push_back(_intercircleY[i]);
453 tempDD.push_back(_intercircleDist[i]);
454 // fprintf(fdata,"\n%f %f %f",_intercircleDist[i],_intercircleX[i],_intercircleY[i]);
456 int sizep = _interbewteencirclePos.size();
457 //Copy all the points where there is an intersection with the center but inverted
458 //JCP 26-09-08 for(i=_interbewteencirclePos[sizep-1],j=sizep-1; i>=_interbewteencirclePos[0]; i--,j--)
459 for(i=sizep-1; i >= 0;i--)
461 //JCP 26-09-08 tempXX.push_back(_interbewteencircleX[j]);
462 //JCP 26-09-08 tempYY.push_back(_interbewteencircleY[j]);
463 //JCP 26-09-08 tempDD.push_back(_interbewteencircleDist[j]);
464 tempXX.push_back(_interbewteencircleX[i]);
465 tempYY.push_back(_interbewteencircleY[i]);
466 tempDD.push_back(_interbewteencircleDist[i]);
467 // fprintf(fdata,"\n%f %f %f",_interbewteencircleDist[j],_interbewteencircleX[j],_interbewteencircleY[j]);
469 for(i=_interbewteencirclePos[0]; i<(int)(_intercircleX.size()); i++)
471 tempXX.push_back(_intercircleX[i]);
472 tempYY.push_back(_intercircleY[i]);
473 tempDD.push_back(_intercircleDist[i]);
474 // fprintf(fdata,"\n%f %f %f",_intercircleDist[i],_intercircleX[i],_intercircleY[i]);
477 _intercircleX.clear();
478 _intercircleY.clear();
479 _intercircleDist.clear();
480 vecf->copyVector(&tempXX,&_intercircleX);
481 vecf->copyVector(&tempYY,&_intercircleY);
482 vecf->copyVector(&tempDD,&_intercircleDist);
489 // std::ofstream file1;
490 // file1.open( "1_Intersection.txt" );
491 // for(int i = 0; i < (int)(_intercircleX.size()); i++)
493 // file1<<"X= "<<_intercircleX[i] << "\tY= "<<_intercircleY[i] << "\tDist= "<<_intercircleDist[i]<<std::endl;
499 //-----------------------------------------------------------------------------------------------------------------------------------------
500 void AutoControlPoints::maxminLocal()
503 _posmaxlocal.clear();
504 _posminlocal.clear();
505 _posminmaxlocal.clear();
510 _minmaxlocalX.clear();
511 _minmaxlocalY.clear();
513 if(_intercircleDist.size() != 0)
515 //JCP 26 - 09 - 08 This change was du to the posibility of having a maximum or a minimum value in the limits of
516 //JCP 26 - 09 - 08 the array
517 double lastdist, currentdist, nextdist;
518 for(i=0; i < (int)(_intercircleDist.size()); i++)
522 currentdist = _intercircleDist[i];
524 lastdist = _intercircleDist[_intercircleDist.size()-1];
525 nextdist = _intercircleDist[i+1];
526 }else if (i == (int)(_intercircleDist.size())-1){
527 lastdist = _intercircleDist[i-1];
528 nextdist = _intercircleDist[0];
530 lastdist = _intercircleDist[i-1];
531 nextdist = _intercircleDist[i+1];
535 //JCP 26-09-08 if( (_intercircleDist[i-1]<_intercircleDist[i]) && (_intercircleDist[i]>_intercircleDist[i+1]))
536 if(lastdist < currentdist && currentdist > nextdist)
538 _posmaxlocal.push_back(i);
539 _maxlocalX.push_back(_intercircleX[i]);
540 _maxlocalY.push_back(_intercircleY[i]);
541 _minmaxlocalX.push_back(_intercircleX[i]);
542 _minmaxlocalY.push_back(_intercircleY[i]);
543 _posminmaxlocal.push_back(i);
546 //JCP 26-09-08 if( (_intercircleDist[i-1]>_intercircleDist[i]) && (_intercircleDist[i]<_intercircleDist[i+1]))
547 if(lastdist > currentdist && currentdist < nextdist)
549 _posminlocal.push_back(i);
550 _minlocalX.push_back(_intercircleX[i]);
551 _minlocalY.push_back(_intercircleY[i]);
552 _minmaxlocalX.push_back(_intercircleX[i]);
553 _minmaxlocalY.push_back(_intercircleY[i]);
554 _posminmaxlocal.push_back(i);
559 vectorFunctions *vecf = new vectorFunctions();
560 std::vector<double> tempZ;
563 vecf->copyVector(&_minlocalX,&_controlpointsX);
564 vecf->copyVector(&_minlocalY,&_controlpointsY);
565 for(i=0; i<(int)(_minlocalX.size()); i++)
567 tempZ.push_back(_controlpointsZ[0]);
569 vecf->copyVector(&tempZ,&_controlpointsZ);
573 // std::ofstream file1;
574 // file1.open( "2_MaxMin.txt" );
575 // for(int i = 0; i < (int)(_controlpointsX.size()); i++)
577 // file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
584 //-----------------------------------------------------------------------------------------------------------------------------------------
585 //ELIMINATES THE POINTS WITH A DISTANCE < val
586 void AutoControlPoints::fixBetweenPoints(double val)
588 int size = _controlpointsX.size();
592 std::vector<double> tempX;
593 std::vector<double> tempY;
594 std::vector<double> tempZ;
600 vectorFunctions *vecf = new vectorFunctions();
601 for(int i=0; i<size; i++)
604 dist = sqrt(pow(_controlpointsX[i]-_controlpointsX[ii],2)+pow(_controlpointsY[i]-_controlpointsY[ii],2));
607 tempX.push_back(_controlpointsX[i]);
608 tempY.push_back(_controlpointsY[i]);
609 tempZ.push_back(_controlpointsZ[i]);
612 _controlpointsX.clear();
613 _controlpointsY.clear();
614 _controlpointsZ.clear();
616 vecf->copyVector(&tempX,&_controlpointsX);
617 vecf->copyVector(&tempY,&_controlpointsY);
618 vecf->copyVector(&tempZ,&_controlpointsZ);
621 // std::ofstream file1;
622 // file1.open( "3_PointsFixed.txt" );
623 // for(int i = 0; i < (int)(_controlpointsX.size()); i++)
625 // file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
632 //-----------------------------------------------------------------------------------------------------------------------------------------
633 //ALL THE INTERSECTIONS
634 void AutoControlPoints::InterBetweenContours(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
636 _intervectorX.clear();
637 _intervectorY.clear();
641 double m1,mn,m2,xinter,yinter;
642 if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points
646 // fd = fopen("C:/bbtk_JS/data/interBetweenContours.txt","w");
647 for(i=0; i<(int)(_chargecontrolpointsX.size()); i++)
649 ii = (i+1)%(_chargecontrolpointsX.size());
651 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
653 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
654 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
656 Vector *vecX = new Vector();
657 Vector *vecY = new Vector();
658 vecX->set_var(_chargecontrolpointsX[i]);
659 vecY->set_var(_chargecontrolpointsY[i]);
661 for(j=0; j<(int)(InX->size()); j++)
663 jj = (j+1)%(InX->size());
664 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);
665 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],(*InX)[j],(*InY)[j],mn,m2,&xinter,&yinter);
667 if(((*InX)[j] <= xinter && xinter <= (*InX)[jj]) || (xinter<=(*InX)[j] && xinter>=(*InX)[jj])){
668 vecX->set_vec(xinter);
669 vecY->set_vec(yinter);
672 if( (*InX)[j]<=(*InX)[jj] )
674 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) )
676 //If the point is a CP, the intersection is itself.
677 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
679 vecX->set_vec(xinter);
680 vecY->set_vec(yinter);
681 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
685 vecX->set_vec(xinter);
686 vecY->set_vec(yinter);
687 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
691 if( (*InX)[j]>(*InX)[jj] )
693 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) )
695 //If the point is a CP, the intersection is itself.
696 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
698 vecX->set_vec(xinter);
699 vecY->set_vec(yinter);
700 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
704 vecX->set_vec(xinter);
705 vecY->set_vec(yinter);
706 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
712 _intervectorX.push_back(*vecX);
713 _intervectorY.push_back(*vecY);
721 //-----------------------------------------------------------------------------------------------------------------------------------------
722 void AutoControlPoints::GetInterBetweenContours(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
726 int size = _intervectorX.size();
730 for(i=0; i<size; i++)
732 interVX->push_back(_intervectorX[i]);
733 interVY->push_back(_intervectorY[i]);
737 //-----------------------------------------------------------------------------------------------------------------------------------------
738 //ONLY THE LOGICAL INTERSECTIONS
739 void AutoControlPoints::IntersectionPoints()
741 if(_intervectorX.size() != 0)
743 _interpointsX.clear();
744 _interpointsY.clear();
748 // fd = fopen("C:/bbtk_JS/data/IntersectionPoints.txt","w");
755 for(j=0; j<_intervectorX[0].getsize_vec(); j++)
757 dist = sqrt( pow( _intervectorX[0].get_vec(j)-_intervectorX[0].get_var(),2 ) + pow( _intervectorY[0].get_vec(j)-_intervectorY[0].get_var(),2 ) );
766 _interpointsX.push_back(_intervectorX[0].get_vec(posj));
767 _interpointsY.push_back(_intervectorY[0].get_vec(posj));
768 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[0].get_var(),_intervectorY[0].get_var());
769 // fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[0],_interpointsY[0]);
773 printf("\n\n There is an invalid intersection: Must see AutoControlPoints::IntersectionPoints() method");
776 for(i=0; i<(int)(_intervectorX.size()); i++){
779 for(j=0; j<_intervectorX[i].getsize_vec(); j++) {
780 dist = sqrt( pow( _intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2 ) + pow( _intervectorY[i].get_vec(j)-_intervectorX[i].get_var(),2 ) );
786 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
787 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
790 for(i=1; i<_intervectorX.size(); i++)
794 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
795 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
797 //TYPE: LE PLUS PRES VOISIN
798 dist = sqrt( pow( _intervectorX[i].get_vec(j)-_interpointsX[i-1],2 ) + pow( _intervectorY[i].get_vec(j)-_interpointsY[i-1],2 ) );
799 //TYPE: LE PLUS PRES DANS LA M�ME DROITE
800 //dist = sqrt(pow(_intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2)+pow(_intervectorY[i].get_vec(j)-_intervectorY[i].get_var(),2));
808 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
809 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
810 // fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[i],_interpointsY[i]);
816 //-----------------------------------------------------------------------------------------------------------------------------------------
817 void AutoControlPoints::GetIntersectionPoints(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
819 int size = _interpointsX.size();
823 Vector *vecX = new Vector();
824 Vector *vecY = new Vector();
827 for(i=0; i<size; i++)
829 vecX->set_var(_controlpointsZ[0]);
830 vecX->set_vec(_interpointsX[i]);
831 vecY->set_var(_controlpointsZ[0]);
832 vecY->set_vec(_interpointsY[i]);
833 interVX->push_back(*vecX);
834 interVY->push_back(*vecY);
840 //-----------------------------------------------------------------------------------------------------------------------------------------
841 //ERROR BETWEEN THE LOGICAL INTERSECTIONS
842 void AutoControlPoints::ErrorBetweenContours()
845 if(_interpointsX.size() != 0)
847 _errorvector.clear();
852 // fd = fopen("C:/bbtk_JS/data/interErrorData.txt","w");
853 for(i=0; i<(int)(_interpointsX.size()); i++)
855 _errorvector.push_back( (sqrt( pow( _interpointsX[i]-_intervectorX[i].get_var(),2 ) + pow( _interpointsY[i]-_intervectorY[i].get_var(),2 ) )/_pathsize)*100 );
856 // fprintf(fd,"\n%d %f",i,_errorvector[i]);
860 for(i=0; i<(int)(_errorvector.size()); i++)
862 if(_interpointsX[i] != -1)
864 if(_errorvector[i]>max)
866 max = _errorvector[i];
873 //-----------------------------------------------------------------------------------------------------------------------------------------
874 void AutoControlPoints::GetErrorBetweenContours( std::vector<double>*vec )
877 vectorFunctions *vf = new vectorFunctions();
878 vf->copyVector(&_errorvector,vec);
881 //-----------------------------------------------------------------------------------------------------------------------------------------
882 void AutoControlPoints::AddControlPoint(bool activate)
886 double xmax = _interpointsX[(int)_errorpos];
887 double ymax = _interpointsY[(int)_errorpos];
888 double xx = _intervectorX[(int)_errorpos].get_var();
889 double yy = _intervectorY[(int)_errorpos].get_var();
890 printf("\n XMAX = %f, YMAX = %f, XX = %f, YY = %f",xmax,ymax,xx,yy);
892 int i,ii,j,posA=-1,posB=-1;
893 bool findA=false, findB=false;
895 for(i=(int)_errorpos; findA!=true; i++)
897 ii = i%_errorvector.size();
898 for(j=0; j<(int)(_controlpointsX.size()); j++)
900 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[ii].get_var()) && ((float)_intervectorX[ii].get_var()<=(float)_controlpointsX[j]+1.5) &&
901 ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[ii].get_var()) && ((float)_intervectorY[ii].get_var()<=(float)_controlpointsY[j]+1.5) )
909 for(i=(int)_errorpos; findB!=true; i--)
913 i = _errorvector.size();
915 for(j=0; j<(int)(_controlpointsX.size()); j++)
917 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[i].get_var()) && ((float)_intervectorX[i].get_var()<=(float)_controlpointsX[j]+1.5) &&
918 ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[i].get_var()) && ((float)_intervectorY[i].get_var()<=(float)_controlpointsY[j]+1.5) )
932 if( ( posB = _controlpointsX.size()-1) ) // ?!? // JPRx // ?!? EED
937 printf("\n POSA = %d, X = %f, Y = %f",posA,_controlpointsX[posA],_controlpointsY[posA]);
938 printf("\n POSB = %d, X = %f, Y = %f",posB,_controlpointsX[posB],_controlpointsY[posB]);
942 if(((posA!=-1)&&(posB!=-1)))
946 printf("\n ID = %d",id);
949 std::vector<double> tempX;
950 std::vector<double> tempY;
951 std::vector<double> tempZ;
952 for(i=0; i<(int)(_controlpointsX.size()); i++)
956 tempX.push_back(xmax);
957 tempY.push_back(ymax);
958 tempZ.push_back(_controlpointsZ[0]);
960 tempX.push_back(_controlpointsX[i]);
961 tempY.push_back(_controlpointsY[i]);
962 tempZ.push_back(_controlpointsZ[i]);
967 vectorFunctions *vf = new vectorFunctions();
968 vf->copyVector(&tempX,&_controlpointsX);
969 vf->copyVector(&tempY,&_controlpointsY);
970 vf->copyVector(&tempZ,&_controlpointsZ);
977 //-----------------------------------------------------------------------------------------------------------------------------------------
978 void AutoControlPoints::InterBetweenControl( )
984 double m1,mn,m2,xinter,yinter;
985 if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points
990 // fd = fopen("C:/bbtk_JS/data/InterBetweenControl.txt","w");
991 for(i=0; i<(int)(_chargecontrolpointsX.size())-1; i++)
993 ii = (i+1)%(_chargecontrolpointsX.size());
994 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
996 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
997 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
999 Vector *vecX = new Vector();
1000 Vector *vecY = new Vector();
1001 vecX->set_var(_chargecontrolpointsX[i]);
1002 vecY->set_var(_chargecontrolpointsY[i]);
1004 for(j=0; j<(int)(_chargecontrolpointsX.size()); j++)
1006 jj = (j+1)%(_chargecontrolpointsX.size());
1007 m2 = Slope(_chargecontrolpointsX[j],_chargecontrolpointsY[j],_chargecontrolpointsX[jj],_chargecontrolpointsY[jj]);
1008 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[j],_chargecontrolpointsY[j],mn,m2,&xinter,&yinter);
1009 if( _chargecontrolpointsX[j]<=_chargecontrolpointsX[jj] )
1011 if( (xinter>=_chargecontrolpointsX[j]) && (xinter<=_chargecontrolpointsX[jj]) )
1013 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1018 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1019 vecX->set_vec(xinter);
1020 vecY->set_vec(yinter);
1024 if( _chargecontrolpointsX[j]>_chargecontrolpointsX[jj] )
1026 if( (xinter<=_chargecontrolpointsX[j]) && (xinter>=_chargecontrolpointsX[jj]) )
1028 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1033 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1034 vecX->set_vec(xinter);
1035 vecY->set_vec(yinter);
1040 _intervecXX.push_back(*vecX);
1041 _intervecYY.push_back(*vecY);
1051 //-----------------------------------------------------------------------------------------------------------------------------------------
1052 void AutoControlPoints::fixBetweenControl()
1054 _interitselfX.clear();
1055 _interitselfY.clear();
1057 float vecx,vecy,varx,vary;
1059 // fd = fopen("C:/bbtk_JS/data/InterBetweenControlFix.txt","w");
1060 for(i=0; i<(int)(_intervecXX.size()); i++)
1062 Vector *vx = new Vector();
1063 Vector *vy = new Vector();
1064 vx->set_var(_intervecXX[i].get_var());
1065 vy->set_var(_intervecYY[i].get_var());
1066 // fprintf(fd,"\n Para X = %f, Y = %f",_intervecXX[i].get_var(),_intervecYY[i].get_var());
1067 for(j=0; j<_intervecXX[i].getsize_vec(); j++)
1069 vecx = _intervecXX[i].get_vec(j);
1070 varx = _intervecXX[i].get_var();
1071 vecy = _intervecYY[i].get_vec(j);
1072 vary = _intervecYY[i].get_var();
1073 if( (vecx == varx) && (vecy == vary) )
1078 vx->set_vec((double)vecx);
1079 vy->set_vec((double)vecy);
1080 // fprintf(fd,"\n => x_int = %f, y_int = %f",vecx,vecy);
1083 _interitselfX.push_back(*vx);
1084 _interitselfY.push_back(*vy);
1090 //-----------------------------------------------------------------------------------------------------------------------------------------
1091 void AutoControlPoints::PossibleIntersections( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1093 InterBetweenContours(InX,InY,InZ); //_intervectorX
1094 //InterBetweenControl(); //_intervecXX
1095 //fixBetweenControl(); //_interitselfX
1097 std::vector<Vector> tempX;
1098 std::vector<Vector> tempY;
1102 //double dist1,dist2; // JPRx
1107 fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1110 for(i=0; i<_intervectorX.size(); i++)
1112 fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1113 Vector *vx = new Vector();
1114 Vector *vy = new Vector();
1115 vx->set_var(_intervectorX[i].get_var());
1116 vy->set_var(_intervectorY[i].get_var());
1118 for(j=0; j<_intervectorX[i].getsize_vec() ; j++)
1120 dist1 = sqrt( pow(_intervectorX[i].get_var()-_intervectorX[i].get_vec(j),2) + pow(_intervectorY[i].get_var()-_intervectorY[i].get_vec(j),2) );
1121 for(k=0; (k<_interitselfX[i].getsize_vec()) && (ready!=true); k++)
1123 dist2 = sqrt( pow(_interitselfX[i].get_var()-_interitselfX[i].get_vec(k),2) + pow(_interitselfY[i].get_var()-_interitselfY[i].get_vec(k),2) );
1126 fprintf(fd,"\n => x_int = %f, y_int = %f",_intervectorX[i].get_vec(j),_intervectorY[i].get_vec(j));
1127 vx->set_vec(_intervectorX[i].get_vec(j));
1128 vy->set_vec(_intervectorY[i].get_vec(j));
1133 tempX.push_back(*vx);
1134 tempY.push_back(*vy);
1140 _intervectorX.clear();
1141 _intervectorY.clear();
1142 Vector *vv = new Vector();
1143 vv->copyVector(&tempX,&_intervectorX);
1144 vv->copyVector(&tempY,&_intervectorY);
1146 //vv->printVector(&_intervectorX);
1148 std::vector<double> arrX;
1149 std::vector<double> arrY;
1150 std::vector<double>::iterator itx;
1151 std::vector<double>::iterator ity;
1152 std::vector<double>::iterator itxx;
1153 std::vector<double>::iterator ityy;
1154 double distA, distB;
1155 if(_intervectorX.size() != 0)
1157 // fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1158 for(i=0; i<(int)(_intervectorX.size()); i++)
1160 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1161 if(_intervectorX[i].getsize_vec() > 1)
1165 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
1167 arrX.push_back(_intervectorX[i].get_vec(j));
1168 arrY.push_back(_intervectorY[i].get_vec(j));
1170 //printf("\n arrX Size = %d",arrX.size());
1173 itxx = arrX.begin()+1;
1174 ityy = arrY.begin()+1;
1175 for(j=0; j<(int)(arrX.size())-1; j++)
1178 if( (*itx > _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1179 (*itxx > _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1181 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1182 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1197 else if( (*itx < _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1198 (*itxx < _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1200 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1201 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1216 else if( (*itx < _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1217 (*itxx < _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1219 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1220 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1235 else if( ((double)*itx > _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1236 ((double)*itxx > _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1238 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1239 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1261 _intervectorX[i].resetVec();
1262 _intervectorY[i].resetVec();
1263 //printf("\n _intervector(%d) Size = %d",i,_intervectorX[i].getsize_vec());
1264 for(k=0; k<(int)(arrX.size()); k++)
1266 //printf("\n arr(%d) X = %f, Y = %f",k,arrX[k],arrY[k]);
1267 // fprintf(fd,"\n => x_int = %f, y_int = %f",arrX[k],arrY[k]);
1268 _intervectorX[i].set_vec(arrX[k]);
1269 _intervectorY[i].set_vec(arrY[k]);
1279 //-----------------------------------------------------------------------------------------------------------------------------------------
1280 void AutoControlPoints::ControlInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1283 _contIncontpos.clear();
1286 for(i=0; i<(int)(_controlpointsX.size()); i++)
1289 for(j=0; (j<(int)(InX->size())) && (find!=true); j++)
1291 if( ((*InX)[j]-range<=_controlpointsX[i]) && (_controlpointsX[i]<=(*InX)[j]+range) && ((*InY)[j]-range<=_controlpointsY[i]) && (_controlpointsY[i]<=(*InY)[j]+range) )
1293 _contIncontpos.push_back(j);
1299 //-----------------------------------------------------------------------------------------------------------------------------------------
1300 void AutoControlPoints::NearMaxError2Control()
1302 if(_interpointsX.size() != 0)
1304 AddControlPoint(false);
1306 double distA = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posA],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posA],2) );
1307 double distB = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posB],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posB],2) );
1318 } // if interpointsX
1320 //-----------------------------------------------------------------------------------------------------------------------------------------
1321 void AutoControlPoints::MoveControlPointInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1325 //PRINTF---------------------------------------------------------------
1326 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1327 for(i=0; i<_controlpointsX.size(); i++)
1329 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1331 //---------------------------------------------------------------------
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
1340 std::vector<double> tempX;
1341 std::vector<double> tempY;
1342 std::vector<double> tempZ;
1347 vf->copyVector(&_controlpointsX,&tempX);
1348 vf->copyVector(&_controlpointsY,&tempY);
1349 vf->copyVector(&_controlpointsZ,&tempZ);
1350 _controlpointsX.clear();
1351 _controlpointsY.clear();
1352 _controlpointsZ.clear();
1354 for(i=0; i<(int)(tempX.size()); i++)
1358 _controlpointsX.push_back( (*InX)[_contIncontpos[_posn]] );
1359 _controlpointsY.push_back( (*InY)[_contIncontpos[_posn]] );
1360 _controlpointsZ.push_back( (*InZ)[_contIncontpos[_posn]] );
1362 _controlpointsX.push_back( tempX[i] );
1363 _controlpointsY.push_back( tempY[i] );
1364 _controlpointsZ.push_back( tempZ[i] );
1368 fixBetweenPoints(5.0);
1369 PossibleIntersections(InX,InY,InZ);
1370 IntersectionPoints();
1371 ErrorBetweenContours();
1372 double promactualIn = vf->promVector(&_errorvector,false);
1378 //double prom1final; // JPRx
1386 promactual = promactualIn;
1387 _controlpointsX.clear();
1388 _controlpointsY.clear();
1389 _controlpointsZ.clear();
1390 for(i=0; promactual > prom; i++)
1393 for(i=0; i<(int)(tempX.size()); i++)
1397 _controlpointsX.push_back( (*InX)[_contIncontpos[posact]] );
1398 _controlpointsY.push_back( (*InY)[_contIncontpos[posact]] );
1399 _controlpointsZ.push_back( (*InZ)[_contIncontpos[posact]] );
1401 _controlpointsX.push_back( tempX[i] );
1402 _controlpointsY.push_back( tempY[i] );
1403 _controlpointsZ.push_back( tempZ[i] );
1414 fixBetweenPoints(5.0);
1415 PossibleIntersections(InX,InY,InZ);
1416 IntersectionPoints();
1417 ErrorBetweenContours();
1418 promactual = vf->promVector(&_errorvector,false);
1419 //printf("\n The point in the position %d, has moved %d times",_posn,i);
1422 prom2final = promactual;
1426 //--------------------------------------------------------------------------------------------------------------------------------
1427 double AutoControlPoints::MoveAndAverage(int dir, std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1430 //PRINTF---------------------------------------------------------------
1432 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1433 for(i=0; i<_controlpointsX.size(); i++)
1435 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1437 for(i=0; i<_contIncontpos.size(); i++)
1439 printf("\n contIncont pos = %d",_contIncontpos[i]);
1442 //IMPLEMENTATION-------------------------------------------------------
1443 if( (_contIncontpos.size() != 0) && (_controlpointsX.size() != 0) )
1445 vectorFunctions *vf = new vectorFunctions();
1446 std::vector<double>::iterator itx;
1447 std::vector<double>::iterator ity;
1448 std::vector<double> tempX;
1449 std::vector<double> tempY;
1452 vf->copyVector(&_controlpointsX,&tempX);
1453 vf->copyVector(&_controlpointsY,&tempY);
1454 int i,j /*,pos = 0*/ ; // JPRx
1455 double prom1=0,promactual1=1;
1456 //double prom2=0,promactual2=1; // JPRx
1459 if(_contIncontpos[h]>_contIncontpos[hh])
1461 itx = _controlpointsX.begin();
1462 ity = _controlpointsY.begin();
1463 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i>_contIncontpos[hh]) && (promactual1>prom1); i--)
1465 if(j == (int)(InX->size()))
1469 prom1 = promactual1;
1472 printf("\n itx = %f, ity = %f", *itx,*ity);
1473 fixBetweenPoints(5.0);
1474 PossibleIntersections(InX,InY,InZ);
1475 IntersectionPoints();
1476 ErrorBetweenContours();
1477 promactual1 = vf->promVector(&_errorvector,false);
1481 if(_contIncontpos[h]<_contIncontpos[hh])
1483 itx = _controlpointsX.begin();
1484 ity = _controlpointsY.begin();
1485 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i<_contIncontpos[hh]) && (promactual1>prom1); i++)
1491 prom1 = promactual1;
1494 printf("\n itx = %f, ity = %f", *itx,*ity);
1495 fixBetweenPoints(5.0);
1496 PossibleIntersections(InX,InY,InZ);
1497 IntersectionPoints();
1498 ErrorBetweenContours();
1499 promactual1 = vf->promVector(&_errorvector,false);
1507 //--------------------------------------------------------------------------------------------------------------------------------
1508 void AutoControlPoints::MoveControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1510 ControlInContour(InX,InY,InZ);
1511 NearMaxError2Control();
1512 MoveAndAverage(1,InX,InY,InZ);
1514 //-----------------------------------------------------------------------------------------------------------------------------------------
1515 void AutoControlPoints::GetNewPoints( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1517 vectorFunctions *vf = new vectorFunctions();
1518 double prom,maxerror;
1520 InterCircle(InX,InY,InZ);
1522 fixBetweenPoints(5.0);
1523 PossibleIntersections(InX,InY,InZ);
1524 IntersectionPoints();
1525 ErrorBetweenContours();
1526 prom = vf->promVector(&_errorvector,false);
1527 vf->maxVector(&_errorvector,&maxerror);
1531 _controlpointsX.clear();
1532 _controlpointsY.clear();
1533 _controlpointsZ.clear();
1534 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1535 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1536 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1538 _controlpointsZ.push_back( (*InZ)[0] );
1540 fixBetweenPoints(5.0);
1541 PossibleIntersections(InX,InY,InZ);
1542 IntersectionPoints();
1543 ErrorBetweenContours();
1544 prom = vf->promVector(&_errorvector,false);
1545 vf->maxVector(&_errorvector,&maxerror);
1549 std::vector<double> cpX;
1550 std::vector<double> cpY;
1551 std::vector<double> cpZ;
1555 vf->copyVector(&_controlpointsX,&cpX);
1556 vf->copyVector(&_controlpointsY,&cpY);
1557 vf->copyVector(&_controlpointsZ,&cpZ);
1560 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1562 AddControlPoint(true);
1563 fixBetweenPoints(5.0);
1564 PossibleIntersections(InX,InY,InZ);
1565 IntersectionPoints();
1566 ErrorBetweenContours();
1567 prom = vf->promVector(&_errorvector,false);
1568 vf->maxVector(&_errorvector,&maxerror);
1574 _controlpointsX.clear();
1575 _controlpointsY.clear();
1576 _controlpointsZ.clear();
1577 int inicontrolpoints = cpX.size();
1578 double inipercentage = (inicontrolpoints*100)/InX->size();
1581 if(inicontrolpoints<10)
1583 int points = (int)((inipercentage*3*InX->size())/100);
1584 for (int i=0; i<(int)(InX->size()); i++, h++)
1588 _controlpointsX.push_back( (*InX)[i] );
1589 _controlpointsY.push_back( (*InY)[i] );
1590 _controlpointsZ.push_back( (*InZ)[i] );
1594 } // if initontrolpoints
1596 if(inicontrolpoints>=10)
1598 int points = (int)((inipercentage*2*InX->size())/100);
1599 for (int i=0; i<(int)(InX->size()); i++, h++)
1603 _controlpointsX.push_back( (*InX)[i] );
1604 _controlpointsY.push_back( (*InY)[i] );
1605 _controlpointsZ.push_back( (*InZ)[i] );
1609 } // if inicontrolpoints
1612 fixBetweenPoints(5.0);
1613 PossibleIntersections(InX,InY,InZ);
1614 IntersectionPoints();
1615 ErrorBetweenContours();
1616 prom = vf->promVector(&_errorvector,false);
1617 vf->maxVector(&_errorvector,&maxerror);
1620 printf("\n Error Average = %f",prom);
1621 printf("\n Error Max = %f",maxerror);
1622 AddControlPoint(false);
1625 //if( (prom>1) || (maxerror>2))
1628 printf("\n Error Average is grater than 1 !!");
1629 MoveControlPoints(InX,InY,InZ);
1634 //------------------------------------------------------------------------------------------------------------------------------------------
1635 void AutoControlPoints::GetInitialNewPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1637 vectorFunctions *vf = new vectorFunctions();
1638 double prom,maxerror;
1640 InterCircle(InX,InY,InZ);
1642 fixBetweenPoints(5.0);
1643 PossibleIntersections(InX,InY,InZ);
1644 IntersectionPoints();
1645 ErrorBetweenContours();
1646 prom = vf->promVector(&_errorvector,false);
1647 vf->maxVector(&_errorvector,&maxerror);
1651 _controlpointsX.clear();
1652 _controlpointsY.clear();
1653 _controlpointsZ.clear();
1654 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1655 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1656 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1658 _controlpointsZ.push_back( (*InZ)[0] );
1660 fixBetweenPoints(5.0);
1661 PossibleIntersections(InX,InY,InZ);
1662 IntersectionPoints();
1663 ErrorBetweenContours();
1664 prom = vf->promVector(&_errorvector,false);
1665 vf->maxVector(&_errorvector,&maxerror);
1668 std::vector<double> cpX;
1669 std::vector<double> cpY;
1670 std::vector<double> cpZ;
1674 vf->copyVector(&_controlpointsX,&cpX);
1675 vf->copyVector(&_controlpointsY,&cpY);
1676 vf->copyVector(&_controlpointsZ,&cpZ);
1678 double promini = prom;
1681 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1683 AddControlPoint(true);
1684 fixBetweenPoints(5.0);
1685 PossibleIntersections(InX,InY,InZ);
1686 IntersectionPoints();
1687 ErrorBetweenContours();
1688 prom = vf->promVector(&_errorvector,false);
1689 vf->maxVector(&_errorvector,&maxerror);
1692 if( i==10 || prom > promini)
1694 _controlpointsX.clear();
1695 _controlpointsY.clear();
1696 _controlpointsZ.clear();
1697 vf->copyVector(&cpX,&_controlpointsX);
1698 vf->copyVector(&cpY,&_controlpointsY);
1699 vf->copyVector(&cpZ,&_controlpointsZ);
1703 //------------------------------------------------------------------------------------------------------------------------------------------
1704 void AutoControlPoints::CalculeControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1707 _controlpointsX.clear();
1708 _controlpointsY.clear();
1709 _controlpointsZ.clear();
1710 _controlpointsZ.push_back((*InZ)[0]);
1711 GetNewPoints( InX,InY,InZ );
1713 //-----------------------------------------------------------------------------------------------------------------------------------------
1714 void AutoControlPoints::CalculeInitialControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1716 _controlpointsX.clear();
1717 _controlpointsY.clear();
1718 _controlpointsZ.clear();
1719 _controlpointsZ.push_back((*InZ)[0]);
1720 GetInitialNewPoints( InX,InY,InZ );
1722 //-----------------------------------------------------------------------------------------------------------------------------------------
1723 void AutoControlPoints::GetControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1725 vectorFunctions *vf = new vectorFunctions();
1729 vf->copyVector(&_controlpointsX,OutX);
1730 vf->copyVector(&_controlpointsY,OutY);
1731 vf->copyVector(&_controlpointsZ,OutZ);
1734 //-----------------------------------------------------------------------------------------------------------------------------------------
1735 void AutoControlPoints::GetInitialControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1737 vectorFunctions *vf = new vectorFunctions();
1741 vf->copyVector(&_controlpointsX,OutX);
1742 vf->copyVector(&_controlpointsY,OutY);
1743 vf->copyVector(&_controlpointsZ,OutZ);
1747 //-----------------------------------------------------------------------------------------------------------------------------------------
1748 void AutoControlPoints::SetNumSplineInterpolation(int num)
1752 //-----------------------------------------------------------------------------------------------------------------------------------------
1753 //-----------------------------------------------------------------------------------------------------------------------------------------
1754 //-----------------------------------------------------------------------------------------------------------------------------------------