Subversion Repositories gelsvn

Rev

Rev 515 | Rev 519 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 515 Rev 518
Line 12... Line 12...
12
#include "dual.h"
12
#include "dual.h"
13
 
13
 
14
#include <vector>
14
#include <vector>
15
#include <CGLA/Vec3f.h>
15
#include <CGLA/Vec3f.h>
16
 
16
 
-
 
17
#include "Manifold.h"
17
#include "AttributeVector.h"
18
#include "AttributeVector.h"
18
 
19
 
19
namespace HMesh
20
namespace HMesh
20
{
21
{
21
    using namespace std;
22
    using namespace std;
22
    using namespace CGLA;
23
    using namespace CGLA;
23
 
24
 
24
    void dual(Manifold& m)
25
    void dual(Manifold& m)
25
    {
26
    {
26
    // make sure every face knows its number
27
    // make sure every face knows its number
27
    IndexType i = 0;
28
    int i = 0;
28
 
29
 
29
    FaceAttributeVector<int> ftouched(m);
30
    FaceAttributeVector<int> ftouched(m);
30
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
31
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
31
        ftouched[*f] = i;
32
        ftouched[*f] = i;
32
 
33
 
33
    vector<Vec3f> vertices(m.no_vertices());
34
    vector<Vec3f> vertices;
-
 
35
    vertices.reserve(m.no_faces());
34
    vector<unsigned int> faces;
36
    vector<int> faces;
35
    vector<unsigned int> indices;
37
    vector<int> indices;
36
 
38
 
37
    // Create new vertices. Each face becomes a vertex whose position
39
    // Create new vertices. Each face becomes a vertex whose position
38
    // is the centre of the face
40
    // is the centre of the face
39
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f)
41
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f)
40
        vertices[ftouched[*f]] = centre(m, *f);
42
        vertices.push_back(centre(m, *f));
41
 
43
 
42
    // Create new faces. Each vertex is a new face with N=valency of vertex
44
    // Create new faces. Each vertex is a new face with N=valency of vertex
43
    // edges.
45
    // edges.
44
    for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
46
    for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
45
        if(!boundary(m, *v)){
47
        if(!boundary(m, *v)){
46
            HalfEdgeWalker w = m.halfedgewalker(*v);
48
            HalfEdgeWalker w = m.halfedgewalker(*v);
47
            vector<unsigned int> index_tmp;
49
            vector<int> index_tmp;
48
            for(; !w.full_circle(); w = w.circulate_vertex_cw())
50
            for(; !w.full_circle(); w = w.circulate_vertex_cw())
49
                index_tmp.push_back(ftouched[w.face()]);
51
                index_tmp.push_back(ftouched[w.face()]);
50
 
52
 
51
            // Push vertex indices for this face onto indices vector.
53
            // Push vertex indices for this face onto indices vector.
52
            // The circulator moves around the face in a clockwise fashion
54
            // The circulator moves around the face in a clockwise fashion
53
            // so we just reverse the ordering.
55
            // so we just reverse the ordering.
54
            indices.insert(indices.end(), index_tmp.rbegin(), index_tmp.rend());
56
            indices.insert(indices.end(), index_tmp.rbegin(), index_tmp.rend());
55
 
57
 
56
            // Insert face valency in the face vector.
58
            // Insert face valency in the face vector.
57
            faces.push_back(w.no_steps());
59
            faces.push_back(w.no_steps());
58
        }
60
        }
59
    }
61
    }
60
 
62
 
61
    // Clear the manifold before new geometry is inserted.
63
    // Clear the manifold before new geometry is inserted.
62
    m.clear();
64
    m.clear();
63
 
65
 
64
    // And build
66
    // And build
65
    m.build(static_cast<unsigned int>(vertices.size()), 
67
    m.build(    vertices.size(), 
66
        reinterpret_cast<float*>(&vertices[0]), 
68
                reinterpret_cast<float*>(&vertices[0]), 
67
        static_cast<unsigned int>(faces.size()), 
69
                faces.size(), 
68
        static_cast<const unsigned int*>(&faces[0]),
70
                &faces[0],
69
        static_cast<const unsigned int*>(&indices[0]));
71
                &indices[0]);
70
    }
72
    }
71
}
73
}
72
 
74