-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDualMesh.hh
More file actions
62 lines (54 loc) · 2.05 KB
/
Copy pathDualMesh.hh
File metadata and controls
62 lines (54 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef DUAL_MESH_HH
#define DUAL_MESH_HH
#include <MeshFEM/MeshIO.hh>
template<class Mesh>
void barycentricDual(const Mesh &m,
std::vector<MeshIO::IOVertex > &dualVertices,
std::vector<MeshIO::IOElement> &dualPolygons) {
const size_t ne = m.numElements();
dualVertices.clear();
dualVertices.reserve(ne);
for (size_t ei = 0; ei < ne; ++ei)
dualVertices.push_back(m.elementBarycenter(ei));
const size_t nv = m.numVertices();
dualPolygons.clear();
dualPolygons.reserve(nv); // There will be fewer than nv polygons, since we we only have them for internal vertices.
for (const auto v : m.vertices()) {
if (v.isBoundary()) continue;
dualPolygons.emplace_back();
// Circulate counter-clockwise.
for (const auto he : v.incidentHalfEdges()) {
assert(!he.isBoundary());
dualPolygons.back().push_back(he.tri().index());
}
}
}
// Assumes the dual region is convex...
template<class Mesh>
void triangulatedBarycentricDual(const Mesh &m,
std::vector<MeshIO::IOVertex > &dualVertices,
std::vector<MeshIO::IOElement> &dualTriangles,
std::vector<size_t> &originatingPolygon) {
std::vector<MeshIO::IOElement> dualPolygons;
barycentricDual(m, dualVertices, dualPolygons);
dualTriangles.clear();
originatingPolygon.clear();
bool toggle = false;
for (size_t pi = 0; pi < dualPolygons.size(); ++pi) {
const auto &p = dualPolygons[pi];
size_t start = 0, end = p.size() - 1;
while (end - start + 1 >= 3) {
if (toggle) {
dualTriangles.emplace_back(p[start], p[start + 1], p[end]);
++start;
}
else {
dualTriangles.emplace_back(p[start], p[end - 1], p[end]);
--end;
}
originatingPolygon.push_back(pi);
toggle = !toggle;
}
}
}
#endif /* end of include guard: DUAL_MESH_HH */