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 voxel_range option for mesh to voxel conversion #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kosuke55
Copy link
Contributor

Hi, thank you for the work.

Some meshes cannot be voxelized unless normalize=True.
The ShapeNet_Voxels class also raises an error with some data.

tfs.TriangleMeshToVoxelGrid(res, normalize=False, vertex_offset=0.5),

For example, this object cannot be voxelized.
http://shapenet.cs.stanford.edu/shapenet/obj-zip/ShapeNetCore.v1/04379243/10657fcfce1d326b30bbd4cddd04c77b/model.obj

import kaolin as kal

mesh = kal.rep.TriangleMesh.from_obj(
    '/media/kosuke/SANDISK/meshdata/ShapeNetCore.v2/04379243/10657fcfce1d326b30bbd4cddd04c77b/model.obj')
print(mesh.vertices.min(), mesh.vertices.max())  # tensor(-0.3166) tensor(0.5718)

The maximum value of this mesh is 0.5718, and when it is moved by the offset, it becomes 1.0718.
Since the range of voxelization is 0 to 1, an error occurs due to overflow.

In [2]: voxels = kal.conversions.trianglemesh_to_voxelgrid(mesh, 32, normalize=False, vertex_offset=0.5)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-2-dd3bce34a4e9> in <module>
----> 1 voxels = kal.conversions.trianglemesh_to_voxelgrid(mesh, 32, normalize=False, vertex_offset=0.5)

~/.pyenv/versions/anaconda3-5.3.1/envs/kaolin/lib/python3.6/site-packages/kaolin-0.1.0-py3.6-linux-x86_64.egg/kaolin/conversions/meshconversions.py in trianglemesh_to_voxelgrid(mesh, resolution, normalize, vertex_offset, voxel_range)
    140     points = torch.split(points.permute(1, 0), 1, dim=0)
    141     points = [m.unsqueeze(0) for m in points]
--> 142     voxel[points] = 1
    143     return voxel
    144

IndexError: index 32 is out of bounds for dimension 0 with size 32

This PR solved this problem by expanding voxel_range.

In [3]: voxels = kal.conversions.trianglemesh_to_voxelgrid(mesh, 32, normalize=False, vertex_offset=0.5, voxel_range=1.08)

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.

1 participant