1 #include "AutoControlPoints.h"
2 //------------------------------------------------------------------------------------------------------------------------------------------
3 //CLASS: AutoControlPoints -----------------------------------------------------------------------------------------------------------------
4 //------------------------------------------------------------------------------------------------------------------------------------------
6 AutoControlPoints::AutoControlPoints()
12 AutoControlPoints::~AutoControlPoints()
15 //------------------------------------------------------------------------------------------------------------------------------------------
16 int AutoControlPoints::GetSizeVector(std::vector<double>*Vector)
20 return _SizeVectorIn = Vector->size();
24 return _SizeVectorIn = -1;
27 //------------------------------------------------------------------------------------------------------------------------------------------
28 void AutoControlPoints::PointLeft ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
29 double* lex, double* ley, double* lez )
33 int size = GetSizeVector(InX);
36 for(int i=0; i< size; i++)
38 if( (*InX)[i] < LeftX )
49 //------------------------------------------------------------------------------------------------------------------------------------------
50 void AutoControlPoints::PointRight( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
51 double* rix, double* riy, double* riz )
55 int size = GetSizeVector(InX);
58 for(int i=0; i< size; i++)
60 if( (*InX)[i] > RightX )
71 //------------------------------------------------------------------------------------------------------------------------------------------
72 void AutoControlPoints::PointHigh ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
73 double* hix, double* hiy, double* hiz )
77 int size = InX->size();
80 for(int i = 1; i < size; i++){
81 if((*InY)[i] < HighY){
92 int size = GetSizeVector(InX);
95 for(int i=0; i< _SizeVectorIn; i++)
97 if( (*InY)[i] < HighY )
111 //------------------------------------------------------------------------------------------------------------------------------------------
112 void AutoControlPoints::PointLow ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ,
113 double *lox, double *loy, double *loz)
117 int size = GetSizeVector(InX);
120 for(int i=0; i< _SizeVectorIn; i++)
122 if( (*InY)[i] > LowY )
133 //------------------------------------------------------------------------------------------------------------------------------------------
134 void AutoControlPoints::TwoPoints ( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
136 double hiX=0,hiY=0,hiZ=0;
137 PointHigh ( InX,InY,InZ,&hiX,&hiY,&hiZ );
139 double leX=0,leY=0,leZ=0;
140 PointLeft ( InX,InY,InZ,&leX,&leY,&leZ );
142 double loX=0,loY=0,loZ=0;
143 PointLow ( InX,InY,InZ,&loX,&loY,&loZ );
145 double riX=0,riY=0,riZ=0;
146 PointRight( InX,InY,InZ,&riX,&riY,&riZ );
148 double distHiLo = sqrt( pow(hiX-loX,2) + pow(hiY-loY,2) );
149 double distRiLe = sqrt( pow(riX-leX,2) + pow(riY-leY,2) );
151 _controlpointsX.clear();
152 _controlpointsY.clear();
153 _controlpointsZ.clear();
154 if(distHiLo >= distRiLe)
156 _controlpointsX.push_back(hiX);
157 _controlpointsY.push_back(hiY);
158 _controlpointsZ.push_back(hiZ);
160 _controlpointsX.push_back(loX);
161 _controlpointsY.push_back(loY);
162 _controlpointsZ.push_back(loZ);
166 _controlpointsX.push_back(riX);
167 _controlpointsY.push_back(riY);
168 _controlpointsZ.push_back(riZ);
170 _controlpointsX.push_back(leX);
171 _controlpointsY.push_back(leY);
172 _controlpointsZ.push_back(leZ);
175 //------------------------------------------------------------------------------------------------------------------------------------------
176 void AutoControlPoints::CircleCenter(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ, double *cx, double *cy, double *r)
178 double hiX=0,hiY=0,hiZ=0;
179 PointHigh ( InX,InY,InZ,&hiX,&hiY,&hiZ );
181 double leX=0,leY=0,leZ=0;
182 PointLeft ( InX,InY,InZ,&leX,&leY,&leZ );
184 double loX=0,loY=0,loZ=0;
185 PointLow ( InX,InY,InZ,&loX,&loY,&loZ );
187 double riX=0,riY=0,riZ=0;
188 PointRight( InX,InY,InZ,&riX,&riY,&riZ );
192 *r = sqrt(pow(leX-*cx,2)+pow(hiY-*cy,2)) + 7;
194 //------------------------------------------------------------------------------------------------------------------------------------------
195 void AutoControlPoints::CirclePoints(double cx, double cy, double r, double grad, double *x, double *y)
197 double alpha = (2*3.14159265*grad)/360;
199 *x = cx + (r*cos(alpha));
200 *y = cy + (r*sin(alpha));
202 //------------------------------------------------------------------------------------------------------------------------------------------
203 void AutoControlPoints::ChargeSpline( )
205 int size = _controlpointsX.size();
208 _mContourModel = new manualContourModel();
209 if( _controlpointsX.size() == 2 )
211 _mContourModel->SetCloseContour(false);
213 if( _controlpointsX.size() > 2 )
215 _mContourModel->SetCloseContour(true);
218 _mContourModel->DeleteAllPoints();
219 _mContourModel->SetNumberOfPointsSpline(_numspline);
220 for(int i=0; i<size; i++)
222 _mContourModel->AddPoint(_controlpointsX[i],_controlpointsY[i],_controlpointsZ[i]);
224 _mContourModel->UpdateSpline();
225 int numspline = _mContourModel->GetNumberOfPointsSpline();
227 _chargecontrolpointsX.clear();
228 _chargecontrolpointsY.clear();
229 _chargecontrolpointsZ.clear();
230 for(int j=0; j<numspline; j++)
232 _mContourModel->GetSpline_i_Point(j,&x,&y,&z);
233 _chargecontrolpointsX.push_back(x);
234 _chargecontrolpointsY.push_back(y);
235 _chargecontrolpointsZ.push_back(z);
237 _pathsize = _mContourModel->GetPathSize();
238 //printf("\nPATH SIZE = %f",_pathsize);
241 file1.open( "4_SplinePoints.txt" );
243 for(int i = 0; i < numspline; i++){
244 file1<<"X= "<<_chargecontrolpointsX[i] << "\tY= "<<_chargecontrolpointsY[i] << "\tZ= "<<_chargecontrolpointsZ[i]<<std::endl;
250 //Given the coordinates of two points, it calculates the slope
251 double AutoControlPoints::Slope(double x0, double y0, double x1, double y1)
253 double m = (y1-y0)/(x1-x0);
256 //----------------------------------------------------------------------------------------------------------------------------------------
257 //Given the coordinates of two points, it calculates the normal and it's slope
258 double AutoControlPoints::Normal(double x0, double y0, double* m, double xi)
262 y = ((*m)*(xi - x0)) + y0;
265 //----------------------------------------------------------------------------------------------------------------------------------------
266 void AutoControlPoints::Intersection(double x01, double y01, double x02, double y02, double mn, double m2, double* x, double* y)
268 *x = ( y02-y01-(m2*x02)+(mn*x01) )/(mn-m2);
269 *y = m2*(*x-x02)+y02;
271 //-----------------------------------------------------------------------------------------------------------------------------------------
273 **This methods finds the points where each radius of the circle intersect the contour
275 void AutoControlPoints::InterCircle(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
278 CircleCenter(InX,InY,InZ,&cx,&cy,&r);
280 //GENERATE THE CIRCLE'S POINTS
283 std::vector<double>tempX;
284 std::vector<double>tempY;
289 for(i=0; i<360/n; i++)
291 CirclePoints(cx,cy,r,grad,&x,&y);
297 //FIND THE INTERSECTIONS BETWEEN THE CIRCLE AND THE CONTOUR
299 bool interRad = false;
300 double m1, /*mn=0,*/ m2,xinter,yinter,xmin,ymin,min,dist; // JPRx
301 _intercircleX.clear();
302 _intercircleY.clear();
303 _intercircleDist.clear();
304 _interbewteencircleX.clear();
305 _interbewteencircleY.clear();
306 _interbewteencircleDist.clear();
307 _interbewteencirclePos.clear();
311 // fd = fopen("C:/bbtk_JS/data/tempCircle.txt","w");
312 // fexp = fopen("C:/bbtk_JS/data/InterCircle.txt","w");
313 // fprintf(fexp,"\npos min xmin ymin xcir ycir");
315 //std::ofstream file1;
316 //file1.open( "Temp.txt" );
318 for(i=0; i<(int)(tempX.size()); i++)
320 // fprintf(fd,"\n Para X = %f, Y = %f",tempX[i],tempY[i]);
321 _circleX.push_back(tempX[i]);
322 _circleY.push_back(tempY[i]);
323 m1 = Slope(tempX[i],tempY[i],cx,cy);//slope of the radius
325 for(j=0; j<(int)(InX->size()); j++)
327 jj = (j+1)%(InX->size());
328 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);//Slope of the vector between the adjacent points
329 Intersection(tempX[i],tempY[i],(*InX)[j],(*InY)[j],m1,m2,&xinter,&yinter);
332 //If the point of intersection is between two points of the contour
333 if( ((xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]))||((xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) ))
335 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
345 if((*InX)[j]<=(*InX)[jj])
347 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) ) //Intersection entre le cercle et le contour
349 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
358 if((*InX)[j]>(*InX)[jj])
360 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) ) //Intersection entre le cercle et le contour
362 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
376 // fprintf(fd,"\n => x_int = %f, y_int = %f, dist_int = %f",xmin,ymin,min);
377 // fprintf(fexp,"\n%d %f %f %f %f %f",i,min,xmin,ymin,tempX[i],tempY[i]);
378 //JCP 26-09-08 If the distance of the intersection is bigger than the radio we have to invert the segment
382 _interbewteencirclePos.push_back(i);
383 _interbewteencircleX.push_back(xmin);
384 _interbewteencircleY.push_back(ymin);
385 _interbewteencircleDist.push_back( sqrt(pow(cx-xmin,2)+pow(cy-ymin,2)) );
387 // file1<<i<<std::endl;
389 //JCP 26-09-08 if(min<r)
391 _intercircleX.push_back(xmin);
392 _intercircleY.push_back(ymin);
393 _intercircleDist.push_back(min);
394 // file1<<"\t"<<i<<std::endl;
401 //WHEN THERE IS RADIAL INTERSECTION
402 vectorFunctions *vecf = new vectorFunctions();
406 // fdata = fopen("C:/bbtk_JS/data/autoCPdata.txt","w");
409 std::vector<double> tempXX;
410 std::vector<double> tempYY;
411 std::vector<double> tempDD;
415 //Copy of the first points in the array until the first intersection is found
416 for(i=0; i<_interbewteencirclePos[0]; i++)
418 tempXX.push_back(_intercircleX[i]);
419 tempYY.push_back(_intercircleY[i]);
420 tempDD.push_back(_intercircleDist[i]);
421 // fprintf(fdata,"\n%f %f %f",_intercircleDist[i],_intercircleX[i],_intercircleY[i]);
423 int sizep = _interbewteencirclePos.size();
424 //Copy all the points where there is an intersection with the center but inverted
425 //JCP 26-09-08 for(i=_interbewteencirclePos[sizep-1],j=sizep-1; i>=_interbewteencirclePos[0]; i--,j--)
426 for(i=sizep-1; i >= 0;i--)
428 //JCP 26-09-08 tempXX.push_back(_interbewteencircleX[j]);
429 //JCP 26-09-08 tempYY.push_back(_interbewteencircleY[j]);
430 //JCP 26-09-08 tempDD.push_back(_interbewteencircleDist[j]);
431 tempXX.push_back(_interbewteencircleX[i]);
432 tempYY.push_back(_interbewteencircleY[i]);
433 tempDD.push_back(_interbewteencircleDist[i]);
434 // fprintf(fdata,"\n%f %f %f",_interbewteencircleDist[j],_interbewteencircleX[j],_interbewteencircleY[j]);
436 for(i=_interbewteencirclePos[0]; i<(int)(_intercircleX.size()); i++)
438 tempXX.push_back(_intercircleX[i]);
439 tempYY.push_back(_intercircleY[i]);
440 tempDD.push_back(_intercircleDist[i]);
441 // fprintf(fdata,"\n%f %f %f",_intercircleDist[i],_intercircleX[i],_intercircleY[i]);
444 _intercircleX.clear();
445 _intercircleY.clear();
446 _intercircleDist.clear();
447 vecf->copyVector(&tempXX,&_intercircleX);
448 vecf->copyVector(&tempYY,&_intercircleY);
449 vecf->copyVector(&tempDD,&_intercircleDist);
456 file1.open( "1_Intersection.txt" );
458 for(int i = 0; i < (int)(_intercircleX.size()); i++){
459 file1<<"X= "<<_intercircleX[i] << "\tY= "<<_intercircleY[i] << "\tDist= "<<_intercircleDist[i]<<std::endl;
466 //-----------------------------------------------------------------------------------------------------------------------------------------
467 void AutoControlPoints::maxminLocal()
470 _posmaxlocal.clear();
471 _posminlocal.clear();
472 _posminmaxlocal.clear();
477 _minmaxlocalX.clear();
478 _minmaxlocalY.clear();
480 if(_intercircleDist.size() != 0)
482 //JCP 26 - 09 - 08 This change was du to the posibility of having a maximum or a minimum value in the limits of
483 //JCP 26 - 09 - 08 the array
484 double lastdist, currentdist, nextdist;
485 for(i=0; i < (int)(_intercircleDist.size()); i++)
489 currentdist = _intercircleDist[i];
491 lastdist = _intercircleDist[_intercircleDist.size()-1];
492 nextdist = _intercircleDist[i+1];
493 }else if (i == (int)(_intercircleDist.size())-1){
494 lastdist = _intercircleDist[i-1];
495 nextdist = _intercircleDist[0];
497 lastdist = _intercircleDist[i-1];
498 nextdist = _intercircleDist[i+1];
502 //JCP 26-09-08 if( (_intercircleDist[i-1]<_intercircleDist[i]) && (_intercircleDist[i]>_intercircleDist[i+1]))
503 if(lastdist < currentdist && currentdist > nextdist)
505 _posmaxlocal.push_back(i);
506 _maxlocalX.push_back(_intercircleX[i]);
507 _maxlocalY.push_back(_intercircleY[i]);
508 _minmaxlocalX.push_back(_intercircleX[i]);
509 _minmaxlocalY.push_back(_intercircleY[i]);
510 _posminmaxlocal.push_back(i);
513 //JCP 26-09-08 if( (_intercircleDist[i-1]>_intercircleDist[i]) && (_intercircleDist[i]<_intercircleDist[i+1]))
514 if(lastdist > currentdist && currentdist < nextdist)
516 _posminlocal.push_back(i);
517 _minlocalX.push_back(_intercircleX[i]);
518 _minlocalY.push_back(_intercircleY[i]);
519 _minmaxlocalX.push_back(_intercircleX[i]);
520 _minmaxlocalY.push_back(_intercircleY[i]);
521 _posminmaxlocal.push_back(i);
526 vectorFunctions *vecf = new vectorFunctions();
527 std::vector<double> tempZ;
530 vecf->copyVector(&_minlocalX,&_controlpointsX);
531 vecf->copyVector(&_minlocalY,&_controlpointsY);
532 for(i=0; i<(int)(_minlocalX.size()); i++)
534 tempZ.push_back(_controlpointsZ[0]);
536 vecf->copyVector(&tempZ,&_controlpointsZ);
540 file1.open( "2_MaxMin.txt" );
542 for(int i = 0; i < (int)(_controlpointsX.size()); i++){
543 file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
549 //-----------------------------------------------------------------------------------------------------------------------------------------
550 //ELIMINATES THE POINTS WITH A DISTANCE < val
551 void AutoControlPoints::fixBetweenPoints(double val)
553 int size = _controlpointsX.size();
557 std::vector<double> tempX;
558 std::vector<double> tempY;
559 std::vector<double> tempZ;
565 vectorFunctions *vecf = new vectorFunctions();
566 for(int i=0; i<size; i++)
569 dist = sqrt(pow(_controlpointsX[i]-_controlpointsX[ii],2)+pow(_controlpointsY[i]-_controlpointsY[ii],2));
572 tempX.push_back(_controlpointsX[i]);
573 tempY.push_back(_controlpointsY[i]);
574 tempZ.push_back(_controlpointsZ[i]);
577 _controlpointsX.clear();
578 _controlpointsY.clear();
579 _controlpointsZ.clear();
581 vecf->copyVector(&tempX,&_controlpointsX);
582 vecf->copyVector(&tempY,&_controlpointsY);
583 vecf->copyVector(&tempZ,&_controlpointsZ);
586 file1.open( "3_PointsFixed.txt" );
588 for(int i = 0; i < (int)(_controlpointsX.size()); i++){
589 file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
596 //-----------------------------------------------------------------------------------------------------------------------------------------
597 //ALL THE INTERSECTIONS
598 void AutoControlPoints::InterBetweenContours(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
600 _intervectorX.clear();
601 _intervectorY.clear();
605 double m1,mn,m2,xinter,yinter;
606 if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points
610 // fd = fopen("C:/bbtk_JS/data/interBetweenContours.txt","w");
611 for(i=0; i<(int)(_chargecontrolpointsX.size()); i++)
613 ii = (i+1)%(_chargecontrolpointsX.size());
615 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
617 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
618 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
620 Vector *vecX = new Vector();
621 Vector *vecY = new Vector();
622 vecX->set_var(_chargecontrolpointsX[i]);
623 vecY->set_var(_chargecontrolpointsY[i]);
625 for(j=0; j<(int)(InX->size()); j++)
627 jj = (j+1)%(InX->size());
628 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);
629 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],(*InX)[j],(*InY)[j],mn,m2,&xinter,&yinter);
631 if(((*InX)[j] <= xinter && xinter <= (*InX)[jj]) || (xinter<=(*InX)[j] && xinter>=(*InX)[jj])){
632 vecX->set_vec(xinter);
633 vecY->set_vec(yinter);
636 if( (*InX)[j]<=(*InX)[jj] )
638 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) )
640 //If the point is a CP, the intersection is itself.
641 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
643 vecX->set_vec(xinter);
644 vecY->set_vec(yinter);
645 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
649 vecX->set_vec(xinter);
650 vecY->set_vec(yinter);
651 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
655 if( (*InX)[j]>(*InX)[jj] )
657 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) )
659 //If the point is a CP, the intersection is itself.
660 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
662 vecX->set_vec(xinter);
663 vecY->set_vec(yinter);
664 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
668 vecX->set_vec(xinter);
669 vecY->set_vec(yinter);
670 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
676 _intervectorX.push_back(*vecX);
677 _intervectorY.push_back(*vecY);
685 //-----------------------------------------------------------------------------------------------------------------------------------------
686 void AutoControlPoints::GetInterBetweenContours(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
690 int size = _intervectorX.size();
694 for(i=0; i<size; i++)
696 interVX->push_back(_intervectorX[i]);
697 interVY->push_back(_intervectorY[i]);
701 //-----------------------------------------------------------------------------------------------------------------------------------------
702 //ONLY THE LOGICAL INTERSECTIONS
703 void AutoControlPoints::IntersectionPoints()
705 if(_intervectorX.size() != 0)
707 _interpointsX.clear();
708 _interpointsY.clear();
712 // fd = fopen("C:/bbtk_JS/data/IntersectionPoints.txt","w");
719 for(j=0; j<_intervectorX[0].getsize_vec(); j++)
721 dist = sqrt( pow( _intervectorX[0].get_vec(j)-_intervectorX[0].get_var(),2 ) + pow( _intervectorY[0].get_vec(j)-_intervectorY[0].get_var(),2 ) );
730 _interpointsX.push_back(_intervectorX[0].get_vec(posj));
731 _interpointsY.push_back(_intervectorY[0].get_vec(posj));
732 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[0].get_var(),_intervectorY[0].get_var());
733 // fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[0],_interpointsY[0]);
737 printf("\n\n There is an invalid intersection: Must see AutoControlPoints::IntersectionPoints() method");
740 for(i=0; i<(int)(_intervectorX.size()); i++){
743 for(j=0; j<_intervectorX[i].getsize_vec(); j++) {
744 dist = sqrt( pow( _intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2 ) + pow( _intervectorY[i].get_vec(j)-_intervectorX[i].get_var(),2 ) );
750 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
751 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
754 for(i=1; i<_intervectorX.size(); i++)
758 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
759 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
761 //TYPE: LE PLUS PRES VOISIN
762 dist = sqrt( pow( _intervectorX[i].get_vec(j)-_interpointsX[i-1],2 ) + pow( _intervectorY[i].get_vec(j)-_interpointsY[i-1],2 ) );
763 //TYPE: LE PLUS PRES DANS LA MÊME DROITE
764 //dist = sqrt(pow(_intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2)+pow(_intervectorY[i].get_vec(j)-_intervectorY[i].get_var(),2));
772 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
773 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
774 // fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[i],_interpointsY[i]);
780 //-----------------------------------------------------------------------------------------------------------------------------------------
781 void AutoControlPoints::GetIntersectionPoints(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
783 int size = _interpointsX.size();
787 Vector *vecX = new Vector();
788 Vector *vecY = new Vector();
791 for(i=0; i<size; i++)
793 vecX->set_var(_controlpointsZ[0]);
794 vecX->set_vec(_interpointsX[i]);
795 vecY->set_var(_controlpointsZ[0]);
796 vecY->set_vec(_interpointsY[i]);
797 interVX->push_back(*vecX);
798 interVY->push_back(*vecY);
804 //-----------------------------------------------------------------------------------------------------------------------------------------
805 //ERROR BETWEEN THE LOGICAL INTERSECTIONS
806 void AutoControlPoints::ErrorBetweenContours()
809 if(_interpointsX.size() != 0)
811 _errorvector.clear();
816 // fd = fopen("C:/bbtk_JS/data/interErrorData.txt","w");
817 for(i=0; i<(int)(_interpointsX.size()); i++)
819 _errorvector.push_back( (sqrt( pow( _interpointsX[i]-_intervectorX[i].get_var(),2 ) + pow( _interpointsY[i]-_intervectorY[i].get_var(),2 ) )/_pathsize)*100 );
820 // fprintf(fd,"\n%d %f",i,_errorvector[i]);
824 for(i=0; i<(int)(_errorvector.size()); i++)
826 if(_interpointsX[i] != -1)
828 if(_errorvector[i]>max)
830 max = _errorvector[i];
837 //-----------------------------------------------------------------------------------------------------------------------------------------
838 void AutoControlPoints::GetErrorBetweenContours( std::vector<double>*vec )
841 vectorFunctions *vf = new vectorFunctions();
842 vf->copyVector(&_errorvector,vec);
845 //-----------------------------------------------------------------------------------------------------------------------------------------
846 void AutoControlPoints::AddControlPoint(bool activate)
850 double xmax = _interpointsX[(int)_errorpos];
851 double ymax = _interpointsY[(int)_errorpos];
852 double xx = _intervectorX[(int)_errorpos].get_var();
853 double yy = _intervectorY[(int)_errorpos].get_var();
854 printf("\n XMAX = %f, YMAX = %f, XX = %f, YY = %f",xmax,ymax,xx,yy);
856 int i,ii,j,posA=-1,posB=-1;
857 bool findA=false, findB=false;
859 for(i=(int)_errorpos; findA!=true; i++)
861 ii = i%_errorvector.size();
862 for(j=0; j<(int)(_controlpointsX.size()); j++)
864 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[ii].get_var()) && ((float)_intervectorX[ii].get_var()<=(float)_controlpointsX[j]+1.5) &&
865 ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[ii].get_var()) && ((float)_intervectorY[ii].get_var()<=(float)_controlpointsY[j]+1.5) )
873 for(i=(int)_errorpos; findB!=true; i--)
877 i = _errorvector.size();
879 for(j=0; j<(int)(_controlpointsX.size()); j++)
881 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[i].get_var()) && ((float)_intervectorX[i].get_var()<=(float)_controlpointsX[j]+1.5) &&
882 ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[i].get_var()) && ((float)_intervectorY[i].get_var()<=(float)_controlpointsY[j]+1.5) )
896 if(posB = _controlpointsX.size()-1) // ?!? // JPRx // ?!? EED
901 printf("\n POSA = %d, X = %f, Y = %f",posA,_controlpointsX[posA],_controlpointsY[posA]);
902 printf("\n POSB = %d, X = %f, Y = %f",posB,_controlpointsX[posB],_controlpointsY[posB]);
906 if(((posA!=-1)&&(posB!=-1)))
910 printf("\n ID = %d",id);
913 std::vector<double> tempX;
914 std::vector<double> tempY;
915 std::vector<double> tempZ;
916 for(i=0; i<(int)(_controlpointsX.size()); i++)
920 tempX.push_back(xmax);
921 tempY.push_back(ymax);
922 tempZ.push_back(_controlpointsZ[0]);
924 tempX.push_back(_controlpointsX[i]);
925 tempY.push_back(_controlpointsY[i]);
926 tempZ.push_back(_controlpointsZ[i]);
931 vectorFunctions *vf = new vectorFunctions();
932 vf->copyVector(&tempX,&_controlpointsX);
933 vf->copyVector(&tempY,&_controlpointsY);
934 vf->copyVector(&tempZ,&_controlpointsZ);
941 //-----------------------------------------------------------------------------------------------------------------------------------------
942 void AutoControlPoints::InterBetweenControl( )
948 double m1,mn,m2,xinter,yinter;
949 if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points
954 // fd = fopen("C:/bbtk_JS/data/InterBetweenControl.txt","w");
955 for(i=0; i<(int)(_chargecontrolpointsX.size())-1; i++)
957 ii = (i+1)%(_chargecontrolpointsX.size());
958 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
960 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
961 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
963 Vector *vecX = new Vector();
964 Vector *vecY = new Vector();
965 vecX->set_var(_chargecontrolpointsX[i]);
966 vecY->set_var(_chargecontrolpointsY[i]);
968 for(j=0; j<(int)(_chargecontrolpointsX.size()); j++)
970 jj = (j+1)%(_chargecontrolpointsX.size());
971 m2 = Slope(_chargecontrolpointsX[j],_chargecontrolpointsY[j],_chargecontrolpointsX[jj],_chargecontrolpointsY[jj]);
972 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[j],_chargecontrolpointsY[j],mn,m2,&xinter,&yinter);
973 if( _chargecontrolpointsX[j]<=_chargecontrolpointsX[jj] )
975 if( (xinter>=_chargecontrolpointsX[j]) && (xinter<=_chargecontrolpointsX[jj]) )
977 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
982 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
983 vecX->set_vec(xinter);
984 vecY->set_vec(yinter);
988 if( _chargecontrolpointsX[j]>_chargecontrolpointsX[jj] )
990 if( (xinter<=_chargecontrolpointsX[j]) && (xinter>=_chargecontrolpointsX[jj]) )
992 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
997 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
998 vecX->set_vec(xinter);
999 vecY->set_vec(yinter);
1004 _intervecXX.push_back(*vecX);
1005 _intervecYY.push_back(*vecY);
1015 //-----------------------------------------------------------------------------------------------------------------------------------------
1016 void AutoControlPoints::fixBetweenControl()
1018 _interitselfX.clear();
1019 _interitselfY.clear();
1021 float vecx,vecy,varx,vary;
1023 // fd = fopen("C:/bbtk_JS/data/InterBetweenControlFix.txt","w");
1024 for(i=0; i<(int)(_intervecXX.size()); i++)
1026 Vector *vx = new Vector();
1027 Vector *vy = new Vector();
1028 vx->set_var(_intervecXX[i].get_var());
1029 vy->set_var(_intervecYY[i].get_var());
1030 // fprintf(fd,"\n Para X = %f, Y = %f",_intervecXX[i].get_var(),_intervecYY[i].get_var());
1031 for(j=0; j<_intervecXX[i].getsize_vec(); j++)
1033 vecx = _intervecXX[i].get_vec(j);
1034 varx = _intervecXX[i].get_var();
1035 vecy = _intervecYY[i].get_vec(j);
1036 vary = _intervecYY[i].get_var();
1037 if( (vecx == varx) && (vecy == vary) )
1042 vx->set_vec((double)vecx);
1043 vy->set_vec((double)vecy);
1044 // fprintf(fd,"\n => x_int = %f, y_int = %f",vecx,vecy);
1047 _interitselfX.push_back(*vx);
1048 _interitselfY.push_back(*vy);
1054 //-----------------------------------------------------------------------------------------------------------------------------------------
1055 void AutoControlPoints::PossibleIntersections( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1057 InterBetweenContours(InX,InY,InZ); //_intervectorX
1058 //InterBetweenControl(); //_intervecXX
1059 //fixBetweenControl(); //_interitselfX
1061 std::vector<Vector> tempX;
1062 std::vector<Vector> tempY;
1066 //double dist1,dist2; // JPRx
1071 fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1074 for(i=0; i<_intervectorX.size(); i++)
1076 fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1077 Vector *vx = new Vector();
1078 Vector *vy = new Vector();
1079 vx->set_var(_intervectorX[i].get_var());
1080 vy->set_var(_intervectorY[i].get_var());
1082 for(j=0; j<_intervectorX[i].getsize_vec() ; j++)
1084 dist1 = sqrt( pow(_intervectorX[i].get_var()-_intervectorX[i].get_vec(j),2) + pow(_intervectorY[i].get_var()-_intervectorY[i].get_vec(j),2) );
1085 for(k=0; (k<_interitselfX[i].getsize_vec()) && (ready!=true); k++)
1087 dist2 = sqrt( pow(_interitselfX[i].get_var()-_interitselfX[i].get_vec(k),2) + pow(_interitselfY[i].get_var()-_interitselfY[i].get_vec(k),2) );
1090 fprintf(fd,"\n => x_int = %f, y_int = %f",_intervectorX[i].get_vec(j),_intervectorY[i].get_vec(j));
1091 vx->set_vec(_intervectorX[i].get_vec(j));
1092 vy->set_vec(_intervectorY[i].get_vec(j));
1097 tempX.push_back(*vx);
1098 tempY.push_back(*vy);
1104 _intervectorX.clear();
1105 _intervectorY.clear();
1106 Vector *vv = new Vector();
1107 vv->copyVector(&tempX,&_intervectorX);
1108 vv->copyVector(&tempY,&_intervectorY);
1110 //vv->printVector(&_intervectorX);
1112 std::vector<double> arrX;
1113 std::vector<double> arrY;
1114 std::vector<double>::iterator itx;
1115 std::vector<double>::iterator ity;
1116 std::vector<double>::iterator itxx;
1117 std::vector<double>::iterator ityy;
1118 double distA, distB;
1119 if(_intervectorX.size() != 0)
1121 // fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1122 for(i=0; i<(int)(_intervectorX.size()); i++)
1124 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1125 if(_intervectorX[i].getsize_vec() > 1)
1129 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
1131 arrX.push_back(_intervectorX[i].get_vec(j));
1132 arrY.push_back(_intervectorY[i].get_vec(j));
1134 //printf("\n arrX Size = %d",arrX.size());
1137 itxx = arrX.begin()+1;
1138 ityy = arrY.begin()+1;
1139 for(j=0; j<(int)(arrX.size())-1; j++)
1142 if( (*itx > _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1143 (*itxx > _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1145 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1146 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1161 else if( (*itx < _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1162 (*itxx < _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1164 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1165 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1180 else if( (*itx < _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1181 (*itxx < _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1183 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1184 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1199 else if( ((double)*itx > _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1200 ((double)*itxx > _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1202 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1203 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1225 _intervectorX[i].resetVec();
1226 _intervectorY[i].resetVec();
1227 //printf("\n _intervector(%d) Size = %d",i,_intervectorX[i].getsize_vec());
1228 for(k=0; k<(int)(arrX.size()); k++)
1230 //printf("\n arr(%d) X = %f, Y = %f",k,arrX[k],arrY[k]);
1231 // fprintf(fd,"\n => x_int = %f, y_int = %f",arrX[k],arrY[k]);
1232 _intervectorX[i].set_vec(arrX[k]);
1233 _intervectorY[i].set_vec(arrY[k]);
1243 //-----------------------------------------------------------------------------------------------------------------------------------------
1244 void AutoControlPoints::ControlInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1247 _contIncontpos.clear();
1250 for(i=0; i<(int)(_controlpointsX.size()); i++)
1253 for(j=0; (j<(int)(InX->size())) && (find!=true); j++)
1255 if( ((*InX)[j]-range<=_controlpointsX[i]) && (_controlpointsX[i]<=(*InX)[j]+range) && ((*InY)[j]-range<=_controlpointsY[i]) && (_controlpointsY[i]<=(*InY)[j]+range) )
1257 _contIncontpos.push_back(j);
1263 //-----------------------------------------------------------------------------------------------------------------------------------------
1264 void AutoControlPoints::NearMaxError2Control()
1266 if(_interpointsX.size() != 0)
1268 AddControlPoint(false);
1270 double distA = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posA],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posA],2) );
1271 double distB = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posB],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posB],2) );
1286 //-----------------------------------------------------------------------------------------------------------------------------------------
1287 void AutoControlPoints::MoveControlPointInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1291 //PRINTF---------------------------------------------------------------
1292 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1293 for(i=0; i<_controlpointsX.size(); i++)
1295 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1297 //---------------------------------------------------------------------
1299 vectorFunctions *vf = new vectorFunctions();
1300 fixBetweenPoints(5.0);
1301 PossibleIntersections(InX,InY,InZ);
1302 IntersectionPoints();
1303 ErrorBetweenContours();
1304 //double promIn = vf->promVector(&_errorvector,false); // JPRx
1306 std::vector<double> tempX;
1307 std::vector<double> tempY;
1308 std::vector<double> tempZ;
1313 vf->copyVector(&_controlpointsX,&tempX);
1314 vf->copyVector(&_controlpointsY,&tempY);
1315 vf->copyVector(&_controlpointsZ,&tempZ);
1316 _controlpointsX.clear();
1317 _controlpointsY.clear();
1318 _controlpointsZ.clear();
1320 for(i=0; i<(int)(tempX.size()); i++)
1324 _controlpointsX.push_back( (*InX)[_contIncontpos[_posn]] );
1325 _controlpointsY.push_back( (*InY)[_contIncontpos[_posn]] );
1326 _controlpointsZ.push_back( (*InZ)[_contIncontpos[_posn]] );
1330 _controlpointsX.push_back( tempX[i] );
1331 _controlpointsY.push_back( tempY[i] );
1332 _controlpointsZ.push_back( tempZ[i] );
1336 fixBetweenPoints(5.0);
1337 PossibleIntersections(InX,InY,InZ);
1338 IntersectionPoints();
1339 ErrorBetweenContours();
1340 double promactualIn = vf->promVector(&_errorvector,false);
1346 //double prom1final; // JPRx
1354 promactual = promactualIn;
1355 _controlpointsX.clear();
1356 _controlpointsY.clear();
1357 _controlpointsZ.clear();
1358 for(i=0; promactual > prom; i++)
1361 for(i=0; i<(int)(tempX.size()); i++)
1365 _controlpointsX.push_back( (*InX)[_contIncontpos[posact]] );
1366 _controlpointsY.push_back( (*InY)[_contIncontpos[posact]] );
1367 _controlpointsZ.push_back( (*InZ)[_contIncontpos[posact]] );
1371 _controlpointsX.push_back( tempX[i] );
1372 _controlpointsY.push_back( tempY[i] );
1373 _controlpointsZ.push_back( tempZ[i] );
1384 fixBetweenPoints(5.0);
1385 PossibleIntersections(InX,InY,InZ);
1386 IntersectionPoints();
1387 ErrorBetweenContours();
1388 promactual = vf->promVector(&_errorvector,false);
1389 //printf("\n The point in the position %d, has moved %d times",_posn,i);
1392 prom2final = promactual;
1396 //--------------------------------------------------------------------------------------------------------------------------------
1397 double AutoControlPoints::MoveAndAverage(int dir, std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1400 //PRINTF---------------------------------------------------------------
1402 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1403 for(i=0; i<_controlpointsX.size(); i++)
1405 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1407 for(i=0; i<_contIncontpos.size(); i++)
1409 printf("\n contIncont pos = %d",_contIncontpos[i]);
1412 //IMPLEMENTATION-------------------------------------------------------
1413 if( (_contIncontpos.size() != 0) && (_controlpointsX.size() != 0) )
1415 vectorFunctions *vf = new vectorFunctions();
1416 std::vector<double>::iterator itx;
1417 std::vector<double>::iterator ity;
1418 std::vector<double> tempX;
1419 std::vector<double> tempY;
1422 vf->copyVector(&_controlpointsX,&tempX);
1423 vf->copyVector(&_controlpointsY,&tempY);
1424 int i,j /*,pos = 0*/ ; // JPRx
1425 double prom1=0,promactual1=1;
1426 //double prom2=0,promactual2=1; // JPRx
1429 if(_contIncontpos[h]>_contIncontpos[hh])
1431 itx = _controlpointsX.begin();
1432 ity = _controlpointsY.begin();
1433 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i>_contIncontpos[hh]) && (promactual1>prom1); i--)
1435 if(j == (int)(InX->size()))
1439 prom1 = promactual1;
1442 printf("\n itx = %f, ity = %f", *itx,*ity);
1443 fixBetweenPoints(5.0);
1444 PossibleIntersections(InX,InY,InZ);
1445 IntersectionPoints();
1446 ErrorBetweenContours();
1447 promactual1 = vf->promVector(&_errorvector,false);
1451 if(_contIncontpos[h]<_contIncontpos[hh])
1453 itx = _controlpointsX.begin();
1454 ity = _controlpointsY.begin();
1455 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i<_contIncontpos[hh]) && (promactual1>prom1); i++)
1461 prom1 = promactual1;
1464 printf("\n itx = %f, ity = %f", *itx,*ity);
1465 fixBetweenPoints(5.0);
1466 PossibleIntersections(InX,InY,InZ);
1467 IntersectionPoints();
1468 ErrorBetweenContours();
1469 promactual1 = vf->promVector(&_errorvector,false);
1477 //--------------------------------------------------------------------------------------------------------------------------------
1478 void AutoControlPoints::MoveControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1480 ControlInContour(InX,InY,InZ);
1481 NearMaxError2Control();
1482 MoveAndAverage(1,InX,InY,InZ);
1484 //-----------------------------------------------------------------------------------------------------------------------------------------
1485 void AutoControlPoints::GetNewPoints( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1487 vectorFunctions *vf = new vectorFunctions();
1488 double prom,maxerror;
1490 InterCircle(InX,InY,InZ);
1492 fixBetweenPoints(5.0);
1493 PossibleIntersections(InX,InY,InZ);
1494 IntersectionPoints();
1495 ErrorBetweenContours();
1496 prom = vf->promVector(&_errorvector,false);
1497 vf->maxVector(&_errorvector,&maxerror);
1501 _controlpointsX.clear();
1502 _controlpointsY.clear();
1503 _controlpointsZ.clear();
1504 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1505 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1506 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1508 _controlpointsZ.push_back( (*InZ)[0] );
1510 fixBetweenPoints(5.0);
1511 PossibleIntersections(InX,InY,InZ);
1512 IntersectionPoints();
1513 ErrorBetweenContours();
1514 prom = vf->promVector(&_errorvector,false);
1515 vf->maxVector(&_errorvector,&maxerror);
1519 std::vector<double> cpX;
1520 std::vector<double> cpY;
1521 std::vector<double> cpZ;
1525 vf->copyVector(&_controlpointsX,&cpX);
1526 vf->copyVector(&_controlpointsY,&cpY);
1527 vf->copyVector(&_controlpointsZ,&cpZ);
1530 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1532 AddControlPoint(true);
1533 fixBetweenPoints(5.0);
1534 PossibleIntersections(InX,InY,InZ);
1535 IntersectionPoints();
1536 ErrorBetweenContours();
1537 prom = vf->promVector(&_errorvector,false);
1538 vf->maxVector(&_errorvector,&maxerror);
1544 _controlpointsX.clear();
1545 _controlpointsY.clear();
1546 _controlpointsZ.clear();
1547 int inicontrolpoints = cpX.size();
1548 double inipercentage = (inicontrolpoints*100)/InX->size();
1550 if(inicontrolpoints<10)
1552 int points = (int)((inipercentage*3*InX->size())/100);
1553 for (int i=0; i<(int)(InX->size()); i++, h++)
1557 _controlpointsX.push_back( (*InX)[i] );
1558 _controlpointsY.push_back( (*InY)[i] );
1559 _controlpointsZ.push_back( (*InZ)[i] );
1564 if(inicontrolpoints>=10)
1566 int points = (int)((inipercentage*2*InX->size())/100);
1567 for (int i=0; i<(int)(InX->size()); i++, h++)
1571 _controlpointsX.push_back( (*InX)[i] );
1572 _controlpointsY.push_back( (*InY)[i] );
1573 _controlpointsZ.push_back( (*InZ)[i] );
1580 fixBetweenPoints(5.0);
1581 PossibleIntersections(InX,InY,InZ);
1582 IntersectionPoints();
1583 ErrorBetweenContours();
1584 prom = vf->promVector(&_errorvector,false);
1585 vf->maxVector(&_errorvector,&maxerror);
1588 printf("\n Error Average = %f",prom);
1589 printf("\n Error Max = %f",maxerror);
1590 AddControlPoint(false);
1593 //if( (prom>1) || (maxerror>2))
1596 printf("\n Error Average is grater than 1 !!");
1597 MoveControlPoints(InX,InY,InZ);
1602 //------------------------------------------------------------------------------------------------------------------------------------------
1603 void AutoControlPoints::GetInitialNewPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1605 vectorFunctions *vf = new vectorFunctions();
1606 double prom,maxerror;
1608 InterCircle(InX,InY,InZ);
1610 fixBetweenPoints(5.0);
1611 PossibleIntersections(InX,InY,InZ);
1612 IntersectionPoints();
1613 ErrorBetweenContours();
1614 prom = vf->promVector(&_errorvector,false);
1615 vf->maxVector(&_errorvector,&maxerror);
1619 _controlpointsX.clear();
1620 _controlpointsY.clear();
1621 _controlpointsZ.clear();
1622 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1623 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1624 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1626 _controlpointsZ.push_back( (*InZ)[0] );
1628 fixBetweenPoints(5.0);
1629 PossibleIntersections(InX,InY,InZ);
1630 IntersectionPoints();
1631 ErrorBetweenContours();
1632 prom = vf->promVector(&_errorvector,false);
1633 vf->maxVector(&_errorvector,&maxerror);
1636 std::vector<double> cpX;
1637 std::vector<double> cpY;
1638 std::vector<double> cpZ;
1642 vf->copyVector(&_controlpointsX,&cpX);
1643 vf->copyVector(&_controlpointsY,&cpY);
1644 vf->copyVector(&_controlpointsZ,&cpZ);
1646 double promini = prom;
1649 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1651 AddControlPoint(true);
1652 fixBetweenPoints(5.0);
1653 PossibleIntersections(InX,InY,InZ);
1654 IntersectionPoints();
1655 ErrorBetweenContours();
1656 prom = vf->promVector(&_errorvector,false);
1657 vf->maxVector(&_errorvector,&maxerror);
1660 if( i==10 || prom > promini)
1662 _controlpointsX.clear();
1663 _controlpointsY.clear();
1664 _controlpointsZ.clear();
1665 vf->copyVector(&cpX,&_controlpointsX);
1666 vf->copyVector(&cpY,&_controlpointsY);
1667 vf->copyVector(&cpZ,&_controlpointsZ);
1671 //------------------------------------------------------------------------------------------------------------------------------------------
1672 void AutoControlPoints::CalculeControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1675 _controlpointsX.clear();
1676 _controlpointsY.clear();
1677 _controlpointsZ.clear();
1678 _controlpointsZ.push_back((*InZ)[0]);
1679 GetNewPoints( InX,InY,InZ );
1681 //-----------------------------------------------------------------------------------------------------------------------------------------
1682 void AutoControlPoints::CalculeInitialControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1685 _controlpointsX.clear();
1686 _controlpointsY.clear();
1687 _controlpointsZ.clear();
1688 _controlpointsZ.push_back((*InZ)[0]);
1689 GetInitialNewPoints( InX,InY,InZ );
1691 //-----------------------------------------------------------------------------------------------------------------------------------------
1692 void AutoControlPoints::GetControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1694 vectorFunctions *vf = new vectorFunctions();
1698 vf->copyVector(&_controlpointsX,OutX);
1699 vf->copyVector(&_controlpointsY,OutY);
1700 vf->copyVector(&_controlpointsZ,OutZ);
1703 //-----------------------------------------------------------------------------------------------------------------------------------------
1704 void AutoControlPoints::GetInitialControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1706 vectorFunctions *vf = new vectorFunctions();
1710 vf->copyVector(&_controlpointsX,OutX);
1711 vf->copyVector(&_controlpointsY,OutY);
1712 vf->copyVector(&_controlpointsZ,OutZ);
1716 //-----------------------------------------------------------------------------------------------------------------------------------------
1717 void AutoControlPoints::SetNumSplineInterpolation(int num)
1721 //-----------------------------------------------------------------------------------------------------------------------------------------
1722 //-----------------------------------------------------------------------------------------------------------------------------------------
1723 //-----------------------------------------------------------------------------------------------------------------------------------------