[vtkusers] Fixing Python examples; question about best practice...

Emmet Caulfield emmet-vtkusers at caulfield.info
Wed Apr 2 22:39:21 EDT 2014


I've been going through the Python examples from the Wiki, fixing
broken examples.

In many cases, the problem is that one line written for versions < 6
are broken in version 6+, such as:

    mapper.SetInput( source.GetOutput() )

These are amenable to two distinct solutions, both of which I have
seen in examples:

    mapper.SetInputConnection( source.GetOutputPort() )

and

    if vtk.VTK_MAJOR_VERSION <= 5:
        mapper.SetInput( source.GetOutput() )
    else:
        mapper.SetInputData( source.GetOutput() )

or

    if vtk.VTK_MAJOR_VERSION <= 5:
        mapper.SetInput( source.GetOutput() )
    else:
        mapper.SetInputData( source )

Now, my question is: in a case where one of more of the above fixes
works (in the sense that the example now appears to work in version
5.x and 6.x), which ought to be preferred (and why)?

Thanks,

Emmet.


More information about the vtkusers mailing list