Test for KdTree nearestKSearch */
| 70 | } |
| 71 | |
| 72 | /* Test for KdTree nearestKSearch */TEST (PCL, KdTree_nearestKSearch) |
| 73 | { |
| 74 | pcl::search::KdTree<PointXYZ> kdtree; |
| 75 | kdtree.setInputCloud (cloud.makeShared ()); |
| 76 | PointXYZ test_point (0.01f, 0.01f, 0.01f); |
| 77 | unsigned int no_of_neighbors = 20; |
| 78 | std::multimap<float, int> sorted_brute_force_result; |
| 79 | for (std::size_t i = 0; i < cloud.size (); ++i) |
| 80 | { |
| 81 | float distance = euclideanDistance (cloud[i], test_point); |
| 82 | sorted_brute_force_result.insert (std::make_pair (distance, static_cast<int> (i))); |
| 83 | } |
| 84 | float max_dist = 0.0f; |
| 85 | unsigned int counter = 0; |
| 86 | for (auto it = sorted_brute_force_result.begin (); it != sorted_brute_force_result.end () |
| 87 | && counter < no_of_neighbors; ++it) |
| 88 | { |
| 89 | max_dist = std::max (max_dist, it->first); |
| 90 | ++counter; |
| 91 | } |
| 92 | |
| 93 | pcl::Indices k_indices; |
| 94 | k_indices.resize (no_of_neighbors); |
| 95 | std::vector<float> k_distances; |
| 96 | k_distances.resize (no_of_neighbors); |
| 97 | |
| 98 | kdtree.nearestKSearch (test_point, no_of_neighbors, k_indices, k_distances); |
| 99 | |
| 100 | //if (k_indices.size () != no_of_neighbors) std::cerr << "Found "<<k_indices.size ()<<" instead of "<<no_of_neighbors<<" neighbors.\n"; |
| 101 | EXPECT_EQ (k_indices.size (), no_of_neighbors); |
| 102 | |
| 103 | // Check if all found neighbors have distance smaller than max_dist |
| 104 | for (const auto &k_index : k_indices) |
| 105 | { |
| 106 | const PointXYZ& point = cloud[k_index]; |
| 107 | bool ok = euclideanDistance (test_point, point) <= max_dist; |
| 108 | if (!ok) |
| 109 | ok = (std::abs (euclideanDistance (test_point, point)) - max_dist) <= 1e-6; |
| 110 | //if (!ok) std::cerr << k_indices[i] << " is not correct...\n"; |
| 111 | //else std::cerr << k_indices[i] << " is correct...\n"; |
| 112 | EXPECT_TRUE (ok); |
| 113 | } |
| 114 | |
| 115 | ScopeTime scopeTime ("FLANN nearestKSearch"); |
| 116 | { |
| 117 | pcl::search::KdTree<PointXYZ> kdtree; |
| 118 | //kdtree.initSearchDS (); |
| 119 | kdtree.setInputCloud (cloud_big.makeShared ()); |
| 120 | for (const auto &point : cloud_big.points) |
| 121 | kdtree.nearestKSearch (point, no_of_neighbors, k_indices, k_distances); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /* Test the templated NN search (for different query point types) */ |
nothing calls this directly
no test coverage detected