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

trimesh.bounds.oriented_bounds is slow for NumPy array input. #2342

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

guystoppi
Copy link
Contributor

Hello,

While using trimesh==4.5.0 to compute the minimum volume oriented bounding box of a mesh, I noticed the following bug. Running the below code seems to take an extremely long time:

torus_mesh = g.trimesh.creation.torus(major_radius=5, minor_radius=1, major_sections=512, minor_sections=256)
trimesh.bounds.oriented_bounds(torus_mesh.vertices)

But running this similar piece of code completed in ~7 seconds:

torus_mesh = g.trimesh.creation.torus(major_radius=5, minor_radius=1, major_sections=512, minor_sections=256)
trimesh.bounds.oriented_bounds(trimesh.Trimesh(vertices=torus_mesh.vertices))

My best guess is that, in the first case, the computed convex hull's face adjacencies seem to be wrong although I'm not sure how exactly. Line 253 in bounds.py computes 139156 edges that need to be checked, which doesn't seem right. In the second case, only 516 edges are checked.

I noticed that, in the first case, the convex hull is being computed by trimesh.convex.convex_hull(..., repair=False) and, in the second case, the convex hull is effectively being computed with trimesh.convex.convex_hull(..., repair=True). This PR makes both cases use repair = True. Hopefully the solution is indeed that simple.

Thanks for the great library!

@mikedh mikedh changed the base branch from main to refactor/loadtype January 21, 2025 19:33
@mikedh mikedh merged commit f55646a into mikedh:refactor/loadtype Jan 21, 2025
@mikedh
Copy link
Owner

mikedh commented Jan 21, 2025

Good catch, and thanks for the fix!! Yeah it looks like with repair=False the hull early-exits before removing zero-magnitude faces and other stuff.

@guystoppi guystoppi deleted the obb_vertices_fix branch January 21, 2025 19:52
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.

2 participants