【发布时间】:2014-07-23 21:40:14
【问题描述】:
我正在使用 ILNumerics 生成曲面图。
我想使用平面阴影颜色图(即颜色范围)而不是平滑阴影颜色图(即每个像素都有自己的颜色)。
ILNumerics 可以做到这一点吗?
平面阴影图和彩条图例示例:
Smooth-Shaded 曲面图和彩条图例示例:
【问题讨论】:
标签: colors ilnumerics color-mapping
我正在使用 ILNumerics 生成曲面图。
我想使用平面阴影颜色图(即颜色范围)而不是平滑阴影颜色图(即每个像素都有自己的颜色)。
ILNumerics 可以做到这一点吗?
平面阴影图和彩条图例示例:
Smooth-Shaded 曲面图和彩条图例示例:
【问题讨论】:
标签: colors ilnumerics color-mapping
您可以创建一个显示平面着色行为的颜色图。只需复制公共颜色图中存在的关键点,以便对分配相同颜色的一系列颜色数据进行建模。
根据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];
}
}
【讨论】:
这是不可能的。 ILNumerics 中的曲面图总是在网格点之间插入颜色。对于其他着色模型,您必须创建自己的表面类。
【讨论】: