[vtkusers] GetTransform error with vtkAffineRepresentation2D

Jothy jothybasu at gmail.com
Mon Jun 28 12:46:46 EDT 2010


Hi all,

I am trying to use vtkAffineWidgwet ( modified from the vtk/Example).

I am able to render both the image and widget, but there is no transform
effect and there it throws an error in the line

transform=rep.GetTransform()

Here is the code

from vtk import*


# Demonstrate how to use the vtkAffineWidget to apply affine transforms
# ( translate, scale, rotate, shear ) to an actor.

# Start by reading in data
#
v16=vtkVolume16Reader()
v16.SetDataDimensions(64,64)
v16.SetDataByteOrderToLittleEndian()
v16.SetImageRange( 1 ,93)
v16.SetDataSpacing(3.2, 3.2, 1.5)
v16.SetFilePrefix ("C:\Python26\VTKData/Data/headsq/quarter")
v16.ReleaseDataFlagOn()
v16.SetDataMask(0x7fff)
v16.Update()

rang= v16.GetOutput().GetScalarRange()

# vtkImageActor requires unsigned char or unsigned short data, so
# we will transform the data with a linear shift/scale filter.
#
shifter=vtkImageShiftScale()
shifter.SetShift(-1.0*rang[0])
shifter.SetScale(255.0/(rang[1]-rang[0]))
shifter.SetOutputScalarTypeToUnsignedChar()
shifter.SetInputConnection(v16.GetOutputPort())
shifter.ReleaseDataFlagOff()
shifter.Update()

# An actor to display one slice of 3D image data.
#
imageActor=vtkImageActor()
imageActor.SetInput(shifter.GetOutput())
imageActor.VisibilityOn()
imageActor.SetDisplayExtent(0 ,63, 0, 63, 46, 46)
imageActor.InterpolateOn()

bounds=imageActor.GetBounds()
#xMin xMax yMin yMax zMin zMax

#  Create a renderer and a render window,
#
ren1=vtkRenderer()
renWin=vtkRenderWindow()
renWin.AddRenderer(ren1)

# Create an interactor to respond to mouse events.
#
iren=vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Create an interactor style that works specifically with images:
# middle button: pan image
# right button: zoom image
# left button + ctrl key: rotate image
#
style=vtkInteractorStyleImage()
iren.SetInteractorStyle(style)

# VTK widgets consist of two parts: the widget part that handles event
processing;
# and the widget representation that defines how the widget appears in the
scene
# (i.e., matters pertaining to geometry).  The affine 2D representation
consists
# of a set of axes inside a circle set inside a box.  Clicking on an edge or
# a corner of the box will set the scaling.  Clicking the the axes will set
# the translation.  Clicking on the circle and dragging along its
circumference
# sets the rotation.  Clicking on an edge while depressing the ctrl key will
# set the shear (currently not fully implemented).
#
rep=vtkAffineRepresentation2D()
rep.SetBoxWidth( 100)
rep.SetCircleWidth( 75)
rep.SetAxesWidth( 60)
rep.DisplayTextOn()
rep.PlaceWidget(bounds)

widget=vtkAffineWidget()
widget.SetInteractor(iren)
widget.SetRepresentation(rep)


# Add an observer to apply the affine transform to the image actor at
# the end of interaction with the widget.
def WidgetCallback(rep,imageActor):
    #tr=vtkTransform()
    trans=rep.GetTransform()
    imageActor.SetUserTransform(trans)

widget.AddObserver('InteractionEvent',WidgetCallback(rep,imageActor))



# Transorm generated by the affine widget's representation that
# will transform the image actor.
#


#  Add the actor to the renderer, set the background and size.
#
ren1.AddActor(imageActor)
ren1.SetBackground (0.1, 0.2, 0.4)
renWin.SetSize(600, 600)

# Render the image.
renWin.Render()
iren.Initialize()
widget.On()


Thanks,

Jothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100628/37f4f314/attachment.htm>


More information about the vtkusers mailing list