我正试图从tvtk.RectilinearGrid
对象构造tvtk.RectilinearGridSource
,以便将其添加到mayavi.engine
中。
我曾经这样做:
import mayavi.mlab as mlab
r = tvtk.RectilinearGrid()
r.point_data.scalars = data.ravel()
r.point_data.scalars.name = 'Temperature'
d = mlab.pipline.add_dataset(r)
但我更愿意这样称呼它:
from mayavi.api import Engine
e = Engine()
e.start()
s = e.new_scene()
src = tvtk.RectilinearGridSource()
然后将src
与r
链接,即与之前定义的我的RectilinearGrid
链接。
有办法做到这一点吗?
我找到了答案:
r = tvtk.RectilinearGrid()
r.point_data.scalars = data.ravel()
r.point_data.scalars.name = 'Temperature'
from mayavi.sources.vtk_data_source import VTKDataSource
src = VTKDataSource(data=r)
e.add_source(d)