|
| 1 | +#include <pcl/features/normal_3d_omp.h> |
| 2 | +#include <pcl/features/shot_omp.h> |
| 3 | +#include <pcl/io/pcd_io.h> |
| 4 | +#include <pcl/point_cloud.h> |
| 5 | +#include <pcl/point_types.h> |
| 6 | + |
| 7 | +#include <benchmark/benchmark.h> |
| 8 | + |
| 9 | +static void |
| 10 | +BM_SHOT352(benchmark::State& state, const std::string& file) |
| 11 | +{ |
| 12 | + pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); |
| 13 | + pcl::PCDReader reader; |
| 14 | + reader.read(file, *cloud); |
| 15 | + |
| 16 | + pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> ne; |
| 17 | + ne.setInputCloud(cloud); |
| 18 | + ne.setKSearch(10); |
| 19 | + pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>); |
| 20 | + ne.compute(*normals); |
| 21 | + |
| 22 | + pcl::SHOTEstimation<pcl::PointXYZ, pcl::Normal, pcl::SHOT352> shot; |
| 23 | + shot.setInputCloud(cloud); |
| 24 | + shot.setInputNormals(normals); |
| 25 | + shot.setRadiusSearch(0.04); |
| 26 | + |
| 27 | + pcl::PointCloud<pcl::SHOT352>::Ptr output(new pcl::PointCloud<pcl::SHOT352>); |
| 28 | + for (auto _ : state) { |
| 29 | + shot.compute(*output); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +static void |
| 34 | +BM_SHOT352_OMP(benchmark::State& state, const std::string& file) |
| 35 | +{ |
| 36 | + pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); |
| 37 | + pcl::PCDReader reader; |
| 38 | + reader.read(file, *cloud); |
| 39 | + |
| 40 | + pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> ne; |
| 41 | + ne.setInputCloud(cloud); |
| 42 | + ne.setKSearch(10); |
| 43 | + pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>); |
| 44 | + ne.compute(*normals); |
| 45 | + |
| 46 | + pcl::SHOTEstimationOMP<pcl::PointXYZ, pcl::Normal, pcl::SHOT352> shot( |
| 47 | + 0, state.range(0) // |
| 48 | + ); |
| 49 | + shot.setInputCloud(cloud); |
| 50 | + shot.setInputNormals(normals); |
| 51 | + shot.setRadiusSearch(0.04); |
| 52 | + |
| 53 | + pcl::PointCloud<pcl::SHOT352>::Ptr output(new pcl::PointCloud<pcl::SHOT352>); |
| 54 | + for (auto _ : state) { |
| 55 | + shot.compute(*output); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +static void |
| 60 | +BM_SHOT1344(benchmark::State& state, const std::string& file) |
| 61 | +{ |
| 62 | + pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz(new pcl::PointCloud<pcl::PointXYZ>); |
| 63 | + pcl::PCDReader reader; |
| 64 | + reader.read(file, *cloud_xyz); |
| 65 | + |
| 66 | + pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> ne; |
| 67 | + ne.setInputCloud(cloud_xyz); |
| 68 | + ne.setKSearch(10); |
| 69 | + pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>); |
| 70 | + ne.compute(*normals); |
| 71 | + |
| 72 | + pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_rgba( |
| 73 | + new pcl::PointCloud<pcl::PointXYZRGBA>); |
| 74 | + |
| 75 | + for (int i = 0; i < static_cast<int>(cloud_xyz->size()); ++i) { |
| 76 | + pcl::PointXYZRGBA p; |
| 77 | + p.x = (*cloud_xyz)[i].x; |
| 78 | + p.y = (*cloud_xyz)[i].y; |
| 79 | + p.z = (*cloud_xyz)[i].z; |
| 80 | + |
| 81 | + p.rgba = ((i % 255) << 16) + (((255 - i) % 255) << 8) + ((i * 37) % 255); |
| 82 | + cloud_rgba->push_back(p); |
| 83 | + } |
| 84 | + |
| 85 | + pcl::SHOTColorEstimation<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT1344> shot(true, |
| 86 | + true); |
| 87 | + shot.setInputCloud(cloud_rgba); |
| 88 | + shot.setInputNormals(normals); |
| 89 | + shot.setRadiusSearch(0.04); |
| 90 | + |
| 91 | + pcl::PointCloud<pcl::SHOT1344>::Ptr output(new pcl::PointCloud<pcl::SHOT1344>); |
| 92 | + for (auto _ : state) { |
| 93 | + shot.compute(*output); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +static void |
| 98 | +BM_SHOT1344_OMP(benchmark::State& state, const std::string& file) |
| 99 | +{ |
| 100 | + pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz(new pcl::PointCloud<pcl::PointXYZ>); |
| 101 | + pcl::PCDReader reader; |
| 102 | + reader.read(file, *cloud_xyz); |
| 103 | + |
| 104 | + pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> ne; |
| 105 | + ne.setInputCloud(cloud_xyz); |
| 106 | + ne.setKSearch(10); |
| 107 | + pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>); |
| 108 | + ne.compute(*normals); |
| 109 | + |
| 110 | + pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_rgba( |
| 111 | + new pcl::PointCloud<pcl::PointXYZRGBA>); |
| 112 | + |
| 113 | + for (int i = 0; i < static_cast<int>(cloud_xyz->size()); ++i) { |
| 114 | + pcl::PointXYZRGBA p; |
| 115 | + p.x = (*cloud_xyz)[i].x; |
| 116 | + p.y = (*cloud_xyz)[i].y; |
| 117 | + p.z = (*cloud_xyz)[i].z; |
| 118 | + |
| 119 | + p.rgba = ((i % 255) << 16) + (((255 - i) % 255) << 8) + ((i * 37) % 255); |
| 120 | + cloud_rgba->push_back(p); |
| 121 | + } |
| 122 | + |
| 123 | + pcl::SHOTColorEstimationOMP<pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT1344> shot( |
| 124 | + true, true, 0, state.range(0)); |
| 125 | + shot.setInputCloud(cloud_rgba); |
| 126 | + shot.setInputNormals(normals); |
| 127 | + shot.setRadiusSearch(0.04); |
| 128 | + |
| 129 | + pcl::PointCloud<pcl::SHOT1344>::Ptr output(new pcl::PointCloud<pcl::SHOT1344>); |
| 130 | + for (auto _ : state) { |
| 131 | + shot.compute(*output); |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +int |
| 136 | +main(int argc, char** argv) |
| 137 | +{ |
| 138 | + if (argc < 2) { |
| 139 | + std::cerr << "No test files given. Please provide a PCD file paths for SHOT352 " |
| 140 | + "and SHOT1344 benchmarks." |
| 141 | + << std::endl; |
| 142 | + return (-1); |
| 143 | + } |
| 144 | + |
| 145 | + constexpr int runs = 100; |
| 146 | + |
| 147 | + benchmark::RegisterBenchmark("BM_SHOT352", &BM_SHOT352, argv[1]) |
| 148 | + ->Unit(benchmark::kMillisecond) |
| 149 | + ->Iterations(runs); |
| 150 | + benchmark::RegisterBenchmark("BM_SHOT352_OMP", &BM_SHOT352_OMP, argv[1]) |
| 151 | + ->Arg(64) |
| 152 | + ->Arg(128) |
| 153 | + ->Arg(256) |
| 154 | + ->Unit(benchmark::kMillisecond) |
| 155 | + ->Iterations(runs); |
| 156 | + |
| 157 | + benchmark::RegisterBenchmark("BM_SHOT1344", &BM_SHOT1344, argv[1]) |
| 158 | + ->Unit(benchmark::kMillisecond) |
| 159 | + ->Iterations(runs); |
| 160 | + benchmark::RegisterBenchmark("BM_SHOT1344_OMP", &BM_SHOT1344_OMP, argv[1]) |
| 161 | + ->Arg(64) |
| 162 | + ->Arg(128) |
| 163 | + ->Arg(256) |
| 164 | + ->Unit(benchmark::kMillisecond) |
| 165 | + ->Iterations(runs); |
| 166 | + |
| 167 | + benchmark::Initialize(&argc, argv); |
| 168 | + benchmark::RunSpecifiedBenchmarks(); |
| 169 | +} |
0 commit comments