简体   繁体   English

PyVista:使用附加点更新 PolyData

[英]PyVista: Update PolyData with additional points

I would like to add points (and cells) to the pyvista.PolyData in the plotter.我想向绘图仪中的pyvista.PolyData添加点(和单元格)。 I tried using the Plotter.update_coordinates function however this is only useful for point data with equal size:我尝试使用Plotter.update_coordinates function 但这仅对大小相等的点数据有用:

import numpy as np
import pyvista as pv
import pyvistaqt

points = np.array([[1, 0, 0],
                   [2, 0, 0],
                   [3, 0, 0]])


point_cloud = pv.PolyData(points)

plotter = pyvistaqt.BackgroundPlotter()
a = plotter.add_points(point_cloud)
plotter.show()

new_points = np.array([[1, 0, 0],
                       [2, 0, 0],
                       [5, 0, 0], 
                       [7, 0, 0]])  # Not updated in the plotter

plotter.update_coordinates(new_points, point_cloud, render=True)

It seems the points are updated, however not the cells.似乎点已更新,但单元格未更新。 Hence, only the corresponding cells are modified in the plotter.因此,在绘图仪中仅修改相应的单元格。

What is the best practice to update the PolyData, which includes new (additional) points?更新包含新(附加)点的 PolyData 的最佳做法是什么?

You said你说

I would like to add points (and cells) to the pyvista.PolyData in the plotter我想在绘图仪中向pyvista.PolyData添加点(和单元格)

But this is not clear to me.但这对我来说并不清楚。 You have two options: either add further points to a PolyData and then plot that one mesh, or you can add two different PolyData objects to the same plotter.您有两种选择:要么向PolyData添加更多点,然后向该网格添加 plot,要么您可以向同一绘图仪添加两个不同的PolyData对象。

Here are the two options:以下是两个选项:

import pyvista as pv

sphere_a = pv.Sphere()
sphere_b = sphere_a.translate((1, 0, 0), inplace=False)

# option 1: merge the PolyData
spheres = sphere_a + sphere_b
# alternatively: sphere_a += sphere_b for an in-place operation
spheres.plot()  # plot the two spheres in one PolyData
# we could also use a Plotter for this

# option 2: add both PolyData to the same plotter
plotter = pv.Plotter()
plotter.add_mesh(sphere_a)  # or add_points() for a point cloud
plotter.add_mesh(sphere_b)
plotter.show()  # show the two spheres from two PolyData

And as a side note, if you only have a point cloud (ie no cells) you should consider using the new PointSet class .附带说明一下,如果您只有点云(即没有单元格),则应考虑使用 新的PointSet class This needs PyVista 0.34.0 and VTK 9.1.0 or higher.这需要 PyVista 0.34.0 和 VTK 9.1.0 或更高版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM