isl-org / isl-org/Open3D

Negative value returned by open3d.geometry.VoxelGrid.get_voxel()

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

Description

### Checklist

- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).

### Describe the issue

I create an `open3d.geometry.VoxelGrid` object using pointcloud in `numpy.array` format.

Then given a 3D position, I want to query the grid index of the voxel where point is in.

But I got negative number when I use the function `get_voxel()`.

Does the "voxel index" returned by `get_voxel()` the same as the "grid index"? If yes, the return value should be >= 0.

The file for reproducing the bug is [here](https://drive.google.com/file/d/1_Y5eyyfK6Y-6VnS6H9lGQSYdKV9v-9fr/view?usp=sharing)

### Steps to reproduce the bug

```python
import numpy as np
import msgpack
import msgpack_numpy
msgpack_numpy.patch()
import zstandard as zstd
import open3d as o3d
import torch
from pytorch3d.ops import knn_points

N = 100

### read particle positions

datapath = 'datasets/ours_default_data/train/sim_0001_00.msgpack.zst'
decompressor = zstd.ZstdDecompressor()

# read all data from file
with open(datapath, 'rb') as f:
data = msgpack.unpackb(decompressor.decompress(f.read()), raw=False)
pos = data[0]['pos']

### pcd2voxel

pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(pos)

# 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])

voxel_grid = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd, voxel_size=0.05)
voxels = voxel_grid.get_voxels()
voxel_index = np.array([voxels[i].grid_index for i in range(len(voxels))])
print(voxel_index.max(),voxel_index.min()) # [20, 0]

# create a hash table to map the voxel grid_index to the voxel number in the voxels list
voxel_hash = {}
for i in range(len(voxels)):
voxel_hash[tuple(voxels[i].grid_index)] = i

pos_grid_index = []
for i in range (len(pos)):
pos_grid_index.append(voxel_grid.get_voxel(pos[i]))
pos_grid_index = np.array(pos_grid_index)
print(pos_grid_index.shape)
print(pos_grid_index.max(), pos_grid_index.min()) # [26, -6]
```

### Error message

_No response_

### Expected behavior

I am expecting the `get_voxel()` function to return a 3D list with numbers >= 0.

### Open3D, Python and System information

```markdown
- Operating system: Ubuntu 20.04
- Python version: Python 3.7.16
- Open3D version: 0.16.0
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip
- Compiler version (if built from source): gcc 11.2.0
```

### Additional information

_No response_

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.