File: voxel_grid.cpp

package info (click to toggle)
pcl 1.15.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 143,128 kB
  • sloc: cpp: 520,234; xml: 28,792; ansic: 8,212; python: 334; lisp: 93; sh: 49; makefile: 30
file content (72 lines) | stat: -rw-r--r-- 2,114 bytes parent folder | download | duplicates (3)
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
68
69
70
71
72
#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/pcd_io.h> // for PCDReader

#include <benchmark/benchmark.h>

static void
BM_VoxelGrid(benchmark::State& state, const std::string& file)
{
  // Perform setup here
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
  pcl::PCDReader reader;
  reader.read(file, *cloud);

  pcl::VoxelGrid<pcl::PointXYZ> vg;
  vg.setLeafSize(0.01, 0.01, 0.01);
  vg.setInputCloud(cloud);

  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_voxelized(
      new pcl::PointCloud<pcl::PointXYZ>);
  for (auto _ : state) {
    // This code gets timed
    vg.filter(*cloud_voxelized);
  }
}

static void
BM_ApproxVoxelGrid(benchmark::State& state, const std::string& file)
{
  // Perform setup here
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
  pcl::PCDReader reader;
  reader.read(file, *cloud);

  pcl::ApproximateVoxelGrid<pcl::PointXYZ> avg;
  avg.setLeafSize(0.01, 0.01, 0.01);
  avg.setInputCloud(cloud);

  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_voxelized(
      new pcl::PointCloud<pcl::PointXYZ>);
  for (auto _ : state) {
    // This code gets timed
    avg.filter(*cloud_voxelized);
  }
}

int
main(int argc, char** argv)
{
  if (argc < 3) {
    std::cerr
        << "No test files given. Please download `table_scene_mug_stereo_textured.pcd` "
           "and `milk_cartoon_all_small_clorox.pcd`, and pass their paths to the test."
        << std::endl;
    return (-1);
  }

  benchmark::RegisterBenchmark("BM_VoxelGrid_milk", &BM_VoxelGrid, argv[2])
      ->Unit(benchmark::kMillisecond);
  benchmark::RegisterBenchmark(
      "BM_ApproximateVoxelGrid_milk", &BM_ApproxVoxelGrid, argv[2])
      ->Unit(benchmark::kMillisecond);

  benchmark::RegisterBenchmark("BM_VoxelGrid_mug", &BM_VoxelGrid, argv[1])
      ->Unit(benchmark::kMillisecond);
  benchmark::RegisterBenchmark(
      "BM_ApproximateVoxelGrid_mug", &BM_ApproxVoxelGrid, argv[1])
      ->Unit(benchmark::kMillisecond);

  benchmark::Initialize(&argc, argv);
  benchmark::RunSpecifiedBenchmarks();
}