エッジを抽出

エッジを抽出#

サーフェスからエッジを抽出します.

from __future__ import annotations

import pyvista as pv
from pyvista import examples

vtkのマニュアルによると,メッシュのエッジは次のいずれかです.

  1. 境界(1つのポリゴンで使用)またはラインセル

  2. 非多様体(3つ以上の多角形によって使用されます)

  3. フィーチャエッジ(2つの3角形で使用され,2面角がfeature_angleより大きいエッジ)

  4. 多様体のエッジ(ちょうど2つのポリゴンで使用されるエッジ).

extract_feature_edges() フィルタは,特徴的な角度が与えられたときにそれらのエッジを抽出し,元のメッシュのエッジを表す線を含むデータセットを返します.

まず,サンプルのCADモデルの周囲のエッジを抽出してみましょう.

# Download the example CAD model and extract all feature edges above 45 degrees
mesh = examples.download_cad_model()
edges = mesh.extract_feature_edges(45)

# Render the edge lines on top of the original mesh.  Zoom in to provide a better figure.
pl = pv.Plotter()
pl.add_mesh(mesh, color=True)
pl.add_mesh(edges, color='red', line_width=5)
pl.camera.zoom(1.5)
pl.show()
extract edges

この解析は pyvista.PolyData オブジェクトに対して行うことができます.牛のメッシュの例を見てみましょう.

mesh = examples.download_cow()
edges = mesh.extract_feature_edges(20)

pl = pv.Plotter()
pl.add_mesh(mesh, color=True)
pl.add_mesh(edges, color='red', line_width=5)
pl.camera_position = pv.CameraPosition(
    position=(9.5, 3.0, 5.5), focal_point=(2.5, 1, 0), viewup=(0, 1, 0)
)
pl.show()
extract edges

pyvista.PolyData.n_open_edges プロパティと pyvista.DataSetFilters.extract_feature_edges() フィルタを利用して, pyvista.PolyData メッシュの開いたエッジをカウントおよび抽出できます.

# Download a sample surface mesh with visible open edges
mesh = examples.download_bunny()
mesh
PolyDataInformation
N Cells69451
N Points35947
N Strips0
X Bounds-9.469e-02, 6.101e-02
Y Bounds3.299e-02, 1.873e-01
Z Bounds-6.187e-02, 5.880e-02
N Arrays0


次のコマンドを使用すると,開いたエッジの数を取得できます:

223

pyvista.DataSetFilters.extract_feature_edges()boundary_edges オプションを使用すると,これらのエッジを抽出できます.

edges = mesh.extract_feature_edges(
    boundary_edges=True, feature_edges=False, manifold_edges=False
)

pl = pv.Plotter()
pl.add_mesh(mesh, color=True)
pl.add_mesh(edges, color='red', line_width=5)
pl.camera_position = pv.CameraPosition(
    position=(-0.2, -0.13, 0.12),
    focal_point=(-0.015, 0.10, -0.0),
    viewup=(0.28, 0.26, 0.9),
)
pl.show()
extract edges

Tags: filter

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

Sphinx-Galleryによるギャラリー