ILNumerics曲面图中的颜色范围

时间:2014-07-23 21:40:14

标签: colors ilnumerics color-mapping

我正在使用ILNumerics生成表面图。

我想使用平面阴影颜色图(即颜色范围)而不是平滑的阴影颜色图(即每个像素具有它自己的颜色)。

ILNumerics可以实现吗?

平面阴影曲面图和颜色条图例:

Flat Surface Plot Flat Color Map

平滑阴影曲面图和颜色条图例的示例:

Smooth Surface Plot Smooth Color Map

2 个答案:

答案 0 :(得分:1)

这是不可能的。 ILNumerics中的曲面图总是在网格点之间插入颜色。对于其他着色模型,您必须创建自己的表面类。

答案 1 :(得分:1)

您可以创建一个曝光平面着色行为的色彩映射表。只需复制公共色图中存在的关键点,即可为获得相同颜色的颜色数据建模。

平面阴影色彩图的工作方式

根据documentation,色彩映射的关键点由5列组成:“位置”和4个颜色值(RGBA)。为了模拟“平面”阴影色彩图,将两个关键点“几乎”精确地放在彼此的顶部,使第一个关键点为下一个较低范围的颜色,第二个为下一个较高范围的颜色。因此,颜色范围由分配了相同颜色的两个关键点建模。

我在上面的段落中写了“差不多”,因为我认为你必须在两个范围的边缘之间留下至少一个微小的间隙 - 希望没有实际的颜色数据值能够达到这个差距。但看起来,根本不需要间隙,可以给两个关键点完全相同的值。但是在排序时你必须要小心:不要混淆颜色(ILMath.sort()中的快速排序不稳定!)

在以下示例中,从Colormaps.Jet

创建平面着色色彩映射
Keypoints for Colormaps.Jet (original, interpolating)
<Single> [6,5]
[0]:          0          0          0     0,5625          1 
[1]:     0,1094          0          0     0,9375          1 
[2]:     0,3594          0     0,9375          1          1 
[3]:     0,6094     0,9375          1     0,0625          1 
[4]:     0,8594          1     0,0625          0          1 
[5]:          1     0,5000          0          0          1 

源自它的平面着色版本:

Colormaps.Jet - flat shading version
<Single> [11,5]
[0]:          0          0          0     0,5625          1 
[1]:     0,1094          0          0     0,5625          1 
[2]:     0,1094          0          0     0,9375          1 
[3]:     0,3594          0          0     0,9375          1 
[4]:     0,3594          0     0,9375          1          1 
[5]:     0,6094          0     0,9375          1          1 
[6]:     0,6094     0,9375          1     0,0625          1 
[7]:     0,8594     0,9375          1     0,0625          1 
[8]:     0,8594          1     0,0625          0          1 
[9]:     1,0000          1     0,0625          0          1 
[10]:          1     0,5000          0          0          1 

您可以很容易地看到,我在CreateFlatShadedColormap()中犯了一个错误:最后一个关键点(0.5,0,0,1)永远不会被使用。我会把它留作练习来修复......;)

全平面阴影示例

private void ilPanel1_Load(object sender, EventArgs e) {
    ILArray<float> A = ILMath.tosingle(ILSpecialData.terrain["0:400;0:400"]);
    // derive a 'flat shaded' colormap from Jet colormap
    var cm = new ILColormap(Colormaps.Jet);
    ILArray<float> cmData = cm.Data;
    cmData.a = Computation.CreateFlatShadedColormap(cmData);
    cm.SetData(cmData); 
    // display interpolating colormap
    ilPanel1.Scene.Add(new ILPlotCube() { 
        Plots = {
            new ILSurface(A, colormap: Colormaps.Jet) {
                Children = { new ILColorbar() },
                Wireframe = { Visible = false }
            }
        }, 
        ScreenRect = new RectangleF(0,-0.05f,1,0.6f)
    }); 

    // display flat shading colormap
    ilPanel1.Scene.Add(new ILPlotCube() {
        Plots = {
            new ILSurface(A, colormap: cm) {
                Children = { new ILColorbar() },
                Wireframe = { Visible = false }
            }
        },
        ScreenRect = new RectangleF(0, 0.40f, 1, 0.6f)
    }); 

}

private class Computation : ILMath {
    public static ILRetArray<float> CreateFlatShadedColormap(ILInArray<float> cm) {
        using (ILScope.Enter(cm)) {
            // create array large enough to hold new colormap
            ILArray<float> ret = zeros<float>(cm.S[0] * 2 - 1, cm.S[1]);
            // copy the original
            ret[r(0, cm.S[0] - 1), full] = cm; 
            // double original keypoints, give small offset (may not even be needed?) 
            ret[r(cm.S[0], end), 0] = cm[r(1, end), 0] - epsf;
            ret[r(cm.S[0], end), r(1, end)] = cm[r(0, end - 1), r(1, end)];
            // reorder to sort keypoints in ascending order
            ILArray<int> I = 1;
            sort(ret[full, 0], Indices: I);
            return ret[I, full];
        }

    }

结果

Flat Shaded Colormaps in ILNumerics