-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
100 lines (84 loc) · 2.01 KB
/
main.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "include/delaunay.h"
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <random>
/*
Test cases:
simple.obj
random.obj
large_random.obj
*/
#define DEFAULT_RANDOM_LIMIT (100.0f)
float random_float(float min_x = -DEFAULT_RANDOM_LIMIT, float min_y = DEFAULT_RANDOM_LIMIT)
{
static std::random_device rd;
static std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(min_x, min_y);
return dis(gen);
}
// Test with points to form
// /|---|\
// / | \ | \
// \ | \| /
// \|---|/
void TestSimple()
{
Delaunay::Points points
{
Mesh::Point(-2.0f, 0.0f, 0.0f),
Mesh::Point(-1.0f, 1.0f, 0.0f),
Mesh::Point(-1.0f, -1.0f, 0.0f),
Mesh::Point(1.0f, -1.0f, 0.0f),
Mesh::Point(1.0f, 1.0f, 0.0f),
Mesh::Point(2.0f, 0.0f, 0.0f),
};
Delaunay::DelaunayMesh mesh(std::move(points));
// write mesh
auto filename = "simple.obj";
if (!OpenMesh::IO::write_mesh(mesh, filename))
{
std::cerr << "Cannot write mesh to file " << filename << std::endl;
}
}
// Test with 10 points between [-100, 100]
void TestRandom()
{
Delaunay::Points points;
for (auto i = 0; i < 10; i++)
{
auto x = random_float();
auto y = random_float();
points.emplace_back(Mesh::Point(x, y, 0.0f));
}
Delaunay::DelaunayMesh mesh(std::move(points));
// write mesh
auto filename = "random.obj";
if (!OpenMesh::IO::write_mesh(mesh, filename))
{
std::cerr << "Cannot write mesh to file " << filename << std::endl;
}
}
// Test with 100 points between [-100, 100]
void TestLargeRandom()
{
Delaunay::Points points;
for (auto i = 0; i < 100; i++)
{
auto x = random_float();
auto y = random_float();
points.emplace_back(Mesh::Point(x, y, 0.0f));
}
Delaunay::DelaunayMesh mesh(std::move(points));
// write mesh
auto filename = "large_random.obj";
if (!OpenMesh::IO::write_mesh(mesh, filename))
{
std::cerr << "Cannot write mesh to file " << filename << std::endl;
}
}
int main(int argc, char **argv)
{
TestSimple();
TestRandom();
TestLargeRandom();
return 0;
}