Subversion Repositories gelsvn

Rev

Rev 630 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 630 Rev 643
Line 17... Line 17...
17
    using namespace std;
17
    using namespace std;
18
    using namespace CGLA;
18
    using namespace CGLA;
19
    
19
    
20
    void dual(Manifold& m)
20
    void dual(Manifold& m)
21
    {
21
    {
-
 
22
        // Create new vertices. Each face becomes a vertex whose position
22
        // make sure every face knows its number
23
        // is the centre of the face
23
        int i = 0;
24
        int i = 0;
24
        
-
 
25
        FaceAttributeVector<int> ftouched;
25
        FaceAttributeVector<int> ftouched;
26
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
-
 
27
            ftouched[*f] = i;
-
 
28
        
-
 
29
        vector<Vec3d> vertices;
26
        vector<Vec3d> vertices;
30
        vertices.resize(m.no_faces());
27
        vertices.resize(m.no_faces());
-
 
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.
31
        vector<int> faces;
33
        vector<int> faces;
32
        vector<int> indices;
34
        vector<int> indices;
33
        
-
 
34
        // Create new vertices. Each face becomes a vertex whose position
-
 
35
        // is the centre of the face
35
        for(auto v : m.vertices())
36
        i = 0;
-
 
37
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
-
 
38
            vertices[i] = centre(m, *f);
36
            if(valency(m, v) > 2 && !(boundary(m, v)))
39
            
37
            {
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){
-
 
43
                if(boundary(m, *v))
-
 
44
                    continue;
-
 
45
                
-
 
46
                Walker w = m.walker(*v);
-
 
47
                vector<int> index_tmp;
-
 
48
                for(; !w.full_circle(); w = w.circulate_vertex_ccw())
38
                int N =circulate_vertex_ccw(m, v, [&](FaceID fid) {
49
                    indices.push_back(ftouched[w.face()]);
39
                    indices.push_back(ftouched[fid]);
50
                
40
                });
51
                // Insert face valency in the face vector.
41
                // Insert face valency in the face vector.
52
                faces.push_back(w.no_steps());
42
                faces.push_back(N);
53
                
-
 
54
            }
43
            }
55
            
-
 
56
            // Clear the manifold before new geometry is inserted.
-
 
57
            m.clear();
-
 
58
            
-
 
59
            // And build
-
 
60
            m.build(    vertices.size(), 
-
 
61
                    reinterpret_cast<double*>(&vertices[0]),
-
 
62
                    faces.size(), 
-
 
63
                    &faces[0],
-
 
64
                    &indices[0]);
-
 
65
        }
-
 
66
    }
-
 
67
 
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
}
-
 
56
 
68

Generated by GNU Enscript 1.6.6.
57

Generated by GNU Enscript 1.6.6.