ILNumerics 隐藏 PlotCube

ILNumerics hide PlotCube

我有一个包含两个不同 PlotCube 的场景,它们必须单独显示。隐藏和显示 PlotCubes 的最佳程序是什么。我试过删除,但这似乎改变了 PlotCube 对象。 代码行是:

IlPanel1.Scene.add(PlotCube1)  
IlPanel1.Scene.add(PlotCube2)  

现在两个立方体都可见。现在我只想显示 PlotCube2:

IlPanel1.Scene.Remove(PlotCube1)  
IlPanel1.Scene.add(PlotCube2)

切换回 PlotCube1:

IlPanel1.Scene.Remove(PlotCube2)  
IlPanel1.Scene.add(PlotCube1)  

但这不起作用。 remove 语句似乎删除了整个对象。有没有办法在不影响原始对象的情况下将 add/remove 元素作为 LinePlots、SurfacePlots、PlotCubes?

使用 Visible property of the plot cube 设置其可见性:

// stores the current state. (You may even use one of the ILPlotCube.Visible flags directly)
bool m_panelState = false;

// give the plot cubes unique tags so we can find them later.
private void ilPanel1_Load(object sender, EventArgs e) {
    ilPanel1.Scene.Add(new ILPlotCube("plotcube1") {
        Plots = {
            Shapes.Circle100, // just some arbitrary content
            new ILLabel("Plot Cube 1")
        },
        // first plot cube starts invisible
        Visible = false
    });
    ilPanel1.Scene.Add(new ILPlotCube("plotcube2") {
        Plots = {
            Shapes.Hemisphere, // just some content
            new ILLabel("Plot Cube 2")
        }
    });
}
// a button is used to switch between the plot cubes
private void button1_Click(object sender, EventArgs e) {
    m_panelState = !m_panelState;
    SetState(); 
}
// both plot cubes are made (un)visible depending on the value of the state variable
private void SetState() {
    ilPanel1.Scene.First<ILPlotCube>("plotcube1").Visible = m_panelState;
    ilPanel1.Scene.First<ILPlotCube>("plotcube2").Visible = !m_panelState;
    ilPanel1.Refresh(); 
}

重要的部分是在面板上调用 Refresh() 以便立即显示修改。

请注意,一般来说,如果您以后可能再次需要它们,最好将绘图对象放在周围。将对象设置为 Visible = false 不是将它们从场景图中移除然后重新创建类似的对象,而是要快得多并且不会产生(重新)创建图形对象的相当大的成本。