From a1c1ef17c7eb4b1fc203e42e938821d92ff6a70c Mon Sep 17 00:00:00 2001 From: Dominic Koepke Date: Fri, 14 Apr 2023 14:16:44 +0200 Subject: [PATCH 1/4] mark container emplacement as critical section --- cpp/open3d/geometry/ISSKeypoints.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/open3d/geometry/ISSKeypoints.cpp b/cpp/open3d/geometry/ISSKeypoints.cpp index 39f8602a737..940234f8976 100644 --- a/cpp/open3d/geometry/ISSKeypoints.cpp +++ b/cpp/open3d/geometry/ISSKeypoints.cpp @@ -118,6 +118,7 @@ std::shared_ptr ComputeISSKeypoints( if (nb_neighbors >= min_neighbors && IsLocalMaxima(i, nn_indices, third_eigen_values)) { +#pragma omp critical kp_indices.emplace_back(i); } } From 2f5f39ea9747208a8036eba4e57fba68cc526975 Mon Sep 17 00:00:00 2001 From: Dominic Koepke Date: Fri, 14 Apr 2023 14:42:26 +0200 Subject: [PATCH 2/4] fix: explicitly check for more than 2 found indices --- cpp/open3d/geometry/ISSKeypoints.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cpp/open3d/geometry/ISSKeypoints.cpp b/cpp/open3d/geometry/ISSKeypoints.cpp index 940234f8976..92222a970bf 100644 --- a/cpp/open3d/geometry/ISSKeypoints.cpp +++ b/cpp/open3d/geometry/ISSKeypoints.cpp @@ -11,8 +11,10 @@ #include #include +#include #include #include +#include #include #include @@ -41,15 +43,20 @@ double ComputeModelResolution(const std::vector& points, const geometry::KDTreeFlann& kdtree) { std::vector indices(2); std::vector distances(2); - double resolution = 0.0; + const double resolution = std::accumulate( + points.begin(), + points.end(), + 0., + [&](double state, const Eigen::Vector3d& point) { + if (kdtree.SearchKNN(point, 2, indices, distances) >= 2) { + state += std::sqrt(distances[1]); + } - for (const auto& point : points) { - if (kdtree.SearchKNN(point, 2, indices, distances) != 0) { - resolution += std::sqrt(distances[1]); + return state; } - } - resolution /= points.size(); - return resolution; + ); + + return resolution / static_cast(points.size()); } } // namespace From 85d39deacd76669e3cd99efa3ae8775e2a05fb61 Mon Sep 17 00:00:00 2001 From: Dominic Koepke Date: Fri, 14 Apr 2023 14:47:00 +0200 Subject: [PATCH 3/4] refactor: utilize none_of algorithm in IsLocalMaxima --- cpp/open3d/geometry/ISSKeypoints.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cpp/open3d/geometry/ISSKeypoints.cpp b/cpp/open3d/geometry/ISSKeypoints.cpp index 92222a970bf..e17839edeaf 100644 --- a/cpp/open3d/geometry/ISSKeypoints.cpp +++ b/cpp/open3d/geometry/ISSKeypoints.cpp @@ -31,12 +31,13 @@ namespace { bool IsLocalMaxima(int query_idx, const std::vector& indices, const std::vector& third_eigen_values) { - for (const auto& idx : indices) { - if (third_eigen_values[query_idx] < third_eigen_values[idx]) { - return false; + return std::none_of( + indices.begin(), + indices.end(), + [&third_eigen_values, value = third_eigen_values[query_idx]](const int idx) { + return value < third_eigen_values[idx]; } - } - return true; + ); } double ComputeModelResolution(const std::vector& points, @@ -51,7 +52,6 @@ double ComputeModelResolution(const std::vector& points, if (kdtree.SearchKNN(point, 2, indices, distances) >= 2) { state += std::sqrt(distances[1]); } - return state; } ); From 219dfbc5bf2e06fb9900edfae73aad43d6d8af85 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Fri, 30 Jun 2023 10:54:34 +0200 Subject: [PATCH 4/4] apply style --- cpp/open3d/geometry/ISSKeypoints.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/cpp/open3d/geometry/ISSKeypoints.cpp b/cpp/open3d/geometry/ISSKeypoints.cpp index e17839edeaf..f47abae1ad2 100644 --- a/cpp/open3d/geometry/ISSKeypoints.cpp +++ b/cpp/open3d/geometry/ISSKeypoints.cpp @@ -32,12 +32,9 @@ bool IsLocalMaxima(int query_idx, const std::vector& indices, const std::vector& third_eigen_values) { return std::none_of( - indices.begin(), - indices.end(), - [&third_eigen_values, value = third_eigen_values[query_idx]](const int idx) { - return value < third_eigen_values[idx]; - } - ); + indices.begin(), indices.end(), + [&third_eigen_values, value = third_eigen_values[query_idx]]( + const int idx) { return value < third_eigen_values[idx]; }); } double ComputeModelResolution(const std::vector& points, @@ -45,16 +42,13 @@ double ComputeModelResolution(const std::vector& points, std::vector indices(2); std::vector distances(2); const double resolution = std::accumulate( - points.begin(), - points.end(), - 0., - [&](double state, const Eigen::Vector3d& point) { - if (kdtree.SearchKNN(point, 2, indices, distances) >= 2) { - state += std::sqrt(distances[1]); - } - return state; - } - ); + points.begin(), points.end(), 0., + [&](double state, const Eigen::Vector3d& point) { + if (kdtree.SearchKNN(point, 2, indices, distances) >= 2) { + state += std::sqrt(distances[1]); + } + return state; + }); return resolution / static_cast(points.size()); }