[英]How to insert points extracted from multiple .vtp files into a single polydata
我將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的所有點的polydata,我怎樣才能做到這一點?
這可能是你正在尋找的。
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.