mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
2.94k stars 574 forks source link

Normal consistency based closest point #2061

Open Sentient07 opened 10 months ago

Sentient07 commented 10 months ago

Hello Mike @mikedh ,

I would like to align two meshes that are close in Euclidean space. For this, I'm using trimesh.proximity.closest_point. In my alignment problem, I would like to not just find the closest point, but a point where normals don't differ by 90deg. I would imagine this implies filtering of candidates here (https://github.com/mikedh/trimesh/blob/main/trimesh/proximity.py#L152). However, while doing so, there is a chance that none of candidates satisfy normal constraint. For this, I am assuming that I should expand my search window. Could you tell me how to go about this?

Thanks

Kiord commented 10 months ago

Assuming you are implementing an ICP algorithm, you probably are calling procustes at least once in a loop.

What about setting a low weight when the angle is > 90 deg ?

weights = np.ones(len(candidates))
weights[where angle is > 90deg] = 0.01 # not 0 to prevent breaking when there are less than 3 good pairs
transform = procrustes(source_points, target_points, weights)

I feel like expanding the search window of the closest point algorithm goes a bit against the idea behind ICP. Yet you can try to remove temporarily the "bad" points from one of the meshes and try calling closest_point again until finding enough "good" pairs. It would hurt the performances though.