Subversion Repositories gelsvn

Rev

Rev 595 | Rev 630 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
515 s042372 1
/* ----------------------------------------------------------------------- *
572 jab 2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
515 s042372 5
 * ----------------------------------------------------------------------- */
6
 
7
#include "dual.h"
8
 
9
#include <vector>
601 jab 10
#include "../CGLA/Vec3d.h"
515 s042372 11
 
518 s042372 12
#include "Manifold.h"
515 s042372 13
#include "AttributeVector.h"
14
 
15
namespace HMesh
16
{
17
    using namespace std;
18
    using namespace CGLA;
587 jab 19
 
515 s042372 20
    void dual(Manifold& m)
518 s042372 21
    {
587 jab 22
        // make sure every face knows its number
23
        int i = 0;
536 s042372 24
 
587 jab 25
        FaceAttributeVector<int> ftouched;
26
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
27
            ftouched[*f] = i;
536 s042372 28
 
587 jab 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
    }