Subversion Repositories gelsvn

Rev

Go to most recent revision | Details | 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
 
39 bj 7
#include <iostream>
8
 
9
#include "QEM.h"
10
#include "LinAlg/LapackFunc.h"
11
 
12
using namespace LinAlg;
13
using namespace CGLA;
14
using namespace std;
15
 
16
namespace Geometry
17
{
357 jab 18
	Vec3d QEM::opt_pos(double sv_thresh, const CGLA::Vec3d& p0) const
39 bj 19
	{
595 jab 20
        CMatrix U,S,V;
21
        SVD(A,U,S,V);
22
        CMatrix Sp(3,3,0.0);
23
 
24
        double s00 = S.get(0,0);
25
        double limit = sv_thresh * s00;
26
 
27
        Sp.set(0,0,1.0/s00);
28
        Vec3d diff(0.0);
29
        for(int i=1;i<3;++i)
30
        {
31
            double sii = S.get(i,i);
32
            if(sii < limit)
33
            {
34
                Sp.set(i,i,0.0);
35
                Vec3d vi(V.get(0,i), V.get(1,i), V.get(2,i));
36
                diff += vi*dot(vi, p0);
37
            }
38
            else
39
                Sp.set(i,i,1.0/sii);
40
        }
41
 
42
        CMatrix Ap = V * Sp * U.Transposed();
43
 
44
        CVector x(3);
45
        x = Ap * CVector(b*0.5);
46
 
47
        return diff-Vec3d(x[0],x[1],x[2]);
220 jab 48
	}
595 jab 49
 
39 bj 50
}