@@ -257,53 +257,20 @@ void RayGroundFilterComponent::ClassifyPointCloud(
257
257
// return (true);
258
258
// }
259
259
260
- void RayGroundFilterComponent::initializePointCloud2 (
261
- const PointCloud2::ConstSharedPtr & in_cloud_ptr, PointCloud2::SharedPtr & out_cloud_msg_ptr)
262
- {
263
- out_cloud_msg_ptr->header = in_cloud_ptr->header ;
264
- out_cloud_msg_ptr->height = in_cloud_ptr->height ;
265
- out_cloud_msg_ptr->fields = in_cloud_ptr->fields ;
266
- out_cloud_msg_ptr->is_bigendian = in_cloud_ptr->is_bigendian ;
267
- out_cloud_msg_ptr->point_step = in_cloud_ptr->point_step ;
268
- out_cloud_msg_ptr->is_dense = in_cloud_ptr->is_dense ;
269
- out_cloud_msg_ptr->data .resize (in_cloud_ptr->data .size ());
270
- }
271
-
272
260
void RayGroundFilterComponent::ExtractPointsIndices (
273
- const PointCloud2::ConstSharedPtr in_cloud_ptr, pcl::PointIndices & in_indices,
274
- PointCloud2::SharedPtr ground_cloud_msg_ptr, PointCloud2::SharedPtr no_ground_cloud_msg_ptr)
261
+ const pcl::PointCloud<PointType_>::Ptr in_cloud_ptr, const pcl::PointIndices & in_indices,
262
+ pcl::PointCloud<PointType_>::Ptr out_only_indices_cloud_ptr,
263
+ pcl::PointCloud<PointType_>::Ptr out_removed_indices_cloud_ptr)
275
264
{
276
- initializePointCloud2 (in_cloud_ptr, ground_cloud_msg_ptr);
277
- initializePointCloud2 (in_cloud_ptr, no_ground_cloud_msg_ptr);
278
- int point_step = in_cloud_ptr->point_step ;
279
- size_t ground_count = 0 ;
280
- size_t no_ground_count = 0 ;
281
- std::vector<bool > is_ground_idx (in_cloud_ptr->width , false );
282
- for (const auto & idx : in_indices.indices ) {
283
- if (std::size_t (idx) >= is_ground_idx.size ()) {
284
- continue ;
285
- }
286
- is_ground_idx[idx] = true ;
287
- }
288
- for (size_t i = 0 ; i < is_ground_idx.size (); ++i) {
289
- if (is_ground_idx[i]) {
290
- std::memcpy (
291
- &ground_cloud_msg_ptr->data [ground_count * point_step], &in_cloud_ptr->data [i * point_step],
292
- point_step);
293
- ground_count++;
294
- } else {
295
- std::memcpy (
296
- &no_ground_cloud_msg_ptr->data [no_ground_count * point_step],
297
- &in_cloud_ptr->data [i * point_step], point_step);
298
- no_ground_count++;
299
- }
300
- }
301
- ground_cloud_msg_ptr->data .resize (ground_count * point_step);
302
- no_ground_cloud_msg_ptr->data .resize (no_ground_count * point_step);
303
- ground_cloud_msg_ptr->width = ground_count;
304
- no_ground_cloud_msg_ptr->width = no_ground_count;
305
- ground_cloud_msg_ptr->row_step = ground_count * point_step;
306
- no_ground_cloud_msg_ptr->row_step = no_ground_count * point_step;
265
+ pcl::ExtractIndices<PointType_> extract_ground;
266
+ extract_ground.setInputCloud (in_cloud_ptr);
267
+ extract_ground.setIndices (pcl::make_shared<pcl::PointIndices>(in_indices));
268
+
269
+ extract_ground.setNegative (false ); // true removes the indices, false leaves only the indices
270
+ extract_ground.filter (*out_only_indices_cloud_ptr);
271
+
272
+ extract_ground.setNegative (true ); // true removes the indices, false leaves only the indices
273
+ extract_ground.filter (*out_removed_indices_cloud_ptr);
307
274
}
308
275
309
276
void RayGroundFilterComponent::filter (
@@ -332,11 +299,14 @@ void RayGroundFilterComponent::filter(
332
299
pcl::PointCloud<PointType_>::Ptr no_ground_cloud_ptr (new pcl::PointCloud<PointType_>);
333
300
pcl::PointCloud<pcl::PointXYZRGB>::Ptr radials_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
334
301
302
+ ExtractPointsIndices (
303
+ current_sensor_cloud_ptr, ground_indices, ground_cloud_ptr, no_ground_cloud_ptr);
304
+
335
305
sensor_msgs::msg::PointCloud2::SharedPtr no_ground_cloud_msg_ptr (
336
306
new sensor_msgs::msg::PointCloud2);
337
- sensor_msgs::msg::PointCloud2::SharedPtr ground_cloud_msg_ptr (new sensor_msgs::msg::PointCloud2);
307
+ pcl::toROSMsg (*no_ground_cloud_ptr, *no_ground_cloud_msg_ptr);
308
+ no_ground_cloud_msg_ptr->header = input->header ;
338
309
339
- ExtractPointsIndices (input, ground_indices, ground_cloud_msg_ptr, no_ground_cloud_msg_ptr);
340
310
output = *no_ground_cloud_msg_ptr;
341
311
}
342
312
0 commit comments