From 75ee76b233a50b153573bf067625f5d2b056bcad Mon Sep 17 00:00:00 2001 From: ponchio Date: Mon, 21 Jul 2008 08:34:31 +0000 Subject: [PATCH] PlaneFitting returns the eigenvalues instead of true now. --- vcg/space/fitting3.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/vcg/space/fitting3.h b/vcg/space/fitting3.h index 97251fad..23abc1ae 100644 --- a/vcg/space/fitting3.h +++ b/vcg/space/fitting3.h @@ -46,7 +46,7 @@ created namespace vcg { template -bool PlaneFittingPoints( std::vector< Point3 > & samples,Plane3 &p){ +Point3 PlaneFittingPoints( std::vector< Point3 > & samples,Plane3 &p){ int j; Matrix44 m;m.SetZero(); @@ -73,17 +73,25 @@ bool PlaneFittingPoints( std::vector< Point3 > & samples,Plane3 &p){ Point3 d; Jacobi(m,e,res,n); - S mx = fabs(e[0]); int mxi=0; - for(j=1; j < 3; ++j) if( (fabs(e[j]) < mx) ) {mx=fabs(e[j]); mxi = j;} - - d[0]=res[0][mxi]; - d[1]=res[1][mxi]; - d[2]=res[2][mxi]; + //Sort eigenvalues (tarinisort) + e[0] = fabs(e[0]); + e[1] = fabs(e[1]); + e[2] = fabs(e[2]); + Point3 eval; + int maxi,mini,medi; + if (e[1] > e[0]) { maxi=1; mini=0; } else { maxi=0; mini=1;} + if (e[maxi] < e[2]) maxi=2; else if(e[mini] > e[2]) mini=2; + medi = 3 - maxi -mini; + eval = Point3(e[mini], e[medi], e[maxi]); + + d[0]=res[0][mini]; + d[1]=res[1][mini]; + d[2]=res[2][mini]; p.SetOffset(c*d/d.Norm()); p.SetDirection(d/d.Norm()); -return true; + return eval; } template