PlaneFitting returns the eigenvalues instead of true now.

This commit is contained in:
Federico Ponchio 2008-07-21 08:34:31 +00:00
parent 0b6af20c93
commit 75ee76b233
1 changed files with 16 additions and 8 deletions

View File

@ -46,7 +46,7 @@ created
namespace vcg { namespace vcg {
template <class S> template <class S>
bool PlaneFittingPoints( std::vector< Point3<S> > & samples,Plane3<S> &p){ Point3<S> PlaneFittingPoints( std::vector< Point3<S> > & samples,Plane3<S> &p){
int j; int j;
Matrix44<S> m;m.SetZero(); Matrix44<S> m;m.SetZero();
@ -73,17 +73,25 @@ bool PlaneFittingPoints( std::vector< Point3<S> > & samples,Plane3<S> &p){
Point3<S> d; Point3<S> d;
Jacobi(m,e,res,n); Jacobi(m,e,res,n);
S mx = fabs(e[0]); int mxi=0; //Sort eigenvalues (tarinisort)
for(j=1; j < 3; ++j) if( (fabs(e[j]) < mx) ) {mx=fabs(e[j]); mxi = j;} e[0] = fabs(e[0]);
e[1] = fabs(e[1]);
e[2] = fabs(e[2]);
Point3<S> 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<S>(e[mini], e[medi], e[maxi]);
d[0]=res[0][mxi]; d[0]=res[0][mini];
d[1]=res[1][mxi]; d[1]=res[1][mini];
d[2]=res[2][mxi]; d[2]=res[2][mini];
p.SetOffset(c*d/d.Norm()); p.SetOffset(c*d/d.Norm());
p.SetDirection(d/d.Norm()); p.SetDirection(d/d.Norm());
return true; return eval;
} }
template<class S> template<class S>