Skip to content

Commit c003623

Browse files
committed
discrete updates: only add one point per voxel
Only add and ray trace one point per voxel. When another point is in a voxel that has already been added, skip it.
1 parent 9940358 commit c003623

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

octomap_server/src/octomap_server.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ void OctomapServer::insertScan(
497497
{
498498
const auto sensor_origin = octomap::pointTfToOctomap(sensor_origin_tf);
499499

500+
bool discrete = true;
501+
500502
if (!octree_->coordToKeyChecked(sensor_origin, update_bbox_min_) ||
501503
!octree_->coordToKeyChecked(sensor_origin, update_bbox_max_))
502504
{
@@ -513,18 +515,25 @@ void OctomapServer::insertScan(
513515
point = sensor_origin + (point - sensor_origin).normalized() * max_range_;
514516
}
515517

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
521519
octomap::OcTreeKey end_key;
522520
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+
}
523527
updateMinKey(end_key, update_bbox_min_);
524528
updateMaxKey(end_key, update_bbox_max_);
525529
} else {
526530
RCLCPP_ERROR_STREAM(get_logger(), "Could not generate Key for endpoint " << point);
527531
}
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+
}
528537
}
529538

530539
// all other points: free on ray, occupied on endpoint:

0 commit comments

Comments
 (0)