python - 如何将从多个 .vtp 文件中提取的点插入到单个多数据中
问题描述
我将 slice10 中的点保存到 polydata 10 中,将 slice11 中的点保存到 polydata11 中
slice10 = 'Slices\Slice10\Slice10_0_0.vtp'
slice11 = 'Slices\Slice11\Slice11_0_0.vtp'
readerSlice10 = vtk.vtkXMLPolyDataReader()
readerSlice10.SetFileName(slice10)
readerSlice10.Update()
readerSlice11 = vtk.vtkXMLPolyDataReader()
readerSlice11.SetFileName(slice11)
readerSlice11.Update()
polydata10 = vtk.vtkPolyData()
polydata10.SetPoints(readerSlice10.GetOutput().GetPoints())
polydata11 = vtk.vtkPolyData()
polydata11.SetPoints(readerSlice11.GetOutput().GetPoints())
现在我想拥有一个单一的多数据,其中所有点从 slice10 和 slice11 一起形成,我该如何实现呢?
解决方案
这可能是您正在寻找的。
import vtk
# Generate two sets of points for this example.
points0 = vtk.vtkPoints()
points1 = vtk.vtkPoints()
points0.InsertNextPoint(1., 0., 0.)
points0.InsertNextPoint(1., 1., 0.)
points1.InsertNextPoint(1., 0., 1.)
points1.InsertNextPoint(1., 1., 1.)
polydata10 = vtk.vtkPolyData()
polydata11 = vtk.vtkPolyData()
polydata10.SetPoints(points0)
polydata11.SetPoints(points1)
#-------------------------------------
# Create a set of points that joints the two sets of points from polydata10 and polydata11.
pointsJoined = vtk.vtkPoints()
for i in range(polydata10.GetNumberOfPoints()):
pointsJoined.InsertNextPoint(polydata10.GetPoint(i))
for i in range(polydata11.GetNumberOfPoints()):
pointsJoined.InsertNextPoint(polydata11.GetPoint(i))
# Initialize a polydata object and set the joint point set.
polydata = vtk.vtkPolyData()
polydata.SetPoints(pointsJoined)
# Create verticies so the points can be visualized
verts = vtk.vtkCellArray()
for i in range(polydata.GetNumberOfPoints()):
verts.InsertNextCell(1) # Create a 1 dimensional cell
verts.InsertCellPoint(i) # Append point i to the verts array
polydata.SetVerts(verts)
# Setup and run the visualization
ren = vtk.vtkRenderer() #: vtk.vtkRenderer, The renderer for the visualization
renWin = vtk.vtkRenderWindow() #: vtk.vtkRenderWindow, The render window
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor() #: vtk.vtkRenderWindowInteractor, The render window interactor
iren.SetRenderWindow(renWin)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(polydata)
actor = vtk.vtkActor()
actor.GetProperty().SetPointSize(5) # Increase the size of the points
actor.SetMapper(mapper)
ren.AddActor(actor)
iren.Start()
推荐阅读
- c++ - 在 C/C++ 中,我试图在没有 if-else 阶梯的 for 循环中调用不同的函数(在描述中解释)
- css - 如何在中间显示图标和文本
- css - CSS 网格忽略第二列 minmax() 中指定的最小宽度
- r - 我们如何在 shinyapp 中复制具有不同属性名称的现有属性值?
- windows - 在 Inno Setup 中将图标图像添加到上下文菜单
- angular - 将选择器名称转换为可迭代的字符串或对象
- c# - 功能
延长条件 - excel - 有没有可能添加新行并插入更新的公式的方法?
- sql - Oracle SQL 中的 FOR 循环或将 SQL 应用于多个 Oracle 表
- javascript - electron-forge:如何指定钩子?