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

Nacho/get rid of get adjacent voxels #291

Merged
merged 4 commits into from
Mar 18, 2024

Conversation

nachovizzo
Copy link
Collaborator

@nachovizzo nachovizzo commented Mar 5, 2024

Follow up from #290

New result: reads much better

Eigen::Vector3d GetClosestNeighbor(const Eigen::Vector3d &point,
                                   const kiss_icp::VoxelHashMap &voxel_map) {
    // Convert the point to voxel coordinates
    const Voxel voxel(static_cast<int>(point[0] / voxel_map.voxel_size()),
                      static_cast<int>(point[1] / voxel_map.voxel_size()),
                      static_cast<int>(point[2] / voxel_map.voxel_size()));
    // Get nearby voxels on the map
    const auto &query_voxels = GetAdjacentVoxels(voxel);
    // Extract the points contained within the neighborhood voxels
    const auto &neighbors = voxel_map.GetPoints(query_voxels);

    // Find the nearest neighbor
    Eigen::Vector3d closest_neighbor;
    double closest_distance2 = std::numeric_limits<double>::max();
    std::for_each(neighbors.cbegin(), neighbors.cend(), [&](const auto &neighbor) {
        double distance = (neighbor - point).squaredNorm();
        if (distance < closest_distance2) {
            closest_neighbor = neighbor;
            closest_distance2 = distance;
        }
    });
    return closest_neighbor;
}

@nachovizzo nachovizzo added the core label Mar 5, 2024
@nachovizzo nachovizzo merged commit a71c0e7 into main Mar 18, 2024
17 checks passed
@nachovizzo nachovizzo deleted the nacho/get_rid_of_get_adjacent_voxels branch March 18, 2024 09:52
@nachovizzo nachovizzo added the voxelization All the topic related to voxelization utilities label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core voxelization All the topic related to voxelization utilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants