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

add add_voxel in pybind for VoxelGrid::AddVoxel #6023

Merged
merged 4 commits into from
Aug 29, 2023

Conversation

ohkwon718
Copy link
Contributor

@ohkwon718 ohkwon718 commented Mar 22, 2023

I hope this update doesn't make any conflict with other features.
Regarding issues #2660, #1101, and #3133, there are needs for people to manually control voxels in VoxelGrid. Although it is already implemented in c++, there are no corresponding lines in pybind.

import open3d as o3d

print('input')
N = 2000

armadillo = o3d.data.ArmadilloMesh()
mesh = o3d.io.read_triangle_mesh(armadillo.path)
pcd = mesh.sample_points_poisson_disk(N)
# fit to unit cube
pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()),
          center=pcd.get_center())
pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0, 1, size=(N, 3)))
# o3d.visualization.draw_geometries([pcd])

print('voxelization')
voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd,
                                                            voxel_size=0.05)
o3d.visualization.draw_geometries([voxel_grid])
voxel_grid.add_voxel(o3d.geometry.Voxel([20,0,13], [1.0,0.0,0.0]))
o3d.visualization.draw_geometries([voxel_grid])


image

More discussions

  • Is AddVoxel a profer name? Since the voxel can be overwritten several times with the function, the name could be something else e.g. "SetVoxel"
  • EraseVoxel(or RemoveVoxel) function would be useful. It must not be hard work with 'std::unordered_map::erase'.

This change is Reviewable

@update-docs
Copy link

update-docs bot commented Mar 22, 2023

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@ohkwon718
Copy link
Contributor Author

More commit for remove_voxel

import open3d as o3d

print('input')
N = 2000

armadillo = o3d.data.ArmadilloMesh()
mesh = o3d.io.read_triangle_mesh(armadillo.path)
pcd = mesh.sample_points_poisson_disk(N)
# fit to unit cube
pcd.scale(1 / np.max(pcd.get_max_bound() - pcd.get_min_bound()),
          center=pcd.get_center())
pcd.colors = o3d.utility.Vector3dVector(np.random.uniform(0, 1, size=(N, 3)))
# o3d.visualization.draw_geometries([pcd])

print('voxelization')
voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd,
                                                            voxel_size=0.05)

for i in range(10):
    for j in range(10):       
        for k in range(20):
            voxel_grid.remove_voxel([i,j,k])
o3d.visualization.draw_geometries([voxel_grid])

image

@ssheorey ssheorey self-requested a review June 12, 2023 15:11
@ssheorey ssheorey closed this Jun 12, 2023
@ssheorey ssheorey reopened this Jun 12, 2023
@ssheorey ssheorey self-assigned this Jun 12, 2023
@ssheorey
Copy link
Member

Hi @ohkwon718 thanks for submitting this PR. Please update the code style to match Open3D code style by running:

python util/check_style.py --apply

@justdigi
Copy link

I could use this feature. I hope it can be submitted!

Copy link
Collaborator

@reyanshsolis reyanshsolis left a comment

Choose a reason for hiding this comment

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

Re-triggering CI. LGTM, once all are passing.

Copy link
Member

@ssheorey ssheorey left a comment

Choose a reason for hiding this comment

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

Thanks @ohkwon718 for the useful feature! Thanks @reyanshsolis for your review.

@ssheorey ssheorey merged commit 3db1647 into isl-org:master Aug 29, 2023
36 checks passed
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.

4 participants