Subversion Repositories gelsvn

Rev

Go to most recent revision | Details | 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>
10
#include <CGLA/Vec3f.h>
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;
19
 
20
    void dual(Manifold& m)
518 s042372 21
    {
22
    // make sure every face knows its number
23
    int i = 0;
24
 
519 s042372 25
    FaceAttributeVector<int> ftouched(m.total_faces());
518 s042372 26
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
27
        ftouched[*f] = i;
28
 
29
    vector<Vec3f> vertices;
536 s042372 30
    vertices.resize(m.active_faces());
518 s042372 31
    vector<int> faces;
32
    vector<int> indices;
33
 
34
    // Create new vertices. Each face becomes a vertex whose position
35
    // is the centre of the face
536 s042372 36
    i = 0;
37
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
38
        vertices[i] = centre(m, *f);
518 s042372 39
 
40
    // Create new faces. Each vertex is a new face with N=valency of vertex
41
    // edges.
42
    for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
536 s042372 43
        if(boundary(m, *v))
44
            continue;
45
 
46
        HalfEdgeWalker w = m.halfedgewalker(*v);
47
        vector<int> index_tmp;
48
        for(; !w.full_circle(); w = w.circulate_vertex_cw())
49
            index_tmp.push_back(ftouched[w.face()]);
518 s042372 50
 
536 s042372 51
        // Push vertex indices for this face onto indices vector.
52
        // The circulator moves around the face in a clockwise fashion
53
        // so we just reverse the ordering.
54
        indices.insert(indices.end(), index_tmp.rbegin(), index_tmp.rend());
518 s042372 55
 
536 s042372 56
        // Insert face valency in the face vector.
57
        faces.push_back(w.no_steps());
58
 
515 s042372 59
    }
518 s042372 60
 
61
    // Clear the manifold before new geometry is inserted.
62
    m.clear();
63
 
64
    // And build
65
    m.build(    vertices.size(), 
66
                reinterpret_cast<float*>(&vertices[0]), 
67
                faces.size(), 
68
                &faces[0],
69
                &indices[0]);
70
    }
515 s042372 71
}