Subversion Repositories gelsvn

Rev

Rev 519 | Rev 572 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
515 s042372 1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
4
 *
5
 * Principal authors:
6
 *  Christian Thode Larsen (thode2d@gmail.com)
7
 *  J. Andreas Baerentzen (jab@imm.dtu.dk)
8
 *
9
 * See LICENSE.txt for licensing information
10
 * ----------------------------------------------------------------------- */
11
 
12
#include "dual.h"
13
 
14
#include <vector>
15
#include <CGLA/Vec3f.h>
16
 
518 s042372 17
#include "Manifold.h"
515 s042372 18
#include "AttributeVector.h"
19
 
20
namespace HMesh
21
{
22
    using namespace std;
23
    using namespace CGLA;
24
 
25
    void dual(Manifold& m)
518 s042372 26
    {
27
    // make sure every face knows its number
28
    int i = 0;
29
 
519 s042372 30
    FaceAttributeVector<int> ftouched(m.total_faces());
518 s042372 31
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
32
        ftouched[*f] = i;
33
 
34
    vector<Vec3f> vertices;
536 s042372 35
    vertices.resize(m.active_faces());
518 s042372 36
    vector<int> faces;
37
    vector<int> indices;
38
 
39
    // Create new vertices. Each face becomes a vertex whose position
40
    // is the centre of the face
536 s042372 41
    i = 0;
42
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
43
        vertices[i] = centre(m, *f);
518 s042372 44
 
45
    // Create new faces. Each vertex is a new face with N=valency of vertex
46
    // edges.
47
    for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
536 s042372 48
        if(boundary(m, *v))
49
            continue;
50
 
51
        HalfEdgeWalker w = m.halfedgewalker(*v);
52
        vector<int> index_tmp;
53
        for(; !w.full_circle(); w = w.circulate_vertex_cw())
54
            index_tmp.push_back(ftouched[w.face()]);
518 s042372 55
 
536 s042372 56
        // Push vertex indices for this face onto indices vector.
57
        // The circulator moves around the face in a clockwise fashion
58
        // so we just reverse the ordering.
59
        indices.insert(indices.end(), index_tmp.rbegin(), index_tmp.rend());
518 s042372 60
 
536 s042372 61
        // Insert face valency in the face vector.
62
        faces.push_back(w.no_steps());
63
 
515 s042372 64
    }
518 s042372 65
 
66
    // Clear the manifold before new geometry is inserted.
67
    m.clear();
68
 
69
    // And build
70
    m.build(    vertices.size(), 
71
                reinterpret_cast<float*>(&vertices[0]), 
72
                faces.size(), 
73
                &faces[0],
74
                &indices[0]);
75
    }
515 s042372 76
}