Subversion Repositories gelsvn

Rev

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

Rev Author Line No. Line
515 s042372 1
/* ----------------------------------------------------------------------- *
572 jab 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
515 s042372 5
 * ----------------------------------------------------------------------- */
6
 
7
#include "dual.h"
8
 
9
#include <vector>
601 jab 10
#include "../CGLA/Vec3d.h"
515 s042372 11
 
518 s042372 12
#include "Manifold.h"
515 s042372 13
#include "AttributeVector.h"
14
 
15
namespace HMesh
16
{
17
    using namespace std;
18
    using namespace CGLA;
587 jab 19
 
515 s042372 20
    void dual(Manifold& m)
518 s042372 21
    {
643 janba 22
        // Create new vertices. Each face becomes a vertex whose position
23
        // is the centre of the face
587 jab 24
        int i = 0;
25
        FaceAttributeVector<int> ftouched;
26
        vector<Vec3d> vertices;
27
        vertices.resize(m.no_faces());
643 janba 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.
587 jab 33
        vector<int> faces;
34
        vector<int> indices;
643 janba 35
        for(auto v : m.vertices())
36
            if(valency(m, v) > 2 && !(boundary(m, v)))
37
            {
38
                int N =circulate_vertex_ccw(m, v, [&](FaceID fid) {
39
                    indices.push_back(ftouched[fid]);
40
                });
587 jab 41
                // Insert face valency in the face vector.
643 janba 42
                faces.push_back(N);
587 jab 43
            }
643 janba 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
}