这可以使用自定义颜色图来实现。但必须小心,才能可靠地做到这一点。简单地在颜色图的中间放置一个新的红色关键点会产生非常不正确的结果......:|
我稍微修改并记录了您的示例。基本上,颜色图包含具有位置和颜色的关键点。位置通常(但不一定)范围为 [0..1]。颜色始终在 [0..1] 范围内。这里的挑战是在颜色图范围内找到“0”cdata 值的正确位置。
首先,创建默认的冷色图。它有以下两个关键点(行):
colorkeys
<Single> [2,5]
[0]: 0,00000 0,00000 1,00000 1,00000 1,00000 <- position: 0, color: RGBA
[1]: 1,00000 1,00000 0,00000 1,00000 1,00000 <- position: 1
您必须添加至少 3 个新关键点:前两个对标记区域边缘的原始颜色进行采样。第三个将标记区域变为红色。简单地添加红色关键点是行不通的,因为这会影响地图中的所有值,而不仅仅是 0 附近的数据值。
最后,关键点如下所示:
colorkeys
<Single> [5,5]
[0]: 0,00000 0,00000 1,00000 1,00000 1,00000
[1]: 1,00000 1,00000 0,00000 1,00000 1,00000
[2]: 0,49150 0,49150 0,50850 1,00000 1,00000
[3]: 0,49702 0,49702 0,50298 1,00000 1,00000
[4]: 0,49426 1,00000 0,00000 0,00000 1,00000
请注意,关键点的顺序并不重要。在创建新颜色图时,它们无论如何都会被排序。新地图只是简单地提供给 ILSurface:
private void ilPanel1_Load(object sender, EventArgs e) {
// create some X/Y meshgrid data
ILArray<float> y = 1, R = ILMath.linspace<float>(-4, 4, 100);
ILArray<float> x = ILMath.meshgrid(R, ILMath.linspace<float>(-4, 4, 100), y);
// precreate the surface data array
ILArray<float> Z = ILMath.zeros<float>(x.S[0], x.S[1], 3);
// surface expects Z, X and Y coords (in that order)
Z[":;:;2"] = y; Z[":;:;1"] = x;
Z[":;:;0"] = 0.4f * x * x - 0.2f * y * y * y;
// our color data are based on another function
ILArray<float> cdata = 1.4f * x * x * x + 0.13f * y * y;
// we need cdatas limits for creating a new colormap
float min, max; cdata.GetLimits(out min, out max);
// get default 'Cool' colormap
var colormap = new ILColormap(Colormaps.Cool);
// get colormap keys as array: [position,R,G,B,A]
ILArray<float> colorkeys = colormap.Data;
// helper function to map true values to 0..1 range
Func<float, float> map = a => { return (a - min) / (max - min); };
// the value to mark and +/- tolerance width (to make it a visible strip at least)
float markValue = 0, tolerance = 0.5f;
// sample the colormap at the marked edges
Vector4 key1 = colormap.Map(markValue - tolerance, new Tuple<float, float>(min, max));
Vector4 key2 = colormap.Map(markValue + tolerance, new Tuple<float, float>(min, max));
// create new keypoints at the edges of marked area
colorkeys[ILMath.end + 1, ":"] = ILMath.array(map(markValue - tolerance), key1.X, key1.Y, key1.Z, 1f);
colorkeys[ILMath.end + 1, ":"] = ILMath.array(map(markValue + tolerance), key2.X, key2.Y, key2.Z, 1f);
// create new keypoint for the marked area itself; color red
colorkeys[ILMath.end + 1, ":"] = ILMath.array(map(markValue), 1f, 0f, 0f, 1f); // red
// make a new colormap out of it
colormap = new ILColormap(colorkeys);
// create & add a plot cube
ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false) {
// add surface plot, give custom colormap & colormap data ...
new ILSurface(Z, colormap: colormap, C: cdata) {
// add colorbar
Childs = { new ILColorbar() }
}
});
}
这会产生以下输出: