<div dir="ltr">Hi all, <br><br>I am trying to use vtkAffineWidgwet ( modified from the vtk/Example).<br><br>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<br>
<br>transform=rep.GetTransform()<br><br>Here is the code<br><br>from vtk import*<br><br><br># Demonstrate how to use the vtkAffineWidget to apply affine transforms<br># ( translate, scale, rotate, shear ) to an actor.<br>
<br># Start by reading in data<br>#<br>v16=vtkVolume16Reader()<br>v16.SetDataDimensions(64,64)<br>v16.SetDataByteOrderToLittleEndian()<br>v16.SetImageRange( 1 ,93)<br>v16.SetDataSpacing(3.2, 3.2, 1.5)<br>v16.SetFilePrefix (&quot;C:\Python26\VTKData/Data/headsq/quarter&quot;)<br>
v16.ReleaseDataFlagOn()<br>v16.SetDataMask(0x7fff)<br>v16.Update()<br><br>rang= v16.GetOutput().GetScalarRange()<br><br># vtkImageActor requires unsigned char or unsigned short data, so<br># we will transform the data with a linear shift/scale filter.<br>
#<br>shifter=vtkImageShiftScale()<br>shifter.SetShift(-1.0*rang[0])<br>shifter.SetScale(255.0/(rang[1]-rang[0]))<br>shifter.SetOutputScalarTypeToUnsignedChar()<br>shifter.SetInputConnection(v16.GetOutputPort())<br>shifter.ReleaseDataFlagOff()<br>
shifter.Update()<br><br># An actor to display one slice of 3D image data.<br>#<br>imageActor=vtkImageActor()<br>imageActor.SetInput(shifter.GetOutput())<br>imageActor.VisibilityOn()<br>imageActor.SetDisplayExtent(0 ,63, 0, 63, 46, 46)<br>
imageActor.InterpolateOn()<br><br>bounds=imageActor.GetBounds()<br>#xMin xMax yMin yMax zMin zMax<br><br>#  Create a renderer and a render window,<br>#<br>ren1=vtkRenderer()<br>renWin=vtkRenderWindow()<br>renWin.AddRenderer(ren1)<br>
<br># Create an interactor to respond to mouse events.<br>#<br>iren=vtkRenderWindowInteractor()<br>iren.SetRenderWindow(renWin)<br><br># Create an interactor style that works specifically with images:<br># middle button: pan image<br>
# right button: zoom image<br># left button + ctrl key: rotate image<br>#<br>style=vtkInteractorStyleImage()<br>iren.SetInteractorStyle(style)<br><br># VTK widgets consist of two parts: the widget part that handles event processing;<br>
# and the widget representation that defines how the widget appears in the scene<br># (i.e., matters pertaining to geometry).  The affine 2D representation consists<br># of a set of axes inside a circle set inside a box.  Clicking on an edge or<br>
# a corner of the box will set the scaling.  Clicking the the axes will set<br># the translation.  Clicking on the circle and dragging along its circumference<br># sets the rotation.  Clicking on an edge while depressing the ctrl key will<br>
# set the shear (currently not fully implemented).<br>#<br>rep=vtkAffineRepresentation2D()<br>rep.SetBoxWidth( 100)<br>rep.SetCircleWidth( 75)<br>rep.SetAxesWidth( 60)<br>rep.DisplayTextOn()<br>rep.PlaceWidget(bounds)<br>
<br>widget=vtkAffineWidget()<br>widget.SetInteractor(iren)<br>widget.SetRepresentation(rep)<br><br><br># Add an observer to apply the affine transform to the image actor at<br># the end of interaction with the widget.<br>
def WidgetCallback(rep,imageActor):<br>    #tr=vtkTransform()<br>    trans=rep.GetTransform()<br>    imageActor.SetUserTransform(trans)<br><br>widget.AddObserver(&#39;InteractionEvent&#39;,WidgetCallback(rep,imageActor))<br>
<br><br><br># Transorm generated by the affine widget&#39;s representation that<br># will transform the image actor.<br>#<br><br><br>#  Add the actor to the renderer, set the background and size.<br>#<br>ren1.AddActor(imageActor)<br>
ren1.SetBackground (0.1, 0.2, 0.4)<br>renWin.SetSize(600, 600)<br><br># Render the image.<br>renWin.Render()<br>iren.Initialize()<br>widget.On()<br><br><br>Thanks,<br><br>Jothy<br></div>