如何将从多个.vtp文件提取的点插入单个多数据

时间:2019-03-29 16:32:57

标签: python polygon vtk point

我将slice10中的点保存到了多数据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在一起,如何实现呢?

1 个答案:

答案 0 :(得分:0)

这可能就是您想要的。

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()