-----更新和解决方案-------
除非
renderwindow.Render()
在
中调用UpdateData()
功能行为仍然不稳定。 因此,渲染窗口也需要更新。
我正在尝试在vtk中可视化真正的大图像。为此,我已将它们细分为瓷砖,现在我正在尝试浏览它们,随时调整相机。
目前我已经将WASD键分配给左右上下移动的功能。 每当我在我的数据集中上下移动时,视图都会毫无问题地更新,但是每当我左右移动时图像都不会移动。如果我再次上下移动,图像会跳到正确的位置。总之,只有左右不起作用。这让我很困惑,因为我使用了几乎相同的动作功能,附加的是我的示例代码:
# current position is a list with x y z coordinates as filenames
#reader
metaImageReader = vtk.vtkMetaImageReader()
metaImageReader.SetFileName(filefolder + "%03d_%03d_%03d"%(currentPosition[0],currentPosition[1], currentPosition[2]) + extension)
metaImageReader.SetDataScalarTypeToUnsignedChar()
#metaImageReader.SetFileDimensionality(3)
metaImageReader.Update()
#create renderwindow
renWin = vtk.vtkRenderWindow()
renWin.SetSize(600,300)
#create renderer1
renderer_2d = vtk.vtkRenderer()
renderer_2d.SetViewport(0,0,0.5,1)
renderer_2d.SetBackground(1.0,1.0,1.0)
renWin.AddRenderer(renderer_2d)
#create renderer2
renderer_3d = vtk.vtkRenderer()
renderer_3d.SetViewport(0.5,0,1,1)
renderer_3d.SetBackground(0.0,0.0,0.0)
renWin.AddRenderer(renderer_3d)
mapper = vtk.vtkImageSliceMapper()
mapper.SetInput(metaImageReader.GetOutput())
mapper.Update()
actor = vtk.vtkImageSlice()
actor.SetMapper(mapper)
actor.Update()
renderer_2d.AddActor(actor)
def updateData():
global metaImageReader, actor, mapper, currentPosition, filefolder, extension, viewer, origin
metaImageReader.SetFileName(filefolder + "%03d_%03d_%03d"%(currentPosition[0],currentPosition[1], currentPosition[2]) + extension)
metaImageReader.Update()
mapper.Update()
actor.Update()
def keypress(obj,event):
key = obj.GetKeySym()
print key
if key == "w":
print "w"
moveUp()
elif key == "s":
print "s"
moveDown()
elif key == "d":
print "d"
moveRight()
elif key == "a":
print "a"
moveLeft()
def moveUp():
global currentPosition
x,y,z = currentPosition
y = y-1
currentPosition = x,y,z
updateData()
def moveDown():
global currentPosition
x,y,z = currentPosition
y = y+1
currentPosition = x,y,z
updateData()
def moveRight():
global currentPosition
x,y,z = currentPosition
x = x+1
currentPosition = x,y,z
updateData()
def moveLeft():
global currentPosition
x,y,z = currentPosition
x = x-1
currentPosition = x,y,z
updateData()
#create interactor
iren = vtk.vtkRenderWindowInteractor()
iren.AddObserver("KeyPressEvent", keypress)
iren.SetRenderWindow(renWin)
#visualization pipeline
# Source -> Reader -> Filter -> Mapper -> Actor
iren.Start()
renWin.Render()
答案 0 :(得分:0)
除非
renderwindow.Render()
在
中调用的UpdateData()
功能行为仍然不稳定。因此,渲染窗口也需要更新。