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);
262 _pathsize = _mContourModel->GetPathSize();
263 //printf("\nPATH SIZE = %f",_pathsize);
266 file1.open( "4_SplinePoints.txt" );
268 for(int i = 0; i < numspline; i++){
269 file1<<"X= "<<_chargecontrolpointsX[i] << "\tY= "<<_chargecontrolpointsY[i] << "\tZ= "<<_chargecontrolpointsZ[i]<<std::endl;
275 //Given the coordinates of two points, it calculates the slope
276 double AutoControlPoints::Slope(double x0, double y0, double x1, double y1)
278 double m = (y1-y0)/(x1-x0);
281 //----------------------------------------------------------------------------------------------------------------------------------------
282 //Given the coordinates of two points, it calculates the normal and it's slope
283 double AutoControlPoints::Normal(double x0, double y0, double* m, double xi)
287 y = ((*m)*(xi - x0)) + y0;
290 //----------------------------------------------------------------------------------------------------------------------------------------
291 void AutoControlPoints::Intersection(double x01, double y01, double x02, double y02, double mn, double m2, double* x, double* y)
293 *x = ( y02-y01-(m2*x02)+(mn*x01) )/(mn-m2);
294 *y = m2*(*x-x02)+y02;
296 //-----------------------------------------------------------------------------------------------------------------------------------------
298 **This methods finds the points where each radius of the circle intersect the contour
300 void AutoControlPoints::InterCircle(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
303 CircleCenter(InX,InY,InZ,&cx,&cy,&r);
305 //GENERATE THE CIRCLE'S POINTS
308 std::vector<double>tempX;
309 std::vector<double>tempY;
314 for(i=0; i<360/n; i++)
316 CirclePoints(cx,cy,r,grad,&x,&y);
322 //FIND THE INTERSECTIONS BETWEEN THE CIRCLE AND THE CONTOUR
324 bool interRad = false;
325 double m1, /*mn=0,*/ m2,xinter,yinter,xmin,ymin,min,dist; // JPRx
326 _intercircleX.clear();
327 _intercircleY.clear();
328 _intercircleDist.clear();
329 _interbewteencircleX.clear();
330 _interbewteencircleY.clear();
331 _interbewteencircleDist.clear();
332 _interbewteencirclePos.clear();
336 // fd = fopen("C:/bbtk_JS/data/tempCircle.txt","w");
337 // fexp = fopen("C:/bbtk_JS/data/InterCircle.txt","w");
338 // fprintf(fexp,"\npos min xmin ymin xcir ycir");
340 //std::ofstream file1;
341 //file1.open( "Temp.txt" );
343 for(i=0; i<(int)(tempX.size()); i++)
345 // fprintf(fd,"\n Para X = %f, Y = %f",tempX[i],tempY[i]);
346 _circleX.push_back(tempX[i]);
347 _circleY.push_back(tempY[i]);
348 m1 = Slope(tempX[i],tempY[i],cx,cy);//slope of the radius
350 for(j=0; j<(int)(InX->size()); j++)
352 jj = (j+1)%(InX->size());
353 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);//Slope of the vector between the adjacent points
354 Intersection(tempX[i],tempY[i],(*InX)[j],(*InY)[j],m1,m2,&xinter,&yinter);
357 //If the point of intersection is between two points of the contour
358 if( ((xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]))||((xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) ))
360 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
370 if((*InX)[j]<=(*InX)[jj])
372 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) ) //Intersection entre le cercle et le contour
374 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
383 if((*InX)[j]>(*InX)[jj])
385 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) ) //Intersection entre le cercle et le contour
387 dist = sqrt(pow(tempX[i]-xinter,2) + pow(tempY[i]-yinter,2));
401 // fprintf(fd,"\n => x_int = %f, y_int = %f, dist_int = %f",xmin,ymin,min);
402 // fprintf(fexp,"\n%d %f %f %f %f %f",i,min,xmin,ymin,tempX[i],tempY[i]);
403 //JCP 26-09-08 If the distance of the intersection is bigger than the radio we have to invert the segment
407 _interbewteencirclePos.push_back(i);
408 _interbewteencircleX.push_back(xmin);
409 _interbewteencircleY.push_back(ymin);
410 _interbewteencircleDist.push_back( sqrt(pow(cx-xmin,2)+pow(cy-ymin,2)) );
412 // file1<<i<<std::endl;
414 //JCP 26-09-08 if(min<r)
416 _intercircleX.push_back(xmin);
417 _intercircleY.push_back(ymin);
418 _intercircleDist.push_back(min);
419 // file1<<"\t"<<i<<std::endl;
426 //WHEN THERE IS RADIAL INTERSECTION
427 vectorFunctions *vecf = new vectorFunctions();
431 // fdata = fopen("C:/bbtk_JS/data/autoCPdata.txt","w");
434 std::vector<double> tempXX;
435 std::vector<double> tempYY;
436 std::vector<double> tempDD;
440 //Copy of the first points in the array until the first intersection is found
441 for(i=0; i<_interbewteencirclePos[0]; i++)
443 tempXX.push_back(_intercircleX[i]);
444 tempYY.push_back(_intercircleY[i]);
445 tempDD.push_back(_intercircleDist[i]);
446 // fprintf(fdata,"\n%f %f %f",_intercircleDist[i],_intercircleX[i],_intercircleY[i]);
448 int sizep = _interbewteencirclePos.size();
449 //Copy all the points where there is an intersection with the center but inverted
450 //JCP 26-09-08 for(i=_interbewteencirclePos[sizep-1],j=sizep-1; i>=_interbewteencirclePos[0]; i--,j--)
451 for(i=sizep-1; i >= 0;i--)
453 //JCP 26-09-08 tempXX.push_back(_interbewteencircleX[j]);
454 //JCP 26-09-08 tempYY.push_back(_interbewteencircleY[j]);
455 //JCP 26-09-08 tempDD.push_back(_interbewteencircleDist[j]);
456 tempXX.push_back(_interbewteencircleX[i]);
457 tempYY.push_back(_interbewteencircleY[i]);
458 tempDD.push_back(_interbewteencircleDist[i]);
459 // fprintf(fdata,"\n%f %f %f",_interbewteencircleDist[j],_interbewteencircleX[j],_interbewteencircleY[j]);
461 for(i=_interbewteencirclePos[0]; i<(int)(_intercircleX.size()); i++)
463 tempXX.push_back(_intercircleX[i]);
464 tempYY.push_back(_intercircleY[i]);
465 tempDD.push_back(_intercircleDist[i]);
466 // fprintf(fdata,"\n%f %f %f",_intercircleDist[i],_intercircleX[i],_intercircleY[i]);
469 _intercircleX.clear();
470 _intercircleY.clear();
471 _intercircleDist.clear();
472 vecf->copyVector(&tempXX,&_intercircleX);
473 vecf->copyVector(&tempYY,&_intercircleY);
474 vecf->copyVector(&tempDD,&_intercircleDist);
481 file1.open( "1_Intersection.txt" );
483 for(int i = 0; i < (int)(_intercircleX.size()); i++){
484 file1<<"X= "<<_intercircleX[i] << "\tY= "<<_intercircleY[i] << "\tDist= "<<_intercircleDist[i]<<std::endl;
491 //-----------------------------------------------------------------------------------------------------------------------------------------
492 void AutoControlPoints::maxminLocal()
495 _posmaxlocal.clear();
496 _posminlocal.clear();
497 _posminmaxlocal.clear();
502 _minmaxlocalX.clear();
503 _minmaxlocalY.clear();
505 if(_intercircleDist.size() != 0)
507 //JCP 26 - 09 - 08 This change was du to the posibility of having a maximum or a minimum value in the limits of
508 //JCP 26 - 09 - 08 the array
509 double lastdist, currentdist, nextdist;
510 for(i=0; i < (int)(_intercircleDist.size()); i++)
514 currentdist = _intercircleDist[i];
516 lastdist = _intercircleDist[_intercircleDist.size()-1];
517 nextdist = _intercircleDist[i+1];
518 }else if (i == (int)(_intercircleDist.size())-1){
519 lastdist = _intercircleDist[i-1];
520 nextdist = _intercircleDist[0];
522 lastdist = _intercircleDist[i-1];
523 nextdist = _intercircleDist[i+1];
527 //JCP 26-09-08 if( (_intercircleDist[i-1]<_intercircleDist[i]) && (_intercircleDist[i]>_intercircleDist[i+1]))
528 if(lastdist < currentdist && currentdist > nextdist)
530 _posmaxlocal.push_back(i);
531 _maxlocalX.push_back(_intercircleX[i]);
532 _maxlocalY.push_back(_intercircleY[i]);
533 _minmaxlocalX.push_back(_intercircleX[i]);
534 _minmaxlocalY.push_back(_intercircleY[i]);
535 _posminmaxlocal.push_back(i);
538 //JCP 26-09-08 if( (_intercircleDist[i-1]>_intercircleDist[i]) && (_intercircleDist[i]<_intercircleDist[i+1]))
539 if(lastdist > currentdist && currentdist < nextdist)
541 _posminlocal.push_back(i);
542 _minlocalX.push_back(_intercircleX[i]);
543 _minlocalY.push_back(_intercircleY[i]);
544 _minmaxlocalX.push_back(_intercircleX[i]);
545 _minmaxlocalY.push_back(_intercircleY[i]);
546 _posminmaxlocal.push_back(i);
551 vectorFunctions *vecf = new vectorFunctions();
552 std::vector<double> tempZ;
555 vecf->copyVector(&_minlocalX,&_controlpointsX);
556 vecf->copyVector(&_minlocalY,&_controlpointsY);
557 for(i=0; i<(int)(_minlocalX.size()); i++)
559 tempZ.push_back(_controlpointsZ[0]);
561 vecf->copyVector(&tempZ,&_controlpointsZ);
565 file1.open( "2_MaxMin.txt" );
567 for(int i = 0; i < (int)(_controlpointsX.size()); i++){
568 file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
574 //-----------------------------------------------------------------------------------------------------------------------------------------
575 //ELIMINATES THE POINTS WITH A DISTANCE < val
576 void AutoControlPoints::fixBetweenPoints(double val)
578 int size = _controlpointsX.size();
582 std::vector<double> tempX;
583 std::vector<double> tempY;
584 std::vector<double> tempZ;
590 vectorFunctions *vecf = new vectorFunctions();
591 for(int i=0; i<size; i++)
594 dist = sqrt(pow(_controlpointsX[i]-_controlpointsX[ii],2)+pow(_controlpointsY[i]-_controlpointsY[ii],2));
597 tempX.push_back(_controlpointsX[i]);
598 tempY.push_back(_controlpointsY[i]);
599 tempZ.push_back(_controlpointsZ[i]);
602 _controlpointsX.clear();
603 _controlpointsY.clear();
604 _controlpointsZ.clear();
606 vecf->copyVector(&tempX,&_controlpointsX);
607 vecf->copyVector(&tempY,&_controlpointsY);
608 vecf->copyVector(&tempZ,&_controlpointsZ);
611 file1.open( "3_PointsFixed.txt" );
613 for(int i = 0; i < (int)(_controlpointsX.size()); i++){
614 file1<<"X= "<<_controlpointsX[i] << "\tY= "<<_controlpointsY[i] << "\tZ= "<<_controlpointsZ[i]<<std::endl;
621 //-----------------------------------------------------------------------------------------------------------------------------------------
622 //ALL THE INTERSECTIONS
623 void AutoControlPoints::InterBetweenContours(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
625 _intervectorX.clear();
626 _intervectorY.clear();
630 double m1,mn,m2,xinter,yinter;
631 if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points
635 // fd = fopen("C:/bbtk_JS/data/interBetweenContours.txt","w");
636 for(i=0; i<(int)(_chargecontrolpointsX.size()); i++)
638 ii = (i+1)%(_chargecontrolpointsX.size());
640 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
642 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
643 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
645 Vector *vecX = new Vector();
646 Vector *vecY = new Vector();
647 vecX->set_var(_chargecontrolpointsX[i]);
648 vecY->set_var(_chargecontrolpointsY[i]);
650 for(j=0; j<(int)(InX->size()); j++)
652 jj = (j+1)%(InX->size());
653 m2 = Slope((*InX)[j],(*InY)[j],(*InX)[jj],(*InY)[jj]);
654 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],(*InX)[j],(*InY)[j],mn,m2,&xinter,&yinter);
656 if(((*InX)[j] <= xinter && xinter <= (*InX)[jj]) || (xinter<=(*InX)[j] && xinter>=(*InX)[jj])){
657 vecX->set_vec(xinter);
658 vecY->set_vec(yinter);
661 if( (*InX)[j]<=(*InX)[jj] )
663 if( (xinter>=(*InX)[j]) && (xinter<=(*InX)[jj]) )
665 //If the point is a CP, the intersection is itself.
666 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
668 vecX->set_vec(xinter);
669 vecY->set_vec(yinter);
670 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
674 vecX->set_vec(xinter);
675 vecY->set_vec(yinter);
676 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
680 if( (*InX)[j]>(*InX)[jj] )
682 if( (xinter<=(*InX)[j]) && (xinter>=(*InX)[jj]) )
684 //If the point is a CP, the intersection is itself.
685 if((xinter==_chargecontrolpointsX[i]) && (yinter==_chargecontrolpointsY[i]))
687 vecX->set_vec(xinter);
688 vecY->set_vec(yinter);
689 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
693 vecX->set_vec(xinter);
694 vecY->set_vec(yinter);
695 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
701 _intervectorX.push_back(*vecX);
702 _intervectorY.push_back(*vecY);
710 //-----------------------------------------------------------------------------------------------------------------------------------------
711 void AutoControlPoints::GetInterBetweenContours(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
715 int size = _intervectorX.size();
719 for(i=0; i<size; i++)
721 interVX->push_back(_intervectorX[i]);
722 interVY->push_back(_intervectorY[i]);
726 //-----------------------------------------------------------------------------------------------------------------------------------------
727 //ONLY THE LOGICAL INTERSECTIONS
728 void AutoControlPoints::IntersectionPoints()
730 if(_intervectorX.size() != 0)
732 _interpointsX.clear();
733 _interpointsY.clear();
737 // fd = fopen("C:/bbtk_JS/data/IntersectionPoints.txt","w");
744 for(j=0; j<_intervectorX[0].getsize_vec(); j++)
746 dist = sqrt( pow( _intervectorX[0].get_vec(j)-_intervectorX[0].get_var(),2 ) + pow( _intervectorY[0].get_vec(j)-_intervectorY[0].get_var(),2 ) );
755 _interpointsX.push_back(_intervectorX[0].get_vec(posj));
756 _interpointsY.push_back(_intervectorY[0].get_vec(posj));
757 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[0].get_var(),_intervectorY[0].get_var());
758 // fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[0],_interpointsY[0]);
762 printf("\n\n There is an invalid intersection: Must see AutoControlPoints::IntersectionPoints() method");
765 for(i=0; i<(int)(_intervectorX.size()); i++){
768 for(j=0; j<_intervectorX[i].getsize_vec(); j++) {
769 dist = sqrt( pow( _intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2 ) + pow( _intervectorY[i].get_vec(j)-_intervectorX[i].get_var(),2 ) );
775 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
776 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
779 for(i=1; i<_intervectorX.size(); i++)
783 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
784 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
786 //TYPE: LE PLUS PRES VOISIN
787 dist = sqrt( pow( _intervectorX[i].get_vec(j)-_interpointsX[i-1],2 ) + pow( _intervectorY[i].get_vec(j)-_interpointsY[i-1],2 ) );
788 //TYPE: LE PLUS PRES DANS LA M�ME DROITE
789 //dist = sqrt(pow(_intervectorX[i].get_vec(j)-_intervectorX[i].get_var(),2)+pow(_intervectorY[i].get_vec(j)-_intervectorY[i].get_var(),2));
797 _interpointsX.push_back(_intervectorX[i].get_vec(posj));
798 _interpointsY.push_back(_intervectorY[i].get_vec(posj));
799 // fprintf(fd,"\n => x_int = %f, y_int = %f",_interpointsX[i],_interpointsY[i]);
805 //-----------------------------------------------------------------------------------------------------------------------------------------
806 void AutoControlPoints::GetIntersectionPoints(std::vector<Vector>*interVX, std::vector<Vector>*interVY)
808 int size = _interpointsX.size();
812 Vector *vecX = new Vector();
813 Vector *vecY = new Vector();
816 for(i=0; i<size; i++)
818 vecX->set_var(_controlpointsZ[0]);
819 vecX->set_vec(_interpointsX[i]);
820 vecY->set_var(_controlpointsZ[0]);
821 vecY->set_vec(_interpointsY[i]);
822 interVX->push_back(*vecX);
823 interVY->push_back(*vecY);
829 //-----------------------------------------------------------------------------------------------------------------------------------------
830 //ERROR BETWEEN THE LOGICAL INTERSECTIONS
831 void AutoControlPoints::ErrorBetweenContours()
834 if(_interpointsX.size() != 0)
836 _errorvector.clear();
841 // fd = fopen("C:/bbtk_JS/data/interErrorData.txt","w");
842 for(i=0; i<(int)(_interpointsX.size()); i++)
844 _errorvector.push_back( (sqrt( pow( _interpointsX[i]-_intervectorX[i].get_var(),2 ) + pow( _interpointsY[i]-_intervectorY[i].get_var(),2 ) )/_pathsize)*100 );
845 // fprintf(fd,"\n%d %f",i,_errorvector[i]);
849 for(i=0; i<(int)(_errorvector.size()); i++)
851 if(_interpointsX[i] != -1)
853 if(_errorvector[i]>max)
855 max = _errorvector[i];
862 //-----------------------------------------------------------------------------------------------------------------------------------------
863 void AutoControlPoints::GetErrorBetweenContours( std::vector<double>*vec )
866 vectorFunctions *vf = new vectorFunctions();
867 vf->copyVector(&_errorvector,vec);
870 //-----------------------------------------------------------------------------------------------------------------------------------------
871 void AutoControlPoints::AddControlPoint(bool activate)
875 double xmax = _interpointsX[(int)_errorpos];
876 double ymax = _interpointsY[(int)_errorpos];
877 double xx = _intervectorX[(int)_errorpos].get_var();
878 double yy = _intervectorY[(int)_errorpos].get_var();
879 printf("\n XMAX = %f, YMAX = %f, XX = %f, YY = %f",xmax,ymax,xx,yy);
881 int i,ii,j,posA=-1,posB=-1;
882 bool findA=false, findB=false;
884 for(i=(int)_errorpos; findA!=true; i++)
886 ii = i%_errorvector.size();
887 for(j=0; j<(int)(_controlpointsX.size()); j++)
889 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[ii].get_var()) && ((float)_intervectorX[ii].get_var()<=(float)_controlpointsX[j]+1.5) &&
890 ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[ii].get_var()) && ((float)_intervectorY[ii].get_var()<=(float)_controlpointsY[j]+1.5) )
898 for(i=(int)_errorpos; findB!=true; i--)
902 i = _errorvector.size();
904 for(j=0; j<(int)(_controlpointsX.size()); j++)
906 if( ((float)_controlpointsX[j]-1.5<=(float)_intervectorX[i].get_var()) && ((float)_intervectorX[i].get_var()<=(float)_controlpointsX[j]+1.5) &&
907 ((float)_controlpointsY[j]-1.5<=(float)_intervectorY[i].get_var()) && ((float)_intervectorY[i].get_var()<=(float)_controlpointsY[j]+1.5) )
921 if( ( posB = _controlpointsX.size()-1) ) // ?!? // JPRx // ?!? EED
926 printf("\n POSA = %d, X = %f, Y = %f",posA,_controlpointsX[posA],_controlpointsY[posA]);
927 printf("\n POSB = %d, X = %f, Y = %f",posB,_controlpointsX[posB],_controlpointsY[posB]);
931 if(((posA!=-1)&&(posB!=-1)))
935 printf("\n ID = %d",id);
938 std::vector<double> tempX;
939 std::vector<double> tempY;
940 std::vector<double> tempZ;
941 for(i=0; i<(int)(_controlpointsX.size()); i++)
945 tempX.push_back(xmax);
946 tempY.push_back(ymax);
947 tempZ.push_back(_controlpointsZ[0]);
949 tempX.push_back(_controlpointsX[i]);
950 tempY.push_back(_controlpointsY[i]);
951 tempZ.push_back(_controlpointsZ[i]);
956 vectorFunctions *vf = new vectorFunctions();
957 vf->copyVector(&tempX,&_controlpointsX);
958 vf->copyVector(&tempY,&_controlpointsY);
959 vf->copyVector(&tempZ,&_controlpointsZ);
966 //-----------------------------------------------------------------------------------------------------------------------------------------
967 void AutoControlPoints::InterBetweenControl( )
973 double m1,mn,m2,xinter,yinter;
974 if(_chargecontrolpointsX.size() > 1) //These condition exists because there is a method for find the initial control points
979 // fd = fopen("C:/bbtk_JS/data/InterBetweenControl.txt","w");
980 for(i=0; i<(int)(_chargecontrolpointsX.size())-1; i++)
982 ii = (i+1)%(_chargecontrolpointsX.size());
983 m1 = Slope(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[ii],_chargecontrolpointsY[ii]);
985 Normal(_chargecontrolpointsX[i],_chargecontrolpointsY[i],&mn,_chargecontrolpointsX[i]+1);
986 // fprintf(fd,"\n Para X = %f, Y = %f",_chargecontrolpointsX[i],_chargecontrolpointsY[i]);
988 Vector *vecX = new Vector();
989 Vector *vecY = new Vector();
990 vecX->set_var(_chargecontrolpointsX[i]);
991 vecY->set_var(_chargecontrolpointsY[i]);
993 for(j=0; j<(int)(_chargecontrolpointsX.size()); j++)
995 jj = (j+1)%(_chargecontrolpointsX.size());
996 m2 = Slope(_chargecontrolpointsX[j],_chargecontrolpointsY[j],_chargecontrolpointsX[jj],_chargecontrolpointsY[jj]);
997 Intersection(_chargecontrolpointsX[i],_chargecontrolpointsY[i],_chargecontrolpointsX[j],_chargecontrolpointsY[j],mn,m2,&xinter,&yinter);
998 if( _chargecontrolpointsX[j]<=_chargecontrolpointsX[jj] )
1000 if( (xinter>=_chargecontrolpointsX[j]) && (xinter<=_chargecontrolpointsX[jj]) )
1002 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1007 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1008 vecX->set_vec(xinter);
1009 vecY->set_vec(yinter);
1013 if( _chargecontrolpointsX[j]>_chargecontrolpointsX[jj] )
1015 if( (xinter<=_chargecontrolpointsX[j]) && (xinter>=_chargecontrolpointsX[jj]) )
1017 if(((float)xinter==(float)_chargecontrolpointsX[i]) && ((float)yinter==(float)_chargecontrolpointsY[i]))
1022 // fprintf(fd,"\n => x_int = %f, y_int = %f",xinter,yinter);
1023 vecX->set_vec(xinter);
1024 vecY->set_vec(yinter);
1029 _intervecXX.push_back(*vecX);
1030 _intervecYY.push_back(*vecY);
1040 //-----------------------------------------------------------------------------------------------------------------------------------------
1041 void AutoControlPoints::fixBetweenControl()
1043 _interitselfX.clear();
1044 _interitselfY.clear();
1046 float vecx,vecy,varx,vary;
1048 // fd = fopen("C:/bbtk_JS/data/InterBetweenControlFix.txt","w");
1049 for(i=0; i<(int)(_intervecXX.size()); i++)
1051 Vector *vx = new Vector();
1052 Vector *vy = new Vector();
1053 vx->set_var(_intervecXX[i].get_var());
1054 vy->set_var(_intervecYY[i].get_var());
1055 // fprintf(fd,"\n Para X = %f, Y = %f",_intervecXX[i].get_var(),_intervecYY[i].get_var());
1056 for(j=0; j<_intervecXX[i].getsize_vec(); j++)
1058 vecx = _intervecXX[i].get_vec(j);
1059 varx = _intervecXX[i].get_var();
1060 vecy = _intervecYY[i].get_vec(j);
1061 vary = _intervecYY[i].get_var();
1062 if( (vecx == varx) && (vecy == vary) )
1067 vx->set_vec((double)vecx);
1068 vy->set_vec((double)vecy);
1069 // fprintf(fd,"\n => x_int = %f, y_int = %f",vecx,vecy);
1072 _interitselfX.push_back(*vx);
1073 _interitselfY.push_back(*vy);
1079 //-----------------------------------------------------------------------------------------------------------------------------------------
1080 void AutoControlPoints::PossibleIntersections( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1082 InterBetweenContours(InX,InY,InZ); //_intervectorX
1083 //InterBetweenControl(); //_intervecXX
1084 //fixBetweenControl(); //_interitselfX
1086 std::vector<Vector> tempX;
1087 std::vector<Vector> tempY;
1091 //double dist1,dist2; // JPRx
1096 fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1099 for(i=0; i<_intervectorX.size(); i++)
1101 fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1102 Vector *vx = new Vector();
1103 Vector *vy = new Vector();
1104 vx->set_var(_intervectorX[i].get_var());
1105 vy->set_var(_intervectorY[i].get_var());
1107 for(j=0; j<_intervectorX[i].getsize_vec() ; j++)
1109 dist1 = sqrt( pow(_intervectorX[i].get_var()-_intervectorX[i].get_vec(j),2) + pow(_intervectorY[i].get_var()-_intervectorY[i].get_vec(j),2) );
1110 for(k=0; (k<_interitselfX[i].getsize_vec()) && (ready!=true); k++)
1112 dist2 = sqrt( pow(_interitselfX[i].get_var()-_interitselfX[i].get_vec(k),2) + pow(_interitselfY[i].get_var()-_interitselfY[i].get_vec(k),2) );
1115 fprintf(fd,"\n => x_int = %f, y_int = %f",_intervectorX[i].get_vec(j),_intervectorY[i].get_vec(j));
1116 vx->set_vec(_intervectorX[i].get_vec(j));
1117 vy->set_vec(_intervectorY[i].get_vec(j));
1122 tempX.push_back(*vx);
1123 tempY.push_back(*vy);
1129 _intervectorX.clear();
1130 _intervectorY.clear();
1131 Vector *vv = new Vector();
1132 vv->copyVector(&tempX,&_intervectorX);
1133 vv->copyVector(&tempY,&_intervectorY);
1135 //vv->printVector(&_intervectorX);
1137 std::vector<double> arrX;
1138 std::vector<double> arrY;
1139 std::vector<double>::iterator itx;
1140 std::vector<double>::iterator ity;
1141 std::vector<double>::iterator itxx;
1142 std::vector<double>::iterator ityy;
1143 double distA, distB;
1144 if(_intervectorX.size() != 0)
1146 // fd = fopen("C:/bbtk_JS/data/InterPossibleIntersections.txt","w");
1147 for(i=0; i<(int)(_intervectorX.size()); i++)
1149 // fprintf(fd,"\n Para X = %f, Y = %f",_intervectorX[i].get_var(),_intervectorY[i].get_var());
1150 if(_intervectorX[i].getsize_vec() > 1)
1154 for(j=0; j<_intervectorX[i].getsize_vec(); j++)
1156 arrX.push_back(_intervectorX[i].get_vec(j));
1157 arrY.push_back(_intervectorY[i].get_vec(j));
1159 //printf("\n arrX Size = %d",arrX.size());
1162 itxx = arrX.begin()+1;
1163 ityy = arrY.begin()+1;
1164 for(j=0; j<(int)(arrX.size())-1; j++)
1167 if( (*itx > _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1168 (*itxx > _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1170 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1171 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1186 else if( (*itx < _intervectorX[i].get_var()) && (*ity < _intervectorY[i].get_var()) &&
1187 (*itxx < _intervectorX[i].get_var()) && (*ityy < _intervectorY[i].get_var()) )
1189 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1190 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1205 else if( (*itx < _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1206 (*itxx < _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1208 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1209 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1224 else if( ((double)*itx > _intervectorX[i].get_var()) && (*ity > _intervectorY[i].get_var()) &&
1225 ((double)*itxx > _intervectorX[i].get_var()) && (*ityy > _intervectorY[i].get_var()) )
1227 distA = sqrt( pow(*itx-_intervectorX[i].get_var(),2) + pow(*ity-_intervectorY[i].get_var(),2) );
1228 distB = sqrt( pow(*itxx-_intervectorX[i].get_var(),2) + pow(*ityy-_intervectorY[i].get_var(),2) );
1250 _intervectorX[i].resetVec();
1251 _intervectorY[i].resetVec();
1252 //printf("\n _intervector(%d) Size = %d",i,_intervectorX[i].getsize_vec());
1253 for(k=0; k<(int)(arrX.size()); k++)
1255 //printf("\n arr(%d) X = %f, Y = %f",k,arrX[k],arrY[k]);
1256 // fprintf(fd,"\n => x_int = %f, y_int = %f",arrX[k],arrY[k]);
1257 _intervectorX[i].set_vec(arrX[k]);
1258 _intervectorY[i].set_vec(arrY[k]);
1268 //-----------------------------------------------------------------------------------------------------------------------------------------
1269 void AutoControlPoints::ControlInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1272 _contIncontpos.clear();
1275 for(i=0; i<(int)(_controlpointsX.size()); i++)
1278 for(j=0; (j<(int)(InX->size())) && (find!=true); j++)
1280 if( ((*InX)[j]-range<=_controlpointsX[i]) && (_controlpointsX[i]<=(*InX)[j]+range) && ((*InY)[j]-range<=_controlpointsY[i]) && (_controlpointsY[i]<=(*InY)[j]+range) )
1282 _contIncontpos.push_back(j);
1288 //-----------------------------------------------------------------------------------------------------------------------------------------
1289 void AutoControlPoints::NearMaxError2Control()
1291 if(_interpointsX.size() != 0)
1293 AddControlPoint(false);
1295 double distA = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posA],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posA],2) );
1296 double distB = sqrt( pow(_interpointsX[_errorpos]-_controlpointsX[_posB],2) + pow(_interpointsY[_errorpos]-_controlpointsY[_posB],2) );
1311 //-----------------------------------------------------------------------------------------------------------------------------------------
1312 void AutoControlPoints::MoveControlPointInContour(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1316 //PRINTF---------------------------------------------------------------
1317 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1318 for(i=0; i<_controlpointsX.size(); i++)
1320 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1322 //---------------------------------------------------------------------
1324 vectorFunctions *vf = new vectorFunctions();
1325 fixBetweenPoints(5.0);
1326 PossibleIntersections(InX,InY,InZ);
1327 IntersectionPoints();
1328 ErrorBetweenContours();
1329 //double promIn = vf->promVector(&_errorvector,false); // JPRx
1331 std::vector<double> tempX;
1332 std::vector<double> tempY;
1333 std::vector<double> tempZ;
1338 vf->copyVector(&_controlpointsX,&tempX);
1339 vf->copyVector(&_controlpointsY,&tempY);
1340 vf->copyVector(&_controlpointsZ,&tempZ);
1341 _controlpointsX.clear();
1342 _controlpointsY.clear();
1343 _controlpointsZ.clear();
1345 for(i=0; i<(int)(tempX.size()); i++)
1349 _controlpointsX.push_back( (*InX)[_contIncontpos[_posn]] );
1350 _controlpointsY.push_back( (*InY)[_contIncontpos[_posn]] );
1351 _controlpointsZ.push_back( (*InZ)[_contIncontpos[_posn]] );
1355 _controlpointsX.push_back( tempX[i] );
1356 _controlpointsY.push_back( tempY[i] );
1357 _controlpointsZ.push_back( tempZ[i] );
1361 fixBetweenPoints(5.0);
1362 PossibleIntersections(InX,InY,InZ);
1363 IntersectionPoints();
1364 ErrorBetweenContours();
1365 double promactualIn = vf->promVector(&_errorvector,false);
1371 //double prom1final; // JPRx
1379 promactual = promactualIn;
1380 _controlpointsX.clear();
1381 _controlpointsY.clear();
1382 _controlpointsZ.clear();
1383 for(i=0; promactual > prom; i++)
1386 for(i=0; i<(int)(tempX.size()); i++)
1390 _controlpointsX.push_back( (*InX)[_contIncontpos[posact]] );
1391 _controlpointsY.push_back( (*InY)[_contIncontpos[posact]] );
1392 _controlpointsZ.push_back( (*InZ)[_contIncontpos[posact]] );
1396 _controlpointsX.push_back( tempX[i] );
1397 _controlpointsY.push_back( tempY[i] );
1398 _controlpointsZ.push_back( tempZ[i] );
1409 fixBetweenPoints(5.0);
1410 PossibleIntersections(InX,InY,InZ);
1411 IntersectionPoints();
1412 ErrorBetweenContours();
1413 promactual = vf->promVector(&_errorvector,false);
1414 //printf("\n The point in the position %d, has moved %d times",_posn,i);
1417 prom2final = promactual;
1421 //--------------------------------------------------------------------------------------------------------------------------------
1422 double AutoControlPoints::MoveAndAverage(int dir, std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1425 //PRINTF---------------------------------------------------------------
1427 printf("\n CONTROL POINTS BEFORE MOVEMENT");
1428 for(i=0; i<_controlpointsX.size(); i++)
1430 printf("\n X = %f, Y = %f",_controlpointsX[i],_controlpointsY[i]);
1432 for(i=0; i<_contIncontpos.size(); i++)
1434 printf("\n contIncont pos = %d",_contIncontpos[i]);
1437 //IMPLEMENTATION-------------------------------------------------------
1438 if( (_contIncontpos.size() != 0) && (_controlpointsX.size() != 0) )
1440 vectorFunctions *vf = new vectorFunctions();
1441 std::vector<double>::iterator itx;
1442 std::vector<double>::iterator ity;
1443 std::vector<double> tempX;
1444 std::vector<double> tempY;
1447 vf->copyVector(&_controlpointsX,&tempX);
1448 vf->copyVector(&_controlpointsY,&tempY);
1449 int i,j /*,pos = 0*/ ; // JPRx
1450 double prom1=0,promactual1=1;
1451 //double prom2=0,promactual2=1; // JPRx
1454 if(_contIncontpos[h]>_contIncontpos[hh])
1456 itx = _controlpointsX.begin();
1457 ity = _controlpointsY.begin();
1458 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i>_contIncontpos[hh]) && (promactual1>prom1); i--)
1460 if(j == (int)(InX->size()))
1464 prom1 = promactual1;
1467 printf("\n itx = %f, ity = %f", *itx,*ity);
1468 fixBetweenPoints(5.0);
1469 PossibleIntersections(InX,InY,InZ);
1470 IntersectionPoints();
1471 ErrorBetweenContours();
1472 promactual1 = vf->promVector(&_errorvector,false);
1476 if(_contIncontpos[h]<_contIncontpos[hh])
1478 itx = _controlpointsX.begin();
1479 ity = _controlpointsY.begin();
1480 for(i=_contIncontpos[h],j=_contIncontpos[h]; (i<_contIncontpos[hh]) && (promactual1>prom1); i++)
1486 prom1 = promactual1;
1489 printf("\n itx = %f, ity = %f", *itx,*ity);
1490 fixBetweenPoints(5.0);
1491 PossibleIntersections(InX,InY,InZ);
1492 IntersectionPoints();
1493 ErrorBetweenContours();
1494 promactual1 = vf->promVector(&_errorvector,false);
1502 //--------------------------------------------------------------------------------------------------------------------------------
1503 void AutoControlPoints::MoveControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1505 ControlInContour(InX,InY,InZ);
1506 NearMaxError2Control();
1507 MoveAndAverage(1,InX,InY,InZ);
1509 //-----------------------------------------------------------------------------------------------------------------------------------------
1510 void AutoControlPoints::GetNewPoints( std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1512 vectorFunctions *vf = new vectorFunctions();
1513 double prom,maxerror;
1515 InterCircle(InX,InY,InZ);
1517 fixBetweenPoints(5.0);
1518 PossibleIntersections(InX,InY,InZ);
1519 IntersectionPoints();
1520 ErrorBetweenContours();
1521 prom = vf->promVector(&_errorvector,false);
1522 vf->maxVector(&_errorvector,&maxerror);
1526 _controlpointsX.clear();
1527 _controlpointsY.clear();
1528 _controlpointsZ.clear();
1529 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1530 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1531 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1533 _controlpointsZ.push_back( (*InZ)[0] );
1535 fixBetweenPoints(5.0);
1536 PossibleIntersections(InX,InY,InZ);
1537 IntersectionPoints();
1538 ErrorBetweenContours();
1539 prom = vf->promVector(&_errorvector,false);
1540 vf->maxVector(&_errorvector,&maxerror);
1544 std::vector<double> cpX;
1545 std::vector<double> cpY;
1546 std::vector<double> cpZ;
1550 vf->copyVector(&_controlpointsX,&cpX);
1551 vf->copyVector(&_controlpointsY,&cpY);
1552 vf->copyVector(&_controlpointsZ,&cpZ);
1555 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1557 AddControlPoint(true);
1558 fixBetweenPoints(5.0);
1559 PossibleIntersections(InX,InY,InZ);
1560 IntersectionPoints();
1561 ErrorBetweenContours();
1562 prom = vf->promVector(&_errorvector,false);
1563 vf->maxVector(&_errorvector,&maxerror);
1569 _controlpointsX.clear();
1570 _controlpointsY.clear();
1571 _controlpointsZ.clear();
1572 int inicontrolpoints = cpX.size();
1573 double inipercentage = (inicontrolpoints*100)/InX->size();
1575 if(inicontrolpoints<10)
1577 int points = (int)((inipercentage*3*InX->size())/100);
1578 for (int i=0; i<(int)(InX->size()); i++, h++)
1582 _controlpointsX.push_back( (*InX)[i] );
1583 _controlpointsY.push_back( (*InY)[i] );
1584 _controlpointsZ.push_back( (*InZ)[i] );
1589 if(inicontrolpoints>=10)
1591 int points = (int)((inipercentage*2*InX->size())/100);
1592 for (int i=0; i<(int)(InX->size()); i++, h++)
1596 _controlpointsX.push_back( (*InX)[i] );
1597 _controlpointsY.push_back( (*InY)[i] );
1598 _controlpointsZ.push_back( (*InZ)[i] );
1605 fixBetweenPoints(5.0);
1606 PossibleIntersections(InX,InY,InZ);
1607 IntersectionPoints();
1608 ErrorBetweenContours();
1609 prom = vf->promVector(&_errorvector,false);
1610 vf->maxVector(&_errorvector,&maxerror);
1613 printf("\n Error Average = %f",prom);
1614 printf("\n Error Max = %f",maxerror);
1615 AddControlPoint(false);
1618 //if( (prom>1) || (maxerror>2))
1621 printf("\n Error Average is grater than 1 !!");
1622 MoveControlPoints(InX,InY,InZ);
1627 //------------------------------------------------------------------------------------------------------------------------------------------
1628 void AutoControlPoints::GetInitialNewPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ )
1630 vectorFunctions *vf = new vectorFunctions();
1631 double prom,maxerror;
1633 InterCircle(InX,InY,InZ);
1635 fixBetweenPoints(5.0);
1636 PossibleIntersections(InX,InY,InZ);
1637 IntersectionPoints();
1638 ErrorBetweenContours();
1639 prom = vf->promVector(&_errorvector,false);
1640 vf->maxVector(&_errorvector,&maxerror);
1644 _controlpointsX.clear();
1645 _controlpointsY.clear();
1646 _controlpointsZ.clear();
1647 vf->copyVector(&_minmaxlocalX,&_controlpointsX);
1648 vf->copyVector(&_minmaxlocalY,&_controlpointsY);
1649 for(int i=0; i<(int)(_minmaxlocalX.size()); i++)
1651 _controlpointsZ.push_back( (*InZ)[0] );
1653 fixBetweenPoints(5.0);
1654 PossibleIntersections(InX,InY,InZ);
1655 IntersectionPoints();
1656 ErrorBetweenContours();
1657 prom = vf->promVector(&_errorvector,false);
1658 vf->maxVector(&_errorvector,&maxerror);
1661 std::vector<double> cpX;
1662 std::vector<double> cpY;
1663 std::vector<double> cpZ;
1667 vf->copyVector(&_controlpointsX,&cpX);
1668 vf->copyVector(&_controlpointsY,&cpY);
1669 vf->copyVector(&_controlpointsZ,&cpZ);
1671 double promini = prom;
1674 for(i=0; (i<10)&&(maxerror>0.5)&&(prom>0.15); i++ )
1676 AddControlPoint(true);
1677 fixBetweenPoints(5.0);
1678 PossibleIntersections(InX,InY,InZ);
1679 IntersectionPoints();
1680 ErrorBetweenContours();
1681 prom = vf->promVector(&_errorvector,false);
1682 vf->maxVector(&_errorvector,&maxerror);
1685 if( i==10 || prom > promini)
1687 _controlpointsX.clear();
1688 _controlpointsY.clear();
1689 _controlpointsZ.clear();
1690 vf->copyVector(&cpX,&_controlpointsX);
1691 vf->copyVector(&cpY,&_controlpointsY);
1692 vf->copyVector(&cpZ,&_controlpointsZ);
1696 //------------------------------------------------------------------------------------------------------------------------------------------
1697 void AutoControlPoints::CalculeControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1700 _controlpointsX.clear();
1701 _controlpointsY.clear();
1702 _controlpointsZ.clear();
1703 _controlpointsZ.push_back((*InZ)[0]);
1704 GetNewPoints( InX,InY,InZ );
1706 //-----------------------------------------------------------------------------------------------------------------------------------------
1707 void AutoControlPoints::CalculeInitialControlPoints(std::vector<double>*InX, std::vector<double>*InY, std::vector<double>*InZ)
1710 _controlpointsX.clear();
1711 _controlpointsY.clear();
1712 _controlpointsZ.clear();
1713 _controlpointsZ.push_back((*InZ)[0]);
1714 GetInitialNewPoints( InX,InY,InZ );
1716 //-----------------------------------------------------------------------------------------------------------------------------------------
1717 void AutoControlPoints::GetControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1719 vectorFunctions *vf = new vectorFunctions();
1723 vf->copyVector(&_controlpointsX,OutX);
1724 vf->copyVector(&_controlpointsY,OutY);
1725 vf->copyVector(&_controlpointsZ,OutZ);
1728 //-----------------------------------------------------------------------------------------------------------------------------------------
1729 void AutoControlPoints::GetInitialControlPoints(std::vector<double>*OutX, std::vector<double>*OutY, std::vector<double>*OutZ)
1731 vectorFunctions *vf = new vectorFunctions();
1735 vf->copyVector(&_controlpointsX,OutX);
1736 vf->copyVector(&_controlpointsY,OutY);
1737 vf->copyVector(&_controlpointsZ,OutZ);
1741 //-----------------------------------------------------------------------------------------------------------------------------------------
1742 void AutoControlPoints::SetNumSplineInterpolation(int num)
1746 //-----------------------------------------------------------------------------------------------------------------------------------------
1747 //-----------------------------------------------------------------------------------------------------------------------------------------
1748 //-----------------------------------------------------------------------------------------------------------------------------------------