Subversion Repositories gelsvn

Rev

Rev 39 | Rev 136 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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