2016-01-29 27 views
3

我一直比較喜歡vtk的原始Python API的pythonic tvtk,但是從MacPorts獲得的最新版本中,我遇到了基本問題不再適用的問題。下面的代碼片段從tvtv documentation採取:如何解決「TraitError:...實例的'input'特性是'只讀'。」

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 

隨着「輸入」特質每次初始化,我得到這樣

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

錯誤我發現有很多類似的問題,錯誤報告等,但它們都指向有關VTK 6(SetInputDataSetInputConnection代替SetInput),其中should be supported in Mayavi 4.4.2變化,我有:

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) 

PolyDataMapper具有以下輸入-性狀:

'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>, 

回答

2

Mayavi的同時支持VTK 5.10和VTK 6.x的,其具有在內部不同的API來配置到管線。 tvtk包有一個通用的API,支持兩種版本的可移植性。

更改:

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

到:

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

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

+0

間接地,上面包含了我一直在尋找的答案,即 「正確」 的新的API。我對VTK 5支持不感興趣,但我沒有看到代碼需要如何適應。從鏈接看來,好像沒有非連接情況的特徵,但是'set_input_data(some_data)'是我所缺少的。 –

相關問題