Question

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.

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top