forked from xw0/spherical_voronoi_core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
67 lines (45 loc) · 1.58 KB
/
example.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
#include <vector>
#include "svData.h"
#include <random>
#include "svVoronoiCore.h"
#include <iostream>
#include <chrono>
std::vector<sv::Real3> generatePoints(size_t count) {
std::vector<sv::Real3> points;
std::random_device rd;
std::mt19937 rng(rd());
std::uniform_real_distribution<> heightDistribution(-1, 1);
std::uniform_real_distribution<> angleDistribution(0, 2 * M_PI);
for (size_t i = 0; i < count; i++) {
double z = heightDistribution(rng);
double phi = angleDistribution(rng);
double theta = asin(z);
double x = cos(theta) * cos(phi);
double y = cos(theta) * sin(phi);
points.push_back(sv::Real3(x, y, z));
}
return points;
}
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cout << "Usage: " << argv[0] << " [Number of cells]\n";
return 1;
}
int cellCount = std::stoi(argv[1]);
auto points = generatePoints(cellCount);
auto constructStart = std::chrono::high_resolution_clock::now();
sv::SphericalVoronoiCore voronoiDiagram(points);
auto constructEnd = std::chrono::high_resolution_clock::now();
auto constructDur = constructEnd - constructStart;
std::cout << "Construct took " << std::chrono::duration_cast<std::chrono::nanoseconds>(constructDur).count() << " ns\n";
voronoiDiagram.solve();
auto solveEnd = std::chrono::high_resolution_clock::now();
/*voronoiDiagram.solve([](int value)
{
std::cout << "In callback: " << value << std::endl;
});*/
auto solveDur = solveEnd - constructEnd;
std::cout << "Solve took " << std::chrono::duration_cast<std::chrono::nanoseconds>(solveDur).count() << " ns\n";
system("pause");
return 0;
}