Python,C ++ VTK仿射变换

时间:2017-08-21 18:56:59

标签: python vtk

我的第一个问题。我正在使用vtk库(神经影像数据)创建可视化管道。但是,我真的在努力处理仿射问题。从文档(例如,doxygen,书籍)看来我应该使用这样的东西:

transform = vtkTransform()
matrix_vtk =vtkMatrix4x4()
matrix_vtk.DeepCopy((1, 0, 0, 0, 0, 1, 0, 1, 0,0,1,0,0,0,0,1))
transform.SetMatrix(matrix_vtk)
transform_filter = vtkTransformPolyDataFilter()
transform_filter.SetTransform(transform)
dataset_mapper = vtk.vtkDataSetMapper()
dataset_mapper.SetInputConnection(transform_filter.GetOutputPort())
actor.SetMapper(dataset_mapper)

然而,结果不是我预期的结果:D 完整的代码是:

from vtk import *

fname_trk = "test/L113619_imfs_d10_110mm.trk"
fname_vtk = "test/L113619_imfs_d10.vtk"
fname_ply = "test/113619_Lwhite.ply"

reader = vtkPLYReader()
reader.SetFileName(fname_ply)
reader_vtk = vtkPolyDataReader()
reader_vtk.SetFileName(fname_vtk)

ren = vtkRenderer()
wren = vtkRenderWindow()
iren = vtkRenderWindowInteractor()
wren.AddRenderer(ren)
iren.SetRenderWindow(wren)
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(reader.GetOutputPort())
mapper_vtk = vtkPolyDataMapper()
mapper_vtk.SetInputConnection(reader_vtk.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)
actor_vtk = vtkActor()
# actor_vtk.SetMapper(mapper_vtk)
ren.AddActor(actor_vtk)
ren.AddActor(actor)

transform = vtkTransform()
matrix_vtk =vtkMatrix4x4()
matrix_vtk.DeepCopy((1, 0, 0, 0, 0, 1, 0, 1, 0,0,1,0,0,0,0,1))
transform.SetMatrix(matrix_vtk)
transform_filter = vtkTransformPolyDataFilter()
transform_filter.SetTransform(transform)
dataset_mapper = vtk.vtkDataSetMapper()
dataset_mapper.SetInputConnection(transform_filter.GetOutputPort())
actor.SetMapper(dataset_mapper)
actor.SetMapper(datasetmapper)

iren.Initialize()
iren.Start()

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

您没有将任何输入连接到过滤器,例如transform_filter.SetInputData(reader.GetOutputPort())

如果你能写出你期望的东西会很有帮助。

答案 1 :(得分:0)

您的过程正确,但是,您的输出未正确定义。您可以逐行运行它并跟踪输出。