From 549a5e32d482a89202a466c0174a7829fec6dc64 Mon Sep 17 00:00:00 2001 From: Yahor Zabalotski Date: Wed, 30 Oct 2024 14:53:17 +0300 Subject: [PATCH 01/12] Fix middleSplit_ for same points --- include/nanoflann.hpp | 4 +++- tests/test_main.cpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/nanoflann.hpp b/include/nanoflann.hpp index ced16be..05748d9 100644 --- a/include/nanoflann.hpp +++ b/include/nanoflann.hpp @@ -1135,6 +1135,8 @@ class KDTreeBaseClass NodePtr divideTree( Derived& obj, const Offset left, const Offset right, BoundingBox& bbox) { + assert(left < obj.dataset_.kdtree_get_point_count()); + NodePtr node = obj.pool_.template allocate(); // allocate memory const auto dims = (DIM > 0 ? DIM : obj.dim_); @@ -1306,7 +1308,7 @@ class KDTreeBaseClass for (Dimension i = 0; i < dims; ++i) { ElementType span = bbox[i].high - bbox[i].low; - if (span > (1 - EPS) * max_span) + if (span >= (1 - EPS) * max_span) { ElementType min_elem_, max_elem_; computeMinMax(obj, ind, count, i, min_elem_, max_elem_); diff --git a/tests/test_main.cpp b/tests/test_main.cpp index e91abaf..ac27547 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -815,3 +815,22 @@ TEST(kdtree, L2_concurrent_build_vs_L2) L2_concurrent_build_vs_L2_test(100, 7); } } + +TEST(kdtree, same_points) +{ + using num_t = double; + using point_cloud_t = PointCloud; + using kdtree_t = KDTreeSingleIndexAdaptor< + L2_Simple_Adaptor, point_cloud_t, 3 /* dim */>; + + point_cloud_t cloud; + cloud.pts.resize(16); + for (size_t i = 0; i < 16; ++i) + { + cloud.pts[i].x = -1.; + cloud.pts[i].y = 0.; + cloud.pts[i].z = 1.; + } + + kdtree_t idx(3 /*dim*/, cloud); +} From 5bd34615427c80daa6045bdc0d0e855ec9b904b0 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Mon, 4 Nov 2024 22:58:47 +0100 Subject: [PATCH 02/12] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a607b59..fa4b32f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# nanoflann 1.6.2: Released Nov 4, 2024 + - BUG FIX: Fix middleSplit_ for same points by @yzabalotski in https://github.com/jlblancoc/nanoflann/pull/250 + # nanoflann 1.6.1: Released Aug 24, 2024 - Add conan install instructions. - Add multiple thread kdtree build support for KDTreeEigenMatrixAdaptor ([PR #246](https://github.com/jlblancoc/nanoflann/pull/246)) From c4f0cabc5ac42452c19a592f12f1c6b05afee081 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Mon, 4 Nov 2024 22:58:55 +0100 Subject: [PATCH 03/12] Update version in .hpp --- include/nanoflann.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nanoflann.hpp b/include/nanoflann.hpp index 05748d9..58e2f32 100644 --- a/include/nanoflann.hpp +++ b/include/nanoflann.hpp @@ -61,7 +61,7 @@ #include /** Library version: 0xMmP (M=Major,m=minor,P=patch) */ -#define NANOFLANN_VERSION 0x161 +#define NANOFLANN_VERSION 0x162 // Avoid conflicting declaration of min/max macros in Windows headers #if !defined(NOMINMAX) && \ From b7208aa9fbb38bd0beefb48895b0b54a264a7a1e Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Mon, 4 Nov 2024 23:09:11 +0100 Subject: [PATCH 04/12] Fix compiler warnings --- examples/matrix_example.cpp | 2 +- examples/utils.h | 1 + include/nanoflann.hpp | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/matrix_example.cpp b/examples/matrix_example.cpp index 915e583..669adb2 100644 --- a/examples/matrix_example.cpp +++ b/examples/matrix_example.cpp @@ -115,7 +115,7 @@ void kdtree_demo(const size_t nSamples, const size_t dim) << " out_dist_sqr=" << out_dists_sqr[i] << std::endl; } -int main(int argc, char** argv) +int main(int /*argc*/, char** /*argv*/) { // Randomize Seed // srand(static_cast(time(nullptr))); diff --git a/examples/utils.h b/examples/utils.h index 9427838..5c53588 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -182,6 +182,7 @@ struct PointCloud_Orient // "if/else's" are actually solved at compile time. inline T kdtree_get_pt(const size_t idx, const size_t dim = 0) const { + (void)dim; return pts[idx].theta; } diff --git a/include/nanoflann.hpp b/include/nanoflann.hpp index 58e2f32..339a194 100644 --- a/include/nanoflann.hpp +++ b/include/nanoflann.hpp @@ -1808,7 +1808,8 @@ class KDTreeSingleIndexAdaptor // Create a permutable array of indices to the input vectors. Base::size_ = dataset_.kdtree_get_point_count(); if (Base::vAcc_.size() != Base::size_) Base::vAcc_.resize(Base::size_); - for (Size i = 0; i < Base::size_; i++) Base::vAcc_[i] = i; + for (IndexType i = 0; i < static_cast(Base::size_); i++) + Base::vAcc_[i] = i; } void computeBoundingBox(BoundingBox& bbox) From 26071402db0e690f6e009e64080fda653fac2ae6 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Mon, 4 Nov 2024 23:09:52 +0100 Subject: [PATCH 05/12] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa4b32f..205c179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # nanoflann 1.6.2: Released Nov 4, 2024 - BUG FIX: Fix middleSplit_ for same points by @yzabalotski in https://github.com/jlblancoc/nanoflann/pull/250 + - Fix build warnings. # nanoflann 1.6.1: Released Aug 24, 2024 - Add conan install instructions. From a21598464eac5150b48dffdc8da537428eb920d5 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 7 Jan 2025 17:48:51 +0100 Subject: [PATCH 06/12] CMake: Bump minimum version Avoids the deprecation message stating support for version<3.10 will become obsolete --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88b6309..9f80a5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # ---------------------------------------------------------------------------- # Root CMake file for nanoflann # ---------------------------------------------------------------------------- -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) # Extract library version into "NANOFLANN_VERSION" # ----------------------------------------------------- From 0bd754d9f43c840d801a2d4a563f96fa16999d96 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Tue, 7 Jan 2025 23:34:44 +0100 Subject: [PATCH 07/12] bump clang-format version to 14 --- .circleci/clang_git_format/clang_git_format/config.py | 2 +- .github/workflows/check-clang-format.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/clang_git_format/clang_git_format/config.py b/.circleci/clang_git_format/clang_git_format/config.py index c834781..c969020 100644 --- a/.circleci/clang_git_format/clang_git_format/config.py +++ b/.circleci/clang_git_format/clang_git_format/config.py @@ -1,2 +1,2 @@ -PROGNAME = "clang-format-11" +PROGNAME = "clang-format-14" diff --git a/.github/workflows/check-clang-format.yml b/.github/workflows/check-clang-format.yml index 7d478ac..b6ed6aa 100644 --- a/.github/workflows/check-clang-format.yml +++ b/.github/workflows/check-clang-format.yml @@ -31,7 +31,7 @@ jobs: - name: Install Dependencies run: | - sudo apt install clang-format-11 -yq + sudo apt install clang-format-14 -yq pip3 install --user -r .circleci/python_reqs.txt - name: Check code style From 69c9a2b9a664856e2cf99af92b4fc4984ca9b30b Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Tue, 7 Jan 2025 23:36:52 +0100 Subject: [PATCH 08/12] fix clang-format in examples --- examples/dynamic_pointcloud_example.cpp | 2 +- examples/pointcloud_adaptor_example.cpp | 3 ++- examples/pointcloud_example.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/dynamic_pointcloud_example.cpp b/examples/dynamic_pointcloud_example.cpp index ec05c9e..8153e6d 100644 --- a/examples/dynamic_pointcloud_example.cpp +++ b/examples/dynamic_pointcloud_example.cpp @@ -116,7 +116,7 @@ void kdtree_demo(const size_t N) const num_t radiusSqr = 1; std::vector> indices_dists; nanoflann::RadiusResultSet resultSet( - radiusSqr, indices_dists); + radiusSqr, indices_dists); index.findNeighbors(resultSet, query_pt); diff --git a/examples/pointcloud_adaptor_example.cpp b/examples/pointcloud_adaptor_example.cpp index 76cda36..7f15632 100644 --- a/examples/pointcloud_adaptor_example.cpp +++ b/examples/pointcloud_adaptor_example.cpp @@ -101,7 +101,8 @@ void kdtree_demo(const size_t N) dump_mem_usage(); - auto do_knn_search = [](const my_kd_tree_t& index) { + auto do_knn_search = [](const my_kd_tree_t& index) + { // do a knn search const size_t num_results = 1; size_t ret_index; diff --git a/examples/pointcloud_example.cpp b/examples/pointcloud_example.cpp index cfa64f4..9fb8813 100644 --- a/examples/pointcloud_example.cpp +++ b/examples/pointcloud_example.cpp @@ -78,7 +78,7 @@ void kdtree_demo(const size_t N) const num_t squaredRadius = 1; std::vector> indices_dists; nanoflann::RadiusResultSet resultSet( - squaredRadius, indices_dists); + squaredRadius, indices_dists); index.findNeighbors(resultSet, query_pt); From 7b5672e03aa4542aba478cf5ee0414835c058547 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Tue, 7 Jan 2025 23:39:00 +0100 Subject: [PATCH 09/12] copyright year bump; changelog --- CHANGELOG.md | 4 ++++ examples/SO2_adaptor_example.cpp | 2 +- examples/SO3_adaptor_example.cpp | 2 +- examples/dynamic_pointcloud_example.cpp | 2 +- examples/example_with_cmake/pointcloud_example.cpp | 2 +- examples/example_with_pkgconfig/pointcloud_example.cpp | 2 +- .../nanoflann_gui_example_R3/nanoflann_gui_example_R3.cpp | 2 +- .../nanoflann_gui_example_bearings.cpp | 2 +- examples/matrix_example.cpp | 2 +- examples/pointcloud_adaptor_example.cpp | 2 +- examples/pointcloud_custom_metric.cpp | 2 +- examples/pointcloud_custom_resultset.cpp | 2 +- examples/pointcloud_example.cpp | 2 +- examples/pointcloud_kdd_radius.cpp | 2 +- examples/saveload_example.cpp | 2 +- examples/utils.h | 2 +- examples/vector_of_vectors_example.cpp | 2 +- include/nanoflann.hpp | 2 +- tests/test_main.cpp | 4 ++-- 19 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 205c179..ad610e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# nanoflann 1.6.3: Released Jan 7, 2025 + - cmake_required_version bumped to 3.10 + - clang-format version bumped to 14 + # nanoflann 1.6.2: Released Nov 4, 2024 - BUG FIX: Fix middleSplit_ for same points by @yzabalotski in https://github.com/jlblancoc/nanoflann/pull/250 - Fix build warnings. diff --git a/examples/SO2_adaptor_example.cpp b/examples/SO2_adaptor_example.cpp index 6c41d3c..6b45e01 100644 --- a/examples/SO2_adaptor_example.cpp +++ b/examples/SO2_adaptor_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/SO3_adaptor_example.cpp b/examples/SO3_adaptor_example.cpp index 534330e..12b6e5e 100644 --- a/examples/SO3_adaptor_example.cpp +++ b/examples/SO3_adaptor_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/dynamic_pointcloud_example.cpp b/examples/dynamic_pointcloud_example.cpp index 8153e6d..97e8aee 100644 --- a/examples/dynamic_pointcloud_example.cpp +++ b/examples/dynamic_pointcloud_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/example_with_cmake/pointcloud_example.cpp b/examples/example_with_cmake/pointcloud_example.cpp index b0cca59..29325dd 100644 --- a/examples/example_with_cmake/pointcloud_example.cpp +++ b/examples/example_with_cmake/pointcloud_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/example_with_pkgconfig/pointcloud_example.cpp b/examples/example_with_pkgconfig/pointcloud_example.cpp index b0cca59..29325dd 100644 --- a/examples/example_with_pkgconfig/pointcloud_example.cpp +++ b/examples/example_with_pkgconfig/pointcloud_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/examples_gui/nanoflann_gui_example_R3/nanoflann_gui_example_R3.cpp b/examples/examples_gui/nanoflann_gui_example_R3/nanoflann_gui_example_R3.cpp index cf77e9b..860e94f 100644 --- a/examples/examples_gui/nanoflann_gui_example_R3/nanoflann_gui_example_R3.cpp +++ b/examples/examples_gui/nanoflann_gui_example_R3/nanoflann_gui_example_R3.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/examples_gui/nanoflann_gui_example_bearings/nanoflann_gui_example_bearings.cpp b/examples/examples_gui/nanoflann_gui_example_bearings/nanoflann_gui_example_bearings.cpp index 35fe223..8726ae5 100644 --- a/examples/examples_gui/nanoflann_gui_example_bearings/nanoflann_gui_example_bearings.cpp +++ b/examples/examples_gui/nanoflann_gui_example_bearings/nanoflann_gui_example_bearings.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/matrix_example.cpp b/examples/matrix_example.cpp index 669adb2..cbddc7b 100644 --- a/examples/matrix_example.cpp +++ b/examples/matrix_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/pointcloud_adaptor_example.cpp b/examples/pointcloud_adaptor_example.cpp index 7f15632..ace3f77 100644 --- a/examples/pointcloud_adaptor_example.cpp +++ b/examples/pointcloud_adaptor_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/pointcloud_custom_metric.cpp b/examples/pointcloud_custom_metric.cpp index 4eb0f28..6e6db8c 100644 --- a/examples/pointcloud_custom_metric.cpp +++ b/examples/pointcloud_custom_metric.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/pointcloud_custom_resultset.cpp b/examples/pointcloud_custom_resultset.cpp index 1988924..89553ab 100644 --- a/examples/pointcloud_custom_resultset.cpp +++ b/examples/pointcloud_custom_resultset.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/pointcloud_example.cpp b/examples/pointcloud_example.cpp index 9fb8813..1d61e99 100644 --- a/examples/pointcloud_example.cpp +++ b/examples/pointcloud_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/pointcloud_kdd_radius.cpp b/examples/pointcloud_kdd_radius.cpp index e4c34fd..78e760e 100644 --- a/examples/pointcloud_kdd_radius.cpp +++ b/examples/pointcloud_kdd_radius.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/saveload_example.cpp b/examples/saveload_example.cpp index 1d49980..25c5c71 100644 --- a/examples/saveload_example.cpp +++ b/examples/saveload_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/utils.h b/examples/utils.h index 5c53588..44ed5e2 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/examples/vector_of_vectors_example.cpp b/examples/vector_of_vectors_example.cpp index 0636435..56fa98d 100644 --- a/examples/vector_of_vectors_example.cpp +++ b/examples/vector_of_vectors_example.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/include/nanoflann.hpp b/include/nanoflann.hpp index 339a194..03634c0 100644 --- a/include/nanoflann.hpp +++ b/include/nanoflann.hpp @@ -3,7 +3,7 @@ * * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * THE BSD LICENSE diff --git a/tests/test_main.cpp b/tests/test_main.cpp index ac27547..0aa3da0 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * Software License Agreement (BSD License) * - * Copyright 2011-2024 Jose Luis Blanco (joseluisblancoc@gmail.com). + * Copyright 2011-2025 Jose Luis Blanco (joseluisblancoc@gmail.com). * All rights reserved. * * THE BSD LICENSE @@ -821,7 +821,7 @@ TEST(kdtree, same_points) using num_t = double; using point_cloud_t = PointCloud; using kdtree_t = KDTreeSingleIndexAdaptor< - L2_Simple_Adaptor, point_cloud_t, 3 /* dim */>; + L2_Simple_Adaptor, point_cloud_t, 3 /* dim */>; point_cloud_t cloud; cloud.pts.resize(16); From 8a6c5dfe62390e4ada924ee860d2abb400d54e27 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Tue, 7 Jan 2025 23:39:21 +0100 Subject: [PATCH 10/12] version bump in .h --- include/nanoflann.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nanoflann.hpp b/include/nanoflann.hpp index 03634c0..3ac048f 100644 --- a/include/nanoflann.hpp +++ b/include/nanoflann.hpp @@ -61,7 +61,7 @@ #include /** Library version: 0xMmP (M=Major,m=minor,P=patch) */ -#define NANOFLANN_VERSION 0x162 +#define NANOFLANN_VERSION 0x163 // Avoid conflicting declaration of min/max macros in Windows headers #if !defined(NOMINMAX) && \ From 9c84c4c32c2bfa7077cc8873dd3b5bcbb557da90 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Mon, 3 Feb 2025 09:05:56 +0100 Subject: [PATCH 11/12] ResultSets::worstDist(): clarify the meaning of its return value, and made to return the actual worst distance in the found set (only if set is full) --- include/nanoflann.hpp | 20 +++++++++++++++----- tests/test_main.cpp | 24 ++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/include/nanoflann.hpp b/include/nanoflann.hpp index 3ac048f..a88eec0 100644 --- a/include/nanoflann.hpp +++ b/include/nanoflann.hpp @@ -220,8 +220,6 @@ class KNNResultSet indices = indices_; dists = dists_; count = 0; - if (capacity) - dists[capacity - 1] = (std::numeric_limits::max)(); } CountType size() const { return count; } @@ -268,7 +266,13 @@ class KNNResultSet return true; } - DistanceType worstDist() const { return dists[capacity - 1]; } + //! Returns the worst distance among found solutions if the search result is + //! full, or the maximum possible distance, if not full yet. + DistanceType worstDist() const + { + return count < capacity ? std::numeric_limits::max() + : dists[count - 1]; + } void sort() { @@ -357,7 +361,13 @@ class RKNNResultSet return true; } - DistanceType worstDist() const { return dists[capacity - 1]; } + //! Returns the worst distance among found solutions if the search result is + //! full, or the maximum possible distance, if not full yet. + DistanceType worstDist() const + { + return count < capacity ? maximumSearchDistanceSquared + : dists[count - 1]; + } void sort() { @@ -1690,7 +1700,7 @@ class KDTreeSingleIndexAdaptor // fixed or variable-sized container (depending on DIM) distance_vector_t dists; // Fill it with zeros. - auto zero = static_cast(0); + auto zero = static_cast(0); assign(dists, (DIM > 0 ? DIM : Base::dim_), zero); DistanceType dist = this->computeInitialDistances(*this, vec, dists); searchLevel(result, vec, Base::root_node_, dist, dists, epsError); diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 0aa3da0..8dde2f8 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -88,14 +88,17 @@ void L2_vs_L2_simple_test(const size_t N, const size_t num_results) index2.findNeighbors(resultSet, &query_pt[0]); - for (size_t i = 0; i < num_results; i++) + if (N >= num_results) { EXPECT_EQ(resultSet.size(), num_results); } + else { EXPECT_EQ(resultSet.size(), N); } + + for (size_t i = 0; i < resultSet.size(); i++) { EXPECT_EQ(ret_index1[i], ret_index[i]); EXPECT_DOUBLE_EQ(out_dist_sqr1[i], out_dist_sqr[i]); } // Ensure results are sorted: num_t lastDist = -1; - for (size_t i = 0; i < out_dist_sqr.size(); i++) + for (size_t i = 0; i < resultSet.size(); i++) { const num_t newDist = out_dist_sqr[i]; EXPECT_GE(newDist, lastDist); @@ -180,6 +183,12 @@ void L2_vs_bruteforce_test( const auto nFound = resultSet.size(); + EXPECT_TRUE(nFound > 0); + if (resultSet.full()) + { + EXPECT_EQ(resultSet.worstDist(), out_dists_sqr.at(nFound - 1)); + } + // Brute force neighbors: std::multimap bf_nn; { @@ -252,6 +261,11 @@ void rknn_L2_vs_bruteforce_test( const auto nFound = resultSet.size(); + if (resultSet.full()) + { + EXPECT_EQ(resultSet.worstDist(), out_dists_sqr.at(nFound - 1)); + } + // Brute force neighbors: std::multimap bf_nn; { @@ -596,6 +610,8 @@ TEST(kdtree, L2_vs_L2_simple) { for (int nResults = 1; nResults < 10; nResults++) { + L2_vs_L2_simple_test(5, nResults); + L2_vs_L2_simple_test(100, nResults); L2_vs_L2_simple_test(100, nResults); } @@ -637,6 +653,8 @@ TEST(kdtree, L2_vs_bruteforce) { for (int i = 0; i < 500; i++) { + L2_vs_bruteforce_test(10, 2, knn); + L2_vs_bruteforce_test(100, 2, knn); L2_vs_bruteforce_test(100, 3, knn); L2_vs_bruteforce_test(100, 7, knn); @@ -674,6 +692,8 @@ TEST(kdtree, SO3_vs_bruteforce) srand(static_cast(time(nullptr))); for (int i = 0; i < 10; i++) { + SO3_vs_bruteforce_test(5); + SO3_vs_bruteforce_test(100); SO3_vs_bruteforce_test(100); SO3_vs_bruteforce_test(100); From 518b2b97e484715d757c2960aefb26a25d0b7aab Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Mon, 3 Feb 2025 10:02:36 +0100 Subject: [PATCH 12/12] Changelog and version in .h for 1.7.0 --- CHANGELOG.md | 3 +++ include/nanoflann.hpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad610e6..6edeede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# nanoflann 1.7.0: Released Feb 3, 2025 + - ResultSets::worstDist(): clarify the meaning of its return value, and made to return the actual worst distance in the found set (only if set is full) + # nanoflann 1.6.3: Released Jan 7, 2025 - cmake_required_version bumped to 3.10 - clang-format version bumped to 14 diff --git a/include/nanoflann.hpp b/include/nanoflann.hpp index a88eec0..503f9fa 100644 --- a/include/nanoflann.hpp +++ b/include/nanoflann.hpp @@ -61,7 +61,7 @@ #include /** Library version: 0xMmP (M=Major,m=minor,P=patch) */ -#define NANOFLANN_VERSION 0x163 +#define NANOFLANN_VERSION 0x170 // Avoid conflicting declaration of min/max macros in Windows headers #if !defined(NOMINMAX) && \