From 8b645cc1a00b62c79649f5fa6e043a9f6753c876 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Mon, 20 Dec 2021 05:34:15 +0900 Subject: [PATCH 01/11] Add `makeNonTrivial` helper in `Search` --- search/include/pcl/search/impl/search.hpp | 125 +++++++++++++++++++--- search/include/pcl/search/search.h | 95 +++++++++++++++- test/search/test_search.cpp | 62 +++++++++++ 3 files changed, 268 insertions(+), 14 deletions(-) diff --git a/search/include/pcl/search/impl/search.hpp b/search/include/pcl/search/impl/search.hpp index aa8d229fd89..e4f4ba3754c 100644 --- a/search/include/pcl/search/impl/search.hpp +++ b/search/include/pcl/search/impl/search.hpp @@ -40,9 +40,11 @@ #include +namespace pcl{ +namespace search { /////////////////////////////////////////////////////////////////////////////////////////// template -pcl::search::Search::Search (const std::string& name, bool sorted) +Search::Search (const std::string& name, bool sorted) : input_ () , sorted_results_ (sorted) , name_ (name) @@ -51,28 +53,28 @@ pcl::search::Search::Search (const std::string& name, bool sorted) /////////////////////////////////////////////////////////////////////////////////////////// template const std::string& -pcl::search::Search::getName () const +Search::getName () const { return (name_); } /////////////////////////////////////////////////////////////////////////////////////////// template void -pcl::search::Search::setSortedResults (bool sorted) +Search::setSortedResults (bool sorted) { sorted_results_ = sorted; } /////////////////////////////////////////////////////////////////////////////////////////// template bool -pcl::search::Search::getSortedResults () +Search::getSortedResults () const { return (sorted_results_); } /////////////////////////////////////////////////////////////////////////////////////////// template void -pcl::search::Search::setInputCloud ( +Search::setInputCloud ( const PointCloudConstPtr& cloud, const IndicesConstPtr &indices) { input_ = cloud; @@ -82,7 +84,7 @@ pcl::search::Search::setInputCloud ( /////////////////////////////////////////////////////////////////////////////////////////// template int -pcl::search::Search::nearestKSearch ( +Search::nearestKSearch ( const PointCloud &cloud, index_t index, int k, Indices &k_indices, std::vector &k_sqr_distances) const { @@ -92,7 +94,7 @@ pcl::search::Search::nearestKSearch ( /////////////////////////////////////////////////////////////////////////////////////////// template int -pcl::search::Search::nearestKSearch ( +Search::nearestKSearch ( index_t index, int k, Indices &k_indices, std::vector &k_sqr_distances) const @@ -110,7 +112,7 @@ pcl::search::Search::nearestKSearch ( /////////////////////////////////////////////////////////////////////////////////////////// template void -pcl::search::Search::nearestKSearch ( +Search::nearestKSearch ( const PointCloud& cloud, const Indices& indices, int k, std::vector& k_indices, std::vector< std::vector >& k_sqr_distances) const @@ -133,7 +135,7 @@ pcl::search::Search::nearestKSearch ( /////////////////////////////////////////////////////////////////////////////////////////// template int -pcl::search::Search::radiusSearch ( +Search::radiusSearch ( const PointCloud &cloud, index_t index, double radius, Indices &k_indices, std::vector &k_sqr_distances, unsigned int max_nn) const @@ -144,7 +146,7 @@ pcl::search::Search::radiusSearch ( /////////////////////////////////////////////////////////////////////////////////////////// template int -pcl::search::Search::radiusSearch ( +Search::radiusSearch ( index_t index, double radius, Indices &k_indices, std::vector &k_sqr_distances, unsigned int max_nn ) const { @@ -159,7 +161,7 @@ pcl::search::Search::radiusSearch ( /////////////////////////////////////////////////////////////////////////////////////////// template void -pcl::search::Search::radiusSearch ( +Search::radiusSearch ( const PointCloud& cloud, const Indices& indices, double radius, @@ -185,7 +187,7 @@ pcl::search::Search::radiusSearch ( /////////////////////////////////////////////////////////////////////////////////////////// template void -pcl::search::Search::sortResults ( +Search::sortResults ( Indices& indices, std::vector& distances) const { Indices order (indices.size ()); @@ -205,6 +207,105 @@ pcl::search::Search::sortResults ( sort (distances.begin (), distances.end ()); } +template +std::size_t +Search::makeNonTrivial(Indices& k_indices, + std::vector& k_sqr_distances) const +{ + assert(k_indices.size() == k_sqr_distances.size()); + if (k_indices.empty()) { + return 0; + } + + if (getSortedResults()) { + std::size_t num_zero_elements = 0; + // distances are sorted, so if we encounter a non-zero, we can bail early + for (const auto& distance : k_sqr_distances) { + if (distance) { + break; + } + ++num_zero_elements; + } + // We need to remove `num_zero_elements` initial elements + k_indices.erase(k_indices.begin(), k_indices.begin() + num_zero_elements); + k_sqr_distances.erase(k_sqr_distances.begin(), + k_sqr_distances.begin() + num_zero_elements); + } + else { + const auto zero_distance_it = + std::find(k_sqr_distances.begin(), k_sqr_distances.end(), 0); + const auto zero_distance_idx = + std::distance(k_sqr_distances.begin(), zero_distance_it); + // From zero_distance_idx, we start removing elements + std::size_t last_good_idx = zero_distance_idx - 1; + for (std::size_t i = zero_distance_idx + 1; i < k_sqr_distances.size(); ++i) { + if (k_sqr_distances[i] == 0) { + continue; + } + ++last_good_idx; + k_sqr_distances[last_good_idx] = k_sqr_distances[i]; + k_indices[last_good_idx] = k_indices[i]; + } + // We need to remove elements after `last_good_idx` + const auto new_end = last_good_idx + 1; + k_indices.erase(k_indices.begin() + new_end, k_indices.end()); + k_sqr_distances.erase(k_sqr_distances.begin() + new_end, k_sqr_distances.end()); + } + assert(k_indices.size() == k_sqr_distances.size()); + return k_indices.size(); +} + +template +std::size_t +Search::makeNonTrivial(index_t index, + Indices& k_indices, + std::vector& k_sqr_distances) const +{ + assert(k_indices.size() == k_sqr_distances.size()); + if (k_indices.empty()) { + return 0; + } + + if (getSortedResults()) { + std::size_t same_idx_elements = 0; + // distances are sorted, so if we encounter a non-zero, we can bail early + for (const auto& idx : k_indices) { + if (idx == index) { + break; + } + ++same_idx_elements; + } + // We need to remove `same_idx_elements` initial elements + k_indices.erase(k_indices.begin(), k_indices.begin() + same_idx_elements); + k_sqr_distances.erase(k_sqr_distances.begin(), + k_sqr_distances.begin() + same_idx_elements); + } + else { + const auto same_idx_it = + std::find(k_indices.begin(), k_indices.end(), index); + const auto same_idx = std::distance(k_indices.begin(), same_idx_it); + // From same_idx, we start removing elements + std::size_t last_good_idx = same_idx - 1; + for (std::size_t i = same_idx + 1; i < k_indices.size(); ++i) { + if (k_indices[i] == index) { + continue; + } + ++last_good_idx; + k_sqr_distances[last_good_idx] = k_sqr_distances[i]; + k_indices[last_good_idx] = k_indices[i]; + } + // We need to remove elements after `last_good_idx` + const auto new_end = last_good_idx + 1; + k_indices.erase(k_indices.begin() + new_end, k_indices.end()); + k_sqr_distances.erase(k_sqr_distances.begin() + new_end, k_sqr_distances.end()); + } + + assert(k_indices.size() == k_sqr_distances.size()); + return k_indices.size(); +} +} // namespace search +} // namespace pcl + #define PCL_INSTANTIATE_Search(T) template class PCL_EXPORTS pcl::search::Search; #endif //#ifndef _PCL_SEARCH_SEARCH_IMPL_HPP_ diff --git a/search/include/pcl/search/search.h b/search/include/pcl/search/search.h index 201b92568a9..6d92989e1d5 100644 --- a/search/include/pcl/search/search.h +++ b/search/include/pcl/search/search.h @@ -109,7 +109,7 @@ namespace pcl * Otherwise the results may be returned in any order. */ virtual bool - getSortedResults (); + getSortedResults () const; /** \brief Pass the input dataset that the search will be performed on. @@ -396,6 +396,97 @@ namespace pcl } } + /** + * \brief Removes indices and sqr distances, where sqr_distance == 0 + * \param k_indices Indices returned from \a nearestKSearch{,T} or \a + * radiusSearch{,T} + * \param k_sqr_distances Distances returned from \a nearestKSearch{,T} or \a + * radiusSearch{,T} + * \return std::size_t number of non trivial neighbors found + * \details Example usage: + * \code {.cpp} + * // First populate the two vectors + * nearestKSearch(point, k + 1, k_indices, k_sqr_distances); + * const auto num_neighbors = makeNonTrivial(k_indices, k_sqr_distances); + * \endcode + */ + std::size_t + makeNonTrivial(Indices& k_indices, std::vector& k_sqr_distances) const; + + /** + * \brief Removes indices and sqr distances, where sqr_distance == 0 + * \param k_indices Indices returned from \a nearestKSearch{,T} or \a + * radiusSearch{,T}, k_indices[i] corresponds to the neighbors of the query + * point i + * \param k_sqr_distances Distances returned from \a nearestKSearch{,T} or \a + * radiusSearch{,T}, k_sqr_distances[i] corresponds to the neighbors of the + * query point i + * \details Example usage: + * \code {.cpp} + * // First populate the two vectors + * nearestKSearch(point, k + 1, k_indices, k_sqr_distances); + * makeNonTrivial(k_indices, k_sqr_distances); + * \endcode + */ + void + makeNonTrivial(std::vector& k_indices, + std::vector>& k_sqr_distances) const + { + assert(k_indices.size() == k_sqr_distances.size ()); + for (std::size_t i = 0; i < k_indices.size(); ++i) { + makeNonTrivial(k_indices[i], k_sqr_distances[i]); + } + } + + /** + * \brief Removes indices and sqr distances, where k_indices[i] == index + * \param[in] index The index used in a previous search call + * \param k_indices Indices returned from \a nearestKSearch{,T} or \a + * radiusSearch{,T} + * \param k_sqr_distances Distances returned from \a nearestKSearch{,T} or \a + * radiusSearch{,T} + * \return std::size_t number of non trivial neighbors found + * \details Example usage: + * \code {.cpp} + * // First populate the two vectors + * nearestKSearch(point, k + 1, k_indices, k_sqr_distances); + * const auto num_neighbors = makeNonTrivial(k_indices, k_sqr_distances); + * \endcode + */ + std::size_t + makeNonTrivial(index_t index, + Indices& k_indices, + std::vector& k_sqr_distances) const; + + /** + * \brief Removes indices and sqr distances, where k_indices[i][j] == indices[i] + * \param[in] indices a vector of point cloud indices to query for nearest neighbors + * \param k_indices Indices returned from \a nearestKSearch{,T} or \a + * radiusSearch{,T}, k_indices[i] corresponds to the neighbors of the query + * point i + * \param k_sqr_distances Distances returned from \a nearestKSearch{,T} or \a + * radiusSearch{,T}, k_sqr_distances[i] corresponds to the neighbors of the + * query point i + * \details Example usage: + * \code {.cpp} + * // First populate the two vectors + * nearestKSearch(point, k + 1, k_indices, k_sqr_distances); + * makeNonTrivial(k_indices, k_sqr_distances); + * \endcode + */ + void + makeNonTrivial(const Indices& indices, + std::vector& k_indices, + std::vector>& k_sqr_distances) const + { + assert(indices.size() == k_indices.size()); + assert(k_indices.size() == k_sqr_distances.size()); + + for (std::size_t i = 0; i < k_indices.size(); ++i) { + makeNonTrivial(indices[i], k_indices[i], k_sqr_distances[i]); + } + } + protected: void sortResults (Indices& indices, std::vector& distances) const; @@ -421,7 +512,7 @@ namespace pcl const std::vector& distances_; }; - }; // class Search + }; // class Search } // namespace search } // namespace pcl diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index 59cdd319aed..0ff8fd70c2c 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -538,6 +538,68 @@ TEST (PCL, Organized_Sparse_View_Radius) } #endif +TEST(PCL, Search_nonTrivialDistance) +{ + Indices test_indices = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + // 0 added on the end to showcase this case with sorted vs unsorted + std::vector test_distances = {0, 0, 0.0001, 2, 5, 0, 0, 0, 10}; + + // on sorted + { + pcl::search::BruteForce sorted{true}; + auto indices = test_indices; + auto distances = test_distances; + sorted.makeNonTrivial(indices, distances); + + EXPECT_EQ(distances.size(), 7); + EXPECT_EQ_VECTOR(indices, Indices{3, 4, 5, 6, 7, 8, 9}); + } + + // on unsorted + { + pcl::search::BruteForce unsorted{false}; + auto indices = test_indices; + auto distances = test_distances; + unsorted.makeNonTrivial(indices, distances); + + EXPECT_EQ(distances.size(), 4); + EXPECT_EQ_VECTOR(indices, Indices{3, 4, 5, 9}); + } +} +// @TODO +TEST(PCL, Search_nonTrivialDistances) {} +TEST(PCL, Search_nonTrivialIdx) +{ + index_t test_idx = 1; + Indices test_indices = {1, 1, 2, 3, 1, 1, 1, 4, 5}; + // 0 added on the end to showcase this case with sorted vs unsorted + std::vector test_distances = {0, 0, 0.0001, 2, 5, 0, 0, 0, 10}; + + // on sorted + { + pcl::search::BruteForce sorted{true}; + auto indices = test_indices; + auto distances = test_distances; + sorted.makeNonTrivial(test_idx, indices, distances); + + EXPECT_EQ(distances.size(), 7); + EXPECT_EQ_VECTOR(indices, Indices{2, 3, 1, 1, 1, 4, 5}); + } + + // on unsorted + { + pcl::search::BruteForce unsorted{false}; + auto indices = test_indices; + auto distances = test_distances; + unsorted.makeNonTrivial(test_idx, indices, distances); + + EXPECT_EQ(distances.size(), 4); + EXPECT_EQ_VECTOR(indices, Indices{2, 3, 4, 5}); + } +} +// @TODO +TEST (PCL, Search_nonTrivialIdices) {} + /** \brief create subset of point in cloud to use as query points * \param[out] query_indices resulting query indices - not guaranteed to have size of query_count but guaranteed not to exceed that value * \param cloud input cloud required to check for nans and to get number of points From b315b4f05fa1da79f15c99690da1b08aae5e9cf7 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Mon, 20 Dec 2021 10:37:30 +0900 Subject: [PATCH 02/11] Add missing header --- test/search/test_search.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index 0ff8fd70c2c..774ffa4fc0d 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -45,6 +45,7 @@ #include #include #include // for pcl::isFinite +#include // for EXPECT_EQ_VECTOR using namespace pcl; From 02cc64f77c06c8e3836812537353ce35b50238ea Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Mon, 20 Dec 2021 12:16:04 +0900 Subject: [PATCH 03/11] Missed the namespace --- test/search/test_search.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index 774ffa4fc0d..cdecaa00759 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -553,7 +553,7 @@ TEST(PCL, Search_nonTrivialDistance) sorted.makeNonTrivial(indices, distances); EXPECT_EQ(distances.size(), 7); - EXPECT_EQ_VECTOR(indices, Indices{3, 4, 5, 6, 7, 8, 9}); + test::EXPECT_EQ_VECTORS(indices, Indices{3, 4, 5, 6, 7, 8, 9}); } // on unsorted @@ -564,7 +564,7 @@ TEST(PCL, Search_nonTrivialDistance) unsorted.makeNonTrivial(indices, distances); EXPECT_EQ(distances.size(), 4); - EXPECT_EQ_VECTOR(indices, Indices{3, 4, 5, 9}); + test::EXPECT_EQ_VECTORS(indices, Indices{3, 4, 5, 9}); } } // @TODO @@ -584,7 +584,7 @@ TEST(PCL, Search_nonTrivialIdx) sorted.makeNonTrivial(test_idx, indices, distances); EXPECT_EQ(distances.size(), 7); - EXPECT_EQ_VECTOR(indices, Indices{2, 3, 1, 1, 1, 4, 5}); + test::EXPECT_EQ_VECTORS(indices, Indices{2, 3, 1, 1, 1, 4, 5}); } // on unsorted @@ -595,7 +595,7 @@ TEST(PCL, Search_nonTrivialIdx) unsorted.makeNonTrivial(test_idx, indices, distances); EXPECT_EQ(distances.size(), 4); - EXPECT_EQ_VECTOR(indices, Indices{2, 3, 4, 5}); + test::EXPECT_EQ_VECTORS(indices, Indices{2, 3, 4, 5}); } } // @TODO From 33c716bc7996fff35e0ab41e5482f86d58ceebe1 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Mon, 20 Dec 2021 15:26:56 +0900 Subject: [PATCH 04/11] Oopsie in if condition --- search/include/pcl/search/impl/search.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/include/pcl/search/impl/search.hpp b/search/include/pcl/search/impl/search.hpp index e4f4ba3754c..8db7c1f255d 100644 --- a/search/include/pcl/search/impl/search.hpp +++ b/search/include/pcl/search/impl/search.hpp @@ -270,7 +270,7 @@ Search::makeNonTrivial(index_t index, std::size_t same_idx_elements = 0; // distances are sorted, so if we encounter a non-zero, we can bail early for (const auto& idx : k_indices) { - if (idx == index) { + if (idx != index) { break; } ++same_idx_elements; From d40f472003559ffaf75b0fb1a5310bbdce0fd643 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Mon, 20 Dec 2021 23:52:32 +0900 Subject: [PATCH 05/11] Add a complicated test --- test/search/test_search.cpp | 87 +++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index cdecaa00759..25585870d76 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -539,6 +539,93 @@ TEST (PCL, Organized_Sparse_View_Radius) } #endif +class MakeNonTrivialTests : public ::testing::TestWithParam { + void + SetUp() override + { + search = pcl::make_shared>(GetParam()); + } + + std::vector test_indices = {{1, 2, 3, 4, 5, 6, 7, 8, 9}, + {1, 1, 2, 3, 1, 1, 1, 4, 5}}; + std::vector> test_distances = {{0, 0, 0.0001, 2, 5, 0, 0, 0, 10}, + {1, 0, 0.0001, 2, 5, 0, 0, 0, 10}}; + + Indices test_seeds = {1, 9}; + + pcl::shared_ptr> search; +}; + +TEST_P(MakeNonTrivialTests, distance) +{ + std::vector expected_sorted_sizes = {7, 9}, + expected_unsorted_sizes = {4, 5}; + + auto* expected_sizes = + search->getSortedResults() ? &expected_sorted_sizes : &expected_unsorted_sizes; + + for (int i = 0; i < test_distances.size(); i++) { + auto indices = test_indices[i]; + auto distances = test_distances[i]; + auto size = search->makeNonTrivial(indices, distances); + + EXPECT_EQ(indices.size(), size); + EXPECT_EQ(distances.size(), size); + + EXPECT_LE(distances.size(), test_distances[i].size()); + EXPECT_EQ(size, expected_sizes[i]); + + if (distances.empty()) { + continue; + } + + if (search->getSortedResults()) { + EXPECT_TRUE(distances[0]); + } + else { + for (const auto& dist : distances) { + EXPECT_TRUE(dist); + } + } + } +} + +TEST_P(MakeNonTrivialTests, index) +{ + // vector of vectors, per seed + std::vector> expected_sorted_sizes = {{8, 7}, {9, 9}}, + expected_unsorted_sizes = {{8, 4}, {8, 9}}; + + auto* expected_sizes = + search->getSortedResults() ? &expected_sorted_sizes : &expected_unsorted_sizes; + + for (int seed_idx = 0; seed_idx < test_seeds; seed_idx++) { + for (int i = 0; i < test_distances.size(); i++) { + auto indices = test_indices[i]; + auto distances = test_distances[i]; + auto size = search->makeNonTrivial(test_seeds[seed_idx], indices, distances); + + EXPECT_EQ(indices.size(), size); + EXPECT_EQ(distances.size(), size); + + EXPECT_LE(indices.size(), test_indices[i].size()); + EXPECT_EQ(size, expected_sizes[seed_idx][i]); + + if (distances.empty()) { + continue; + } + if (search->getSortedResults()) { + EXPECT_NE(indices[0], test_seeds[seed_idx]); + } + else { + for (const auto& idx : indices) { + EXPECT_NE(idx, test_seeds[seed_idx]); + } + } + } + } +} + TEST(PCL, Search_nonTrivialDistance) { Indices test_indices = {1, 2, 3, 4, 5, 6, 7, 8, 9}; From f8da5b59ae10efeae9f295e2dd29daeab9a6bec3 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Tue, 21 Dec 2021 00:37:26 +0900 Subject: [PATCH 06/11] Fix visibility --- test/search/test_search.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index 25585870d76..f19bf133161 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -546,6 +546,7 @@ class MakeNonTrivialTests : public ::testing::TestWithParam { search = pcl::make_shared>(GetParam()); } +protected: std::vector test_indices = {{1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 1, 2, 3, 1, 1, 1, 4, 5}}; std::vector> test_distances = {{0, 0, 0.0001, 2, 5, 0, 0, 0, 10}, From af3e1abd43cc8db45a149201a05bc6be606c8488 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Tue, 21 Dec 2021 01:20:11 +0900 Subject: [PATCH 07/11] Fix signed of loop idx --- test/search/test_search.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index f19bf133161..540b0fa65fe 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -565,7 +565,7 @@ TEST_P(MakeNonTrivialTests, distance) auto* expected_sizes = search->getSortedResults() ? &expected_sorted_sizes : &expected_unsorted_sizes; - for (int i = 0; i < test_distances.size(); i++) { + for (unsigned int i = 0; i < test_distances.size(); i++) { auto indices = test_indices[i]; auto distances = test_distances[i]; auto size = search->makeNonTrivial(indices, distances); @@ -600,8 +600,8 @@ TEST_P(MakeNonTrivialTests, index) auto* expected_sizes = search->getSortedResults() ? &expected_sorted_sizes : &expected_unsorted_sizes; - for (int seed_idx = 0; seed_idx < test_seeds; seed_idx++) { - for (int i = 0; i < test_distances.size(); i++) { + for (unsigned int seed_idx = 0; seed_idx < test_seeds.size(); seed_idx++) { + for (unsigned int i = 0; i < test_distances.size(); i++) { auto indices = test_indices[i]; auto distances = test_distances[i]; auto size = search->makeNonTrivial(test_seeds[seed_idx], indices, distances); From e4f8ed146fecee8e0ac2e4c9270690ae538d54df Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Tue, 21 Dec 2021 02:40:35 +0900 Subject: [PATCH 08/11] Burnt by my own abstraction --- test/search/test_search.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index 540b0fa65fe..94ec8f98108 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -574,7 +574,7 @@ TEST_P(MakeNonTrivialTests, distance) EXPECT_EQ(distances.size(), size); EXPECT_LE(distances.size(), test_distances[i].size()); - EXPECT_EQ(size, expected_sizes[i]); + EXPECT_EQ(size, *(expected_sizes)[i]); if (distances.empty()) { continue; @@ -610,7 +610,7 @@ TEST_P(MakeNonTrivialTests, index) EXPECT_EQ(distances.size(), size); EXPECT_LE(indices.size(), test_indices[i].size()); - EXPECT_EQ(size, expected_sizes[seed_idx][i]); + EXPECT_EQ(size, *(expected_sizes)[seed_idx][i]); if (distances.empty()) { continue; From 4c6fef9a9e01287d287483b0e99813faa0e3d896 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Tue, 21 Dec 2021 11:25:32 +0900 Subject: [PATCH 09/11] Use reference not pointer --- test/search/test_search.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index 94ec8f98108..2916b98679d 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -562,8 +562,8 @@ TEST_P(MakeNonTrivialTests, distance) std::vector expected_sorted_sizes = {7, 9}, expected_unsorted_sizes = {4, 5}; - auto* expected_sizes = - search->getSortedResults() ? &expected_sorted_sizes : &expected_unsorted_sizes; + auto& expected_sizes = + search->getSortedResults() ? expected_sorted_sizes : expected_unsorted_sizes; for (unsigned int i = 0; i < test_distances.size(); i++) { auto indices = test_indices[i]; @@ -574,7 +574,7 @@ TEST_P(MakeNonTrivialTests, distance) EXPECT_EQ(distances.size(), size); EXPECT_LE(distances.size(), test_distances[i].size()); - EXPECT_EQ(size, *(expected_sizes)[i]); + EXPECT_EQ(size, expected_sizes[i]); if (distances.empty()) { continue; @@ -597,8 +597,8 @@ TEST_P(MakeNonTrivialTests, index) std::vector> expected_sorted_sizes = {{8, 7}, {9, 9}}, expected_unsorted_sizes = {{8, 4}, {8, 9}}; - auto* expected_sizes = - search->getSortedResults() ? &expected_sorted_sizes : &expected_unsorted_sizes; + auto& expected_sizes = + search->getSortedResults() ? expected_sorted_sizes : expected_unsorted_sizes; for (unsigned int seed_idx = 0; seed_idx < test_seeds.size(); seed_idx++) { for (unsigned int i = 0; i < test_distances.size(); i++) { @@ -610,7 +610,7 @@ TEST_P(MakeNonTrivialTests, index) EXPECT_EQ(distances.size(), size); EXPECT_LE(indices.size(), test_indices[i].size()); - EXPECT_EQ(size, *(expected_sizes)[seed_idx][i]); + EXPECT_EQ(size, expected_sizes[seed_idx][i]); if (distances.empty()) { continue; From 041ad2ad8639f74496912676b6aea2f32dfad4bf Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Tue, 21 Dec 2021 13:06:43 +0900 Subject: [PATCH 10/11] Remove old tests --- test/search/test_search.cpp | 62 ------------------------------------- 1 file changed, 62 deletions(-) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index 2916b98679d..d67f5fbec95 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -627,68 +627,6 @@ TEST_P(MakeNonTrivialTests, index) } } -TEST(PCL, Search_nonTrivialDistance) -{ - Indices test_indices = {1, 2, 3, 4, 5, 6, 7, 8, 9}; - // 0 added on the end to showcase this case with sorted vs unsorted - std::vector test_distances = {0, 0, 0.0001, 2, 5, 0, 0, 0, 10}; - - // on sorted - { - pcl::search::BruteForce sorted{true}; - auto indices = test_indices; - auto distances = test_distances; - sorted.makeNonTrivial(indices, distances); - - EXPECT_EQ(distances.size(), 7); - test::EXPECT_EQ_VECTORS(indices, Indices{3, 4, 5, 6, 7, 8, 9}); - } - - // on unsorted - { - pcl::search::BruteForce unsorted{false}; - auto indices = test_indices; - auto distances = test_distances; - unsorted.makeNonTrivial(indices, distances); - - EXPECT_EQ(distances.size(), 4); - test::EXPECT_EQ_VECTORS(indices, Indices{3, 4, 5, 9}); - } -} -// @TODO -TEST(PCL, Search_nonTrivialDistances) {} -TEST(PCL, Search_nonTrivialIdx) -{ - index_t test_idx = 1; - Indices test_indices = {1, 1, 2, 3, 1, 1, 1, 4, 5}; - // 0 added on the end to showcase this case with sorted vs unsorted - std::vector test_distances = {0, 0, 0.0001, 2, 5, 0, 0, 0, 10}; - - // on sorted - { - pcl::search::BruteForce sorted{true}; - auto indices = test_indices; - auto distances = test_distances; - sorted.makeNonTrivial(test_idx, indices, distances); - - EXPECT_EQ(distances.size(), 7); - test::EXPECT_EQ_VECTORS(indices, Indices{2, 3, 1, 1, 1, 4, 5}); - } - - // on unsorted - { - pcl::search::BruteForce unsorted{false}; - auto indices = test_indices; - auto distances = test_distances; - unsorted.makeNonTrivial(test_idx, indices, distances); - - EXPECT_EQ(distances.size(), 4); - test::EXPECT_EQ_VECTORS(indices, Indices{2, 3, 4, 5}); - } -} -// @TODO -TEST (PCL, Search_nonTrivialIdices) {} - /** \brief create subset of point in cloud to use as query points * \param[out] query_indices resulting query indices - not guaranteed to have size of query_count but guaranteed not to exceed that value * \param cloud input cloud required to check for nans and to get number of points From f59bad10b475a4731c4cdfccb9ebac66374005de Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Tue, 21 Dec 2021 20:19:18 +0900 Subject: [PATCH 11/11] Actually run the tests. Thanks Windows --- test/search/test_search.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/search/test_search.cpp b/test/search/test_search.cpp index d67f5fbec95..743e18276c8 100644 --- a/test/search/test_search.cpp +++ b/test/search/test_search.cpp @@ -627,6 +627,8 @@ TEST_P(MakeNonTrivialTests, index) } } +INSTANTIATE_TEST_SUITE_P(PCL, MakeNonTrivialTests, testing::Values(false, true)); + /** \brief create subset of point in cloud to use as query points * \param[out] query_indices resulting query indices - not guaranteed to have size of query_count but guaranteed not to exceed that value * \param cloud input cloud required to check for nans and to get number of points