515 |
s042372 |
1 |
/* ----------------------------------------------------------------------- *
|
|
|
2 |
* This file is part of GEL, www.imm.dtu.dk/GEL
|
|
|
3 |
* Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
|
|
|
4 |
*
|
|
|
5 |
* Principal authors:
|
|
|
6 |
* Christian Thode Larsen (thode2d@gmail.com)
|
|
|
7 |
* J. Andreas Baerentzen (jab@imm.dtu.dk)
|
|
|
8 |
*
|
|
|
9 |
* See LICENSE.txt for licensing information
|
|
|
10 |
* ----------------------------------------------------------------------- */
|
|
|
11 |
|
|
|
12 |
#include "dual.h"
|
|
|
13 |
|
|
|
14 |
#include <vector>
|
|
|
15 |
#include <CGLA/Vec3f.h>
|
|
|
16 |
|
518 |
s042372 |
17 |
#include "Manifold.h"
|
515 |
s042372 |
18 |
#include "AttributeVector.h"
|
|
|
19 |
|
|
|
20 |
namespace HMesh
|
|
|
21 |
{
|
|
|
22 |
using namespace std;
|
|
|
23 |
using namespace CGLA;
|
|
|
24 |
|
|
|
25 |
void dual(Manifold& m)
|
518 |
s042372 |
26 |
{
|
|
|
27 |
// make sure every face knows its number
|
|
|
28 |
int i = 0;
|
|
|
29 |
|
|
|
30 |
FaceAttributeVector<int> ftouched(m);
|
|
|
31 |
for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f, ++i)
|
|
|
32 |
ftouched[*f] = i;
|
|
|
33 |
|
|
|
34 |
vector<Vec3f> vertices;
|
|
|
35 |
vertices.reserve(m.no_faces());
|
|
|
36 |
vector<int> faces;
|
|
|
37 |
vector<int> indices;
|
|
|
38 |
|
|
|
39 |
// Create new vertices. Each face becomes a vertex whose position
|
|
|
40 |
// is the centre of the face
|
|
|
41 |
for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f)
|
|
|
42 |
vertices.push_back(centre(m, *f));
|
|
|
43 |
|
|
|
44 |
// Create new faces. Each vertex is a new face with N=valency of vertex
|
|
|
45 |
// edges.
|
|
|
46 |
for(VertexIDIterator v = m.vertices_begin(); v!= m.vertices_end(); ++v){
|
|
|
47 |
if(!boundary(m, *v)){
|
|
|
48 |
HalfEdgeWalker w = m.halfedgewalker(*v);
|
|
|
49 |
vector<int> index_tmp;
|
|
|
50 |
for(; !w.full_circle(); w = w.circulate_vertex_cw())
|
|
|
51 |
index_tmp.push_back(ftouched[w.face()]);
|
|
|
52 |
|
|
|
53 |
// Push vertex indices for this face onto indices vector.
|
|
|
54 |
// The circulator moves around the face in a clockwise fashion
|
|
|
55 |
// so we just reverse the ordering.
|
|
|
56 |
indices.insert(indices.end(), index_tmp.rbegin(), index_tmp.rend());
|
|
|
57 |
|
|
|
58 |
// Insert face valency in the face vector.
|
|
|
59 |
faces.push_back(w.no_steps());
|
|
|
60 |
}
|
515 |
s042372 |
61 |
}
|
518 |
s042372 |
62 |
|
|
|
63 |
// Clear the manifold before new geometry is inserted.
|
|
|
64 |
m.clear();
|
|
|
65 |
|
|
|
66 |
// And build
|
|
|
67 |
m.build( vertices.size(),
|
|
|
68 |
reinterpret_cast<float*>(&vertices[0]),
|
|
|
69 |
faces.size(),
|
|
|
70 |
&faces[0],
|
|
|
71 |
&indices[0]);
|
|
|
72 |
}
|
515 |
s042372 |
73 |
}
|