11 #include <benchmark/benchmark.h>
15 namespace benchmarks {
23 double AverageDistance(
const std::vector<T> &a,
const std::vector<T> &b) {
24 if (a.size() != b.size()) {
31 for (
size_t i = 0; i < a.size(); ++i) {
32 total += (a[i] - b[i]).norm();
34 return total / a.size();
37 enum class IsAscii : bool {
BINARY =
false,
ASCII =
true };
38 enum class Compressed : bool { UNCOMPRESSED =
false, COMPRESSED =
true };
39 enum class Compare : uint32_t {
44 NORMALS_AND_COLORS = NORMALS | COLORS
46 struct ReadWritePCArgs {
52 std::vector<ReadWritePCArgs> g_pc_args({
54 {
"testau.pcd", IsAscii::ASCII, Compressed::UNCOMPRESSED,
55 Compare::NORMALS_AND_COLORS},
56 {
"testbu.pcd", IsAscii::BINARY, Compressed::UNCOMPRESSED,
57 Compare::NORMALS_AND_COLORS},
58 {
"testbc.pcd", IsAscii::BINARY, Compressed::COMPRESSED,
59 Compare::NORMALS_AND_COLORS},
60 {
"testb.ply", IsAscii::BINARY, Compressed::UNCOMPRESSED,
61 Compare::NORMALS_AND_COLORS},
62 {
"testa.ply", IsAscii::ASCII, Compressed::UNCOMPRESSED,
63 Compare::NORMALS_AND_COLORS},
64 {
"test.pts", IsAscii::BINARY, Compressed::UNCOMPRESSED,
66 {
"test.xyz", IsAscii::BINARY, Compressed::UNCOMPRESSED,
68 {
"test.xyzn", IsAscii::BINARY, Compressed::UNCOMPRESSED,
70 {
"test.xyzrgb", IsAscii::BINARY, Compressed::UNCOMPRESSED,
77 const bool print_progress =
false;
80 void Setup(
int size) {
86 for (
int i = 0; i <
size; ++i) {
90 std::sin(i * .3898546778) * 1000.,
91 std::sin(i * .2509962463) * 1000.});
93 std::sin(i * .9698787116),
94 std::sin(i * .7072878517)});
97 std::fmod(i * .6468026221, 1.0),
98 std::fmod(i * .5376722873, 1.0)});
102 void WriteRead(
int pc_args_id) {
103 const auto &args = g_pc_args[pc_args_id];
104 const auto &pc = pc_;
107 {bool(args.write_ascii), bool(args.compressed),
113 {
"auto", false, false, print_progress})) {
116 auto CheckLE = [](
double a,
double b) {
121 const double pointsMaxError =
123 CheckLE(AverageDistance(pc.getEigenPoints(), pc2.
getEigenPoints()),
125 if (
int(args.compare) &
int(Compare::NORMALS)) {
126 const double normalsMaxError =
128 CheckLE(AverageDistance(pc.getEigenNormals(),
132 if (
int(args.compare) &
int(Compare::COLORS)) {
133 const double colorsMaxError =
135 CheckLE(AverageDistance(pc.getEigenColors(), pc2.
getEigenColors()),
141 TestPCGrid0 test_pc_grid0;
147 int pc_args_id = state.range(0);
148 int size = state.range(1);
149 test_pc_grid0.Setup(
size);
150 for (
auto _ : state) {
151 test_pc_grid0.WriteRead(pc_args_id);
155 for (
int j = 4 * 1024; j <= 256 * 1024; j *= 8) {
156 for (
int i = 0; i < int(g_pc_args.size()); ++i) {
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void addEigenNorm(const Eigen::Vector3d &N)
std::vector< Eigen::Vector3d > getEigenColors() const
void addEigenColor(const Eigen::Vector3d &color)
void clear() override
Clears the entity from all its points and features.
std::vector< Eigen::Vector3d > getEigenNormals() const
void addEigenPoint(const Eigen::Vector3d &point)
std::vector< Eigen::Vector3d > getEigenPoints() const
BENCHMARK(BM_TestKDTreeLine0) -> Args({1<< 5, 1<< 10}) ->Args({1<< 9, 1<< 11})
static void BM_TestPCGrid0_Args(benchmark::internal::Benchmark *b)
static void BM_TestPCGrid0(::benchmark::State &state)
bool ReadPointCloud(const std::string &filename, ccPointCloud &pointcloud, const ReadPointCloudOption ¶ms)
bool WritePointCloud(const std::string &filename, const ccPointCloud &pointcloud, const WritePointCloudOption ¶ms)
bool WritePointCloud(const std::string &filename, const geometry::PointCloud &pointcloud, bool write_ascii, bool compressed, bool print_progress)
bool ReadPointCloud(const std::string &filename, geometry::PointCloud &pointcloud, const std::string &file_format, bool remove_nan_points, bool remove_infinite_points, bool print_progress)
Generic file read and write utility for python interface.