gpt4 book ai didi

render - IL数值连续渲染图

转载 作者:行者123 更新时间:2023-12-02 10:01:18 27 4
gpt4 key购买 nike

有没有办法连续绘制变化的数组数据?我有一个 ILLinePlot 来绘制按钮事件上数据变化的线条图,但我想让它连续。

while (true)
{
float[] RefArray = A.GetArrayForWrite();
//RefArray[0] = 100;
Shuffle<float>(ref RefArray);
Console.Write(A.ToString());
scene = new ILScene();
pc = scene.Add(new ILPlotCube());
linePlot = pc.Add(new ILLinePlot(A.T, lineColor: Color.Green));
ilPanel1.Scene = scene;
ilPanel1.Invalidate();

}

我遇到的问题是循环运行,我可以看到数组的更新,但 ILPanel 没有更新。我想也许是因为这个无限循环导致主循环无法访问,所以我也将它放在自己的线程中,但它仍然没有像我希望的那样渲染......

最佳答案

正如 Paul 指出的,有一种更有效的尝试可以做到这一点:

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

在这里,完整更新在匿名函数内运行,注册到 BeginRenderFrame

场景对象被重用,而不是在每个渲染帧中重新创建。更新结束时,场景需要知道,你通过调用 Configure 就完成了在受影响的节点或其父节点中的某个节点上。这可以防止场景渲染部分更新。

使用 ILNumerics 人工作用域以便在每次更新后进行清理。一旦涉及更大的阵列,这尤其有利可图。我添加了对 ilPanel1.Scene.First<ILPlotCube>().Reset() 的调用为了将绘图立方体的限制重新调整为新的数据内容。

最后,通过启动Clock来启动渲染循环。 ILPanel 的。

结果是动态线图,在每个渲染帧都会更新自身。

enter image description here

关于render - IL数值连续渲染图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21173259/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com