Skip to content

Commit 564cfcc

Browse files
committed
Update to nanoflann 1.6.1
- Add threading in kd three construction. It should improve runtime most of the time.
1 parent 0d7b74f commit 564cfcc

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

include/nn_search.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static std::pair<nb::ndarray<nb::numpy, uint32_t, nb::ndim<2>>, nb::ndarray<nb::
3636

3737
if (knn > data.rows()) { throw std::invalid_argument("knn size is greater than the data point cloud size"); }
3838

39-
kd_tree_t kd_tree(3, data, 10);
39+
kd_tree_t kd_tree(3, data, 10, 0);
4040
const Eigen::Index n_points = query.rows();
4141
uint32_t* indices = new uint32_t[knn * n_points];
4242
nb::capsule owner_indices(indices, [](void* p) noexcept { delete[] (uint32_t*)p; });
@@ -94,7 +94,7 @@ static std::pair<nb::ndarray<nb::numpy, int32_t, nb::ndim<2>>, nb::ndarray<nb::n
9494
throw std::invalid_argument("max knn size is greater than the data point cloud size");
9595
}
9696

97-
kd_tree_t kd_tree(3, data, 10);
97+
kd_tree_t kd_tree(3, data, 10, 0);
9898
const real_t sq_search_radius = search_radius * search_radius;
9999

100100
const Eigen::Index n_points = query.rows();

include/pgeof.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <nanobind/nanobind.h>
55
#include <nanobind/ndarray.h>
66

7-
87
#include <algorithm>
98
#include <cmath>
109
#include <cstdio>
@@ -74,9 +73,10 @@ static inline void flush() { std::cout << std::endl; };
7473
* @return the geometric features associated with each point's neighborhood in a (num_points, features_count) nd::array.
7574
*/
7675
template <typename real_t = float, const size_t feature_count = 11>
77-
static nb::ndarray<nb::numpy, real_t, nb::shape<-1, static_cast<nb::ssize_t>(feature_count)>> compute_geometric_features(
78-
RefCloud<real_t> xyz, nb::ndarray<const uint32_t, nb::ndim<1>> nn, nb::ndarray<const uint32_t, nb::ndim<1>> nn_ptr,
79-
const size_t k_min, const bool verbose)
76+
static nb::ndarray<nb::numpy, real_t, nb::shape<-1, static_cast<nb::ssize_t>(feature_count)>>
77+
compute_geometric_features(
78+
RefCloud<real_t> xyz, nb::ndarray<const uint32_t, nb::ndim<1>> nn,
79+
nb::ndarray<const uint32_t, nb::ndim<1>> nn_ptr, const size_t k_min, const bool verbose)
8080
{
8181
if (k_min < 1) { throw std::invalid_argument("k_min should be > 1"); }
8282
// Each point can be treated in parallel
@@ -330,7 +330,7 @@ static nb::ndarray<nb::numpy, real_t, nb::shape<-1, -1>> compute_geometric_featu
330330
using kd_tree_t = nanoflann::KDTreeEigenMatrixAdaptor<RefCloud<real_t>, 3, nanoflann::metric_L2_Simple>;
331331
// TODO: where knn < num of points
332332

333-
kd_tree_t kd_tree(3, xyz, 10);
333+
kd_tree_t kd_tree(3, xyz, 10, 0);
334334
const size_t feature_count = selected_features.size();
335335
const Eigen::Index n_points = xyz.rows();
336336
real_t sq_search_radius = search_radius * search_radius;

src/pgeof_ext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
#include <nanobind/nanobind.h>
33
#include <nanobind/ndarray.h>
4-
#include <nanobind/stl/pair.h>
54
#include <nanobind/stl/vector.h>
65

76
#include "nn_search.hpp"
@@ -176,4 +175,4 @@ NB_MODULE(pgeof_ext, m)
176175
:param selected_features: List of selected features. See EFeatureID
177176
:return: Geometric features associated with each point's neighborhood in a (num_points, features_count) numpy array.
178177
)");
179-
}
178+
}

0 commit comments

Comments
 (0)