Subversion Repositories gelsvn

Rev

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

Rev 586 Rev 587
Line 5... Line 5...
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
#include "dual.h"
7
#include "dual.h"
8
 
8
 
9
#include <vector>
9
#include <vector>
10
#include <CGLA/Vec3f.h>
10
#include <CGLA/Vec3d.h>
11
 
11
 
12
#include "Manifold.h"
12
#include "Manifold.h"
13
#include "AttributeVector.h"
13
#include "AttributeVector.h"
14
 
14
 
15
namespace HMesh
15
namespace HMesh
16
{
16
{
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
    // make sure every face knows its number
22
        // make sure every face knows its number
23
    int i = 0;
23
        int i = 0;
24
 
-
 
25
    FaceAttributeVector<int> ftouched;
-
 
26
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
-
 
27
        ftouched[*f] = i;
-
 
28
 
-
 
29
    vector<Vec3f> vertices;
-
 
30
    vertices.resize(m.no_faces());
-
 
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
-
 
36
    i = 0;
-
 
37
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
-
 
38
        vertices[i] = centre(m, *f);
-
 
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){
-
 
43
        if(boundary(m, *v))
-
 
44
            continue;
-
 
45
        
24
        
46
        HalfEdgeWalker w = m.halfedgewalker(*v);
-
 
47
        vector<int> index_tmp;
25
        FaceAttributeVector<int> ftouched;
48
        for(; !w.full_circle(); w = w.circulate_vertex_cw())
26
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
49
            index_tmp.push_back(ftouched[w.face()]);
27
            ftouched[*f] = i;
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
        
28
        
59
    }
-
 
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
    }
-
 
71
}
-
 
72
 
29
        vector<Vec3d> vertices;
-
 
30
        vertices.resize(m.no_faces());
-
 
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
-
 
36
        i = 0;
-
 
37
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
-
 
38
            vertices[i] = centre(m, *f);
-
 
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){
-
 
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())
-
 
49
                    indices.push_back(ftouched[w.face()]);
-
 
50
                
-
 
51
                // Insert face valency in the face vector.
-
 
52
                faces.push_back(w.no_steps());
-
 
53
                
-
 
54
            }
-
 
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
 
73

Generated by GNU Enscript 1.6.6.
68

Generated by GNU Enscript 1.6.6.