Subversion Repositories gelsvn

Rev

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

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