[vtkusers] update

j-P cervellone at gmail.com
Mon Mar 17 19:59:03 EDT 2014


Hello all, 

I am trying to visualize really large images in vtk for this i have
subdivided them into tiles and now i am trying to browse through them
adjusting the camera as i go. 

For the time being i have assigned the WASD keys to funktions that do move
up down right and left. 
whenever i move up and down in my dataset the view is updated without
problem however the image does not move whenever i move right and left. If i
move up and down again the image jumps to the correct position. In short
only right and left do not work. This puzzles me as i use virtually the same
function for the movements , appended is my sample code:


thanks 
jp

# 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 getCameraPositions():
    print "camera focal Point ", camera.GetFocalPoint()
    print "camera view Point ", camera.GetViewUp()
    print "Camera position " , camera.GetPosition()

def getVolumePositions():
    print  "origin :",  ox, oy, oz
"""

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()
    #getCameraPositions()
    #getVolumePositions()
    print currentPosition



def keypress(obj,event):
    global slice
    key = obj.GetKeySym()
    print key
    if key == "plus":
        slice +=1
        viewer.SetSlice(slice)
    elif key == "minus":
        slice = slice-1
        viewer.SetSlice(slice)
    elif key == "w":
        print "w"
        moveUp()
    elif key == "s":
        print "s"
        moveDown()
    elif key == "d":
        print "d"
        moveRight()
    elif key == "a":
        print "a"
        moveLeft()
    elif key == "x":
        print "x"
        moveBack()
    elif key== "y":
        print "y"
        moveFront()



def moveUp():
    global currentPosition
    x,y,z = currentPosition
    y = y-1
    currentPosition = x,y,z
    updateData()
    return
def moveDown():
    global currentPosition
    x,y,z = currentPosition
    y = y+1
    currentPosition = x,y,z
    updateData()
    return
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()
def moveFront():
    global currentPosition
    x,y,z = currentPosition
    z = z-1
    currentPosition = x,y,z
    updateData()
def moveBack():
    global currentPosition
    x,y,z = currentPosition
    z = z+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()

 



--
View this message in context: http://vtk.1045678.n5.nabble.com/update-tp5726358.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list