[vtkusers] vtkImagePlaneWidget interpolation problem

Oliver Natt onatt at gmx.de
Thu Sep 28 15:31:28 EDT 2017


Dear vtkusers,

during my work on a small programm for the analysis of computed 
tomography data I found an unexpected behaviour of the 
vtkImagePlaneWidget. I tried to boil down the problem to a small python 
script, which uses a very small image dimension of only 3 x 3 x 3, where 
the effect becomes prominent (see python program below).

The script makes a cut through a 3 x 3 x 3 volume using a 
vtkImagePlaneWidget. The four coloured spheres indicate the expected 
edges of the resulting image slice. The result is pretty much, what I 
expected (see attachement screenshot1.png). However, when I grab the 
vtkImagePlaneWidget using "Control + Middle Mouse Button" an move the 
plane around in the x-y plane, some unexpected effects occur (see 
screenshot2.png): Sometimes some kind of interpolation happens, which 
results in an image that looks rather like a 6 x 3 grid instead of 3 x 3 
and also the position of the image relative to the four coloured spheres 
changes. What I require is a cut through the volume data that preserves 
the correct voxel boundaries. Is that possible using the 
vtkImagePlaneWidget or is there an alternative class, that serves this 
purpose?

Many thanks
Oliver

import vtk
import vtk.util.numpy_support
import numpyas np

# create a renderer renderer = vtk.vtkRenderer()
renderer.SetBackground(0.2,0.2,0.5)
renderer.SetBackground2(0.4,0.4,1.0)
renderer.SetGradientBackground(True)

# create a render_window render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)

# create a renderwindowinteractor iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(render_window)
iren.Initialize()

# Create a 3 x 3 x 3 image data with a spacing of 1. image = vtk.vtkImageData()
dat = np.linspace(1,27,27,dtype=np.int16) *10 dat = np.ascontiguousarray(dat)
dat = vtk.util.numpy_support.numpy_to_vtk(dat,deep=1)
image.SetDimensions(3,3,3)
image.SetSpacing(1,1,1)
image.GetPointData().SetScalars(dat)
image.Modified()

# Create a vtkImagePlaneWidget and activate it plane_widget = vtk.vtkImagePlaneWidget()
plane_widget.TextureInterpolateOff()
plane_widget.SetInputData(image)
plane_widget.SetInteractor(render_window.GetInteractor())
plane_widget.SetOrigin(0,0,0)
plane_widget.SetPoint1(8,0,0)
plane_widget.SetPoint2(0,8,0)
plane_widget.UpdatePlacement()
plane_widget.DisplayTextOn()
plane_widget.On()
plane_widget.SetWindowLevel(200,50)
rs = plane_widget.GetReslice()


def create_sphere(x, y, z, col):
     """Create a small sphere with color col at postion x, y, z""" source = vtk.vtkSphereSource()
     source.SetCenter(x, y, z)
     source.SetRadius(0.2)
     mapper = vtk.vtkPolyDataMapper()
     mapper.SetInputConnection(source.GetOutputPort())
     actor = vtk.vtkActor()
     actor.SetMapper(mapper)
     actor.GetProperty().SetColor(col)
     renderer.AddActor(actor)


# Position 4 small markers at the expected edges of the image slice. create_sphere(0,0,0, (1,0,0))
create_sphere(3,0,0, (0,1,0))
create_sphere(0,3,0, (0,0,1))
create_sphere(3,3,0, (1,1,0))

# Reset the camera and start the RenderWindowInteractor renderer.ResetCamera()
iren.Start()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170928/b1d38f54/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot1.png
Type: image/png
Size: 15542 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170928/b1d38f54/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot2.png
Type: image/png
Size: 14906 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170928/b1d38f54/attachment-0001.png>


More information about the vtkusers mailing list