Skip to content

Commit 3a502ee

Browse files
kyoichi-sugaharaxmfcx
authored andcommitted
improve performance of extraction method
Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp>
1 parent ca9e956 commit 3a502ee

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

sensing/pointcloud_preprocessor/src/outlier_filter/ring_outlier_filter_nodelet.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <sensor_msgs/point_cloud2_iterator.hpp>
2020

21+
#include <pcl/search/pcl_search.h>
22+
2123
#include <algorithm>
2224
#include <vector>
2325
namespace pointcloud_preprocessor
@@ -282,23 +284,21 @@ sensor_msgs::msg::PointCloud2 RingOutlierFilterComponent::extractExcludedPoints(
282284

283285
pcl::PointCloud<pcl::PointXYZ>::Ptr excluded_points(new pcl::PointCloud<pcl::PointXYZ>);
284286

285-
for (const auto & input_point : *input_cloud) {
286-
bool is_excluded = true;
287-
288-
for (const auto & output_point : *output_cloud) {
289-
float distance = autoware::common::geometry::distance_3d(input_point, output_point);
290-
291-
// If the distance is less than the threshold (epsilon), the point is not excluded
292-
if (distance < epsilon) {
293-
is_excluded = false;
294-
break;
295-
}
287+
pcl::search::Search<pcl::PointXYZ>::Ptr tree;
288+
if (output_cloud->isOrganized()) {
289+
tree.reset(new pcl::search::OrganizedNeighbor<pcl::PointXYZ>());
290+
} else {
291+
tree.reset(new pcl::search::KdTree<pcl::PointXYZ>(false));
292+
}
293+
tree->setInputCloud(output_cloud);
294+
std::vector<int> nn_indices(1);
295+
std::vector<float> nn_dists(1);
296+
for (const auto & point : input_cloud->points) {
297+
if (!tree->nearestKSearch(point, 1, nn_indices, nn_dists)) {
298+
continue;
296299
}
297-
298-
// If the point is still marked as excluded after all comparisons, add it to the excluded
299-
// pointcloud
300-
if (is_excluded) {
301-
excluded_points->push_back(input_point);
300+
if (nn_dists[0] > epsilon) {
301+
excluded_points->points.push_back(point);
302302
}
303303
}
304304

0 commit comments

Comments
 (0)