如何在ILNumerics中为自定义对象添加Colorbar?

时间:2014-07-03 05:01:29

标签: colors ilnumerics colorbar box colormap

我想使用带有自定义对象的颜色条。对象根据特定的色彩图进行着色。我想在运行时在colorbar中显示这个colormap。

我已经尝试将其添加到场景中:

        ILColorbar cb = new ILColorbar();
        scene.Add(cb);

或立方体:

        plotCube.Add(cb);

甚至plotCube.Children.Add(cb);

但它仍然无效。显示自定义对象的颜色条的正确方法是什么?

这是我的代码:

private void OKInputBodyListButton_Click(object sender, EventArgs e)
    {
        try
        {
            var sceneBody = new ILScene();
            var plotCubeBody = sceneBody.Add(new ILPlotCube(twoDMode: false));

            foreach (BlockBody item in ObjectList)
            {
                createBlockBody(item, sceneBody, plotCubeBody);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

private void createBlockBody(BlockBody BlockBody, ILScene scene, ILPlotCube plotCube)
    {
        var box = new ILTriangles("tri")
        {
            ...
            ...
        }

        plotCube.Add(box);
        var colormap = new ILColormap(Colormaps.Jet);
        Vector4 key1 = colormap.Map((float)BlockBody.Rho, new Tuple<float, float>(-1, 1));
        var test = key1.ToColor();
        box.Color = test;

        SliceilPanel.Scene = scene;
        SliceilPanel.Refresh();
    }

这是我的数据: enter image description here

1 个答案:

答案 0 :(得分:0)

colorbar需要一些数据:使用的色彩图和色条轴的上/下限。通常,它在运行时从场景中的相应绘图对象(等高线图,曲面图)获取这些信息。 &#39;在运行时&#39;因为它必须能够响应由于交互性而对这些绘图对象的更改。

如果要为自定义对象使用颜色栏,则必须自己提供这些数据。 ILColorbar提供ColormapProvider属性。为其分配一个对象,该对象在运行时提供信息。您可以使用预定义的ILNumerics.Drawing.Plotting.ILStaticColormapProvider或提供您自己的“IILColormapProvider”实现。接口。

这是使用nuget的Community Edition!

private void ilPanel1_Load(object sender, EventArgs e) {

    // We need to provide colormap data to the colorbar at runtime. 
    // We simply take a static colormap provider here:
    var cmProv = new ILStaticColormapProvider(Colormaps.ILNumerics, 0f, 1f);
    // Position data for plotting
    ILArray<float> A = ILMath.tosingle(ILMath.rand(3, 1000));
    // create the points
    ilPanel1.Scene.Add(
        new ILPlotCube(twoDMode: false) {
            new ILPoints("myPoints") {
                Positions = A,
                // since we want to show a colorbar, we need to put the points colors under colormap control
                Colors = cmProv.Colormap.Map(A["1;:"]).T,
                // deactivate single color rendering
                Color = null
            },
            // add the colorbar (somewhere) and give it the colormap provider
            new ILColorbar() {
                ColormapProvider = cmProv
            }
        }); 
}

enter image description here