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

Improvement for VoxelDownsample #347

Closed
wants to merge 8 commits into from
Closed
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
32 changes: 17 additions & 15 deletions cpp/kiss_icp/core/Preprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
#include "Preprocessing.hpp"

#include <tbb/parallel_for.h>
#include <tsl/robin_map.h>
#include <tsl/robin_set.h>

#include <Eigen/Core>
#include <algorithm>
#include <cmath>
#include <sophus/se3.hpp>
#include <vector>

Expand All @@ -43,20 +42,23 @@ struct VoxelHash {

namespace kiss_icp {
std::vector<Eigen::Vector3d> VoxelDownsample(const std::vector<Eigen::Vector3d> &frame,
double voxel_size) {
tsl::robin_map<Voxel, Eigen::Vector3d, VoxelHash> grid;
grid.reserve(frame.size());
for (const auto &point : frame) {
const auto voxel = Voxel((point / voxel_size).cast<int>());
if (grid.contains(voxel)) continue;
grid.insert({voxel, point});
}
const double voxel_size) {
tsl::robin_set<Voxel, VoxelHash> voxels;
std::vector<Eigen::Vector3d> frame_dowsampled;
frame_dowsampled.reserve(grid.size());
for (const auto &[voxel, point] : grid) {
(void)voxel;
frame_dowsampled.emplace_back(point);
}

voxels.reserve(frame.size());
frame_dowsampled.reserve(frame.size());

std::for_each(frame.cbegin(), frame.cend(), [&](const Eigen::Vector3d &point) {
const auto voxel = Voxel((point / voxel_size).cast<int>());
if (!voxels.contains(voxel)) {
voxels.insert(voxel);
frame_dowsampled.emplace_back(point);
}
});

frame_dowsampled.shrink_to_fit();

return frame_dowsampled;
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/kiss_icp/core/Preprocessing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ std::vector<Eigen::Vector3d> CorrectKITTIScan(const std::vector<Eigen::Vector3d>

/// Voxelize point cloud keeping the original coordinates
std::vector<Eigen::Vector3d> VoxelDownsample(const std::vector<Eigen::Vector3d> &frame,
double voxel_size);
const double voxel_size);
} // namespace kiss_icp
9 changes: 2 additions & 7 deletions python/kiss_icp/kiss_icp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def register_frame(self, frame, timestamps):
frame = self.preprocess(frame)

# Voxelize
source, frame_downsample = self.voxelize(frame)
source = voxel_down_sample(frame, self.config.mapping.voxel_size * 1.5)

# Get adaptive_threshold
sigma = self.adaptive_threshold.get_threshold()
Expand All @@ -72,14 +72,9 @@ def register_frame(self, frame, timestamps):

# Update step: threshold, local map, delta, and the last pose
self.adaptive_threshold.update_model_deviation(model_deviation)
self.local_map.update(frame_downsample, new_pose)
self.local_map.update(source, new_pose)
self.last_delta = np.linalg.inv(self.last_pose) @ new_pose
self.last_pose = new_pose

# Return the (deskew) input raw scan (frame) and the points used for registration (source)
return frame, source

def voxelize(self, iframe):
frame_downsample = voxel_down_sample(iframe, self.config.mapping.voxel_size * 0.5)
source = voxel_down_sample(frame_downsample, self.config.mapping.voxel_size * 1.5)
return source, frame_downsample
Loading