Rev 518 | 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 "AttributeVector.h"
namespace HMesh
{
using namespace std;
using namespace CGLA;
void dual(Manifold& m)
{
// make sure every face knows its number
IndexType i = 0;
FaceAttributeVector<int> ftouched(m);
for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
ftouched[*f] = i;
vector<Vec3f> vertices(m.no_vertices());
vector<unsigned int> faces;
vector<unsigned 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[ftouched[*f]] = 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<unsigned 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(static_cast<unsigned int>(vertices.size()),
reinterpret_cast<float*>(&vertices[0]),
static_cast<unsigned int>(faces.size()),
static_cast<const unsigned int*>(&faces[0]),
static_cast<const unsigned int*>(&indices[0]));
}
}
Generated by GNU Enscript 1.6.6.