22
22
#include < memory>
23
23
#include < string>
24
24
#include < vector>
25
+ #include < omp.h>
25
26
26
27
namespace ground_segmentation
27
28
{
@@ -55,6 +56,7 @@ ScanGroundFilterComponent::ScanGroundFilterComponent(const rclcpp::NodeOptions &
55
56
split_height_distance_ = declare_parameter (" split_height_distance" , 0.2 );
56
57
use_virtual_ground_point_ = declare_parameter (" use_virtual_ground_point" , true );
57
58
use_recheck_ground_cluster_ = declare_parameter (" use_recheck_ground_cluster" , true );
59
+ omp_num_threads_ = declare_parameter (" omp_num_threads" , 1 );
58
60
radial_dividers_num_ = std::ceil (2.0 * M_PI / radial_divider_angle_rad_);
59
61
vehicle_info_ = VehicleInfoUtil (*this ).getVehicleInfo ();
60
62
@@ -288,7 +290,12 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan(
288
290
pcl::PointIndices & out_no_ground_indices)
289
291
{
290
292
out_no_ground_indices.indices .clear ();
293
+ std::vector<pcl::PointIndices> ground_indices;
294
+ ground_indices.resize (in_radial_ordered_clouds.size ());
295
+ omp_set_num_threads (omp_num_threads_);
296
+ #pragma omp parallel for
291
297
for (size_t i = 0 ; i < in_radial_ordered_clouds.size (); ++i) {
298
+ auto & ground_indices_private = ground_indices[i];
292
299
PointsCentroid ground_cluster;
293
300
ground_cluster.initialize ();
294
301
std::vector<GridCenter> gnd_grids;
@@ -299,10 +306,9 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan(
299
306
continue ;
300
307
}
301
308
302
- // check the first point in ray
303
- auto * p = &in_radial_ordered_clouds[i][0 ];
304
- PointRef * prev_p;
305
- prev_p = &in_radial_ordered_clouds[i][0 ]; // for checking the distance to prev point
309
+ // // check the first point in ray
310
+ auto p = &in_radial_ordered_clouds[i][0 ];
311
+ auto prev_p = &in_radial_ordered_clouds[i][0 ]; // for checking the distance to prev point
306
312
307
313
bool initialized_first_gnd_grid = false ;
308
314
bool prev_list_init = false ;
@@ -319,7 +325,10 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan(
319
325
if (
320
326
!initialized_first_gnd_grid && global_slope_p >= global_slope_max_angle_rad_ &&
321
327
p->orig_point ->z > non_ground_height_threshold_local) {
322
- out_no_ground_indices.indices .push_back (p->orig_index );
328
+ // #pragma omp critical
329
+ {
330
+ ground_indices_private.indices .push_back (p->orig_index );
331
+ }
323
332
p->point_state = PointLabel::NON_GROUND;
324
333
prev_p = p;
325
334
continue ;
@@ -358,7 +367,7 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan(
358
367
if (p->grid_id > prev_p->grid_id && ground_cluster.getAverageRadius () > 0.0 ) {
359
368
// check if the prev grid have ground point cloud
360
369
if (use_recheck_ground_cluster_) {
361
- recheckGroundCluster (ground_cluster, non_ground_height_threshold_, out_no_ground_indices );
370
+ recheckGroundCluster (ground_cluster, non_ground_height_threshold_, ground_indices_private );
362
371
}
363
372
curr_gnd_grid.radius = ground_cluster.getAverageRadius ();
364
373
curr_gnd_grid.avg_height = ground_cluster.getAverageHeight ();
@@ -380,13 +389,13 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan(
380
389
points_xy_distance < split_points_distance_tolerance_ &&
381
390
p->orig_point ->z > prev_p->orig_point ->z ) {
382
391
p->point_state = PointLabel::NON_GROUND;
383
- out_no_ground_indices .indices .push_back (p->orig_index );
392
+ ground_indices_private .indices .push_back (p->orig_index );
384
393
prev_p = p;
385
394
continue ;
386
395
}
387
396
388
397
if (global_slope_p > global_slope_max_angle_rad_) {
389
- out_no_ground_indices .indices .push_back (p->orig_index );
398
+ ground_indices_private .indices .push_back (p->orig_index );
390
399
prev_p = p;
391
400
continue ;
392
401
}
@@ -401,14 +410,30 @@ void ScanGroundFilterComponent::classifyPointCloudGridScan(
401
410
} else if (p->radius - gnd_grids.back ().radius < gnd_grid_continual_thresh_ * p->grid_size ) {
402
411
checkDiscontinuousGndGrid (*p, gnd_grids);
403
412
} else {
404
- checkBreakGndGrid (*p, gnd_grids);
413
+ // checkBreakGndGrid(*p, gnd_grids);
414
+ {
415
+ float tmp_delta_avg_z = p->orig_point ->z - gnd_grids.back ().avg_height ;
416
+ float tmp_delta_radius = p->radius - gnd_grids.back ().radius ;
417
+ float local_slope = std::atan (tmp_delta_avg_z / tmp_delta_radius);
418
+ if (abs (local_slope) < global_slope_max_angle_rad_) {
419
+ p->point_state = PointLabel::GROUND;
420
+ } else if (local_slope > global_slope_max_angle_rad_) {
421
+ p->point_state = PointLabel::NON_GROUND;
422
+ }
423
+ }
405
424
}
406
425
if (p->point_state == PointLabel::NON_GROUND) {
407
- out_no_ground_indices .indices .push_back (p->orig_index );
426
+ ground_indices_private .indices .push_back (p->orig_index );
408
427
} else if (p->point_state == PointLabel::GROUND) {
409
428
ground_cluster.addPoint (p->radius , p->orig_point ->z , p->orig_index );
410
429
}
411
- prev_p = p;
430
+ prev_p = p;
431
+ }
432
+ }
433
+
434
+ for (size_t i = 0 ; i < in_radial_ordered_clouds.size ();++i){
435
+ if (ground_indices.at (i).indices .size () > 0 ){
436
+ out_no_ground_indices.indices .insert (out_no_ground_indices.indices .end (),ground_indices.at (i).indices .begin (),ground_indices.at (i).indices .end ());
412
437
}
413
438
}
414
439
}
0 commit comments