Extract Cells Inside Surface

Extract Cells Inside Surface#

Extract the cells inside or outside a closed surface using select_interior_points().

from __future__ import annotations

import pyvista as pv
from pyvista import examples

mesh = examples.download_cow()

cpos = pv.CameraPosition(
    position=(13.0, 7.6, -13.85),
    focal_point=(0.44, -0.4, -0.37),
    viewup=(-0.28, 0.9, 0.3),
)

dargs = dict(show_edges=True)
# Rotate the mesh to have a second mesh
rot = mesh.rotate_y(90, inplace=False)

pl = pv.Plotter()
pl.add_mesh(mesh, color='Crimson', **dargs)
pl.add_mesh(rot, color='mintcream', opacity=0.35, **dargs)
pl.camera_position = cpos
pl.show()
extract cells inside surface

Mark points inside with 1 and outside with a 0

PolyData (0x7c85f88b8fa0)
  N Cells:    3263
  N Points:   2903
  N Strips:   0
  X Bounds:   -4.446e+00, 5.998e+00
  Y Bounds:   -3.637e+00, 2.760e+00
  Z Bounds:   -1.701e+00, 1.701e+00
  N Arrays:   1


Extract two meshes, one completely inside and one completely outside the enclosing surface.

inside = select.threshold(0.5)
outside = select.threshold(0.5, invert=True)

display the results

pl = pv.Plotter()
pl.add_mesh(outside, color='Crimson', **dargs)
pl.add_mesh(inside, color='green', **dargs)
pl.add_mesh(rot, color='mintcream', opacity=0.35, **dargs)

pl.camera_position = cpos
pl.show()
extract cells inside surface

Tags: filter

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

Gallery generated by Sphinx-Gallery