提问人:Sterling Butters 提问时间:11/15/2023 更新时间:11/15/2023 访问量:22
PyVista:获取网格索引(三角形)
PyVista: Getting mesh indices (triangles)
问:
我最初使用的是 https://github.com/pmneila/PyMCubes,它可以方便地输出网格点和索引,但后来转向了 PyVista,因为无论出于何种原因,PyMCubes 应用了某种不理想的奇怪转换。如何从PyVista中提取相同的信息?
对于一个简单的球体:
def sphere(x, y, z):
scalar = 8 * np.ones(len(x*y*z))
dist = (x**2 + y**2 + z**2)**(1/2)
scalar[(dist >= 1**2) | (dist <= 0.75**2) | (z <= 0)] = 0
return scalar
# create a uniform grid to sample the function with
n = 100
x_min, y_min, z_min = -2, -2, -2
grid = pv.ImageData(
dimensions=(n, n, n),
spacing=(abs(x_min) / n * 2, abs(y_min) / n * 2, abs(z_min) / n * 2),
origin=(x_min, y_min, z_min),
)
x, y, z = grid.points.T
values = sphere(x, y, z)
fig = go.Figure([go.Scatter3d(x=x, y=y, z=z, name='inner', mode='markers', marker=dict(size=values)),])
# fig.show(renderer='browser')
mesh = grid.contour([1], values, method='marching_cubes').smooth()
dist = np.linalg.norm(mesh.points, axis=1)
mesh.plot(scalars=dist, smooth_shading=True, specular=1, opacity=0.3, cmap="plasma", show_scalar_bar=False)
triangulated = mesh.extract_surface()
triangles = triangulated.surface_indices().reshape(-1, 3)
vertices = mesh.points
我抓取的顶点和网格点肯定彼此不对应,因为独立于 PyVista 绘制它们会产生垃圾。
答: 暂无答案
评论
regular_faces
来获取人脸索引。并使用相同的来获得相应的积分。这是否符合您的期望?.points
surface_indices()
triangulated
triangulated.points
regular_faces