kaolin icon indicating copy to clipboard operation
kaolin copied to clipboard

point_to_mesh_distance returns strange "jumps" in distance

Open lorjul opened this issue 1 year ago • 10 comments

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 avatar Jul 17 '24 15:07 lorjul

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

shumash avatar Jul 19 '24 13:07 shumash

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)

lorjul avatar Jul 22 '24 06:07 lorjul

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]

Caenorst avatar Aug 02 '24 16:08 Caenorst

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 avatar Aug 20 '24 12:08 lorjul

Is there any progress on this problem? We also encounter the strange "jump" in some cases.

sparse-mvs-2 avatar Dec 06 '24 05:12 sparse-mvs-2

Stale issue message

github-actions[bot] avatar Mar 06 '25 21:03 github-actions[bot]

Hi, is there any update on this? I also encounter the same issue.

aidilayce avatar Apr 11 '25 15:04 aidilayce

Stale issue, please reopen if still relevant

github-actions[bot] avatar Aug 27 '25 21:08 github-actions[bot]

Hi all, I've been trying on the model suggested I downloaded the USD model, and couldn't observe the jump, if you have any model with the jump please share I will have a look.

Caenorst avatar Sep 30 '25 05:09 Caenorst