Render a Mayavi scene with a large conveyor faster

I use mayavi.mlab to display 3D data extracted from images. The data is as follows:

  • Parameters of a 3D camera as line 3 in the x, y, x around the center of the camera, usually for about 20 cameras using mlab.plot3d() .
  • 3D colored dots in space for 4000 dots using mlab.points3d() .

For (1) I have a function for each line for each camera separately. If I'm right, all these lines are added to the Mayavi pipeline for the current scene. On mlab.show() scene takes about 10 seconds to display all of these lines.

For (2), I could not find a way to build all the points at once with each point of a different color, so at the moment I'm repeating with mlab.points3d(x,y,z, color = color) . I more expected the completion of this procedure, since it lasts a long time. If I draw all the dots at once with the same color, it takes about 2 seconds.

I already tried to run the script with fig.scene.disable_render = True and reset fig.scene.disable_render = False before displaying the scene with mlab.show() .

How can I display my Mayavi data in a reasonable wait time?

+6
source share
1 answer

The general principle is that vtk objects have a lot of overhead, so for performance rendering you want to pack as many items as possible on one object as much as possible. When you call mlab convenience functions such as points3d , it creates a new vtk object to process this data. Thus, iterating and creating thousands of points as vtk objects is a very bad idea.

The trick of temporarily disabling rendering, as in this other question, the β€œright” way to do this is to have one VTK object that contains all the different points.

To set different points in different colors, give scalar values ​​to the vtk object.

x, y, r = np.random.random ((3,100)) some_data = mlab.points3d (x, y, g, = Colormap 'cool') some_data.mlab_source.dataset.point_data.scalars = np.random.random ( (100))

This only works if you can adequately represent the color values ​​that you need in the color palette. This is easy if you need a small finite number of colors or a small finite number of simple color palettes, but very difficult if you need completely arbitrary colors.

+1
source

Source: https://habr.com/ru/post/944237/


All Articles