我想用vtk模块python显示一个3D图像。图像以.vti格式保存。我编写了以下简单代码,但它不能正常工作。我怎样才能解决这个问题
import vtk
file_name = 'Vug.vti'
# Read the source file.
reader = vtk.vtkNrrdReader()
reader.SetFileName(file_name)
reader.Update()
# Map the image through the lookup table
color = vtk.vtkImageMapToColors()
#color.SetLookupTable(table)
color.SetInputConnection(reader.GetOutputPort())
# Display the image
actor = vtk.vtkImageActor()
actor.GetMapper().SetInputConnection(color.GetOutputPort())
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)
# Set up the interaction
interactor = vtk.vtkRenderWindowInteractor()
window.SetInteractor(interactor)
window.Render()
# Start interaction
interactor.Start()
vtkImageActor将图像显示为二维对象。如果要渲染三维体积,则需要使用vtkVolume对象
此示例显示如何在VTK中进行体积渲染: https://github.com/Kitware/VTK/blob/master/Examples/VolumeRendering/Python/SimpleRayCast.py
对于vtkplotter,这只是:
相关问题 更多 >
编程相关推荐