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

point_to_mesh_distance returns strange "jumps" in distance #807

Open
lorjul opened this issue Jul 17, 2024 · 4 comments
Open

point_to_mesh_distance returns strange "jumps" in distance #807

lorjul opened this issue Jul 17, 2024 · 4 comments

Comments

@lorjul
Copy link

lorjul commented Jul 17, 2024

Hello! I have troubles to get the point_to_mesh_distance function to work. Here is a MWE:

import matplotlib.pyplot as plt
import torch
from kaolin.io import obj
from kaolin.ops.mesh import index_vertices_by_faces
from kaolin.metrics.trianglemesh import point_to_mesh_distance

mesh = obj.import_mesh("/path/to/model.obj", with_normals=True, triangulate=True)

resolution = 64
# hardcoded to match the model bounds
x = torch.linspace(-10, 10, resolution)
y = torch.linspace(-10, 10, resolution)
z = torch.linspace(-10, 10, resolution)
grid_points = torch.stack(torch.meshgrid(x, y, z, indexing="ij"), dim=-1).view(-1, 3)

vertices = mesh.vertices.cuda()
faces = mesh.faces.cuda()
grid_points = grid_points.cuda()

face_vertices = index_vertices_by_faces(vertices[None], faces)
distance, _index, _dist_type = point_to_mesh_distance(grid_points[None], face_vertices)

plt.imshow(distance.reshape(resolution, resolution, resolution).cpu()[:, :, 31])
plt.savefig("df-kaolin.png")

However, the resulting distance field looks way off (I'm especially irritated by the edge in the top part of the image):

mwe

Calculating the distance field using trimesh returns the following, which makes much more sense:

image

What am I doing wrong?

@lorjul lorjul changed the title How do you use point_to_mesh_distance correctly? point_to_mesh_distance correctly returns strange "jumps" in distance Jul 17, 2024
@shumash
Copy link
Collaborator

shumash commented Jul 19, 2024

Would you be able to share the mesh file that is causing this issue?

@lorjul
Copy link
Author

lorjul commented Jul 22, 2024

Here is a link to the used mesh: https://uniaugsburg-my.sharepoint.com/:u:/g/personal/julian_lorenz_uni-a_de/ESAXVkFPQ-xNlEipcrXJjcoBLfyl_CXqIgHLdwnsWAreiQ?e=7H5Ixm

The used mesh was converted to the OBJ file format. The original mesh from Kristen Brown can be found here

(edit: updated the link)

@Caenorst
Copy link
Collaborator

Caenorst commented Aug 2, 2024

Hi @lorjul I can't have access to the first link, just to make sure I'm using the same model can you share it with us? Please contact me at [email protected]

@lorjul
Copy link
Author

lorjul commented Aug 20, 2024

My bad, sorry, the link was set to expire. Here is an updated link which should work: https://uniaugsburg-my.sharepoint.com/:u:/g/personal/julian_lorenz_uni-a_de/ESAXVkFPQ-xNlEipcrXJjcoBLfyl_CXqIgHLdwnsWAreiQ?e=7H5Ixm

@lorjul lorjul changed the title point_to_mesh_distance correctly returns strange "jumps" in distance point_to_mesh_distance returns strange "jumps" in distance Aug 29, 2024
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

No branches or pull requests

3 participants