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 );
272 //printf("\nPATH SIZE = %f",_pathsize);
275 file1.open( "4_SplinePoints.txt" );
277 for(int i = 0; i < numspline; i++){
278 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 file1.open( "1_Intersection.txt" );
492 for(int i = 0; i < (int)(_intercircleX.size()); i++){
493 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 file1.open( "2_MaxMin.txt" );
576 for(int i = 0; i < (int)(_controlpointsX.size()); i++){
577 file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
583 //-----------------------------------------------------------------------------------------------------------------------------------------
584 //ELIMINATES THE POINTS WITH A DISTANCE < val
585 void AutoControlPoints::fixBetweenPoints(double val)
587 int size = _controlpointsX.size();
591 std::vector<double> tempX;
592 std::vector<double> tempY;
593 std::vector<double> tempZ;
599 vectorFunctions *vecf = new vectorFunctions();
600 for(int i=0; i<size; i++)
603 dist = sqrt(pow(_controlpointsX[i]-_controlpointsX[ii],2)+pow(_controlpointsY[i]-_controlpointsY[ii],2));
606 tempX.push_back(_controlpointsX[i]);
607 tempY.push_back(_controlpointsY[i]);
608 tempZ.push_back(_controlpointsZ[i]);
611 _controlpointsX.clear();
612 _controlpointsY.clear();
613 _controlpointsZ.clear();
615 vecf->copyVector(&tempX,&_controlpointsX);
616 vecf->copyVector(&tempY,&_controlpointsY);
617 vecf->copyVector(&tempZ,&_controlpointsZ);
620 file1.open( "3_PointsFixed.txt" );
622 for(int i = 0; i < (int)(_controlpointsX.size()); i++){
623 file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
630 //-----------------------------------------------------------------------------------------------------------------------------------------
631 //ALL THE INTERSECTIONS
632 void AutoControlPoints::InterBetweenContours(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
634 _intervectorX.clear();
635 _intervectorY.clear();
639 double m1,mn,m2,xinter,yinter;
640 if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points
644 // fd = fopen("C:/bbtk_JS/data/interBetweenContours.txt","w");
645 for(i=0; i<(int)(_chargecontrolpointsX.size()); i++)
647 ii = (i+1)%(_chargecontrolpointsX.size());
649 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
651 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
652 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
654 Vector *vecX = new Vector();
655 Vector *vecY = new Vector();
656 vecX->set_var(_chargecontrolpointsX[i]);
657 vecY->set_var(_chargecontrolpointsY[i]);
659 for(j=0; j<(int)(InX->size()); j++)
661 jj = (j+1)%(InX->size());
662 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);
663 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],(*InX)[j],(*InY)[j],mn,m2,&xinter,&yinter);
665 if(((*InX)[j] <= xinter && xinter <= (*InX)[jj]) || (xinter<=(*InX)[j] && xinter>=(*InX)[jj])){
666 vecX->set_vec(xinter);
667 vecY->set_vec(yinter);
670 if( (*InX)[j]<=(*InX)[jj] )
672 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) )
674 //If the point is a CP, the intersection is itself.
675 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
677 vecX->set_vec(xinter);
678 vecY->set_vec(yinter);
679 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
683 vecX->set_vec(xinter);
684 vecY->set_vec(yinter);
685 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
689 if( (*InX)[j]>(*InX)[jj] )
691 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) )
693 //If the point is a CP, the intersection is itself.
694 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
696 vecX->set_vec(xinter);
697 vecY->set_vec(yinter);
698 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
702 vecX->set_vec(xinter);
703 vecY->set_vec(yinter);
704 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
710 _intervectorX.push_back(*vecX);
711 _intervectorY.push_back(*vecY);
719 //-----------------------------------------------------------------------------------------------------------------------------------------
720 void AutoControlPoints::GetInterBetweenContours(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
724 int size = _intervectorX.size();
728 for(i=0; i<size; i++)
730 interVX->push_back(_intervectorX[i]);
731 interVY->push_back(_intervectorY[i]);
735 //-----------------------------------------------------------------------------------------------------------------------------------------
736 //ONLY THE LOGICAL INTERSECTIONS
737 void AutoControlPoints::IntersectionPoints()
739 if(_intervectorX.size() != 0)
741 _interpointsX.clear();
742 _interpointsY.clear();
746 // fd = fopen("C:/bbtk_JS/data/IntersectionPoints.txt","w");
753 for(j=0; j<_intervectorX[0].getsize_vec(); j++)
755 dist = sqrt( pow( _intervectorX[0].get_vec(j)-_intervectorX[0].get_var(),2 ) + pow( _intervectorY[0].get_vec(j)-_intervectorY[0].get_var(),2 ) );
764 _interpointsX.push_back(_intervectorX[0].get_vec(posj));
765 _interpointsY.push_back(_intervectorY[0].get_vec(posj));
766 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[0].get_var(),_intervectorY[0].get_var());
767 // fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[0],_interpointsY[0]);
771 printf("\n\n There is an invalid intersection: Must see AutoControlPoints::IntersectionPoints() method");
774 for(i=0; i<(int)(_intervectorX.size()); i++){
777 for(j=0; j<_intervectorX[i].getsize_vec(); j++) {
778 dist = sqrt( pow( _intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2 ) + pow( _intervectorY[i].get_vec(j)-_intervectorX[i].get_var(),2 ) );
784 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
785 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
788 for(i=1; i<_intervectorX.size(); i++)
792 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
793 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
795 //TYPE: LE PLUS PRES VOISIN
796 dist = sqrt( pow( _intervectorX[i].get_vec(j)-_interpointsX[i-1],2 ) + pow( _intervectorY[i].get_vec(j)-_interpointsY[i-1],2 ) );
797 //TYPE: LE PLUS PRES DANS LA M�ME DROITE
798 //dist = sqrt(pow(_intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2)+pow(_intervectorY[i].get_vec(j)-_intervectorY[i].get_var(),2));
806 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
807 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
808 // fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[i],_interpointsY[i]);
814 //-----------------------------------------------------------------------------------------------------------------------------------------
815 void AutoControlPoints::GetIntersectionPoints(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
817 int size = _interpointsX.size();
821 Vector *vecX = new Vector();
822 Vector *vecY = new Vector();
825 for(i=0; i<size; i++)
827 vecX->set_var(_controlpointsZ[0]);
828 vecX->set_vec(_interpointsX[i]);
829 vecY->set_var(_controlpointsZ[0]);
830 vecY->set_vec(_interpointsY[i]);
831 interVX->push_back(*vecX);
832 interVY->push_back(*vecY);
838 //-----------------------------------------------------------------------------------------------------------------------------------------
839 //ERROR BETWEEN THE LOGICAL INTERSECTIONS
840 void AutoControlPoints::ErrorBetweenContours()
843 if(_interpointsX.size() != 0)
845 _errorvector.clear();
850 // fd = fopen("C:/bbtk_JS/data/interErrorData.txt","w");
851 for(i=0; i<(int)(_interpointsX.size()); i++)
853 _errorvector.push_back( (sqrt( pow( _interpointsX[i]-_intervectorX[i].get_var(),2 ) + pow( _interpointsY[i]-_intervectorY[i].get_var(),2 ) )/_pathsize)*100 );
854 // fprintf(fd,"\n%d %f",i,_errorvector[i]);
858 for(i=0; i<(int)(_errorvector.size()); i++)
860 if(_interpointsX[i] != -1)
862 if(_errorvector[i]>max)
864 max = _errorvector[i];
871 //-----------------------------------------------------------------------------------------------------------------------------------------
872 void AutoControlPoints::GetErrorBetweenContours( std::vector<double>*vec )
875 vectorFunctions *vf = new vectorFunctions();
876 vf->copyVector(&_errorvector,vec);
879 //-----------------------------------------------------------------------------------------------------------------------------------------
880 void AutoControlPoints::AddControlPoint(bool activate)
884 double xmax = _interpointsX[(int)_errorpos];
885 double ymax = _interpointsY[(int)_errorpos];
886 double xx = _intervectorX[(int)_errorpos].get_var();
887 double yy = _intervectorY[(int)_errorpos].get_var();
888 printf("\n XMAX = %f, YMAX = %f, XX = %f, YY = %f",xmax,ymax,xx,yy);
890 int i,ii,j,posA=-1,posB=-1;
891 bool findA=false, findB=false;
893 for(i=(int)_errorpos; findA!=true; i++)
895 ii = i%_errorvector.size();
896 for(j=0; j<(int)(_controlpointsX.size()); j++)
898 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[ii].get_var()) && ((float)_intervectorX[ii].get_var()<=(float)_controlpointsX[j]+1.5) &&
899 ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[ii].get_var()) && ((float)_intervectorY[ii].get_var()<=(float)_controlpointsY[j]+1.5) )
907 for(i=(int)_errorpos; findB!=true; i--)
911 i = _errorvector.size();
913 for(j=0; j<(int)(_controlpointsX.size()); j++)
915 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[i].get_var()) && ((float)_intervectorX[i].get_var()<=(float)_controlpointsX[j]+1.5) &&
916 ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[i].get_var()) && ((float)_intervectorY[i].get_var()<=(float)_controlpointsY[j]+1.5) )
930 if( ( posB = _controlpointsX.size()-1) ) // ?!? // JPRx // ?!? EED
935 printf("\n POSA = %d, X = %f, Y = %f",posA,_controlpointsX[posA],_controlpointsY[posA]);
936 printf("\n POSB = %d, X = %f, Y = %f",posB,_controlpointsX[posB],_controlpointsY[posB]);
940 if(((posA!=-1)&&(posB!=-1)))
944 printf("\n ID = %d",id);
947 std::vector<double> tempX;
948 std::vector<double> tempY;
949 std::vector<double> tempZ;
950 for(i=0; i<(int)(_controlpointsX.size()); i++)
954 tempX.push_back(xmax);
955 tempY.push_back(ymax);
956 tempZ.push_back(_controlpointsZ[0]);
958 tempX.push_back(_controlpointsX[i]);
959 tempY.push_back(_controlpointsY[i]);
960 tempZ.push_back(_controlpointsZ[i]);
965 vectorFunctions *vf = new vectorFunctions();
966 vf->copyVector(&tempX,&_controlpointsX);
967 vf->copyVector(&tempY,&_controlpointsY);
968 vf->copyVector(&tempZ,&_controlpointsZ);
975 //-----------------------------------------------------------------------------------------------------------------------------------------
976 void AutoControlPoints::InterBetweenControl( )
982 double m1,mn,m2,xinter,yinter;
983 if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points
988 // fd = fopen("C:/bbtk_JS/data/InterBetweenControl.txt","w");
989 for(i=0; i<(int)(_chargecontrolpointsX.size())-1; i++)
991 ii = (i+1)%(_chargecontrolpointsX.size());
992 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
994 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
995 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
997 Vector *vecX = new Vector();
998 Vector *vecY = new Vector();
999 vecX->set_var(_chargecontrolpointsX[i]);
1000 vecY->set_var(_chargecontrolpointsY[i]);
1002 for(j=0; j<(int)(_chargecontrolpointsX.size()); j++)
1004 jj = (j+1)%(_chargecontrolpointsX.size());
1005 m2 = Slope(_chargecontrolpointsX[j],_chargecontrolpointsY[j],_chargecontrolpointsX[jj],_chargecontrolpointsY[jj]);
1006 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[j],_chargecontrolpointsY[j],mn,m2,&xinter,&yinter);
1007 if( _chargecontrolpointsX[j]<=_chargecontrolpointsX[jj] )
1009 if( (xinter>=_chargecontrolpointsX[j]) && (xinter<=_chargecontrolpointsX[jj]) )
1011 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1016 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1017 vecX->set_vec(xinter);
1018 vecY->set_vec(yinter);
1022 if( _chargecontrolpointsX[j]>_chargecontrolpointsX[jj] )
1024 if( (xinter<=_chargecontrolpointsX[j]) && (xinter>=_chargecontrolpointsX[jj]) )
1026 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1031 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1032 vecX->set_vec(xinter);
1033 vecY->set_vec(yinter);
1038 _intervecXX.push_back(*vecX);
1039 _intervecYY.push_back(*vecY);
1049 //-----------------------------------------------------------------------------------------------------------------------------------------
1050 void AutoControlPoints::fixBetweenControl()
1052 _interitselfX.clear();
1053 _interitselfY.clear();
1055 float vecx,vecy,varx,vary;
1057 // fd = fopen("C:/bbtk_JS/data/InterBetweenControlFix.txt","w");
1058 for(i=0; i<(int)(_intervecXX.size()); i++)
1060 Vector *vx = new Vector();
1061 Vector *vy = new Vector();
1062 vx->set_var(_intervecXX[i].get_var());
1063 vy->set_var(_intervecYY[i].get_var());
1064 // fprintf(fd,"\n Para X = %f, Y = %f",_intervecXX[i].get_var(),_intervecYY[i].get_var());
1065 for(j=0; j<_intervecXX[i].getsize_vec(); j++)
1067 vecx = _intervecXX[i].get_vec(j);
1068 varx = _intervecXX[i].get_var();
1069 vecy = _intervecYY[i].get_vec(j);
1070 vary = _intervecYY[i].get_var();
1071 if( (vecx == varx) && (vecy == vary) )
1076 vx->set_vec((double)vecx);
1077 vy->set_vec((double)vecy);
1078 // fprintf(fd,"\n => x_int = %f, y_int = %f",vecx,vecy);
1081 _interitselfX.push_back(*vx);
1082 _interitselfY.push_back(*vy);
1088 //-----------------------------------------------------------------------------------------------------------------------------------------
1089 void AutoControlPoints::PossibleIntersections( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1091 InterBetweenContours(InX,InY,InZ); //_intervectorX
1092 //InterBetweenControl(); //_intervecXX
1093 //fixBetweenControl(); //_interitselfX
1095 std::vector<Vector> tempX;
1096 std::vector<Vector> tempY;
1100 //double dist1,dist2; // JPRx
1105 fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1108 for(i=0; i<_intervectorX.size(); i++)
1110 fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1111 Vector *vx = new Vector();
1112 Vector *vy = new Vector();
1113 vx->set_var(_intervectorX[i].get_var());
1114 vy->set_var(_intervectorY[i].get_var());
1116 for(j=0; j<_intervectorX[i].getsize_vec() ; j++)
1118 dist1 = sqrt( pow(_intervectorX[i].get_var()-_intervectorX[i].get_vec(j),2) + pow(_intervectorY[i].get_var()-_intervectorY[i].get_vec(j),2) );
1119 for(k=0; (k<_interitselfX[i].getsize_vec()) && (ready!=true); k++)
1121 dist2 = sqrt( pow(_interitselfX[i].get_var()-_interitselfX[i].get_vec(k),2) + pow(_interitselfY[i].get_var()-_interitselfY[i].get_vec(k),2) );
1124 fprintf(fd,"\n => x_int = %f, y_int = %f",_intervectorX[i].get_vec(j),_intervectorY[i].get_vec(j));
1125 vx->set_vec(_intervectorX[i].get_vec(j));
1126 vy->set_vec(_intervectorY[i].get_vec(j));
1131 tempX.push_back(*vx);
1132 tempY.push_back(*vy);
1138 _intervectorX.clear();
1139 _intervectorY.clear();
1140 Vector *vv = new Vector();
1141 vv->copyVector(&tempX,&_intervectorX);
1142 vv->copyVector(&tempY,&_intervectorY);
1144 //vv->printVector(&_intervectorX);
1146 std::vector<double> arrX;
1147 std::vector<double> arrY;
1148 std::vector<double>::iterator itx;
1149 std::vector<double>::iterator ity;
1150 std::vector<double>::iterator itxx;
1151 std::vector<double>::iterator ityy;
1152 double distA, distB;
1153 if(_intervectorX.size() != 0)
1155 // fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1156 for(i=0; i<(int)(_intervectorX.size()); i++)
1158 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1159 if(_intervectorX[i].getsize_vec() > 1)
1163 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
1165 arrX.push_back(_intervectorX[i].get_vec(j));
1166 arrY.push_back(_intervectorY[i].get_vec(j));
1168 //printf("\n arrX Size = %d",arrX.size());
1171 itxx = arrX.begin()+1;
1172 ityy = arrY.begin()+1;
1173 for(j=0; j<(int)(arrX.size())-1; j++)
1176 if( (*itx > _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1177 (*itxx > _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1179 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1180 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1195 else if( (*itx < _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1196 (*itxx < _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1198 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1199 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1214 else if( (*itx < _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1215 (*itxx < _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1217 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1218 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1233 else if( ((double)*itx > _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1234 ((double)*itxx > _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1236 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1237 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1259 _intervectorX[i].resetVec();
1260 _intervectorY[i].resetVec();
1261 //printf("\n _intervector(%d) Size = %d",i,_intervectorX[i].getsize_vec());
1262 for(k=0; k<(int)(arrX.size()); k++)
1264 //printf("\n arr(%d) X = %f, Y = %f",k,arrX[k],arrY[k]);
1265 // fprintf(fd,"\n => x_int = %f, y_int = %f",arrX[k],arrY[k]);
1266 _intervectorX[i].set_vec(arrX[k]);
1267 _intervectorY[i].set_vec(arrY[k]);
1277 //-----------------------------------------------------------------------------------------------------------------------------------------
1278 void AutoControlPoints::ControlInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1281 _contIncontpos.clear();
1284 for(i=0; i<(int)(_controlpointsX.size()); i++)
1287 for(j=0; (j<(int)(InX->size())) && (find!=true); j++)
1289 if( ((*InX)[j]-range<=_controlpointsX[i]) && (_controlpointsX[i]<=(*InX)[j]+range) && ((*InY)[j]-range<=_controlpointsY[i]) && (_controlpointsY[i]<=(*InY)[j]+range) )
1291 _contIncontpos.push_back(j);
1297 //-----------------------------------------------------------------------------------------------------------------------------------------
1298 void AutoControlPoints::NearMaxError2Control()
1300 if(_interpointsX.size() != 0)
1302 AddControlPoint(false);
1304 double distA = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posA],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posA],2) );
1305 double distB = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posB],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posB],2) );
1316 } // if interpointsX
1318 //-----------------------------------------------------------------------------------------------------------------------------------------
1319 void AutoControlPoints::MoveControlPointInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1323 //PRINTF---------------------------------------------------------------
1324 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1325 for(i=0; i<_controlpointsX.size(); i++)
1327 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1329 //---------------------------------------------------------------------
1331 vectorFunctions *vf = new vectorFunctions();
1332 fixBetweenPoints(5.0);
1333 PossibleIntersections(InX,InY,InZ);
1334 IntersectionPoints();
1335 ErrorBetweenContours();
1336 //double promIn = vf->promVector(&_errorvector,false); // JPRx
1338 std::vector<double> tempX;
1339 std::vector<double> tempY;
1340 std::vector<double> tempZ;
1345 vf->copyVector(&_controlpointsX,&tempX);
1346 vf->copyVector(&_controlpointsY,&tempY);
1347 vf->copyVector(&_controlpointsZ,&tempZ);
1348 _controlpointsX.clear();
1349 _controlpointsY.clear();
1350 _controlpointsZ.clear();
1352 for(i=0; i<(int)(tempX.size()); i++)
1356 _controlpointsX.push_back( (*InX)[_contIncontpos[_posn]] );
1357 _controlpointsY.push_back( (*InY)[_contIncontpos[_posn]] );
1358 _controlpointsZ.push_back( (*InZ)[_contIncontpos[_posn]] );
1360 _controlpointsX.push_back( tempX[i] );
1361 _controlpointsY.push_back( tempY[i] );
1362 _controlpointsZ.push_back( tempZ[i] );
1366 fixBetweenPoints(5.0);
1367 PossibleIntersections(InX,InY,InZ);
1368 IntersectionPoints();
1369 ErrorBetweenContours();
1370 double promactualIn = vf->promVector(&_errorvector,false);
1376 //double prom1final; // JPRx
1384 promactual = promactualIn;
1385 _controlpointsX.clear();
1386 _controlpointsY.clear();
1387 _controlpointsZ.clear();
1388 for(i=0; promactual > prom; i++)
1391 for(i=0; i<(int)(tempX.size()); i++)
1395 _controlpointsX.push_back( (*InX)[_contIncontpos[posact]] );
1396 _controlpointsY.push_back( (*InY)[_contIncontpos[posact]] );
1397 _controlpointsZ.push_back( (*InZ)[_contIncontpos[posact]] );
1399 _controlpointsX.push_back( tempX[i] );
1400 _controlpointsY.push_back( tempY[i] );
1401 _controlpointsZ.push_back( tempZ[i] );
1412 fixBetweenPoints(5.0);
1413 PossibleIntersections(InX,InY,InZ);
1414 IntersectionPoints();
1415 ErrorBetweenContours();
1416 promactual = vf->promVector(&_errorvector,false);
1417 //printf("\n The point in the position %d, has moved %d times",_posn,i);
1420 prom2final = promactual;
1424 //--------------------------------------------------------------------------------------------------------------------------------
1425 double AutoControlPoints::MoveAndAverage(int dir, std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1428 //PRINTF---------------------------------------------------------------
1430 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1431 for(i=0; i<_controlpointsX.size(); i++)
1433 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1435 for(i=0; i<_contIncontpos.size(); i++)
1437 printf("\n contIncont pos = %d",_contIncontpos[i]);
1440 //IMPLEMENTATION-------------------------------------------------------
1441 if( (_contIncontpos.size() != 0) && (_controlpointsX.size() != 0) )
1443 vectorFunctions *vf = new vectorFunctions();
1444 std::vector<double>::iterator itx;
1445 std::vector<double>::iterator ity;
1446 std::vector<double> tempX;
1447 std::vector<double> tempY;
1450 vf->copyVector(&_controlpointsX,&tempX);
1451 vf->copyVector(&_controlpointsY,&tempY);
1452 int i,j /*,pos = 0*/ ; // JPRx
1453 double prom1=0,promactual1=1;
1454 //double prom2=0,promactual2=1; // JPRx
1457 if(_contIncontpos[h]>_contIncontpos[hh])
1459 itx = _controlpointsX.begin();
1460 ity = _controlpointsY.begin();
1461 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i>_contIncontpos[hh]) && (promactual1>prom1); i--)
1463 if(j == (int)(InX->size()))
1467 prom1 = promactual1;
1470 printf("\n itx = %f, ity = %f", *itx,*ity);
1471 fixBetweenPoints(5.0);
1472 PossibleIntersections(InX,InY,InZ);
1473 IntersectionPoints();
1474 ErrorBetweenContours();
1475 promactual1 = vf->promVector(&_errorvector,false);
1479 if(_contIncontpos[h]<_contIncontpos[hh])
1481 itx = _controlpointsX.begin();
1482 ity = _controlpointsY.begin();
1483 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i<_contIncontpos[hh]) && (promactual1>prom1); i++)
1489 prom1 = promactual1;
1492 printf("\n itx = %f, ity = %f", *itx,*ity);
1493 fixBetweenPoints(5.0);
1494 PossibleIntersections(InX,InY,InZ);
1495 IntersectionPoints();
1496 ErrorBetweenContours();
1497 promactual1 = vf->promVector(&_errorvector,false);
1505 //--------------------------------------------------------------------------------------------------------------------------------
1506 void AutoControlPoints::MoveControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1508 ControlInContour(InX,InY,InZ);
1509 NearMaxError2Control();
1510 MoveAndAverage(1,InX,InY,InZ);
1512 //-----------------------------------------------------------------------------------------------------------------------------------------
1513 void AutoControlPoints::GetNewPoints( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1515 vectorFunctions *vf = new vectorFunctions();
1516 double prom,maxerror;
1518 InterCircle(InX,InY,InZ);
1520 fixBetweenPoints(5.0);
1521 PossibleIntersections(InX,InY,InZ);
1522 IntersectionPoints();
1523 ErrorBetweenContours();
1524 prom = vf->promVector(&_errorvector,false);
1525 vf->maxVector(&_errorvector,&maxerror);
1529 _controlpointsX.clear();
1530 _controlpointsY.clear();
1531 _controlpointsZ.clear();
1532 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1533 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1534 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1536 _controlpointsZ.push_back( (*InZ)[0] );
1538 fixBetweenPoints(5.0);
1539 PossibleIntersections(InX,InY,InZ);
1540 IntersectionPoints();
1541 ErrorBetweenContours();
1542 prom = vf->promVector(&_errorvector,false);
1543 vf->maxVector(&_errorvector,&maxerror);
1547 std::vector<double> cpX;
1548 std::vector<double> cpY;
1549 std::vector<double> cpZ;
1553 vf->copyVector(&_controlpointsX,&cpX);
1554 vf->copyVector(&_controlpointsY,&cpY);
1555 vf->copyVector(&_controlpointsZ,&cpZ);
1558 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1560 AddControlPoint(true);
1561 fixBetweenPoints(5.0);
1562 PossibleIntersections(InX,InY,InZ);
1563 IntersectionPoints();
1564 ErrorBetweenContours();
1565 prom = vf->promVector(&_errorvector,false);
1566 vf->maxVector(&_errorvector,&maxerror);
1572 _controlpointsX.clear();
1573 _controlpointsY.clear();
1574 _controlpointsZ.clear();
1575 int inicontrolpoints = cpX.size();
1576 double inipercentage = (inicontrolpoints*100)/InX->size();
1579 if(inicontrolpoints<10)
1581 int points = (int)((inipercentage*3*InX->size())/100);
1582 for (int i=0; i<(int)(InX->size()); i++, h++)
1586 _controlpointsX.push_back( (*InX)[i] );
1587 _controlpointsY.push_back( (*InY)[i] );
1588 _controlpointsZ.push_back( (*InZ)[i] );
1592 } // if initontrolpoints
1594 if(inicontrolpoints>=10)
1596 int points = (int)((inipercentage*2*InX->size())/100);
1597 for (int i=0; i<(int)(InX->size()); i++, h++)
1601 _controlpointsX.push_back( (*InX)[i] );
1602 _controlpointsY.push_back( (*InY)[i] );
1603 _controlpointsZ.push_back( (*InZ)[i] );
1607 } // if inicontrolpoints
1610 fixBetweenPoints(5.0);
1611 PossibleIntersections(InX,InY,InZ);
1612 IntersectionPoints();
1613 ErrorBetweenContours();
1614 prom = vf->promVector(&_errorvector,false);
1615 vf->maxVector(&_errorvector,&maxerror);
1618 printf("\n Error Average = %f",prom);
1619 printf("\n Error Max = %f",maxerror);
1620 AddControlPoint(false);
1623 //if( (prom>1) || (maxerror>2))
1626 printf("\n Error Average is grater than 1 !!");
1627 MoveControlPoints(InX,InY,InZ);
1632 //------------------------------------------------------------------------------------------------------------------------------------------
1633 void AutoControlPoints::GetInitialNewPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1635 vectorFunctions *vf = new vectorFunctions();
1636 double prom,maxerror;
1638 InterCircle(InX,InY,InZ);
1640 fixBetweenPoints(5.0);
1641 PossibleIntersections(InX,InY,InZ);
1642 IntersectionPoints();
1643 ErrorBetweenContours();
1644 prom = vf->promVector(&_errorvector,false);
1645 vf->maxVector(&_errorvector,&maxerror);
1649 _controlpointsX.clear();
1650 _controlpointsY.clear();
1651 _controlpointsZ.clear();
1652 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1653 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1654 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1656 _controlpointsZ.push_back( (*InZ)[0] );
1658 fixBetweenPoints(5.0);
1659 PossibleIntersections(InX,InY,InZ);
1660 IntersectionPoints();
1661 ErrorBetweenContours();
1662 prom = vf->promVector(&_errorvector,false);
1663 vf->maxVector(&_errorvector,&maxerror);
1666 std::vector<double> cpX;
1667 std::vector<double> cpY;
1668 std::vector<double> cpZ;
1672 vf->copyVector(&_controlpointsX,&cpX);
1673 vf->copyVector(&_controlpointsY,&cpY);
1674 vf->copyVector(&_controlpointsZ,&cpZ);
1676 double promini = prom;
1679 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1681 AddControlPoint(true);
1682 fixBetweenPoints(5.0);
1683 PossibleIntersections(InX,InY,InZ);
1684 IntersectionPoints();
1685 ErrorBetweenContours();
1686 prom = vf->promVector(&_errorvector,false);
1687 vf->maxVector(&_errorvector,&maxerror);
1690 if( i==10 || prom > promini)
1692 _controlpointsX.clear();
1693 _controlpointsY.clear();
1694 _controlpointsZ.clear();
1695 vf->copyVector(&cpX,&_controlpointsX);
1696 vf->copyVector(&cpY,&_controlpointsY);
1697 vf->copyVector(&cpZ,&_controlpointsZ);
1701 //------------------------------------------------------------------------------------------------------------------------------------------
1702 void AutoControlPoints::CalculeControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1705 _controlpointsX.clear();
1706 _controlpointsY.clear();
1707 _controlpointsZ.clear();
1708 _controlpointsZ.push_back((*InZ)[0]);
1709 GetNewPoints( InX,InY,InZ );
1711 //-----------------------------------------------------------------------------------------------------------------------------------------
1712 void AutoControlPoints::CalculeInitialControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1714 _controlpointsX.clear();
1715 _controlpointsY.clear();
1716 _controlpointsZ.clear();
1717 _controlpointsZ.push_back((*InZ)[0]);
1718 GetInitialNewPoints( InX,InY,InZ );
1720 //-----------------------------------------------------------------------------------------------------------------------------------------
1721 void AutoControlPoints::GetControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1723 vectorFunctions *vf = new vectorFunctions();
1727 vf->copyVector(&_controlpointsX,OutX);
1728 vf->copyVector(&_controlpointsY,OutY);
1729 vf->copyVector(&_controlpointsZ,OutZ);
1732 //-----------------------------------------------------------------------------------------------------------------------------------------
1733 void AutoControlPoints::GetInitialControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1735 vectorFunctions *vf = new vectorFunctions();
1739 vf->copyVector(&_controlpointsX,OutX);
1740 vf->copyVector(&_controlpointsY,OutY);
1741 vf->copyVector(&_controlpointsZ,OutZ);
1745 //-----------------------------------------------------------------------------------------------------------------------------------------
1746 void AutoControlPoints::SetNumSplineInterpolation(int num)
1750 //-----------------------------------------------------------------------------------------------------------------------------------------
1751 //-----------------------------------------------------------------------------------------------------------------------------------------
1752 //-----------------------------------------------------------------------------------------------------------------------------------------