如何为ILNumerics中的自定义对象添加Colorbar? [英] How to add a Colorbar for Custom Objects in ILNumerics?

查看:748
本文介绍了如何为ILNumerics中的自定义对象添加Colorbar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要使用带有自定义对象的颜色条。对象根据特定的颜色映射色彩。我想在运行时在彩条中显示这个色彩映射。

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

或多维数据集:

        plotCube.Add(cb);

或甚至 plotCube.Children.Add(cb);

但它仍然无法正常工作。

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

这是我的代码:

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:

推荐答案

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

The colorbar needs some data: the colormap used and the upper/lower limits for the colorbar axis. Normally, it takes those information from the corresponding plot object (contour plot, surface plot) in the scene at runtime. 'At runtime' because it must be able to react to changes to these plot objects due to interactivity.

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

If you want to use colorbars for your custom objects you must provide those data yourself. ILColorbar provides the ColormapProvider property. Assign an object to it which provides the information at runtime. You can take the predefined ILNumerics.Drawing.Plotting.ILStaticColormapProvider or provide your own implementation of the 'IILColormapProvider' interface.

这不是使用nuget的社区版!

This is not working with the Community Edition from 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
            }
        }); 
}

这篇关于如何为ILNumerics中的自定义对象添加Colorbar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆