ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
KDTreeFlann.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 
8 #include <Logging.h>
9 #include <benchmark/benchmark.h>
10 #include <ecvKDTreeFlann.h>
11 #include <ecvMesh.h>
12 #include <ecvPointCloud.h>
13 
14 namespace cloudViewer {
15 namespace benchmarks {
16 
18  constexpr static double step = .139;
19  ccPointCloud pc_;
20  geometry::KDTreeFlann kdtree_;
21 
22  int pos_ = 0;
23  int size_ = 0;
24 
25 public:
26  void setup(int size) {
27  if (this->size_ == size) return;
28  utility::LogInfo("setup KDTree size={:d}", size);
29  pc_.clear();
30 
31  this->size_ = size;
32  for (int i = 0; i < size; ++i) {
33  pc_.addEigenPoint({double(i) * step, 0., 0.});
34  }
35 
36  kdtree_.SetGeometry(pc_); // eigen
37  pos_ = size / 2;
38  }
39 
40  void search(int radiusInSteps) {
41  pos_ += 2 * radiusInSteps;
42  if (pos_ >= size_ - radiusInSteps) {
43  pos_ = radiusInSteps;
44  }
45 
46  Eigen::Vector3d query = {(pos_ + 0.1) * step, 0., 0.};
47  double radius = radiusInSteps * step;
48  std::vector<int> indices;
49  std::vector<double> distance2;
50 
51  int result = kdtree_.SearchRadius<Eigen::Vector3d>(query, radius,
52  indices, distance2);
53  if (result != radiusInSteps * 2) {
55  "error! size={:d} radiusInSteps={:d} pos={:d} num={:d}",
56  size_, radiusInSteps, pos_, result);
57  }
58  }
59 };
60 // reuse the same instance so we don't recreate the kdtree every time
62 
63 static void BM_TestKDTreeLine0(benchmark::State& state) {
64  // state.range(n) are arguments that are passed to us
65  int radius = state.range(0);
66  int size = state.range(1);
68  for (auto _ : state) {
69  testKDTreeLine0.search(radius);
70  }
71 }
72 // a few specific sized tests, each ->Args({params}) will be a test
73 BENCHMARK(BM_TestKDTreeLine0)->Args({1 << 5, 1 << 10})->Args({1 << 9, 1 << 11});
74 // let benchmark vary parameters for us; run each test only for 0.1sec so it
75 // doesn't take too long
77  ->MinTime(0.1)
78  ->Ranges({{1 << 0, 1 << 14}, {1 << 16, 1 << 22}});
79 
80 } // namespace benchmarks
81 } // namespace cloudViewer
int size
int64_t size_
Definition: FilePLY.cpp:37
core::Tensor result
Definition: VtkUtils.cpp:76
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void clear() override
Clears the entity from all its points and features.
void addEigenPoint(const Eigen::Vector3d &point)
KDTree with FLANN for nearest neighbor search.
int SearchRadius(const T &query, double radius, std::vector< int > &indices, std::vector< double > &distance2) const
bool SetGeometry(const ccHObject &geometry)
#define LogInfo(...)
Definition: Logging.h:81
#define LogError(...)
Definition: Logging.h:60
BENCHMARK(BM_TestKDTreeLine0) -> Args({1<< 5, 1<< 10}) ->Args({1<< 9, 1<< 11})
static void BM_TestKDTreeLine0(benchmark::State &state)
Definition: KDTreeFlann.cpp:63
TestKDTreeLine0 testKDTreeLine0
Definition: KDTreeFlann.cpp:61
Generic file read and write utility for python interface.