ILNumeric continuous rendering plots

霸气de小男生 提交于 2019-12-05 13:04:40

As Paul pointed out, there is a more efficient attempt to do this:

private void ilPanel1_Load(object sender, EventArgs e) {
    using (ILScope.Enter()) {
        // create some test data
        ILArray<float> A = ILMath.tosingle(ILMath.rand(1, 50));
        // add a plot cube and a line plot (with markers)
        ilPanel1.Scene.Add(new ILPlotCube(){
            new ILLinePlot(A, markerStyle: MarkerStyle.Rectangle)
        }); 
        // register update event
        ilPanel1.BeginRenderFrame += (o, args) =>
        {
            // use a scope for automatic memory cleanup
            using (ILScope.Enter()) {
                // fetch the existint line plot object
                var linePlot = ilPanel1.Scene.First<ILLinePlot>(); 
                // fetch the current positions
                var posBuffer = linePlot.Line.Positions; 
                ILArray<float> data = posBuffer.Storage;
                // add a random offset 
                data = data + ILMath.tosingle(ILMath.randn(1, posBuffer.DataCount) * 0.005f); 
                // update the positions of the line plot
                linePlot.Line.Positions.Update(data);
                // fit the line plot inside the plot cube limits
                ilPanel1.Scene.First<ILPlotCube>().Reset();
                // inform the scene to take the update
                linePlot.Configure();
            }
        }; 
        // start the infinite rendering loop
        ilPanel1.Clock.Running = true; 
    }
} 

Here, the full update runs inside an anonymous function, registered to BeginRenderFrame.

The scene objects are reused instead of getting recreated in every rendering frame. At the end of the update, the scene needs to know, you are done by calling Configure on the affected node or some node among its parent nodes. This prevents the scene from rendering partial updates.

Use an ILNumerics arteficial scope in order to clean up after every update. This is especially profitable once larger arrays are involved. I added a call to ilPanel1.Scene.First<ILPlotCube>().Reset() in order to rescale the limits of the plot cube to the new data content.

At the end, start the rendering loop by starting the Clock of ILPanel.

The result is a dynamic line plot, updating itself at every rendering frame.

I think you need to call Configure() after any modification of a shape or its buffers. Use the BeginRenderFrame event to do your modifications and you should not add infinitely many shapes / new scenes. It is better to reuse them!

Let me know, if you need an example...

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