Wrap a Point Cloud in a Convex Hull#

Create a convex hull from a point cloud using tetrahedralization and surface extraction.

import numpy as np
import pyvista as pv
from pyvista import examples

Load a point cloud#

The download_horse_points() dataset is a dense scan of a horse statue. Subsample it to keep the hull geometry light.

full_cloud = examples.download_horse_points()
rng = np.random.default_rng(seed=2)
sample_ids = rng.choice(full_cloud.n_points, size=4000, replace=False)
cloud = pv.PolyData(full_cloud.points[sample_ids])
cloud
PolyData (0x75ff6cb46b60)
  N Cells:    4000
  N Points:   4000
  N Strips:   0
  X Bounds:   -4.164e-02, 4.188e-02
  Y Bounds:   -9.133e-02, 9.140e-02
  Z Bounds:   -7.651e-02, 7.534e-02
  N Arrays:   0


Extract the outer hull#

A Delaunay tetrahedralization followed by surface extraction returns the outer surface of the cloud.

hull = cloud.delaunay_3d(alpha=cloud.length).extract_surface(algorithm=None)

pl = pv.Plotter()
pl.add_points(
    cloud,
    color='black',
    point_size=6,
    render_points_as_spheres=True,
)
pl.add_mesh(hull, color='royalblue', opacity=0.4, show_edges=True)
pl.camera_position = pv.CameraPosition(
    position=(0.4, -0.5, 0.25),
    focal_point=cloud.center,
    viewup=(0, 0, 1),
)
pl.show()
convex hull

Inspect the wrapped surface#

The result is a closed surface enclosing every input point.

PolyData (0x75ff6aeb6800)
  N Cells:    1964
  N Points:   1580
  N Strips:   0
  X Bounds:   -4.164e-02, 4.188e-02
  Y Bounds:   -9.133e-02, 9.140e-02
  Z Bounds:   -7.651e-02, 7.534e-02
  N Arrays:   2


Tags: filter

Total running time of the script: (0 minutes 0.298 seconds)

Gallery generated by Sphinx-Gallery