【问题标题】:ILNumerics 3D Contour plots legend is not displayed why?ILNumerics 3D Contour plots 图例为什么不显示?
【发布时间】:2013-10-18 23:27:08
【问题描述】:

我用来创建 3D 等高线图的表面等高线。 我现在一直在我的 3D 图形中绘制轮廓线,这也很有效,但是为什么没有显示图例?

代码:

private void button1_Click(object sender, EventArgs e)
{
    ILArray<float> data = ILSpecialData.sincf(50, 50);

    BackgroundWorker bgw = new BackgroundWorker();
    bgw.DoWork += bgwCreateProcess_DoWork;
    bgw.RunWorkerAsync(data);
}

private void bgwCreateProcess_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
    ILArray<float> data = e.Argument as ILArray<float>;

    using (ILScope.Enter())
    {
        ILScene scene = new ILScene();

        ILPlotCube plotCube = new ILPlotCube(twoDMode: false);

        plotCube.Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), Math.PI / 2);

        ILSurface surface = new ILSurface(data);

        List<ContourLevel> conturLevels = new List<ContourLevel>();
        conturLevels.Add(new ContourLevel() { Text = "Limit Max", Value = 0.9f, LineWidth = 2 });
        conturLevels.Add(new ContourLevel() { Text = "Limit Min", Value = -0.1f, LineWidth = 2 });
        conturLevels.Add(new ContourLevel() { Text = "Average", Value = 0.5f, LineWidth = 3 });

        ILContourPlot contourPlot = new ILContourPlot(data, conturLevels, create3D: true);
        plotCube.Children.Add(contourPlot);

        ILLegend legend = new ILLegend();
        legend.Location = new PointF(.99f, 0f);
        surface.Children.Add(legend);

        ILColorbar colorbar = new ILColorbar();
        colorbar.Location = new PointF(.99f, 0.4f);
        surface.Children.Add(colorbar);

        surface.Markable = false;
        surface.Fill.Markable = false;
        surface.Wireframe.Markable = false;

        surface.Wireframe.Visible = true;

        surface.UseLighting = false;

        plotCube.Add(surface);

        scene.Add(plotCube);

        ilPanel.Scene = scene;
    }
}

此代码应扩展为一个 winform、一个 ILPanel 和一个按钮。最后但必须订阅按钮的 Click 事件。更少的代码是不可能的,否则情况就会改变。

【问题讨论】:

  • 能否提供一个可运行的迷你示例?
  • 图例的绘制问题,在没有BackgroundWorker的ILPanel Load事件上创建图表时不会出现。只要我把它变成一个有或没有后台工人的方法,她就不再显示了。
  • Felix,您的示例包含很多不必要的信息/代码。如果没有机会运行代码,我们将无法为您提供帮助。请提供一个较小的示例,仅显示相关部分!
  • 我希望现在更清楚了。

标签: ilnumerics


【解决方案1】:

Felix,代码中有几个问题。其中一些与 ILNumerics 中的错误有关,该错误将在下一个版本中修复。下面的代码创建一个像这样的图像:

private void button1_Click(object sender, EventArgs e) {
    ILArray<float> data = ILSpecialData.sincf(50, 50);

    BackgroundWorker bgw = new BackgroundWorker();
    bgw.DoWork += bgwCreateProcess_DoWork;
    bgw.RunWorkerAsync(data);
}

private void bgwCreateProcess_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) {

    using (ILScope.Enter()) {
        ILArray<float> data = e.Argument as ILArray<float>;
        ILScene scene = new ILScene();

        ILPlotCube plotCube = new ILPlotCube(twoDMode: false);

        plotCube.Rotation = Matrix4.Rotation(new Vector3(1, 0, 0), Math.PI / 2);

        ILSurface surface = new ILSurface(data);

        List<ContourLevel> conturLevels = new List<ContourLevel>();
        conturLevels.Add(new ContourLevel() { Text = "Limit Max", Value = 0.9f, LineWidth = 2 });
        conturLevels.Add(new ContourLevel() { Text = "Limit Min", Value = -0.1f, LineWidth = 2 });
        conturLevels.Add(new ContourLevel() { Text = "Average", Value = 0.5f, LineWidth = 3 });

        ILContourPlot contourPlot = new ILContourPlot(data, conturLevels, create3D: true);
        plotCube.Add(contourPlot);

        ILLegend legend = new ILLegend("one","two","three","four");
        legend.Location = new PointF(.99f, 0f);


        ILColorbar colorbar = new ILColorbar();
        colorbar.Location = new PointF(.99f, 0.4f);
        surface.Add(colorbar);

        surface.Markable = false;
        surface.Fill.Markable = false;
        surface.Wireframe.Markable = false;

        surface.Wireframe.Visible = true;

        surface.UseLighting = false;

        plotCube.Add(surface);
        surface.Fill.Visible = false;

        scene.Add(plotCube);

        contourPlot.Add(legend);
        legend.Configure();  // only needed in version 3.2.2.0!
        scene.Configure();

        ilPanel1.Scene = scene;
    }
}

让我们单步执行代码:

  1. 如您所见,我隐藏了表面填充颜色。否则,等高线图的标签可能会被表面隐藏。

  2. 应该将传奇添加到他们将要描述的情节中。我将图例添加到轮廓图而不是表面。但是,由于某些原因,图例不会自动从等高线图中找到等高线,所以...

  3. ... 我在图例构造函数中手动添加了图例条目。在这里,我只使用了字符串“one”...“three”。你会想用你自己的名字替换它。

  4. 由于我提到的错误,您必须显式调用 legend.Configure()。在 3.2.2.0 版本之后就不需要了。

  5. 您正在后台工作线程中进行场景修改 - 这很好!但是,在完成配置后,必须通知面板刷新自身。但是,ilPanel.Refresh() 需要从主 (GUI-) 线程调用。所以我怀疑,您可以在 bgwCreateProcess_DoWork 的末尾使用 Control.Invoke() 来调用 ilPanel.Refresh()。否则,更改将不会显示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    • 2021-10-24
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    相关资源
    最近更新 更多