简体   繁体   English

使用大型管道更快地渲染mayavi场景

[英]Render a mayavi scene with a large pipeline faster

I am using mayavi.mlab to display 3D data extracted from images. 我使用mayavi.mlab来显示从图像中提取的3D数据。 The data is as follows: 数据如下:

  1. 3D camera parameters as 3 lines in the x, y, x direction around the camera center, usually for about 20 cameras using mlab.plot3d() . 3D摄像机参数为摄像机中心周围x, y, x方向的3条线,通常使用mlab.plot3d()进行约20个摄像机。
  2. 3D coloured points in space for about 4000 points using mlab.points3d() . 使用mlab.points3d()在空间中使用3D着色点约4000点。

For (1) I have a function to draw each line for each camera seperately. 对于(1)我有一个功能来分别为每个摄像机绘制每条线。 If I am correct, all these lines are added to the mayavi pipeline for the current scene. 如果我是正确的,所有这些行都被添加到当前场景的mayavi管道中。 Upon mlab.show() the scene takes about 10 seconds to render all these lines. mlab.show() ,场景需要大约10秒来渲染所有这些线。

For (2) I couldn't find a way to plot all the points at once with each point a different color, so at the moment I iterate with mlab.points3d(x,y,z, color = color) . 对于(2)我找不到一种方法来一次绘制所有点,每个点都有不同的颜色,所以此刻我用mlab.points3d(x,y,z, color = color)进行迭代。 I have newer waited for this routine to finish as it takes to long. 我有更新的等待这个例程完成,因为它需要很长时间。 If I plot all the points at once with the same color, it takes about 2 seconds. 如果我用相同的颜色一次绘制所有点,则需要大约2秒钟。

I already tried to start my script with fig.scene.disable_render = True and resetting fig.scene.disable_render = False before displaying the scene with mlab.show() . 我已经尝试使用fig.scene.disable_render = True启动我的脚本,并在使用mlab.show()显示场景之前重置fig.scene.disable_render = False

How can I display my data with mayavi within a reasonable waiting time? 如何在合理的等待时间内使用mayavi显示我的数据?

The general principle is that vtk objects have a lot of overhead, and so you for rendering performance you want to pack as many things into one object as possible. 一般原则是vtk对象有很多开销,因此您要渲染性能,希望将尽可能多的东西打包到一个对象中。 When you call mlab convenience functions like points3d it creates a new vtk object to handle that data. 当您调用m3便利函数(如points3d它会创建一个新的vtk对象来处理该数据。 Thus iterating and creating thousands of single points as vtk objects is a very bad idea. 因此,迭代和创建数千个单点作为vtk对象是一个非常糟糕的主意。

The trick of temporarily disabling the rendering as in that other question -- the "right" way to do it is to have one VTK object that holds all of the different points. 暂时禁用渲染的技巧与其他问题一样 - “正确”的方法是让一个VTK对象保存所有不同的点。

To set the different points as different colors, give scalar values to the vtk object. 要将不同的点设置为不同的颜色,请为vtk对象提供标量值。

x,y,z=np.random.random((3,100)) some_data=mlab.points3d(x,y,z,colormap='cool') some_data.mlab_source.dataset.point_data.scalars=np.random.random((100,)) x,y,z = np.random.random((3,100))some_data = mlab.points3d(x,y,z,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 you need in a colormap. 仅当您能够充分表示色彩映射中所需的颜色值时,此方法才有效。 This is easy if you need a small finite number of colors or a small finite number of simple colormaps, but very difficult if you need completely arbitrary colors. 如果您需要少量有限数量的颜色或有限数量的简单色图,这很容易,但如果您需要完全任意的颜色则非常困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM