[vtkusers] vtkTransformFilter, Python

David Gobbi dgobbi at irus.rri.on.ca
Thu Jul 20 15:30:21 EDT 2000


Hi Randy,

This is a known (at least to me) problem with the python wrappers.
When you get a vtk object via a GetXXX() method or similar method,
a python-wrapper portion of the VTK object will be created which
has a type corresponding the the return type of the GetXXX() method.
If the the actual vtk object happens to be a derived type of the
return type, then the 'python' type of the vtk object will not match
the 'C++' type of the object.  This will result in problems like
the one you describe i.e. you get argument type errors even though
the 'C++ type' of the argument is correct.  Once the 'python' object is
created it is stored in a hash table, so that it will not have to be
re-created in the future. 

The fact that you can have mismatched C++ vs. Python types for VTK
objects is a serious bug.  But not one that is easy to fix,
unfortunately.  In C++ you can always force an object to be
interpreted as a certain type by doing a type cast -- python has
no such mechanism (nor should it!)

Anyone want to take a stab at fixing this?  It will require some
reorganization of the way that the Python wrappers are generated.

 - David

On Thu, 20 Jul 2000, Randy Heiland wrote:

> 2nd attempt:  As I return to this problem and go dig through
> common/vtkPythonUtil.cxx, thought I'd ask the Python users if they've had any
> ideas.
> 
> Here's a simpler, self-contained example:
> 
> 
> #!/usr/local/bin/python
> 
> from libVTKCommonPython import *
> from libVTKGraphicsPython import *
> 
> #-----------------------
> sg = vtkStructuredGrid()
> sg.Initialize()
> nx=2
> ny=2
> nz=2
> sg.SetDimensions(nx,ny,nz)
> print 'nx*ny*nz=',nx*ny*nz
> 
> pts = vtkPoints()
> # Z=0.0 plane
> pts.InsertPoint(0, 0.0,0.0,0.0);
> pts.InsertPoint(1, 1.0,0.0,0.0);
> pts.InsertPoint(2, 0.0,1.0,0.0);
> pts.InsertPoint(3, 1.0,1.0,0.0);
> # Z=1.0 plane
> pts.InsertPoint(4, 0.0,0.0,1.0);
> pts.InsertPoint(5, 1.0,0.0,1.0);
> pts.InsertPoint(6, 0.0,1.0,1.0);
> pts.InsertPoint(7, 1.0,1.0,1.0);
> 
> sg.SetPoints(pts)
> 
> #-------------------------------------
> # Can I scale the pts in this SG?
> tran = vtkTransform()
> tran.Scale(2,1,1)
> 
> sgXform = vtkTransformFilter()
> sgXform.SetInput(sg)
> sgXform.SetTransform(tran)
> sgXform.Update()
> 
> sg2 = sgXform.GetOutput()
> isaSG = sg2.IsA('vtkStructuredGrid')
> print 'isaSG = ',isaSG
> isaRG = sg2.IsA('vtkRectilinearGrid')
> print 'isaRG = ',isaRG
> 
> 
> #-------------------------------------
> # See if a SGWriter likes sg2 as input
> sgWriter = vtkStructuredGridWriter()
> # -- This works fine
> #sgWriter.SetInput(sg)
> #
> # -- Doing the following results in:
> #     sgWriter.SetInput(sg2)
> #ValueError: method requires a vtkStructuredGrid object, a vtkStructuredGrid
> object was provided.
> 
> sgWriter.SetInput(sg2)
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers





More information about the vtkusers mailing list