Skip to content

Commit

Permalink
VoxelHashMap ereasing of the voxels (#310)
Browse files Browse the repository at this point in the history
* Fix for invalid iterators manipulation
This could potentially lead to undefined behaviour or segmentation faults.

* Remove max_distance_2_

Leave it for other PR

* Avoid corner case

---------

Co-authored-by: Ignacio Vizzo <[email protected]>
  • Loading branch information
kulfer80 and nachovizzo authored Apr 3, 2024
1 parent 11c7d97 commit e808b27
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cpp/kiss_icp/core/VoxelHashMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ void VoxelHashMap::AddPoints(const std::vector<Eigen::Vector3d> &points) {
}

void VoxelHashMap::RemovePointsFarFromLocation(const Eigen::Vector3d &origin) {
for (const auto &[voxel, voxel_block] : map_) {
for (auto it = map_.begin(); it != map_.end();) {
const auto &[voxel, voxel_block] = *it;
const auto &pt = voxel_block.points.front();
const auto max_distance2 = max_distance_ * max_distance_;
if ((pt - origin).squaredNorm() > (max_distance2)) {
map_.erase(voxel);
if ((pt - origin).squaredNorm() >= (max_distance2)) {
it = map_.erase(it);
} else {
++it;
}
}
}
Expand Down

0 comments on commit e808b27

Please sign in to comment.