Subversion Repositories gelsvn

Rev

Rev 443 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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