Subversion Repositories gelsvn

Rev

Rev 518 | Go to most recent revision | Details | 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
 
17
#include "AttributeVector.h"
18
 
19
namespace HMesh
20
{
21
    using namespace std;
22
    using namespace CGLA;
23
 
24
    void dual(Manifold& m)
25
    {
26
    // make sure every face knows its number
27
    IndexType i = 0;
28
 
29
    FaceAttributeVector<int> ftouched(m);
30
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
31
        ftouched[*f] = i;
32
 
33
    vector<Vec3f> vertices(m.no_vertices());
34
    vector<unsigned int> faces;
35
    vector<unsigned int> indices;
36
 
37
    // Create new vertices. Each face becomes a vertex whose position
38
    // is the centre of the face
39
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f)
40
        vertices[ftouched[*f]] = centre(m, *f);
41
 
42
    // Create new faces. Each vertex is a new face with N=valency of vertex
43
    // edges.
44
    for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
45
        if(!boundary(m, *v)){
46
            HalfEdgeWalker w = m.halfedgewalker(*v);
47
            vector<unsigned int> index_tmp;
48
            for(; !w.full_circle(); w = w.circulate_vertex_cw())
49
                index_tmp.push_back(ftouched[w.face()]);
50
 
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());
55
 
56
            // Insert face valency in the face vector.
57
            faces.push_back(w.no_steps());
58
        }
59
    }
60
 
61
    // Clear the manifold before new geometry is inserted.
62
    m.clear();
63
 
64
    // And build
65
    m.build(static_cast<unsigned int>(vertices.size()), 
66
        reinterpret_cast<float*>(&vertices[0]), 
67
        static_cast<unsigned int>(faces.size()), 
68
        static_cast<const unsigned int*>(&faces[0]),
69
        static_cast<const unsigned int*>(&indices[0]));
70
    }
71
}