Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiziano/Remove voxel block #381

Merged
merged 7 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions cpp/kiss_icp/core/VoxelHashMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::vector<Eigen::Vector3d> VoxelHashMap::GetPoints(const std::vector<Voxel> &q
std::for_each(query_voxels.cbegin(), query_voxels.cend(), [&](const auto &query) {
auto search = map_.find(query);
if (search != map_.end()) {
const auto &voxel_points = search->second.points;
const auto &voxel_points = search.value();
points.insert(points.end(), voxel_points.cbegin(), voxel_points.cend());
}
});
Expand All @@ -49,7 +49,7 @@ std::vector<Eigen::Vector3d> VoxelHashMap::Pointcloud() const {
std::vector<Eigen::Vector3d> points;
points.reserve(map_.size() * static_cast<size_t>(max_points_per_voxel_));
std::for_each(map_.cbegin(), map_.cend(), [&](const auto &map_element) {
const auto &voxel_points = map_element.second.points;
const auto &voxel_points = map_element.second;
points.insert(points.end(), voxel_points.cbegin(), voxel_points.cend());
});
points.shrink_to_fit();
Expand All @@ -75,19 +75,24 @@ void VoxelHashMap::AddPoints(const std::vector<Eigen::Vector3d> &points) {
auto voxel = PointToVoxel(point, voxel_size_);
auto search = map_.find(voxel);
if (search != map_.end()) {
auto &voxel_block = search.value();
voxel_block.AddPoint(point);
auto &voxel_points = search.value();
if (voxel_points.size() < max_points_per_voxel_) {
voxel_points.emplace_back(point);
}
} else {
map_.insert({voxel, VoxelBlock{{point}, max_points_per_voxel_}});
std::vector<Eigen::Vector3d> voxel_points;
voxel_points.reserve(max_points_per_voxel_);
voxel_points.emplace_back(point);
map_.insert({voxel, std::move(voxel_points)});
}
});
}

void VoxelHashMap::RemovePointsFarFromLocation(const Eigen::Vector3d &origin) {
const auto max_distance2 = max_distance_ * max_distance_;
for (auto it = map_.begin(); it != map_.end();) {
const auto &[voxel, voxel_block] = *it;
const auto &pt = voxel_block.points.front();
const auto &[voxel, voxel_points] = *it;
const auto &pt = voxel_points.front();
if ((pt - origin).squaredNorm() >= (max_distance2)) {
it = map_.erase(it);
} else {
Expand Down
15 changes: 3 additions & 12 deletions cpp/kiss_icp/core/VoxelHashMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,7 @@

namespace kiss_icp {
struct VoxelHashMap {
struct VoxelBlock {
// buffer of points with a max limit of n_points
std::vector<Eigen::Vector3d> points;
int num_points_;
inline void AddPoint(const Eigen::Vector3d &point) {
if (points.size() < static_cast<size_t>(num_points_)) points.push_back(point);
}
};

explicit VoxelHashMap(double voxel_size, double max_distance, int max_points_per_voxel)
explicit VoxelHashMap(double voxel_size, double max_distance, unsigned int max_points_per_voxel)
: voxel_size_(voxel_size),
max_distance_(max_distance),
max_points_per_voxel_(max_points_per_voxel) {}
Expand All @@ -61,7 +52,7 @@ struct VoxelHashMap {

double voxel_size_;
double max_distance_;
int max_points_per_voxel_;
tsl::robin_map<Voxel, VoxelBlock> map_;
unsigned int max_points_per_voxel_;
tsl::robin_map<Voxel, std::vector<Eigen::Vector3d>> map_;
};
} // namespace kiss_icp
Loading