Skip to content

Voxel grid (#185) #310

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Voxel grid (#185) #310

wants to merge 10 commits into from

Conversation

Udit-git-acc
Copy link

Voxel grid

@edgarriba
Copy link
Member

why touch some many files ?

@Udit-git-acc
Copy link
Author

Sorry, i guess i made some mistake, I just added 2 file, voxelgrid.rs in crates and kornia-py folder. Leme try to fix it.

@edgarriba edgarriba requested a review from Copilot March 30, 2025 10:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces voxel grid functionality with Python bindings, enabling downsampling of point clouds through a voxel grid structure.

  • Added a new PyVoxelGrid class with methods to construct the voxel grid, add points, and downsample the point cloud.
  • Updated the PointCloud conversion and integrated voxel grid functionality with corresponding tests.
  • Extended the voxelgrid implementation in the underlying Rust crate with basic unit tests.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
kornia-py/src/voxelgrid.rs Implements Python bindings for voxel grid operations including initialization and downsampling.
kornia-py/src/pointcloud.rs Minor update to support the point cloud conversion used in the Python bindings.
crates/kornia-3d/src/voxelgrid.rs Provides core voxel grid functionality and a downsampling test to validate behavior.
Comments suppressed due to low confidence (2)

kornia-py/src/voxelgrid.rs:45

  • [nitpick] Consider using a more specific Python exception type instead of the generic PyException to provide clearer error messages when array reshaping fails.
            .map_err(|e| PyErr::new::<pyo3::exceptions::PyException, _>(format!("{}", e)))?;

kornia-py/src/voxelgrid.rs:41

  • [nitpick] Consider verifying that the length of the flattened points vector is divisible by 3 before reshaping, to prevent potential errors with empty point clouds or corrupted data.
        let downsampled_points = downsampled.points().iter().flat_map(|p| p.iter().cloned()).collect::<Vec<f64>>();

@edgarriba
Copy link
Member

Please rebase on main to get rid of ci issues. Please, send a screenshot showing that local test passed correctly

Copy link
Member

@edgarriba edgarriba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide what's the source reference for this implementation ? I believe we should provide a similar functionality found here https://github.com/isl-org/Open3D/blob/main/cpp/open3d/geometry/VoxelGrid.h (not copying but re-implementing) put together the minimum pieces for it

leaf_size: [f64; 3],
min_bounds: [f64; 3],
max_bounds: [f64; 3],
grid: std::collections::HashMap<[i64; 3], Vec<[f64; 3]>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to follow library and in general Rust good practices, add the import on top of the file

@@ -0,0 +1,91 @@
/// A voxel grid for organizing and downsampling point clouds.
pub struct VoxelGrid {
leaf_size: [f64; 3],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would use Vec3 from glam-rs as we have been updating the other 3d library components with it

@Udit-git-acc
Copy link
Author

open3d voxel implementation has separate function for transform, translate, scale rotate and other operations, I just implemented downsample function. Downsample was done on basis of simple averaging values in each voxel.

@edgarriba edgarriba requested a review from Copilot April 2, 2025 10:30
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new voxel grid feature with Python bindings to the existing 3D voxel grid implementation.

  • Introduces Python wrapping for the voxel grid through the PyVoxelGrid class.
  • Adds core voxel grid functionality and associated tests in the kornia-3d crate.
  • Applies a minor update to the point cloud module.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
kornia-py/src/voxelgrid.rs Adds Python bindings for creating and manipulating voxel grids.
kornia-py/src/pointcloud.rs Minor update to the point cloud module.
crates/kornia-3d/src/voxelgrid.rs Implements voxel grid functionality and downsampling with tests.
Comments suppressed due to low confidence (1)

kornia-py/src/voxelgrid.rs:43

  • [nitpick] The error message for a coordinate count not divisible by 3 could be enhanced to describe the expected format of the point cloud data.
if downsampled_points.len() % 3 != 0 {

}
}

/// Add points from a point cloud to the voxel grid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add proper docs for public methods

…point and reverse for using glam in voxel since point cloud is using points
Copy link

sonarqubecloud bot commented Apr 2, 2025

@Udit-git-acc
Copy link
Author

Hi @edgarriba where the changes made correct ? Please suggest changes if any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants