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

face_adjacency_edges_tree invalid for meshes with a boundary/border #2331

Open
DanielGrestH3D opened this issue Dec 17, 2024 · 1 comment
Open

Comments

@DanielGrestH3D
Copy link

DanielGrestH3D commented Dec 17, 2024

We love the trimesh library and are using it a lot in our daily work. Great work !

I have encountered an issue with face_adjacency_edges_tree and edges_faces.
It seems that the data is not valid for meshes, that are not watertight.
A comment about this in the function description would have saved us hours of debugging.
Fixing it would be even better though :)

Code to reproduce:

mesh = trimesh.creation.icosphere(subdivisions=2, radius=1.0)

plane_normal = [0, 0, 1]

plane_origin = [0, 0, 0]

mesh = mesh.slice_plane(plane_origin, plane_normal)

edge = mesh.edges_sorted[0]

adj_index = mesh.face_adjacency_edges_tree.query([edge])[1]

adjacent_faces = mesh.face_adjacency[adj_index]

adjacent_faces

Out[10]: array([[111, 146]])

adjacent_face_definitions = mesh.faces[adjacent_faces]

adjacent_face_definitions

Out[12]: 
TrackedArray([[[50, 64,  6],
               [ 6, 64, 46]]], dtype=int64)

edge
Out[13]: array([ 0, 67], dtype=int64)

trimesh version: 4.5.3

@mikedh
Copy link
Owner

mikedh commented Dec 17, 2024

Hey, I think what may be happening is edge doesn't exist in face_adjacency_edges because presumably it's on a boundary so it's giving a wrong index:

 sliced.face_adjacency_edges_tree.query(edge)
Out[21]: (6.708203932499369, 126)

Since we're sort of using the cKDTree off-script for this backwards index lookup if the distance isn't zero it will be totally wrong, you may want to add a check:

distance_check, adj_index = mesh.face_adjacency_edges_tree.query([edge])
assert (distance_check < 1e-12).all()

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

2 participants