Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
667 khor 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
#include "refine_edges.h"
8
 
9
#include <vector>
10
#include <iterator>
11
 
12
#include "Manifold.h"
13
#include "AttributeVector.h"
14
 
15
namespace HMesh
16
{
17
    using namespace std;
18
 
19
    float average_edge_length(const Manifold& m)
20
    {
21
        float lsum = 0;
22
        for(auto h : m.halfedges())
23
            lsum += length(m, h);
24
        return lsum / m.no_halfedges();
25
    }
26
 
27
    int refine_edges(Manifold& m, float t)
28
    {
29
        vector<HalfEdgeID> hedges;
30
        hedges.reserve(m.no_halfedges());
31
        copy(m.halfedges_begin(), m.halfedges_end(), back_inserter(hedges));
32
 
33
        HalfEdgeAttributeVector<int> touched(m.allocated_halfedges(), 0);
34
 
35
        int work = 0;
36
        for(HalfEdgeID h : hedges){
37
            Walker w = m.walker(h);
38
 
39
            if(!m.in_use(h) || w.face() == InvalidFaceID || length(m, h) < t || touched[h])
40
                continue;
41
            touched[w.opp().halfedge()] = 1;
42
            m.split_edge(h);
43
            ++work;
44
        }
45
        return work;
46
    }
47
 
48
}