Subversion Repositories gelsvn

Rev

Rev 315 | Rev 595 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 315 Rev 357
Line 7... Line 7...
7
using namespace CGLA;
7
using namespace CGLA;
8
using namespace std;
8
using namespace std;
9
 
9
 
10
namespace Geometry
10
namespace Geometry
11
{
11
{
12
	Vec3d QEM::opt_pos(double sv_thresh) const
12
	Vec3d QEM::opt_pos(double sv_thresh, const CGLA::Vec3d& p0) const
13
	{
13
	{
14
			CMatrix U,S,V;
14
			CMatrix U,S,V;
15
			SVD(A,U,S,V);
15
			SVD(A,U,S,V);
16
			CMatrix Sp(3,3,0.0);
16
			CMatrix Sp(3,3,0.0);
17
			
17
			
18
			double s00 = S.get(0,0);
18
			double s00 = S.get(0,0);
19
			double limit = sv_thresh * s00;
19
			double limit = sv_thresh * s00;
20
 
20
 
21
			Sp.set(0,0,1.0/s00);
21
			Sp.set(0,0,1.0/s00);
-
 
22
			Vec3d diff(0.0);
22
			for(int i=1;i<3;++i)
23
			for(int i=1;i<3;++i)
23
			{
24
			{
24
					double sii = S.get(i,i);
25
					double sii = S.get(i,i);
25
					if(sii < limit)
26
					if(sii < limit)
-
 
27
					{
26
							Sp.set(i,i,0.0);
28
						Sp.set(i,i,0.0);
-
 
29
						Vec3d vi(V.get(0,i), V.get(1,i), V.get(2,i));
-
 
30
						diff += vi*dot(vi, p0);
-
 
31
					}
27
					else
32
					else
28
							Sp.set(i,i,1.0/sii);
33
						Sp.set(i,i,1.0/sii);
29
			}
34
			}
30
 
35
 
31
			CMatrix Ap = V * Sp * U.Transposed();
36
			CMatrix Ap = V * Sp * U.Transposed();
32
 
37
 
33
			CVector x(3);
38
			CVector x(3);
34
			x = Ap * (b*0.5);
39
			x = Ap * (b*0.5);
35
			
40
			
36
			Vec3d p(-x[0], -x[1], -x[2]);
41
			return diff-Vec3d(x[0],x[1],x[2]);
37
			return p;
-
 
38
	}
42
	}
39
 
43
 
40
}
44
}