サーフェスメッシュをボクセル化する
閉じたサーフェスまたはボリュームメッシュのボクセルモデル(レゴのように)を作成します.
この例はまた,境界 pyvista.PolyData
表面からの陰的距離を計算する方法を示す.
from __future__ import annotations
import numpy as np
import pyvista as pv
from pyvista import examples
# Load a surface to voxelize
surface = examples . download_foot_bones ()
surface
Copy to clipboard
PolyData Information
N Cells 4204
N Points 2154
N Strips 0
X Bounds -5.633e+00, 5.633e+00
Y Bounds -1.860e+00, 1.860e+00
Z Bounds -2.125e+00, 2.126e+00
N Arrays 0
cpos = [
( 7.656346967151718 , - 9.802071079151158 , - 11.021236183314311 ),
( 0.2224512272564101 , - 0.4594554282112895 , 0.5549738359311297 ),
( - 0.6279216753504941 , - 0.7513057097368635 , 0.20311105371647392 ),
]
surface . plot ( cpos = cpos , opacity = 0.75 )
Copy to clipboard
境界面のボクセルモデルを作成する
voxels = pv . voxelize ( surface , density = surface . length / 200 )
p = pv . Plotter ()
p . add_mesh ( voxels , color = True , show_edges = True , opacity = 0.5 )
p . add_mesh ( surface , color = 'lightblue' , opacity = 0.5 )
p . show ( cpos = cpos )
Copy to clipboard
モデリング用のグリッドを作成する場合に備えて,新しいボクセルモデルにスカラーフィールドを追加することもできます.ここでは,ボーン密度のスカラーフィールドを追加します.
voxels [ 'density' ] = np . full ( voxels . n_cells , 3.65 ) # g/cc
voxels
Copy to clipboard
Header Data Arrays
UnstructuredGrid Information
N Cells 93041
N Points 113192
X Bounds -5.633e+00, 5.584e+00
Y Bounds -1.860e+00, 1.858e+00
Z Bounds -2.125e+00, 2.097e+00
N Arrays 3
Name Field Type N Comp Min Max
vtkOriginalPointIds Points int64 1 4.002e+03 7.213e+05
vtkOriginalCellIds Cells int64 1 3.980e+03 6.947e+05
density Cells float64 1 3.650e+00 3.650e+00
voxels . plot ( scalars = 'density' , cpos = cpos )
Copy to clipboard
一定のスカラーフィールドは退屈なので,バウンディングサーフェスからの距離によって変化するスカラーフィールドを追加して少しおしゃれにしましょう.
voxels . compute_implicit_distance ( surface , inplace = True )
voxels
Copy to clipboard
Header Data Arrays
UnstructuredGrid Information
N Cells 93041
N Points 113192
X Bounds -5.633e+00, 5.584e+00
Y Bounds -1.860e+00, 1.858e+00
Z Bounds -2.125e+00, 2.097e+00
N Arrays 4
Name Field Type N Comp Min Max
vtkOriginalPointIds Points int64 1 4.002e+03 7.213e+05
implicit_distance Points float64 1 -6.951e-01 4.148e-01
vtkOriginalCellIds Cells int64 1 3.980e+03 6.947e+05
density Cells float64 1 3.650e+00 3.650e+00
contours = voxels . contour ( 6 , scalars = 'implicit_distance' )
p = pv . Plotter ()
p . add_mesh ( voxels , opacity = 0.25 , scalars = 'implicit_distance' )
p . add_mesh ( contours , opacity = 0.5 , scalars = 'implicit_distance' )
p . show ( cpos = cpos )
Copy to clipboard
Tags: filter
Total running time of the script: (0 minutes 9.797 seconds)
Sphinx-Galleryによるギャラリー