Error in creating voxelgrid from triangulated mesh
- 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 am facing problems with an occupancy grid from a triangulated mesh using the **o3d.geometry.VoxelGrid.create_from_triangle_mesh** function to create a voxelgrid of occupied voxels. The resulting grid does not include all faces of the mesh. It looks like the voxels are shifted or something, but I couldn't figure out the reason/ logic of what is happening.
### Steps to reproduce the bug
```python
import open3d as o3d
import meshio
import plotly.graph_objects as go
import numpy as np
mesh_monki = o3d.io.read_triangle_mesh('untitled.obj')
trimodel_mesh = meshio.read('untitled.obj')
vertices_trimodel = trimodel_mesh.points
triangles_trimodel = trimodel_mesh.cells_dict['triangle']
x=vertices_trimodel[:, 0]
y=vertices_trimodel[:, 1]
z=vertices_trimodel[:, 2]
i=triangles_trimodel[:, 0]
j=triangles_trimodel[:, 1]
k=triangles_trimodel[:, 2]
edges = []
for face in triangles_trimodel:
for ind in range(len(face)):
if ind < len(face)-1:
edges.append(
(face[ind], face[ind+1])
)
else:
edges.append(
(face[ind], face[0])
)
xe=[]
ye=[]
ze=[]
for edge in edges:
xe.extend([x[edge[0]], x[edge[1]], None])
ye.extend([y[edge[0]], y[edge[1]], None])
ze.extend([z[edge[0]], z[edge[1]], None])
trace_monki_mesh = go.Mesh3d(x=x, y=y, z=z, color='white', alphahull=3, #flatshading=True,
i=i,
j=j,
k=k,)
trace_monki_edges = go.Scatter3d(x=xe, y=ye, z=ze, mode='lines', line=dict(color='pink', width=1))
vs = 0.25
vg_monki = o3d.geometry.VoxelGrid.create_from_triangle_mesh(input=mesh_monki, voxel_size=vs)
monki_vox = vg_monki.get_voxels()
monki_vox_idx = [_.grid_index for _ in monki_vox]
monki_vox_ptx = np.asarray([vg_monki.get_voxel_bounding_points(_) for _ in monki_vox_idx])
edge_x = []
edge_y = []
edge_z = []
for box in monki_vox_ptx:
for pair in [(0,1), (0,2), (0,4), (1,3), (1,5), (2,6), (3,7), (4,5), (4,6), (5,7), (6, 7), (2,3)]:
edge_x.extend([box[pair[0]][0], box[pair[1]][0], None])
edge_y.extend([box[pair[0]][1], box[pair[1]][1], None])
edge_z.extend([box[pair[0]][2], box[pair[1]][2], None])
trace_edges = go.Scatter3d(x=edge_x, y=edge_y, z=edge_z, mode='lines')
data = [trace_monki_mesh, trace_monki_edges, trace_edges]
layout = go.Layout(width=1000,
height=1000,
showlegend=False,
hovermode='closest')
fig = go.Figure(data=data, layout=layout)
fig.update_scenes(camera_projection_type='orthographic')
fig.show()
```
### Error message
_No response_
### Expected behavior
**o3d.geometry.VoxelGrid.create_from_triangle_mesh** should return a grid of occupied voxels, and all faces of the mesh should lie within the occupied voxels; this is not true in my tests (see attached screenshots of the visualization).
### Open3D, Python and System information
```markdown
- Operating system: macOS 12.5.1
- Python version: Python 3.9.9
- Open3D version: 0.14.1
- System architecture: apple-silicon
- Is this a remote workstation?: no
- How did you install Open3D?: pip
- Compiler version (if built from source): NA
```
### Additional information


Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.