5

I have always preferred the more pythonic tvtk over vtk's raw Python API, but with the latest versions I get from MacPorts, I have the problem that basic things don't work anymore. The following snippet is taken from the tvtv documentation:

from tvtk.api import tvtk
cs = tvtk.ConeSource()
cs.resolution = 36
m = tvtk.PolyDataMapper()
m.input = cs.output # <== fails here
a = tvtk.Actor()
a.mapper = m
p = a.property
p.representation = 'w'
print p.representation

With every initialization of 'input' traits, I get an error like

TraitError: The 'input' trait of a PolyDataMapper instance is 'read only'.

I have found many similar questions, bug reports etc., but they all point to changes related to VTK 6 (SetInputData and SetInputConnection instead of SetInput), which should be supported in Mayavi 4.4.2, and I am having:

vtk @6.3.0_0+python27 (active)
py27-traits @4.5.0_0 (active)
py27-traitsui @5.0.0_0 (active)
py27-apptools @4.3.0_0 (active)
py27-envisage @4.4.0_0 (active)
py27-pyface @5.0.0_0+pyqt4 (active)
py27-mayavi @4.4.3_0 (active)

The PolyDataMapper has the following input-traits:

'input': <traits.traits.CTrait at 0x11b23a260>,
'input_algorithm': <traits.traits.CTrait at 0x119516520>,
'input_as_data_set': <traits.traits.CTrait at 0x11b230470>,
'input_connection': <traits.traits.CTrait at 0x119516310>,
'input_executive': <traits.traits.CTrait at 0x1195165d0>,
'input_information': <traits.traits.CTrait at 0x119516680>,

1 Answer 1

5

Mayavi supports both VTK 5.10 and VTK 6.x, which have internally a different API to configure to the pipeline. The tvtk package has a common API that supports both versions for portability.

Changing:

m.input = cs.output # <== fails here

to:

from tvtk.common import configure_input
tvtk.configure_input(m, cs) # <== will work

Ref: https://github.com/enthought/mayavi/blob/master/tvtk/common.py#L79

1
  • 2
    Indirectly, the above contains the answer I was looking for, namely the "correct" new API. I am not interested in VTK 5 support, yet I did not see how the code needs to be adapted. From the link, it appears as if there is no trait for the non-connection case, but set_input_data(some_data) is what I was missing.
    – hans_meine
    Commented Feb 2, 2016 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.