Subversion Repositories gelsvn

Rev

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