1

I want to use a colorbar with custom objects. The objects are colored according to a specific colormap. I want to show this colormap in a colorbar at runtime.

I already tried adding it to scene by:

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

or to the cube:

        plotCube.Add(cb);

or even plotCube.Children.Add(cb);

but it still doesn't work. What is the correct way to display a colorbar for custom objects?

Here is my code:

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();
    }

And this are my figures: enter image description here

4

1 回答 1

0

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

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

不适用于 nuget 的社区版!

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
            }
        }); 
}

在此处输入图像描述

于 2014-07-03T09:48:07.643 回答