public static ILArray <int> configureVertices( ILArray <float> xVals, ILArray <float> yVals, ILArray <float> zVals, ILColormap cmap, C4fN3fV3f[] Vertices, byte opacity) { int i = 0, x, y, y0 = zVals.Dimensions[0] - 1; float minZ, maxZ; if (!zVals.GetLimits(out minZ, out maxZ, false)) { minZ = maxZ = 1.0f; } x = 0; y = 0; ILArray <float> colors = (tosingle((zVals - minZ) / (maxZ - minZ)))[":"] * (cmap.Length - 1); colors[isnan(colors)] = 0; bool useXvals = (xVals != null && !xVals.IsEmpty); bool useYvals = (yVals != null && !yVals.IsEmpty); foreach (float a in zVals.Values) { C4fN3fV3f v = Vertices[i]; v.Position = new ILPoint3Df( (useXvals)? xVals.GetValue(y, x): x , (useYvals)? yVals.GetValue(y, x): y0 - y , a); byte r, g, b; cmap.Map(colors.GetValue(i), out r, out g, out b); v.Color = Color.FromArgb(255, r, g, b); v.Alpha = opacity; Vertices[i++] = v; // set next position if (++y >= zVals.Dimensions[0]) { x++; y = 0; } } // create quad indices int numQuad = (zVals.Dimensions[0] - 1) * (zVals.Dimensions[1] - 1); x = 0; y = 0; ILArray <double> ret = zeros(4, numQuad); ILArray <double> mult = counter(0.0, 1.0, zVals.Dimensions.ToIntArray()); mult = mult["0:" + (zVals.Dimensions[0] - 2), "0:" + (zVals.Dimensions[1] - 2)]; mult = mult[":"].T; ret["0;:"] = mult; ret["3;:"] = mult + 1; mult = mult + zVals.Dimensions.SequentialIndexDistance(1); ret["2;:"] = mult + 1; ret["1;:"] = mult; return(toint32(ret)); }
/// <summary> /// map all elements in A into final colors /// </summary> /// <param name="A">array with elements to map</param> /// <returns>colors as ILArray, the i-th row represents the color for the i-th element of A as RGB tripel.</returns> public ILArray <float> Map(ILArray <float> A) { ILArray <float> ret = new ILArray <float>(A.Dimensions.NumberOfElements, 3); float min, max; if (!A.GetLimits(out min, out max) || min == max) { // special case: all constant: eturn middle of colormap return(ILMath.repmat(m_map[m_map.Length / 2, null], ret.Dimensions[0], 1)); } float dist = (m_map.Dimensions[0] - 1) / (A.MaxValue - min); for (int i = 0; i < ret.Dimensions[0]; i++) { double index = (double)(A.GetValue(i) - min) * dist; if (index >= m_map.Dimensions[0] - 1) { ret[i, null] = m_map["end;:"]; continue; } else if (index < 0) { ret[i, null] = m_map["0;:"]; continue; } int find = (int)Math.Floor(index); if (find == index) { ret[i, null] = m_map[find, null]; continue; } // interpolate index = index - find; float r1 = m_map.GetValue(find, 0); float g1 = m_map.GetValue(find, 1); float b1 = m_map.GetValue(find, 2); r1 = (float)(index * (m_map.GetValue(find + 1, 0) - r1) + r1); g1 = (float)(index * (m_map.GetValue(find + 1, 1) - g1) + g1); b1 = (float)(index * (m_map.GetValue(find + 1, 2) - b1) + b1); ret.SetValue(r1, i, 0); ret.SetValue(g1, i, 1); ret.SetValue(b1, i, 2); } return(ret); }
private void create(ILBaseArray data, Colormaps colormap) { ILArray <float> dataF = ILNumerics.BuiltInFunctions.ILMath.tosingle(data); m_boxes = new ILLitBox3D[data.Dimensions[0], data.Dimensions[1]]; float maxY = data.Dimensions[0] * (m_barLengthY + m_paddingY); // prepare coloring for top quads ILColormap cmap = new ILColormap(colormap); float minV, maxV, mult; dataF.GetLimits(out minV, out maxV); if (maxV > minV) { mult = (cmap.Length - 1) / (maxV - minV); } else { minV = 0; mult = 0; } for (int r = 0; r < data.Dimensions[0]; r++) { for (int c = 0; c < data.Dimensions[1]; c++) { float val = dataF.GetValue(r, c); ILPoint3Df max = new ILPoint3Df( (float)(c * (m_paddingX + m_barLengthX) + m_barLengthX) , (float)(maxY - r * (m_paddingY + m_barLengthY)) , val); ILPoint3Df min = new ILPoint3Df( max.X - m_barLengthX , max.Y - m_barLengthY , 0); Color topColor = cmap.Map((double)(val - minV) * mult); ILLitBox3D box = new ILLitBox3D(m_panel, min, max, m_barColor, topColor); box.GradientColor = m_barColorGradient; box.TopLabel.Color = topColor; box.TopLabel.Text = ""; m_boxes[r, c] = box; Add(box); } } }
/// <summary> /// map all elements in A into final colors /// </summary> /// <param name="A">array with elements to map</param> /// <returns>colors as ILArray, the i-th row represents the color for the i-th element of A as RGB tripel.</returns> public ILArray<float> Map (ILArray<float> A) { ILArray<float> ret = new ILArray<float>(A.Dimensions.NumberOfElements,3); float min, max; if (!A.GetLimits(out min, out max) || min == max) { // special case: all constant: eturn middle of colormap return ILMath.repmat(m_map[m_map.Length / 2, null], ret.Dimensions[0], 1); } float dist = (m_map.Dimensions[0]-1) / (A.MaxValue - min); for (int i = 0; i < ret.Dimensions[0]; i++) { double index = (double)(A.GetValue(i)-min)*dist; if (index >= m_map.Dimensions[0] - 1) { ret[i, null] = m_map["end;:"]; continue; } else if (index < 0) { ret[i, null] = m_map["0;:"]; continue; } int find = (int)Math.Floor(index); if (find == index) { ret[i,null] = m_map[find,null]; continue; } // interpolate index = index - find; float r1 = m_map.GetValue(find,0); float g1 = m_map.GetValue(find,1); float b1 = m_map.GetValue(find,2); r1 = (float)(index*(m_map.GetValue(find+1,0)-r1)+r1); g1 = (float)(index*(m_map.GetValue(find+1,1)-g1)+g1); b1 = (float)(index*(m_map.GetValue(find+1,2)-b1)+b1); ret.SetValue(r1,i,0); ret.SetValue(g1,i,1); ret.SetValue(b1,i,2); } return ret; }
public static ILArray<int> configureVertices( ILArray<float> xVals, ILArray<float> yVals, ILArray<float> zVals, ILColormap cmap, C4fN3fV3f[] Vertices, byte opacity) { int i = 0, x, y, y0 = zVals.Dimensions[0] - 1; float minZ, maxZ; if (!zVals.GetLimits(out minZ, out maxZ,false)) minZ = maxZ = 1.0f; x = 0; y = 0; ILArray<float> colors = (tosingle((zVals - minZ) / (maxZ - minZ)))[":"] * (cmap.Length - 1); colors[isnan(colors)] = 0; bool useXvals = (xVals != null && !xVals.IsEmpty); bool useYvals = (yVals != null && !yVals.IsEmpty); foreach (float a in zVals.Values) { C4fN3fV3f v = Vertices[i]; v.Position = new ILPoint3Df( (useXvals)? xVals.GetValue(y,x): x ,(useYvals)? yVals.GetValue(y,x): y0 - y , a); byte r, g, b; cmap.Map(colors.GetValue(i), out r, out g, out b); v.Color = Color.FromArgb(255, r, g, b); v.Alpha = opacity; Vertices[i++] = v; // set next position if (++y >= zVals.Dimensions[0]) { x++; y = 0; } } // create quad indices int numQuad = (zVals.Dimensions[0] - 1) * (zVals.Dimensions[1] - 1); x = 0; y = 0; ILArray<double> ret = zeros(4, numQuad); ILArray<double> mult = counter(0.0, 1.0, zVals.Dimensions.ToIntArray()); mult = mult["0:" + (zVals.Dimensions[0] - 2), "0:" + (zVals.Dimensions[1] - 2)]; mult = mult[":"].T; ret["0;:"] = mult; ret["3;:"] = mult + 1; mult = mult + zVals.Dimensions.SequentialIndexDistance(1); ret["2;:"] = mult + 1; ret["1;:"] = mult; return toint32(ret); }