Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
660 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 "dual.h"
8
 
9
#include <vector>
10
#include "../CGLA/Vec3d.h"
11
 
12
#include "Manifold.h"
13
#include "AttributeVector.h"
14
 
15
namespace HMesh
16
{
17
    using namespace std;
18
    using namespace CGLA;
19
 
20
    void dual(Manifold& m)
21
    {
22
        // Create new vertices. Each face becomes a vertex whose position
23
        // is the centre of the face
24
        int i = 0;
25
        FaceAttributeVector<int> ftouched;
26
        vector<Vec3d> vertices;
27
        vertices.resize(m.no_faces());
28
        for(auto f : m.faces())
29
            vertices[ftouched[f] = i++] = centre(m, f);
30
 
31
        // Create new faces. Each vertex is a new face with N=valency of vertex
32
        // edges.
33
        vector<int> faces;
34
        vector<int> indices;
35
        for(auto v : m.vertices())
36
            if(valency(m, v) > 2 && !(boundary(m, v)))
37
            {
38
                int N =circulate_vertex_ccw(m, v,  (std::function<void(FaceID)>)[&](FaceID fid) {
39
                    indices.push_back(ftouched[fid]);
40
                });
41
                // Insert face valency in the face vector.
42
                faces.push_back(N);
43
            }
44
 
45
        // Clear the manifold before new geometry is inserted.
46
        m.clear();
47
 
48
        // And build
49
        m.build(    vertices.size(),
50
                reinterpret_cast<double*>(&vertices[0]),
51
                faces.size(),
52
                &faces[0],
53
                &indices[0]);
54
    }
55
}