[vtkusers] vtkTransformFilter/Python problem

Randy Heiland heiland at ncsa.uiuc.edu
Thu Jul 13 11:19:00 EDT 2000


I have a problem when I try to use the output from a vtkTransformFilter on a
Struct Grid in Python (on a Thursday in July :).  I've appended a simple script
which reads in the office dataset and simply displays its bounding box.

When I run the python script, I get:
Traceback (most recent call last):
  File "officeScale.py", line 41, in ?
    outline.SetInput(sgrid)
ValueError: method requires a vtkStructuredGrid object, a vtkStructuredGrid
object was provided.

This is a rather strange "error" msg.

I'm using a nightly from ~May 26 and Python 1.6.  Could some Pythoneer
verify/contradict this problem?

(I've also appended the equivalent Tcl script which does work correctly.  But
no, the moral is not to switch to Tcl).

thanks,
--Randy

========================  python script   =======================
#!/usr/local/bin/python
import os
try:
  VTK_DATA = os.environ['VTK_DATA']
except KeyError:
  VTK_DATA = '../../../vtkdata/'

from libVTKCommonPython import *
from libVTKGraphicsPython import *

from colors import *
ren = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

reader = vtkStructuredGridReader()
reader.SetFileName(VTK_DATA + "/office.vtk")
reader.Update()  #force.a.read.to.occur()

#------------------------------------------------
#-- transform the geometry
xform = vtkTransform()
xform.Scale(3,1,1)

xformFilt = vtkTransformFilter()
xformFilt.SetInput(reader.GetOutput())
xformFilt.SetTransform(xform)
xformFilt.Update()

sgrid = xformFilt.GetOutput()
#-------------------------------------

outline = vtkStructuredGridOutlineFilter()
#  -- original
#outline.SetInput(reader.GetOutput())
#  -- use new xformed grid
outline.SetInput(sgrid)

mapOutline = vtkPolyDataMapper()
mapOutline.SetInput(outline.GetOutput())
outlineActor = vtkActor()
outlineActor.SetMapper(mapOutline)
outlineActor.GetProperty().SetColor(0,0,0)

ren.AddActor(outlineActor)

ren.SetBackground(slate_grey)

renWin.SetSize(500,300)
iren.Initialize()
iren.Start()

========================  end python script   =======================

========================  tcl script   =======================
catch {load vtktcl}
if { [catch {set VTK_TCL $env(VTK_TCL)}] != 0} { set VTK_TCL
"../../examplesTcl" }
if { [catch {set VTK_DATA $env(VTK_DATA)}] != 0} { set VTK_DATA
"../../../vtkdata" }

# get the interactor ui
source $VTK_TCL/vtkInt.tcl
source $VTK_TCL/colors.tcl

vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

vtkDataSetReader reader
    reader SetFileName "$VTK_DATA/office.vtk"
    reader Update;#force a read to occur

#------------------------------------------------
#-- how to transform the geometry (points) in a Struct Grid?
vtkTransform xform
xform Scale 1 1 4

vtkTransformFilter xformFilt
xformFilt SetInput [reader GetOutput]
xformFilt SetTransform xform
xformFilt Update

#vtkStructuredGridSource sgrid
set sgrid [xformFilt GetOutput]
#------------------------------------

vtkStructuredGridOutlineFilter outline
#    outline SetInput [reader GetStructuredGridOutput]
    outline SetInput $sgrid
vtkPolyDataMapper mapOutline
    mapOutline SetInput [outline GetOutput]
vtkActor outlineActor
    outlineActor SetMapper mapOutline
    [outlineActor GetProperty] SetColor 0 0 0

ren1 AddActor outlineActor

eval ren1 SetBackground $slate_grey

renWin SetSize 500 300
iren SetUserMethod {wm deiconify .vtkInteract}
iren Initialize

wm withdraw .

==================  end tcl script  ============================




More information about the vtkusers mailing list