[vtkusers] image moved afer an orientation change
José M. Rodriguez Bacallao
jmrbcu at gmail.com
Wed Dec 12 07:24:46 EST 2012
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?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121212/0a40dbcd/attachment.htm>
More information about the vtkusers
mailing list