Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "TraitError: The 'input' trait of a ... instance is 'read only'."

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>,
like image 497
hans_meine Avatar asked Jan 29 '16 16:01

hans_meine


1 Answers

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

like image 154
3d-indiana-jones Avatar answered Sep 21 '22 18:09

3d-indiana-jones