Subversion Repositories gelsvn

Rev

Rev 207 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 207 Rev 296
1
#ifndef __QEM_H
1
#ifndef __QEM_H
2
#define __QEM_H
2
#define __QEM_H
3
 
3
 
4
#include <cfloat>
4
#include <cfloat>
5
#include "CGLA/Vec3f.h"
-
 
6
#include "CGLA/Vec3d.h"
5
#include "CGLA/Vec3d.h"
7
#include "CGLA/Mat3x3d.h"
6
#include "CGLA/Mat3x3d.h"
8
 
7
 
9
 
8
 
10
namespace
9
namespace
11
{
10
{
12
	inline const CGLA::Mat3x3d direct_product(const CGLA::Vec3d& v0, const CGLA::Vec3d& v1)
11
	inline const CGLA::Mat3x3d direct_product(const CGLA::Vec3d& v0, const CGLA::Vec3d& v1)
13
		{
12
		{
14
			CGLA::Mat3x3d m;
13
			CGLA::Mat3x3d m;
15
			for(int i=0;i<3;++i)
14
			for(int i=0;i<3;++i)
16
				for(int j=0;j<3;++j)
15
				for(int j=0;j<3;++j)
17
					m[i][j] = v0[i]*v1[j];
16
					m[i][j] = v0[i]*v1[j];
18
			return m;
17
			return m;
19
		}
18
		}
20
}
19
}
21
 
20
 
22
namespace Geometry
21
namespace Geometry
23
{
22
{
24
	class QEM
23
	class QEM
25
		{
24
		{
26
			CGLA::Mat3x3d A;
25
			CGLA::Mat3x3d A;
27
			CGLA::Vec3d   b;
26
			CGLA::Vec3d   b;
28
			double   c;
27
			double   c;
29
		public:
28
		public:
30
			
29
			
31
			QEM(): A(0), b(0), c(0) {}
30
			QEM(): A(0), b(0), c(0) {}
32
			
31
			
33
			QEM(const CGLA::Vec3d& p0, const CGLA::Vec3d& n0, double w=1.0f):
32
			QEM(const CGLA::Vec3d& p0, const CGLA::Vec3d& n0, double w=1.0f):
34
				A(direct_product(n0,n0) * w), 
33
				A(direct_product(n0,n0) * w), 
35
				b(-n0*dot(n0,p0) * w), 
34
				b(-n0*dot(n0,p0) * w), 
36
				c(dot(p0,n0)*dot(p0,n0) * w) {}
35
				c(dot(p0,n0)*dot(p0,n0) * w) {}
37
 
36
 
38
			
37
			
39
			void operator+=(const QEM& q)
38
			void operator+=(const QEM& q)
40
				{
39
				{
41
					A += q.A;
40
					A += q.A;
42
					b += q.b;
41
					b += q.b;
43
					c += q.c;
42
					c += q.c;
44
				}
43
				}
45
			
44
			
46
			float error(const CGLA::Vec3f& _p) const
45
			float error(const CGLA::Vec3d& p) const
47
				{
46
				{
48
					CGLA::Vec3d p(_p);
-
 
49
					return dot(p,A*p) + 2*dot(b,p)+ c;
47
					return dot(p,A*p) + 2*dot(b,p)+ c;
50
				}
48
				}
51
 
49
 
52
			double determinant() const
50
			double determinant() const
53
				{
51
				{
54
					return CGLA::determinant(A);
52
					return CGLA::determinant(A);
55
				}
53
				}
56
			
54
			
57
			const CGLA::Vec3f grad(const CGLA::Vec3f& _p) const
55
			const CGLA::Vec3d grad(const CGLA::Vec3d& _p) const
58
				{
56
				{
59
					CGLA::Vec3d p(_p);
57
					CGLA::Vec3d p(_p);
60
					CGLA::Vec3f g(2*A*p+2*b);
58
					CGLA::Vec3d g(2*A*p+2*b);
61
					return g;
59
					return g;
62
				}
60
				}
63
			
61
			
64
			CGLA::Vec3f opt_pos(double QEM_thresh = 0.005) const;
62
			CGLA::Vec3d opt_pos(double QEM_thresh = 0.005) const;
65
			
63
			
66
		};
64
		};
67
}
65
}
68
 
66
 
69
namespace GEO = Geometry;
67
namespace GEO = Geometry;
70
 
68
 
71
#endif
69
#endif
72
 
70