Subversion Repositories gelsvn

Rev

Rev 572 | Details | Compare with Previous | Last modification | View Log | RSS feed

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