Repository navigation
Expand file tree
/
Copy pathread_obj-cgal.cpp
More file actions
59 lines (49 loc) · 1.74 KB
/
Copy pathread_obj-cgal.cpp
File metadata and controls
59 lines (49 loc) · 1.74 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
#include "io_common.hpp"
#include "io_reference.hpp"
#include <CGAL/IO/OBJ.h>
#include <CGAL/Simple_cartesian.h>
#include <trueform/version.hpp>
#include <array>
#include <cstdint>
#include <vector>
#ifndef TRUEFORM_BENCH_COMMIT
#define TRUEFORM_BENCH_COMMIT "working-tree"
#endif
namespace {
using kernel_t = CGAL::Simple_cartesian<float>;
using point_t = kernel_t::Point_3;
struct cgal_obj_output {
std::vector<point_t> points;
std::vector<std::array<std::uint32_t, 3>> triangles;
};
auto read_cgal(const std::string &path) -> cgal_obj_output {
cgal_obj_output output;
std::vector<std::vector<std::size_t>> polygons;
if (!CGAL::IO::read_OBJ(path, output.points, polygons))
return {};
output.triangles.reserve(polygons.size());
for (const auto &polygon : polygons)
if (polygon.size() == 3)
output.triangles.push_back({static_cast<std::uint32_t>(polygon[0]),
static_cast<std::uint32_t>(polygon[1]),
static_cast<std::uint32_t>(polygon[2])});
return output;
}
auto signature(const cgal_obj_output &output) -> bench::io::mesh_signature {
return bench::io::make_signature(
output.points.size(), output.triangles.size(),
[&](std::size_t point, std::size_t dim) {
const auto &p = output.points[point];
return dim == 0 ? p.x() : (dim == 1 ? p.y() : p.z());
},
[&](std::size_t face, std::size_t corner) {
return output.triangles[face][corner];
});
}
} // namespace
int main(int argc, char **argv) {
return bench::io::run_file_benchmark(
argc, argv, "read_obj", "cgal", CGAL_VERSION_STR, tf::version,
TRUEFORM_BENCH_COMMIT, bench::io::read_obj_reference,
bench::io::identity_signature, read_cgal, signature);
}