ilnumerics - 多个 PlotCube 同步

标签 ilnumerics

同一 ILScene 中的多个 ILPlotCube 独立于鼠标交互使用react。文档示例 here .

我的每个 PlotCube 都包含一个 LinePlot,我需要保持两个 PlotCube 的 X 轴对齐。因此,当一个 PlotCube 中的 X 轴由于鼠标交互而改变时,需要一个事件通知我。

在文档或搜索引擎中找不到任何内容。对鼠标事件进行了一些有限的测试(复杂,可能吗?)。找到一个 ILAxisChangedEventArgs 类,但没有事件。

最佳答案

使用 ILPlotCube.Limits反而! ILLimits类管理 plotcube 的轴限制。它提供了 Changed事件。您可以使用它来反射(reflect)对其他绘图立方体的更改。

private void ilPanel1_Load_1(object sender, EventArgs e) {
    // just some data
    ILArray<float> A1 = new float[] { 1,4,3,2,5 };
    // setup new plot cube
    var pc1 = ilPanel1.Scene.Add(new ILPlotCube("pc1") { 
        ScreenRect = new RectangleF(0,0,1,.6f)
    });
    // 2nd plot cube
    ILArray<float> A2 = new float[] { -1,-4,-3,-2,4 };
    var pc2 = ilPanel1.Scene.Add(new ILPlotCube("pc2") {
        ScreenRect = new RectangleF(0, .4f, 1, .6f)
    });
    // add line plots to the plot cubes
    pc1.Add(new ILLinePlot(A1));
    pc2.Add(new ILLinePlot(A2)); 
    // Synchronize changes to the limits property
    // NOTE: mouse interaction is fired on the SYNCHRONIZED COPY 
    // of the plot cube, which is maintained for each individual ILPanel! 
    pc1 = ilPanel1.SceneSyncRoot.First<ILPlotCube>("pc1");
    pc2 = ilPanel1.SceneSyncRoot.First<ILPlotCube>("pc2"); 
    pc1.Limits.Changed += (_s, _a) => { SynchXAxis(pc1.Limits, pc2.Limits); };
    pc2.Limits.Changed += (_s, _a) => { SynchXAxis(pc2.Limits, pc1.Limits); }; 
}

private void SynchXAxis(ILLimits lim1, ILLimits lim2) {
    // synch x-axis lim1 -> lim2
    Vector3 min = lim2.Min;
    Vector3 max = lim2.Max;
    min.X = lim1.XMin; max.X = lim1.XMax;
    // disable eventing to prevent from feedback loops
    lim2.EventingSuspend();
    lim2.Set(min, max);
    lim2.EventingStart();  // discards Changed events
}

enter image description here

现在,当您用鼠标缩放/平移时,对一个绘图立方体的更改会转移到另一个绘图立方体。这仅作用于 X 轴。其他限制不会受到影响。

两个提示

1) 请记住,鼠标交互不会影响您创建的原始绘图立方体对象,而是更改它的同步副本。该副本由 ILPanel 在内部维护,并防止多线程问题以及对一个实例的更改填充回可能存在于其他面板中的其他实例。为了获得有关这些更改的通知,您必须连接到同步副本的事件处理程序。 ILPanel.SceneSynchRoot为您提供访问权限。

2) 从 Limits 传输更改时一个绘图立方体到另一个应该禁用目标限制对象上的事件。否则,它会触发另一个 Changed事件和事件将无休止地触发。 ILLimits.EventingStart()函数在您更改后重新启用事件并丢弃迄今为止累积的所有事件。

关于ilnumerics - 多个 PlotCube 同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23377045/

相关文章:

linqpad - 在 LinqPad 中使用 ILNumerics 绘图时出现问题 - ILPanel 认为它处于设计模式

optimization - F# 和 ILNumerics

c# - 插值 3d 表面 ilnumerics

c# - 如何在 ILCube 中保持形状

c# - 如何将 ILArray 转换为 double[,] 数组?

wpf - WindowsFormsHost 中的 ILScene

c# - 类型推断导致空引用

csv - 如何在 ILArray 中加载大 CSV 文件进行 3d 绘图?

c# - 无法手动或自动将 ILNumerics 控件添加到 VS2012 工具箱

c# - 使用 python/Matplotlib 在 GUI 中进行 3D 绘图还是在 C#/illnumerics 中进行 3D 绘图?