如何在ILNumerics中有效地绘制大表面(例如,1000x1000)?

时间:2013-11-02 14:09:04

标签: plot ilnumerics

这是我使用的代码:

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();
    }
}

每次调用ResetSurface()都需要几秒钟才能完成:在Debug中为~6s,在Release模式下为~4s。

表面更新后,旋转和平移操作非常流畅。

表面越小,更新速度越快。

是否有更有效的方法来更新表面位置/颜色缓冲区?

注意:在带有双显卡(Intel HD 4000 + GeForce GT 650M)的Windows 7笔记本电脑上使用IlNumerics 3.2.2 Community Edition,并激活nvidia卡。

1 个答案:

答案 0 :(得分:0)

您的代码没有明显错误。一个常见的缺陷是线框颜色。如果留下半透明(默认),必要的排序会减慢渲染速度。但您已将其设置为Visible = false

所以在我的机器上(赢7,T430笔记本,i7和类似的图形)更新需要<2秒(没有附带调试器的发布!)。我担心,这就是它所需要的。后面有很多东西......

@Edit使用ILSurface.UpdateRGBA()预先计算颜色并将它们作为离散颜色提供可能会更快。您将不得不尝试使用分析器来调查瓶颈。另一个选择 - 因为你是在一个简单的imagesc风格的情节之后 - 是自己构建imagesc:ILTriangles(-strip)要小得多,并且可能提供更多选项来提高更新速度。但是,您必须自己进行大量的重新排序/顶点生成/颜色计算。此外,这不会为您提供ILSurface的colorbar支持。

@Edit:您可以使用ILImageSCPlot类作为ILSurface的替代品。文档在这里:http://ilnumerics.net/imagesc-plots.html