[vtkusers] image moved afer an orientation change
David Gobbi
david.gobbi at gmail.com
Wed Dec 12 08:54:57 EST 2012
Arrgh. Another typo. The code should be:
camera.SetFocalPoint(focal_point_for_axial_view)
style.SetImageOrientation(orientation_for_axial_view)
And of course you should save the focal point for the
previous orientation at the same time.
- David
On Wed, Dec 12, 2012 at 6:53 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> On Wed, Dec 12, 2012 at 6:51 AM, David Gobbi <david.gobbi at gmail.com> wrote:
>> The slicing and the panning are both controlled via the camera's focal
>> point. So slicing through the axial images causes the camera's
>> FocalPoint to move in and out along the Z axis. Then, when you switch
>> to a new orientation, this "Z" position is centered in the window.
>>
>> If you want to avoid this, you should save the FocalPoint for each
>> view orientation. Then, you can restore the focal point before you
>> call SetImageOrientation, e.g.
>>
>> camera.SetFocalPoint(focal_point_for_axial_view)
>> camera.SetImageOrientation(orientation_for_axial_view)
>>
>> - David
>>
>> On Wed, Dec 12, 2012 at 5:24 AM, José M. Rodriguez Bacallao
>> <jmrbcu at gmail.com> wrote:
>>> no one please, is this normal?
>>>
>>>
>>> On Tue, Dec 11, 2012 at 9:45 AM, José M. Rodriguez Bacallao
>>> <jmrbcu at gmail.com> wrote:
>>>>
>>>> hi folks, I am trying to implement a MPR viewer, so far so good. I am
>>>> using the new image classes, this is test code:
>>>>
>>>> #!/usr/bin/env python
>>>>
>>>> import os
>>>> import gdcm, vtkgdcm, vtk
>>>>
>>>>
>>>> def key_press(sender, event):
>>>> key = interactor.GetKeySym()
>>>> style.SetCurrentRenderer(renderer)
>>>> if key == 'a':
>>>> print 'axial'
>>>> style.SetImageOrientation(
>>>> style.GetZViewRightVector(),
>>>> style.GetZViewUpVector()
>>>> )
>>>> elif key == 'c':
>>>> print 'coronal'
>>>> style.SetImageOrientation(
>>>> style.GetYViewRightVector(),
>>>> style.GetYViewUpVector()
>>>> )
>>>> elif key == 's':
>>>> print 'axial'
>>>> style.SetImageOrientation(
>>>> style.GetXViewRightVector(),
>>>> style.GetXViewUpVector()
>>>> )
>>>> render_window.Render()
>>>>
>>>>
>>>>
>>>> interactor = vtk.vtkRenderWindowInteractor()
>>>> render_window = vtk.vtkRenderWindow()
>>>> render_window.SetSize(400, 400)
>>>> interactor.SetRenderWindow(render_window)
>>>>
>>>> style = vtk.vtkInteractorStyleImage()
>>>> style.SetInteractionModeToImageSlicing()
>>>> interactor.SetInteractorStyle(style)
>>>> style.AddObserver('CharEvent', key_press)
>>>>
>>>> print 'sorting files...'
>>>> path = '/home/jmrbcu/pictures/workpictures/dicom/BRAIN/'
>>>> files = [os.path.join(path, x) for x in os.listdir(path)]
>>>>
>>>> ipp = gdcm.IPPSorter()
>>>> ipp.SetComputeZSpacing(True)
>>>> ipp.SetZSpacingTolerance(1e-3)
>>>> result = ipp.Sort(files)
>>>>
>>>> sorted_files, zspacing = files, 0
>>>> if result:
>>>> sorted_files = ipp.GetFilenames()
>>>> zspacing = ipp.GetZSpacing()
>>>> print 'files sorted, z spacing is: %s' % zspacing
>>>> else:
>>>> print 'cannot sort files, this is not a valid volume'
>>>>
>>>> vtk_files = vtk.vtkStringArray()
>>>> map(vtk_files.InsertNextValue, sorted_files)
>>>>
>>>> reader = vtkgdcm.vtkGDCMImageReader()
>>>> reader.FileLowerLeftOn()
>>>> reader.SetFileNames(vtk_files)
>>>> reader.Update()
>>>>
>>>> spacing = reader.GetOutput().GetSpacing()
>>>> change = vtk.vtkImageChangeInformation()
>>>> change.SetInputConnection(reader.GetOutputPort())
>>>> change.SetOutputSpacing(spacing[0], spacing[1], zspacing)
>>>>
>>>> im = vtk.vtkImageResliceMapper()
>>>> im.SetInputConnection(change.GetOutputPort())
>>>> im.SliceFacesCameraOn()
>>>> im.SliceAtFocalPointOn()
>>>> im.BorderOff()
>>>>
>>>> ip = vtk.vtkImageProperty()
>>>> ip.SetColorWindow(255)
>>>> ip.SetColorLevel(128)
>>>> ip.SetAmbient(0.0)
>>>> ip.SetDiffuse(1.0)
>>>> ip.SetOpacity(1.0)
>>>> ip.SetInterpolationTypeToLinear()
>>>>
>>>> ia = vtk.vtkImageSlice()
>>>> ia.SetMapper(im)
>>>> ia.SetProperty(ip)
>>>>
>>>> renderer = vtk.vtkRenderer()
>>>> renderer.AddViewProp(ia)
>>>> renderer.SetBackground(0 , 0, 0)
>>>> render_window.AddRenderer(renderer)
>>>>
>>>> style.SetCurrentRenderer(renderer)
>>>> style.SetZViewRightVector((1, 0, 0))
>>>> style.SetZViewUpVector((0, -1, 0))
>>>>
>>>> style.SetXViewRightVector((0, 1, 0))
>>>> style.SetXViewUpVector((0, 0, 1))
>>>>
>>>> style.SetYViewRightVector((1, 0, 0))
>>>> style.SetYViewUpVector((0, 0, 1))
>>>> style.SetImageOrientation(style.GetZViewRightVector(),
>>>> style.GetZViewUpVector())
>>>>
>>>> # render the image
>>>> renderer.ResetCamera()
>>>> renderer.GetActiveCamera().ParallelProjectionOn()
>>>> renderer.ResetCameraClippingRange()
>>>> render_window.Render()
>>>>
>>>> interactor.Initialize()
>>>> interactor.Start()
>>>>
>>>> the problems arise in this sequence:
>>>>
>>>> 1- initially display the image: ok
>>>> 2- slice the image to a different slice with ctrl + mosue left: ok
>>>> 3- change the orientation to a different one (sagital or coronal, doesn't
>>>> matter): this is the problem, orientation of the image is changed fine to
>>>> the new one but the image is panned to a different position in the render
>>>> window/renderer, not the center of it and in a different slice (the middle
>>>> slice of the whole image)
>>>>
>>>> how can I avoid this, I mean, keep the image centered in the render
>>>> window/renderer when the image orientation is changed and in the correct
>>>> slice location?
More information about the vtkusers
mailing list