diff --git a/cpp/kiss_icp/core/VoxelHashMap.cpp b/cpp/kiss_icp/core/VoxelHashMap.cpp index faf653c3..a762bf40 100644 --- a/cpp/kiss_icp/core/VoxelHashMap.cpp +++ b/cpp/kiss_icp/core/VoxelHashMap.cpp @@ -71,14 +71,20 @@ void VoxelHashMap::Update(const std::vector &points, const Soph } void VoxelHashMap::AddPoints(const std::vector &points) { + const double map_resolution = std::sqrt(voxel_size_ * voxel_size_ / max_points_per_voxel_); std::for_each(points.cbegin(), points.cend(), [&](const auto &point) { auto voxel = PointToVoxel(point, voxel_size_); auto search = map_.find(voxel); if (search != map_.end()) { auto &voxel_points = search.value(); - if (voxel_points.size() < max_points_per_voxel_) { - voxel_points.emplace_back(point); + if (voxel_points.size() == max_points_per_voxel_ || + std::any_of(voxel_points.cbegin(), voxel_points.cend(), + [&](const auto &voxel_point) { + return (voxel_point - point).norm() < map_resolution; + })) { + return; } + voxel_points.emplace_back(point); } else { std::vector voxel_points; voxel_points.reserve(max_points_per_voxel_);