isl-org / isl-org/Open3D

Voxelgrid `create_from_point_cloud_within_bounds` behaviour

Open
#2,766 2 comments 2 reactions 0 assignees View on GitHub
boundingbox geometry mesh
Dominant language
C++
Stars
14k
Forks
2.6k
Avg merge
5d 18h
Merged PRs (30d)
6

Description

**Describe the bug**
I was trying to voxelize a mesh as shown below using `create_from_point_cloud_within_bounds`. But when I increase the scale of the mesh (keeping the voxel resolution the same) I need more points to achieve the same density in my voxelization. Meaning the voxel grid resolution changes when I change the scale of the points in my point cloud. Which doesn't really make sense !

As a note I know the "right way" of voxelizing a mesh would be to use `create_from_triangle_mesh_within_bounds` but that takes a very long time to calculate the voxelization. (>2mins for voxel res 50). and I need a voxel res of 256.

Further, reading the voxelization code in [here](https://github.com/intel-isl/Open3D/blob/762f25bb4a1ed021df61fbde93e4bac1e34ed590/cpp/open3d/geometry/VoxelGridFactory.cpp#L86). Is there a reason the voxelization is calculated in this way ?

```
for (int i = 0; i < (int)input.points_.size(); i++) {
ref_coord = (input.points_[i] - min_bound) / voxel_size;
voxel_index << int(floor(ref_coord(0))), int(floor(ref_coord(1))),
int(floor(ref_coord(2)));
```

Since to me it seems for the coordinates of the grid to move to left of decimal point we need to also divide by `(max_bound-min_bound)`. like:
`ref_coord = (input.points_[i] - min_bound) / voxel_size /(max_bound-min_bound) ;`
Why this is not done ?
I guess floating point precision can be an issue here, but excluding this division is not exactly a solution.
Including this division resolves the above issue since the scaling factor cancels out from the numerator and denominator.
It is also weird how the `max_bound` is actually never used in this method except to check for an error.

**To Reproduce**
```
# read mesh
mesh = o3d.io.read_triangle_mesh(file_path)
# scale back to original
mesh.scale(scale=2.2, center=(0,0,0))

# Function to sample points from the mesh, where each point has approximately the same distance to the neighbouring points (blue noise).
# Method is based on Yuksel, “Sample Elimination for Generating Poisson Disk Sample Sets”, EUROGRAPHICS, 2015.
pcd = mesh.sample_points_poisson_disk(samples_from_mesh)

#voxelize
voxel_surface = o3d.geometry.VoxelGrid.create_from_point_cloud_within_bounds(
pcd,
voxel_size=1 / voxel_resolution,
min_bound=(-1/2, )*3,
max_bound= (1/2,)*3
)

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.