Subversion Repositories gelsvn

Rev

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

Rev 443 Rev 595
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
-
 
7
/**
-
 
8
 * @file QEM.h
-
 
9
 * @brief Quadric Error Metrics. To be used when simplifying.
-
 
10
 */
-
 
11
 
1
#ifndef __GEOMETRY_QEM_H
12
#ifndef __GEOMETRY_QEM_H
2
#define __GEOMETRY_QEM_H
13
#define __GEOMETRY_QEM_H
3
 
14
 
4
#include <cfloat>
15
#include <cfloat>
5
#include "CGLA/Vec3d.h"
16
#include "CGLA/Vec3d.h"
6
#include "CGLA/Mat3x3d.h"
17
#include "CGLA/Mat3x3d.h"
7
 
18
 
8
 
19
 
9
namespace
20
namespace
10
{
21
{
11
	inline const CGLA::Mat3x3d direct_product(const CGLA::Vec3d& v0, const CGLA::Vec3d& v1)
22
	inline const CGLA::Mat3x3d direct_product(const CGLA::Vec3d& v0, const CGLA::Vec3d& v1)
12
		{
23
		{
13
			CGLA::Mat3x3d m;
24
			CGLA::Mat3x3d m;
14
			for(int i=0;i<3;++i)
25
			for(int i=0;i<3;++i)
15
				for(int j=0;j<3;++j)
26
				for(int j=0;j<3;++j)
16
					m[i][j] = v0[i]*v1[j];
27
					m[i][j] = v0[i]*v1[j];
17
			return m;
28
			return m;
18
		}
29
		}
19
}
30
}
20
 
31
 
21
namespace Geometry
32
namespace Geometry
22
{
33
{
23
	class QEM
34
	class QEM
24
		{
35
		{
25
			CGLA::Mat3x3d A;
36
			CGLA::Mat3x3d A;
26
			CGLA::Vec3d   b;
37
			CGLA::Vec3d   b;
27
			double   c;
38
			double   c;
28
		public:
39
		public:
29
			
40
			
30
			QEM(): A(0), b(0), c(0) {}
41
			QEM(): A(0), b(0), c(0) {}
31
			
42
			
32
			QEM(const CGLA::Vec3d& p0, const CGLA::Vec3d& n0, double w=1.0f):
43
			QEM(const CGLA::Vec3d& p0, const CGLA::Vec3d& n0, double w=1.0f):
33
				A(direct_product(n0,n0) * w), 
44
				A(direct_product(n0,n0) * w), 
34
				b(-2*n0*dot(n0,p0) * w), 
45
				b(-2*n0*dot(n0,p0) * w), 
35
				c(dot(p0,n0)*dot(p0,n0) * w) {}
46
				c(dot(p0,n0)*dot(p0,n0) * w) {}
36
 
47
 
37
			
48
			
38
			void operator+=(const QEM& q)
49
			void operator+=(const QEM& q)
39
				{
50
				{
40
					A += q.A;
51
					A += q.A;
41
					b += q.b;
52
					b += q.b;
42
					c += q.c;
53
					c += q.c;
43
				}
54
				}
44
			
55
			
45
			float error(const CGLA::Vec3d& p) const
56
			float error(const CGLA::Vec3d& p) const
46
				{
57
				{
47
					return dot(p,A*p) + dot(b,p)+ c;
58
					return dot(p,A*p) + dot(b,p)+ c;
48
				}
59
				}
49
 
60
 
50
			double determinant() const
61
			double determinant() const
51
				{
62
				{
52
					return CGLA::determinant(A);
63
					return CGLA::determinant(A);
53
				}
64
				}
54
			
65
			
55
			const CGLA::Vec3d grad(const CGLA::Vec3d& p) const
66
			const CGLA::Vec3d grad(const CGLA::Vec3d& p) const
56
				{
67
				{
57
					return CGLA::Vec3d(2*A*p+b);
68
					return CGLA::Vec3d(2*A*p+b);
58
				}
69
				}
59
			
70
			
60
			CGLA::Vec3d opt_pos(double QEM_thresh = 0.005, const CGLA::Vec3d& p0 = CGLA::Vec3d(0.0)) const;
71
			CGLA::Vec3d opt_pos(double QEM_thresh = 0.005, const CGLA::Vec3d& p0 = CGLA::Vec3d(0.0)) const;
61
			
72
			
62
		};
73
		};
63
}
74
}
64
 
75
 
65
namespace GEO = Geometry;
76
namespace GEO = Geometry;
66
 
77
 
67
#endif
78
#endif
68
 
79