Skip to content

add add_voxel in pybind for VoxelGrid::AddVoxel - #6023

Merged
ssheorey merged 4 commits into
isl-org:masterfrom
ohkwon718:master
Aug 29, 2023
Merged

ssheorey merged 4 commits into
isl-org:masterfrom
ohkwon718:master

Conversation

@ohkwon718

@ohkwon718 ohkwon718 commented Mar 22, 2023 •

Copy link
Copy Markdown
Contributor

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

update-docs Bot commented Mar 22, 2023

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

@reyanshsolis reyanshsolis left a comment

Copy link
Copy Markdown
Collaborator

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.

@ssheorey ssheorey left a comment

Copy link
Copy Markdown
Member

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.

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