Subversion Repositories gelsvn

Rev

Rev 515 | Rev 519 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/* ----------------------------------------------------------------------- *
 * This file is part of GEL, www.imm.dtu.dk/GEL
 * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
 *
 * Principal authors:
 *  Christian Thode Larsen (thode2d@gmail.com)
 *  J. Andreas Baerentzen (jab@imm.dtu.dk)
 *
 * See LICENSE.txt for licensing information
 * ----------------------------------------------------------------------- */

#include "dual.h"

#include <vector>
#include <CGLA/Vec3f.h>

#include "Manifold.h"
#include "AttributeVector.h"

namespace HMesh
{
    using namespace std;
    using namespace CGLA;

    void dual(Manifold& m)
    {
    // make sure every face knows its number
    int i = 0;

    FaceAttributeVector<int> ftouched(m);
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
        ftouched[*f] = i;

    vector<Vec3f> vertices;
    vertices.reserve(m.no_faces());
    vector<int> faces;
    vector<int> indices;

    // Create new vertices. Each face becomes a vertex whose position
    // is the centre of the face
    for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f)
        vertices.push_back(centre(m, *f));

    // Create new faces. Each vertex is a new face with N=valency of vertex
    // edges.
    for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
        if(!boundary(m, *v)){
            HalfEdgeWalker w = m.halfedgewalker(*v);
            vector<int> index_tmp;
            for(; !w.full_circle(); w = w.circulate_vertex_cw())
                index_tmp.push_back(ftouched[w.face()]);

            // Push vertex indices for this face onto indices vector.
            // The circulator moves around the face in a clockwise fashion
            // so we just reverse the ordering.
            indices.insert(indices.end(), index_tmp.rbegin(), index_tmp.rend());

            // Insert face valency in the face vector.
            faces.push_back(w.no_steps());
        }
    }

    // Clear the manifold before new geometry is inserted.
    m.clear();

    // And build
    m.build(    vertices.size(), 
                reinterpret_cast<float*>(&vertices[0]), 
                faces.size(), 
                &faces[0],
                &indices[0]);
    }
}

Generated by GNU Enscript 1.6.6.