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
#include "build_bbtree.h"
7
#include "build_bbtree.h"
8
 
8
 
9
#include <HMesh/Manifold.h>
9
#include "../HMesh/Manifold.h"
10
 
10
 
11
using namespace CGLA;
11
using namespace CGLA;
12
using namespace std;
12
using namespace std;
13
using namespace HMesh;
13
using namespace HMesh;
14
 
14
 
15
namespace
15
namespace
16
{
16
{
17
    const float EDGE_MIN_SQ_LENGTH = CGLA::MINUTE;
17
    const float EDGE_MIN_SQ_LENGTH = CGLA::MINUTE;
18
 
18
 
19
    inline bool degenerate_edge(const Manifold& m, HalfEdgeID h)
19
    inline bool degenerate_edge(const Manifold& m, HalfEdgeID h)
20
    {
20
    {
21
		Walker w = m.walker(h);
21
		Walker w = m.walker(h);
22
        if(sqr_length(m.pos(w.vertex()) - m.pos(w.opp().vertex())) < 1e-8)
22
        if(sqr_length(m.pos(w.vertex()) - m.pos(w.opp().vertex())) < 1e-8)
23
            return true;
23
            return true;
24
        return false;
24
        return false;
25
    }
25
    }
26
 
26
 
27
}
27
}
28
 
28
 
29
namespace Geometry
29
namespace Geometry
30
{
30
{
31
 
31
 
32
    template<class BBTree>
32
    template<class BBTree>
33
    void build_tree_robust(Manifold& m, BBTree& tree)
33
    void build_tree_robust(Manifold& m, BBTree& tree)
34
    {
34
    {
35
        vector<Triangle> triangle_vec;
35
        vector<Triangle> triangle_vec;
36
 
36
 
37
        for(FaceIDIterator fi=m.faces_begin(); fi != m.faces_end();++fi)
37
        for(FaceIDIterator fi=m.faces_begin(); fi != m.faces_end();++fi)
38
        {
38
        {
39
            Vec3d face_normal = normal(m, *fi);
39
            Vec3d face_normal = normal(m, *fi);
40
            
40
            
41
            Walker w = m.walker(*fi);
41
            Walker w = m.walker(*fi);
42
 
42
 
43
            Vec3f v0,v1,v2;
43
            Vec3f v0,v1,v2;
44
            Vec3f vn0,vn1,vn2;
44
            Vec3f vn0,vn1,vn2;
45
            Vec3f en0,en1,en2;
45
            Vec3f en0,en1,en2;
46
 
46
 
47
            v0  = Vec3f(m.pos(w.vertex()));
47
            v0  = Vec3f(m.pos(w.vertex()));
48
            vn0 = Vec3f(normal(m, w.vertex()));
48
            vn0 = Vec3f(normal(m, w.vertex()));
49
            en0 = Vec3f(normalize(face_normal + normal(m, w.next().opp().face())));
49
            en0 = Vec3f(normalize(face_normal + normal(m, w.next().opp().face())));
50
            
50
            
51
            w = w.next();
51
            w = w.next();
52
 
52
 
53
            v1  = Vec3f(m.pos(w.vertex()));
53
            v1  = Vec3f(m.pos(w.vertex()));
54
            vn1 = Vec3f(normal(m, w.vertex()));
54
            vn1 = Vec3f(normal(m, w.vertex()));
55
            en1 = Vec3f(normalize(face_normal + normal(m, w.next().opp().face())));
55
            en1 = Vec3f(normalize(face_normal + normal(m, w.next().opp().face())));
56
 
56
 
57
            
57
            
58
            w = w.next();
58
            w = w.next();
59
 
59
 
60
            v2  = Vec3f(m.pos(w.vertex()));
60
            v2  = Vec3f(m.pos(w.vertex()));
61
            vn2 = Vec3f(normal(m, w.vertex()));
61
            vn2 = Vec3f(normal(m, w.vertex()));
62
            en2 = Vec3f(normalize(face_normal + normal(m, w.next().opp().face())));
62
            en2 = Vec3f(normalize(face_normal + normal(m, w.next().opp().face())));
63
            
63
            
64
            if(sqr_length(v0-v1)>EDGE_MIN_SQ_LENGTH &&
64
            if(sqr_length(v0-v1)>EDGE_MIN_SQ_LENGTH &&
65
                sqr_length(v1-v2)>EDGE_MIN_SQ_LENGTH &&
65
                sqr_length(v1-v2)>EDGE_MIN_SQ_LENGTH &&
66
                sqr_length(v2-v0)>EDGE_MIN_SQ_LENGTH)
66
                sqr_length(v2-v0)>EDGE_MIN_SQ_LENGTH)
67
                triangle_vec.push_back(Triangle(v0,v1,v2,vn0,vn1,vn2,en0,en1,en2));
67
                triangle_vec.push_back(Triangle(v0,v1,v2,vn0,vn1,vn2,en0,en1,en2));
68
            else
68
            else
69
                cout << "Killing degenerate triangle" << endl;
69
                cout << "Killing degenerate triangle" << endl;
70
        }
70
        }
71
 
71
 
72
        tree.build(triangle_vec);
72
        tree.build(triangle_vec);
73
    }
73
    }
74
 
74
 
75
    void build_OBBTree(HMesh::Manifold& m, OBBTree& tree)
75
    void build_OBBTree(HMesh::Manifold& m, OBBTree& tree)
76
    {
76
    {
77
        build_tree_robust<OBBTree>(m, tree);
77
        build_tree_robust<OBBTree>(m, tree);
78
    }
78
    }
79
 
79
 
80
    void build_AABBTree(HMesh::Manifold& m, AABBTree& tree)
80
    void build_AABBTree(HMesh::Manifold& m, AABBTree& tree)
81
    {
81
    {
82
        build_tree_robust<AABBTree>(m, tree);
82
        build_tree_robust<AABBTree>(m, tree);
83
    }
83
    }
84
 
84
 
85
}
85
}
86
 
86