@@ -497,6 +497,8 @@ void OctomapServer::insertScan(
497
497
{
498
498
const auto sensor_origin = octomap::pointTfToOctomap (sensor_origin_tf);
499
499
500
+ bool discrete = true ;
501
+
500
502
if (!octree_->coordToKeyChecked (sensor_origin, update_bbox_min_) ||
501
503
!octree_->coordToKeyChecked (sensor_origin, update_bbox_max_))
502
504
{
@@ -513,18 +515,25 @@ void OctomapServer::insertScan(
513
515
point = sensor_origin + (point - sensor_origin).normalized () * max_range_;
514
516
}
515
517
516
- // only clear space (ground points)
517
- if (octree_->computeRayKeys (sensor_origin, point, key_ray_)) {
518
- free_cells.insert (key_ray_.begin (), key_ray_.end ());
519
- }
520
-
518
+ // free endpoint
521
519
octomap::OcTreeKey end_key;
522
520
if (octree_->coordToKeyChecked (point, end_key)) {
521
+ if (!free_cells.insert (end_key).second ) {
522
+ if (discrete) {
523
+ // This ray has aleady been traced
524
+ continue ;
525
+ }
526
+ }
523
527
updateMinKey (end_key, update_bbox_min_);
524
528
updateMaxKey (end_key, update_bbox_max_);
525
529
} else {
526
530
RCLCPP_ERROR_STREAM (get_logger (), " Could not generate Key for endpoint " << point);
527
531
}
532
+
533
+ // only clear space (ground points)
534
+ if (octree_->computeRayKeys (sensor_origin, point, key_ray_)) {
535
+ free_cells.insert (key_ray_.begin (), key_ray_.end ());
536
+ }
528
537
}
529
538
530
539
// all other points: free on ray, occupied on endpoint:
0 commit comments