@@ -275,34 +275,25 @@ void RayGroundFilterComponent::ExtractPointsIndices(
275
275
{
276
276
initializePointCloud2 (in_cloud_ptr, ground_cloud_msg_ptr);
277
277
initializePointCloud2 (in_cloud_ptr, no_ground_cloud_msg_ptr);
278
- size_t ground_count = 0 ;
279
278
int point_step = in_cloud_ptr->point_step ;
280
- size_t prev_ground_idx = 0 ;
279
+ size_t ground_count = 0 ;
281
280
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 );
284
282
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 {
290
292
std::memcpy (
291
293
&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++;
295
296
}
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 ;
306
297
}
307
298
ground_cloud_msg_ptr->data .resize (ground_count * point_step);
308
299
no_ground_cloud_msg_ptr->data .resize (no_ground_count * point_step);
0 commit comments