| 1 |
""" |
| 2 |
.. _extract_edges_example: |
| 3 |
|
| 4 |
Extract Edges |
| 5 |
~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
Extract edges from a surface. |
| 8 |
""" |
| 9 |
|
| 10 |
# sphinx_gallery_thumbnail_number = 2 |
| 11 |
import pyvista as pv |
| 12 |
from pyvista import examples |
| 13 |
|
| 14 |
# %% |
| 15 |
# From vtk documentation, the edges of a mesh are one of the following: |
| 16 |
# |
| 17 |
# 1. boundary (used by one polygon) or a line cell |
| 18 |
# 2. non-manifold (used by three or more polygons) |
| 19 |
# 3. feature edges (edges used by two triangles and whose dihedral angle > feature_angle) |
| 20 |
# 4. manifold edges (edges used by exactly two polygons). |
| 21 |
# |
| 22 |
# The :func:`extract_feature_edges() <pyvista.DataSetFilters.extract_feature_edges>` |
| 23 |
# filter will extract those edges given a feature angle and return a dataset |
| 24 |
# with lines that represent the edges of the original mesh. |
| 25 |
# |
| 26 |
# To demonstrate, we will first extract the edges around a sample CAD model: |
| 27 |
|
| 28 |
# Download the example CAD model and extract all feature edges above 45 degrees |
| 29 |
mesh = examples.download_cad_model() |
| 30 |
edges = mesh.extract_feature_edges(45) |
| 31 |
|
| 32 |
# Render the edge lines on top of the original mesh. Zoom in to provide a better figure. |
| 33 |
pl = pv.Plotter() |
| 34 |
pl.add_mesh(mesh, color=True) |
| 35 |
pl.add_mesh(edges, color='red', line_width=5) |
| 36 |
pl.camera.zoom(1.5) |
| 37 |
pl.show() |
| 38 |
|
| 39 |
|
| 40 |
# %% |
| 41 |
# We can do this analysis for any :class:`pyvista.PolyData` object. Let's try |
| 42 |
# the cow mesh example: |
| 43 |
|
| 44 |
mesh = examples.download_cow() |
| 45 |
edges = mesh.extract_feature_edges(20) |
| 46 |
|
| 47 |
pl = pv.Plotter() |
| 48 |
pl.add_mesh(mesh, color=True) |
| 49 |
pl.add_mesh(edges, color='red', line_width=5) |
| 50 |
pl.camera_position = pv.CameraPosition( |
| 51 |
position=(9.5, 3.0, 5.5), focal_point=(2.5, 1, 0), viewup=(0, 1, 0) |
| 52 |
) |
| 53 |
pl.show() |
| 54 |
|
| 55 |
|
| 56 |
# %% |
| 57 |
# We can leverage the :any:`pyvista.PolyData.n_open_edges` property and |
| 58 |
# :func:`pyvista.DataSetFilters.extract_feature_edges` filter to count and |
| 59 |
# extract the open edges on a :class:`pyvista.PolyData` mesh. |
| 60 |
|
| 61 |
# Download a sample surface mesh with visible open edges |
| 62 |
mesh = examples.download_bunny() |
| 63 |
mesh |
| 64 |
|
| 65 |
# %% |
| 66 |
# We can get a count of the open edges with: |
| 67 |
mesh.n_open_edges |
| 68 |
|
| 69 |
|
| 70 |
# %% |
| 71 |
# And we can extract those edges with the ``boundary_edges`` option of |
| 72 |
# :func:`pyvista.DataSetFilters.extract_feature_edges`: |
| 73 |
edges = mesh.extract_feature_edges( |
| 74 |
boundary_edges=True, feature_edges=False, manifold_edges=False |
| 75 |
) |
| 76 |
|
| 77 |
pl = pv.Plotter() |
| 78 |
pl.add_mesh(mesh, color=True) |
| 79 |
pl.add_mesh(edges, color='red', line_width=5) |
| 80 |
pl.camera_position = pv.CameraPosition( |
| 81 |
position=(-0.2, -0.13, 0.12), |
| 82 |
focal_point=(-0.015, 0.10, -0.0), |
| 83 |
viewup=(0.28, 0.26, 0.9), |
| 84 |
) |
| 85 |
pl.show() |
| 86 |
# %% |
| 87 |
# .. tags:: filter |