Subversion Repositories gelsvn

Rev

Rev 601 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 601 Rev 630
1
/* ----------------------------------------------------------------------- *
1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * ----------------------------------------------------------------------- */
5
 * ----------------------------------------------------------------------- */
6
 
6
 
7
#include "dual.h"
7
#include "dual.h"
8
 
8
 
9
#include <vector>
9
#include <vector>
10
#include "../CGLA/Vec3d.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
        
24
        
25
        FaceAttributeVector<int> ftouched;
25
        FaceAttributeVector<int> ftouched;
26
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
26
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
27
            ftouched[*f] = i;
27
            ftouched[*f] = i;
28
        
28
        
29
        vector<Vec3d> vertices;
29
        vector<Vec3d> vertices;
30
        vertices.resize(m.no_faces());
30
        vertices.resize(m.no_faces());
31
        vector<int> faces;
31
        vector<int> faces;
32
        vector<int> indices;
32
        vector<int> indices;
33
        
33
        
34
        // Create new vertices. Each face becomes a vertex whose position
34
        // Create new vertices. Each face becomes a vertex whose position
35
        // is the centre of the face
35
        // is the centre of the face
36
        i = 0;
36
        i = 0;
37
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
37
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
38
            vertices[i] = centre(m, *f);
38
            vertices[i] = centre(m, *f);
39
            
39
            
40
            // Create new faces. Each vertex is a new face with N=valency of vertex
40
            // Create new faces. Each vertex is a new face with N=valency of vertex
41
            // edges.
41
            // edges.
42
            for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
42
            for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
43
                if(boundary(m, *v))
43
                if(boundary(m, *v))
44
                    continue;
44
                    continue;
45
                
45
                
46
                Walker w = m.walker(*v);
46
                Walker w = m.walker(*v);
47
                vector<int> index_tmp;
47
                vector<int> index_tmp;
48
                for(; !w.full_circle(); w = w.circulate_vertex_ccw())
48
                for(; !w.full_circle(); w = w.circulate_vertex_ccw())
49
                    indices.push_back(ftouched[w.face()]);
49
                    indices.push_back(ftouched[w.face()]);
50
                
50
                
51
                // Insert face valency in the face vector.
51
                // Insert face valency in the face vector.
52
                faces.push_back(w.no_steps());
52
                faces.push_back(w.no_steps());
53
                
53
                
54
            }
54
            }
55
            
55
            
56
            // Clear the manifold before new geometry is inserted.
56
            // Clear the manifold before new geometry is inserted.
57
            m.clear();
57
            m.clear();
58
            
58
            
59
            // And build
59
            // And build
60
            m.build(    vertices.size(), 
60
            m.build(    vertices.size(), 
61
                    reinterpret_cast<double*>(&vertices[0]),
61
                    reinterpret_cast<double*>(&vertices[0]),
62
                    faces.size(), 
62
                    faces.size(), 
63
                    &faces[0],
63
                    &faces[0],
64
                    &indices[0]);
64
                    &indices[0]);
65
        }
65
        }
66
    }
66
    }
67
 
67
 
68

Generated by GNU Enscript 1.6.6.
68

Generated by GNU Enscript 1.6.6.
69
 
69
 
70
 
70
 
71
 
71