Skip to content

Commit

Permalink
Revert VoxelHashMap change -> Allocations go in a separate PR
Browse files Browse the repository at this point in the history
  • Loading branch information
tizianoGuadagnino committed Dec 4, 2024
1 parent a741512 commit 5ae3283
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cpp/kiss_icp/core/VoxelHashMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@

namespace {
using kiss_icp::Voxel;
static const std::array<Voxel, 27> shifts{
{{0, 0, 0}, {1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1},
{1, 1, 0}, {1, -1, 0}, {-1, 1, 0}, {-1, -1, 0}, {1, 0, 1}, {1, 0, -1}, {-1, 0, 1},
{-1, 0, -1}, {0, 1, 1}, {0, 1, -1}, {0, -1, 1}, {0, -1, -1}, {1, 1, 1}, {1, 1, -1},
{1, -1, 1}, {1, -1, -1}, {-1, 1, 1}, {-1, 1, -1}, {-1, -1, 1}, {-1, -1, -1}}};

std::vector<Voxel> GetAdjacentVoxels(const Voxel &voxel, int adjacent_voxels = 1) {
std::vector<Voxel> voxel_neighborhood;
for (int i = voxel.x() - adjacent_voxels; i < voxel.x() + adjacent_voxels + 1; ++i) {
for (int j = voxel.y() - adjacent_voxels; j < voxel.y() + adjacent_voxels + 1; ++j) {
for (int k = voxel.z() - adjacent_voxels; k < voxel.z() + adjacent_voxels + 1; ++k) {
voxel_neighborhood.emplace_back(i, j, k);
}
}
}
return voxel_neighborhood;
}
} // namespace

namespace kiss_icp {
Expand All @@ -44,11 +51,12 @@ std::tuple<Eigen::Vector3d, double> VoxelHashMap::GetClosestNeighbor(
const Eigen::Vector3d &query) const {
// Convert the point to voxel coordinates
const auto &voxel = PointToVoxel(query, voxel_size_);
// Get nearby voxels on the map
const auto &query_voxels = GetAdjacentVoxels(voxel);
// Find the nearest neighbor
Eigen::Vector3d closest_neighbor = Eigen::Vector3d::Zero();
double closest_distance = std::numeric_limits<double>::max();
std::for_each(shifts.cbegin(), shifts.cend(), [&](const auto &voxel_shift) {
const auto &query_voxel = voxel + voxel_shift;
std::for_each(query_voxels.cbegin(), query_voxels.cend(), [&](const auto &query_voxel) {
auto search = map_.find(query_voxel);
if (search != map_.end()) {
const auto &points = search.value();
Expand Down

0 comments on commit 5ae3283

Please sign in to comment.