Skip to content

Commit

Permalink
Add minimum distance between points added in each voxel (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
tizianoGuadagnino authored Aug 1, 2024
1 parent 05d596e commit 12905ec
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cpp/kiss_icp/core/VoxelHashMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,20 @@ void VoxelHashMap::Update(const std::vector<Eigen::Vector3d> &points, const Soph
}

void VoxelHashMap::AddPoints(const std::vector<Eigen::Vector3d> &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<Eigen::Vector3d> voxel_points;
voxel_points.reserve(max_points_per_voxel_);
Expand Down

0 comments on commit 12905ec

Please sign in to comment.