Last active
October 31, 2021 04:33
-
-
Save flutefreak7/bd621a9a836c8224e92305980ed829b9 to your computer and use it in GitHub Desktop.
Convex Hull with vtk, pyvista, and scipy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.spatial import ConvexHull | |
from pyvista import PolyData | |
def polyhull(x, y, z): | |
hull = ConvexHull(np.column_stack((x, y, z))) | |
faces = np.column_stack((3*np.ones((len(hull.simplices), 1), dtype=np.int), hull.simplices)).flatten() | |
poly = PolyData(hull.points, faces) | |
return poly | |
x, y, z = np.random.rand(100, 3).T | |
hull = polyhull(x, y, z) | |
hull.plot() |
Author
flutefreak7
commented
Nov 13, 2019
I've found scipy's ConvexHull to be 500X faster than using vtkDelaunay3D and vtkDataSetSurfaceFilter because you skip the expensive 3D tesselation of the volume.
Ok, so it looks like Delaunay scales at log(n) with the number of points while Convex Hull doesn't. Above 1000 points, the Delaunay method becomes prohibitively slow.
Without logging the y-axis the difference is stark. Delaunay starts taking seconds near 10,000 where scipy's ConvexHull stays in millisecond territory.
Logging the y-axis doesn't show the contrast as starkly, but allows the data to be read more clearly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment