I am attempting to use an ILLinePlot to plot live data in a WPF app using WindowsFormsHost. I have made a start based on these two SO questions: ILScene in WindowsFormsHost & ILNumeric continuous rendering plots.
My code is:
XAML:
<Window x:Class="Pulse_Generator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:forms="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Title="MainWindow" Height="350" Width="525"
Loaded="ILView_OnLoaded">
<Grid Name="grid1">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<forms:WindowsFormsHost x:Name="WindowsFormsHost" Margin="5" />
</Grid>
</Window>
C#:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private ILPanel ilPanel;
private void IlPanelOnLoad(object sender, EventArgs eventArgs)
{
using (ILScope.Enter())
{
// generate some dummy data
int N = 50000;
ILArray<float> x = ILMath.vec<float>(0, N-1);
ILArray<float> y = ILMath.tosingle(ILMath.rand(N));
ILArray<float> A = ILMath.zeros<float>(2, N);
A["0;:"] = x;
A["1;:"] = y;
ilPanel.Scene.Add(new ILPlotCube(){
new ILLinePlot(A)
});
ilPanel.BeginRenderFrame += (o, args) =>
{
using (ILScope.Enter())
{
var linePlot = ilPanel.Scene.First<ILLinePlot>();
var posBuffer = linePlot.Line.Positions;
ILArray<float> data = posBuffer.Storage;
// update the plot with some new dummy data
data["1;:"] = ILMath.tosingle(ILMath.randn(1, posBuffer.DataCount));
linePlot.Line.Positions.Update(data);
ilPanel.Scene.First<ILPlotCube>().Reset();
linePlot.Configure();
}
};
// start running
ilPanel.Clock.TimeMilliseconds = 15;
ilPanel.Clock.Running = true;
}
}
private void ILView_OnLoaded(object sender, RoutedEventArgs e)
{
ilPanel = new ILPanel();
ilPanel.Load += IlPanelOnLoad;
WindowsFormsHost.Child = ilPanel;
}
}
The problem is that the plot only updates (and BeginRenderFrame only appears to be triggered) when there is mouse interaction on the plot (click/drag/scroll) or the window is resized.
Presumably this is because the clock is not running properly inside the WindowsFormsHost?