## ~mht/cra

cra/triangulate2.cpp -rw-r--r-- 1.7 KiB
d843e514 — Martin Hafskjold Thoresen Fix bug where a boundary would be padded with zeros. 10 months ago
`                                                                                `
```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```
```#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;
typedef Triangulation::Vertex Vertex;
typedef Triangulation::Edge Edge;
typedef Triangulation::Face Face;

void triangulate_stdin() {
// Read in the points into a vec
float x, y;
std::vector<Point> points;
while (1) {
if (!(std::cin >> x))
break;
if (!(std::cin >> y))
break;
points.push_back(Point(x, y));
}

// Output number of points
printf("%zu\n", points.size());

// here you go, cgal
Triangulation triangulation;
triangulation.insert(points.begin(), points.end());

int j = 0;
// std::map<Vertex, int> vert_to_j;
for (auto fi = triangulation.finite_vertices_begin();
fi != triangulation.finite_vertices_end(); fi++) {
// vert_to_j[*fi] = ++j;
// Skip outputting the points, since they all only have the empty set.
}

// std::map<Edge, int> edge_to_j;
for (auto fi = triangulation.finite_edges_begin();
fi != triangulation.finite_edges_end(); fi++) {
printf("edge %d\n", fi->second);
// edge_to_j[*fi] = ++j;
// int v0 = fi->first->vertex(0);
// int v1 = fi->second;
// auto i0 = vert_to_j[v0], i1 = vert_to_j[v1];
// printf("%d %d\n", i0, i1);
}

//   for (auto fi = triangulation.finite_faces_begin();
//        fi != triangulation.finite_faces_end(); fi++) {
//     auto e0 = fi->edge(0), e1 = fi->edge(1), e2 = fi->edge(2);
//     auto i0 = edge_to_j[e0], i1 = edge_to_j[e1], i2 = edge_to_j[e2];
//     printf("%d %d %d\n", i0, i1, i2);
//   }
}

int main() {
triangulate_stdin();
return 0;
}
```