Debian Codegraph @

examples/01-filter/extract_cells_inside_surface.py

raw
1 """
2 .. _extract_cells_inside_surface_example:
3
4 Extract Cells Inside Surface
5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
7 Extract the cells inside or outside a closed surface using
8 :meth:`~pyvista.DataSetFilters.select_interior_points`.
9
10 """
11
12 # %%
13
14 # sphinx_gallery_thumbnail_number = 2
15 import pyvista as pv
16 from pyvista import examples
17
18 mesh = examples.download_cow()
19
20 cpos = pv.CameraPosition(
21 position=(13.0, 7.6, -13.85),
22 focal_point=(0.44, -0.4, -0.37),
23 viewup=(-0.28, 0.9, 0.3),
24 )
25
26 dargs = dict(show_edges=True)
27 # Rotate the mesh to have a second mesh
28 rot = mesh.rotate_y(90, inplace=False)
29
30 pl = pv.Plotter()
31 pl.add_mesh(mesh, color='Crimson', **dargs)
32 pl.add_mesh(rot, color='mintcream', opacity=0.35, **dargs)
33 pl.camera_position = cpos
34 pl.show()
35
36 # %%
37 # Mark points inside with 1 and outside with a 0
38 select = mesh.select_interior_points(rot)
39
40 select
41 # %%
42 # Extract two meshes, one completely inside and one completely outside the
43 # enclosing surface.
44
45 inside = select.threshold(0.5)
46 outside = select.threshold(0.5, invert=True)
47
48 # %%
49 # display the results
50
51 pl = pv.Plotter()
52 pl.add_mesh(outside, color='Crimson', **dargs)
53 pl.add_mesh(inside, color='green', **dargs)
54 pl.add_mesh(rot, color='mintcream', opacity=0.35, **dargs)
55
56 pl.camera_position = cpos
57 pl.show()
58 # %%
59 # .. tags:: filter