ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
PointCloudIO.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include <benchmark/benchmark.h>
11 
16 
17 namespace cloudViewer {
18 namespace t {
19 namespace geometry {
20 
21 // The `Read` benchmark functions are dependent on the corresponding `Write`
22 // benchmark functions to generate the point cloud file in the required format.
23 // To run benchmarks in this file, run the following command from inside the
24 // build directory: ./bin/benchmarks --benchmark_filter=".*IO.*"
25 
26 // This file is just used to load the `point cloud` data. So, format of this
27 // file is not important.
29 static const std::string input_path_pcd = pointcloud_ply_data.GetPath();
30 
31 void IOWriteLegacyPointCloud(benchmark::State& state,
32  const std::string& input_file_path,
33  const std::string& output_file_path,
34  const bool write_ascii,
35  const bool write_compressed) {
36  ccPointCloud pcd;
37  cloudViewer::io::ReadPointCloud(input_file_path, pcd,
38  {"auto", false, false, false});
39 
41  output_file_path, pcd,
43  write_ascii, write_compressed, false, {}));
44 
45  for (auto _ : state) {
47  output_file_path, pcd,
49  write_ascii, write_compressed, false, {}));
50  }
51 }
52 
53 void IOReadLegacyPointCloud(benchmark::State& state,
54  const std::string& input_file_path) {
55  ccPointCloud pcd;
56  cloudViewer::io::ReadPointCloud(input_file_path, pcd,
57  {"auto", false, false, false});
58 
59  for (auto _ : state) {
60  cloudViewer::io::ReadPointCloud(input_file_path, pcd,
61  {"auto", false, false, false});
62  }
63 }
64 
65 void IOWriteTensorPointCloud(benchmark::State& state,
66  const std::string& input_file_path,
67  const std::string& output_file_path,
68  const bool write_ascii,
69  const bool write_compressed) {
71  t::io::ReadPointCloud(input_file_path, pcd, {"auto", false, false, false});
72 
73  t::io::WritePointCloud(output_file_path, pcd,
75  write_ascii, write_compressed, false, {}));
76 
77  for (auto _ : state) {
79  output_file_path, pcd,
81  write_ascii, write_compressed, false, {}));
82  }
83 }
84 
85 void IOReadTensorPointCloud(benchmark::State& state,
86  const std::string& input_file_path) {
88  t::io::ReadPointCloud(input_file_path, pcd, {"auto", false, false, false});
89 
90  for (auto _ : state) {
91  t::io::ReadPointCloud(input_file_path, pcd,
92  {"auto", false, false, false});
93  }
94 }
95 
96 #define ENUM_BM_IO_EXTENSION_FORMAT(EXTENSION_NAME, FILE_NAME, FORMAT_NAME, \
97  ASCII, COMPRESSED) \
98  BENCHMARK_CAPTURE(IOWriteLegacyPointCloud, EXTENSION_NAME##_##FORMAT_NAME, \
99  input_path_pcd, \
100  std::string("tensor_") + std::string(FILE_NAME), ASCII, \
101  COMPRESSED) \
102  ->Unit(benchmark::kMillisecond); \
103  BENCHMARK_CAPTURE(IOReadLegacyPointCloud, EXTENSION_NAME##_##FORMAT_NAME, \
104  std::string("tensor_") + std::string(FILE_NAME)) \
105  ->Unit(benchmark::kMillisecond); \
106  BENCHMARK_CAPTURE(IOWriteTensorPointCloud, EXTENSION_NAME##_##FORMAT_NAME, \
107  input_path_pcd, \
108  std::string("legacy_") + std::string(FILE_NAME), ASCII, \
109  COMPRESSED) \
110  ->Unit(benchmark::kMillisecond); \
111  BENCHMARK_CAPTURE(IOReadTensorPointCloud, EXTENSION_NAME##_##FORMAT_NAME, \
112  std::string("legacy_") + std::string(FILE_NAME)) \
113  ->Unit(benchmark::kMillisecond);
114 
115 #define ENUM_BM_IO_EXTENSION(EXTENSION_NAME, EXTENSION) \
116  ENUM_BM_IO_EXTENSION_FORMAT( \
117  EXTENSION_NAME, std::string("pcd_ascii") + std::string(EXTENSION), \
118  ASCII_UNCOMPRESSED, true, false) \
119  ENUM_BM_IO_EXTENSION_FORMAT( \
120  EXTENSION_NAME, std::string("pcd_bin") + std::string(EXTENSION), \
121  BINARY_UNCOMPRESSED, false, false) \
122  ENUM_BM_IO_EXTENSION_FORMAT( \
123  EXTENSION_NAME, \
124  std::string("pcd_bin_compressed") + std::string(EXTENSION), \
125  BINARY_COMPRESSED, false, true)
126 
130 
131 } // namespace geometry
132 } // namespace t
133 } // namespace cloudViewer
IsAscii write_ascii
#define ENUM_BM_IO_EXTENSION(EXTENSION_NAME, EXTENSION)
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Data class for PLYPointCloud contains the fragment.ply point cloud mesh from the Redwood Living Room ...
Definition: Dataset.h:703
std::string GetPath() const
Path to the PLY format point cloud.
Definition: Dataset.h:708
A point cloud contains a list of 3D points.
Definition: PointCloud.h:82
bool ReadPointCloud(const std::string &filename, ccPointCloud &pointcloud, const ReadPointCloudOption &params)
bool WritePointCloud(const std::string &filename, const ccPointCloud &pointcloud, const WritePointCloudOption &params)
void IOReadLegacyPointCloud(benchmark::State &state, const std::string &input_file_path)
void IOWriteLegacyPointCloud(benchmark::State &state, const std::string &input_file_path, const std::string &output_file_path, const bool write_ascii, const bool write_compressed)
void IOWriteTensorPointCloud(benchmark::State &state, const std::string &input_file_path, const std::string &output_file_path, const bool write_ascii, const bool write_compressed)
static const std::string input_path_pcd
data::PLYPointCloud pointcloud_ply_data
void IOReadTensorPointCloud(benchmark::State &state, const std::string &input_file_path)
bool WritePointCloud(const std::string &filename, const geometry::PointCloud &pointcloud, const cloudViewer::io::WritePointCloudOption &params)
bool ReadPointCloud(const std::string &filename, geometry::PointCloud &pointcloud, const cloudViewer::io::ReadPointCloudOption &params)
Generic file read and write utility for python interface.
Optional parameters to WritePointCloud.
Definition: FileIO.h:77