Search code examples
pythonmayavi

RectilinearGridSource from tvtk.RectilinearGrid()


I am trying to construct tvtk.RectilinearGridSource from tvtk.RectilinearGrid object in order to add it to the mayavi.engine.

I used to do this:

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)

but instead I would prefer to call it this way:

from mayavi.api import Engine
e = Engine()
e.start()
s = e.new_scene()
src = tvtk.RectilinearGridSource()

and then link src with r i.e., with my RectilinearGrid defined before.

Is there any way to do this ?


Solution

  • I've found an answer:

    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)