Skip to content

Commit 5cf469e

Browse files
committed
refactor: ray_ground_filter
Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
1 parent e77389b commit 5cf469e

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

perception/ground_segmentation/src/ray_ground_filter_nodelet.cpp

+13-22
Original file line numberDiff line numberDiff line change
@@ -275,34 +275,25 @@ void RayGroundFilterComponent::ExtractPointsIndices(
275275
{
276276
initializePointCloud2(in_cloud_ptr, ground_cloud_msg_ptr);
277277
initializePointCloud2(in_cloud_ptr, no_ground_cloud_msg_ptr);
278-
size_t ground_count = 0;
279278
int point_step = in_cloud_ptr->point_step;
280-
size_t prev_ground_idx = 0;
279+
size_t ground_count = 0;
281280
size_t no_ground_count = 0;
282-
// sort indices
283-
sort(in_indices.indices.begin(), in_indices.indices.end());
281+
std::vector<bool> is_ground_idx(in_cloud_ptr->width, false);
284282
for (const auto & idx : in_indices.indices) {
285-
std::memcpy(
286-
&ground_cloud_msg_ptr->data[ground_count * point_step], &in_cloud_ptr->data[idx * point_step],
287-
point_step);
288-
ground_count++;
289-
if (idx - prev_ground_idx > 1) {
283+
is_ground_idx[idx] = true;
284+
}
285+
for (size_t i = 0; i < is_ground_idx.size(); ++i) {
286+
if (is_ground_idx[i]) {
287+
std::memcpy(
288+
&ground_cloud_msg_ptr->data[ground_count * point_step], &in_cloud_ptr->data[i * point_step],
289+
point_step);
290+
ground_count++;
291+
} else {
290292
std::memcpy(
291293
&no_ground_cloud_msg_ptr->data[no_ground_count * point_step],
292-
&in_cloud_ptr->data[(prev_ground_idx + 1) * point_step],
293-
point_step * (idx - prev_ground_idx - 1));
294-
no_ground_count += idx - prev_ground_idx - 1;
294+
&in_cloud_ptr->data[i * point_step], point_step);
295+
no_ground_count++;
295296
}
296-
prev_ground_idx = idx;
297-
}
298-
299-
// Check no_ground_points after last idx
300-
if (prev_ground_idx < in_cloud_ptr->width - 1) {
301-
std::memcpy(
302-
&no_ground_cloud_msg_ptr->data[no_ground_count * point_step],
303-
&in_cloud_ptr->data[(prev_ground_idx + 1) * point_step],
304-
point_step * (in_cloud_ptr->width - prev_ground_idx - 1));
305-
no_ground_count += in_cloud_ptr->width - prev_ground_idx - 1;
306297
}
307298
ground_cloud_msg_ptr->data.resize(ground_count * point_step);
308299
no_ground_cloud_msg_ptr->data.resize(no_ground_count * point_step);

0 commit comments

Comments
 (0)