How to efficiently plot a large surface (e.g., 1000x1000) in ILNumerics?

与世无争的帅哥 提交于 2019-12-22 09:21:43

问题


Here's the code I use:

public partial class Form1 : Form
{
    private ILPlotCube plotcube_ = null;
    private ILSurface surface_ = null;

    public Form1()
    {
        InitializeComponent();

        ilPanel1.Driver = RendererTypes.OpenGL;
    }

    private void ilPanel1_Load(object sender, EventArgs e)
    {
        var scene = new ILScene();
        plotcube_ = scene.Add(new ILPlotCube(twoDMode: false));
        plotcube_.MouseDoubleClick += PlotCube_MouseDoubleClick;

        ilPanel1.Scene = scene;
    }

    private void PlotCube_MouseDoubleClick(object sender, ILMouseEventArgs e)
    {
        ResetSurface();
        e.Cancel = true;
        e.Refresh = true;
    }

    private void ResetSurface()
    {
        using (ILScope.Enter())
        {
            ILArray<float> array = ILMath.tosingle(ILSpecialData.sincf(1000, 1000));

            if (surface_ == null)
            {
                surface_ = new ILSurface(0);
                surface_.Fill.Markable = false;
                surface_.Wireframe.Visible = false;
                plotcube_.Add(surface_);
            }

            surface_.UpdateColormapped(array);
            surface_.UseLighting = false;
        }

        plotcube_.Plots.Reset();
    }
}

Each call to ResetSurface() takes a few seconds to complete: ~6s in Debug and ~4s in Release mode.

Once the surface is updated, though, rotation and pan operations are very fluid.

The smaller the surface, the faster the update.

Is there a more efficient way to update the surface positions/colors buffers?

Note: using IlNumerics 3.2.2 Community Edition on Windows 7 laptop with dual graphics (Intel HD 4000 + GeForce GT 650M), with nvidia card activated.


回答1:


There is nothing obviously wrong with your code. A common pitfall is the wireframe color. If it is left to be semitransparent (default), the necessary sorting would slow the rendering down. But you have already set it to Visible = false.

So on my machine (win 7, T430 notebook, i7 and similar graphics) it takes <2 sec to update (Release with no debugger attached!). I am afraid, that's just what it takes. There is a lot of stuff going on in the back ...

@Edit It might be faster to precompute the colors and provide them as discrete color using ILSurface.UpdateRGBA(). You will have to try and use a profiler to investigate the bottleneck. Another option - since you are after a simple imagesc-style plot - is to build the imagesc on your own: ILTriangles(-strip) ist much more slim and probably gives more option to increase the update speed. However, you will have to do a considerable amount of reordering / vertex generation / color computation on your own. Also, this won't give you the colorbar support of ILSurface.

@Edit: You can use the ILImageSCPlot class as a slim replacement for ILSurface. The documentation is here: http://ilnumerics.net/imagesc-plots.html



来源:https://stackoverflow.com/questions/19742746/how-to-efficiently-plot-a-large-surface-e-g-1000x1000-in-ilnumerics

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!