/// <summary> /// create new lit surface, provide data for X,Y and Z coordinates /// </summary> /// <param name="panel">the panel hosting the scene</param> /// <param name="X">X coordinates matrix, same size as Z or null</param> /// <param name="Y">Y coordinates matrix, same size as Z or null</param> /// <param name="Z">Z data matrix, at least 2 rows, 2 columns</param> /// <param name="colormap">colormap used for auto coloring the surface</param> public ILLitSurface(ILPanel panel, ILBaseArray X, ILBaseArray Y, ILBaseArray Z, ILColormap colormap) : base(panel) { if (Z == null || Z.Dimensions[0] < 2 || Z.Dimensions[1] < 2) { throw new ArgumentException("invalid parameter size: Z"); } if (X == null || !X.Dimensions.IsSameSize(Z.Dimensions)) { throw new ArgumentException("invalid parameter size: X"); } if (Y == null || !Y.Dimensions.IsSameSize(Z.Dimensions)) { throw new ArgumentException("invalid parameter size: Y"); } m_quads = new ILLitQuads(panel, Z.Dimensions.NumberOfElements); m_quads.Label.Text = ""; m_quads.Shading = ShadingStyles.Interpolate; Add(m_quads); m_colorMap = colormap; ZValues = Z; XValues = X; YValues = Y; Invalidate(); }
protected override void CreateVertices() { ILColormap colormap = m_panel.Colormap; if (m_vertices == null) { m_vertices = ILMemoryPool.Pool.New <VERTEXTYPEDEF>(m_Vertcount); } float val = 0.0f; float minZ = m_sourceArray.MinValue; float maxZ = m_sourceArray.MaxValue; float a = colormap.Length / (maxZ - minZ); byte ca = (byte)(m_opacity * 255); VERTEXTYPEDEF curVertex; int i = 0; // first row is special (no color, just for grid) for (int c = 0; c < m_cols - 1; c++) { curVertex = new VERTEXTYPEDEF(); curVertex.Vx = c - 0.5f; curVertex.Vy = -0.5f; curVertex.CA = ca; val = m_sourceArray.GetValue(0, c); colormap.Map((val - minZ) * a, out curVertex.CR, out curVertex.CG, out curVertex.CB); m_vertices[i++] = curVertex; } // right corner curVertex = new VERTEXTYPEDEF(); curVertex.Vx = m_cols - 1.5f; curVertex.Vy = -0.5f; curVertex.CA = ca; colormap.Map((val - minZ) * a, out curVertex.CR, out curVertex.CG, out curVertex.CB); m_vertices[i++] = curVertex; for (int r = 0; r < m_rows - 1; r++) { // first col part is special (no color) curVertex = new VERTEXTYPEDEF(); curVertex.Vx = -0.5f; curVertex.Vy = r + 0.5f; curVertex.CA = ca; colormap.Map((m_sourceArray.GetValue(r, 0) - minZ) * a, out curVertex.CR, out curVertex.CG, out curVertex.CB); m_vertices[i++] = curVertex; for (int c = 0; c < m_cols - 1; c++) { curVertex = new VERTEXTYPEDEF(); val = m_sourceArray.GetValue(r, c); // set color values colormap.Map((val - minZ) * a, out curVertex.CR, out curVertex.CG, out curVertex.CB); curVertex.CA = ca; curVertex.Vx = c + 0.5f; curVertex.Vy = r + 0.5f; m_vertices[i++] = curVertex; } } m_vertexReady = true; }
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)); }
public ILColorBar(ILColormap colormap) : base() { base.BorderStyle = BorderStyle.FixedSingle; Padding = new Padding(4); StandardOrientation = TextOrientation.Vertical; m_orientation = TextOrientation.Vertical; Visible = true; BackColor = SystemColors.Info; m_colormap = colormap; }
/// <summary> /// Initialize the graph components /// </summary> public SurfaceGraph() { InitializeComponent(); //Create the panel on the GUI _panel = ILPanel.Create(); //Create the color map for the graph _cm = new ILColormap(_colormapType); //Create the colorbar for the graph _cb = new ILColorBar(_cm); //Add the panel and colorbar on the GUI tableLayoutPanel.Controls.Add(_panel, 0, 0); _panel.Dock = DockStyle.Fill; _panel.Controls.Add(_cb); _cameraView = new ViewPoint(); //plot the waveform with built-in data Plot(stdWfm.Waterfall); this.CubeGridVisible = false; this.AxesLineVisible = true; this.CubeColor = Color.White; this.BackGroundColor = Color.White; this.WireframeVisible = false; this.XAxisTitle = "X"; this.YAxisTitle = "Y"; this.ZAxisTitle = "Z"; this.ColormapType = Colormaps.Hsv; this.isColorbarHorizontal = true; this.DigitsOfColorbar = 5; this.BackColorOfColorBar = Color.Transparent; this.Position = new Point(5, 5); this.WidthofColorBar = 120; this.HeightofColorBar = 45; checkBox_showCB.Checked = true; _cameraView.phi = (float)45.0; _cameraView.rho = (float)89.9; _cameraView.distance = (float)362; InteractiveMode = InteractiveModes.None; ColorBarUpdate(); UpdatePointOfView(); }
internal static ILArray <double> CreateVertices(ILBaseArray dataInput , out ILArray <double> indices , double beta, double scaling , ILColormap colormap) { // each arrow needs 4 vertices (indexed rendering) ILArray <double> data = todouble(dataInput); int numRows = data.Dimensions[0]; int numCols = data.Dimensions[1]; ILArray <double> ret = new ILArray <double>(4, numCols * numRows, 2); // prepare indices indices = repmat(new ILArray <double>(new double[] { 0, 2, 1, 2, 3, 2 }, 6, 1), 1, numCols * numRows); indices = indices + repmat(counter(0.0, 4.0, 1, numCols * numRows), 6, 1); indices = indices.Reshape(2, numRows * numCols * 3); // normalize incoming data to length 1.0 ILArray <double> l = sqrt(sum(data * data, 2)); double maxL = (double)max(maxall(l), MachineParameterDouble.eps); l = (l / maxL)[":"].T * scaling; ILArray <double> alpha = atan2(data[":;:;1"], data[":;:;0"]); alpha = alpha[":"].T; ILArray <double> x = data[":;:;0"][":"].T * scaling; ILArray <double> y = data[":;:;1"][":"].T * scaling; ILArray <double> xO = repmat(linspace(1, numCols, numCols), numRows, 1)[":"].T; ILArray <double> yO = repmat(linspace(numRows, 1, numRows).T, 1, numCols)[":"].T; ret["0;:;0"] = xO - x; ret["1;:;0"] = xO + x - l / 2 * cos(alpha + beta); ret["2;:;0"] = xO + x; ret["3;:;0"] = xO + x - l / 2 * cos(alpha - beta); ret["0;:;1"] = yO - y; ret["1;:;1"] = yO + y - l / 2 * sin(alpha + beta); ret["2;:;1"] = yO + y; ret["3;:;1"] = yO + y - l / 2 * sin(alpha - beta); ret["0;0;2"] = 0.0; // prepare colors ret[":;:;3:5"] = todouble( repmat(colormap.Map (tosingle(l) * colormap.Length).Reshape(1, l.Length, 3) * 255, 4, 1, 1)); return(ret.Reshape(4 * numRows * numCols, 6).T); }
/// <summary> /// Update the colorbar of the surface graph /// </summary> private void ColorBarUpdate() { _panel.Controls.Remove(_cb); _cm = new ILColormap(_colormapType); _cm.Data = ILMath.tosingle(_displayData); _panel.Colormap = _cm; _cb = new ILColorBar(_cm); _cb.Orientation = isHorizontal?TextOrientation.Horizontal:TextOrientation.Vertical; _cb.Precision = _colorbarDigits; _cb.BorderStyle = _borderStyleOfColorbar; _cb.Visible = _colorbarVisible; _cb.BackColor = _backColor; _cb.Width = _widthOfColorbar; _cb.Height = _heightOfColorbar; _cb.Location = _position; _panel.Controls.Add(_cb); AutoScaleColorRange(); }
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); } } }
ILColormap ConstructILColormap(ColorScheme theScheme, double dataMinValue, double dataMaxValue) { ColorScheme newCS = new ColorScheme(""); float[,] colorsArr = new float[5, newCS.colorsArray.Count]; int i = 0; foreach (Bgr bgrColor in newCS.colorsArray) { colorsArr[0, i] = Convert.ToSingle(dataMinValue + (dataMaxValue - dataMinValue) * (double)i / (double)newCS.colorsArray.Count); colorsArr[1, i] = Convert.ToSingle(bgrColor.Red / 255.0d); colorsArr[2, i] = Convert.ToSingle(bgrColor.Green / 255.0d); colorsArr[3, i] = Convert.ToSingle(bgrColor.Blue / 255.0d); colorsArr[4, i] = 1.0f; i++; } ILColormap retColormap = new ILColormap(colorsArr); return(retColormap); }
/// <summary> /// create new vector field (2D) plot /// </summary> /// <param name="panel">panel hosting the scene</param> /// <param name="data">3d data array: :;:;0 - X coords of vectors, :;:;1 - Y coords</param> /// <param name="colormap">Colormap used for coloring, on null: Colormaps.ILNumerics is used as default</param> /// <param name="XLabels">labels for X axis, on null: auto labeling</param> /// <param name="YLabels">labels for Y axis, on null: auto labeling</param> public ILVectorField2D(ILPanel panel, ILBaseArray data , ILColormap colormap, ICollection <string> XLabels , ICollection <string> YLabels) : base(panel) { if (data == null || data.Dimensions[2] != 2 || data.IsEmpty) { throw new ILArgumentException("Invalid parameter: data"); } m_data = data; m_xLabels = XLabels; m_yLabels = YLabels; m_colormap = colormap; m_lines = new ILLines(m_panel, data.Dimensions[0] * data.Dimensions[1] * 4); m_lines.Shading = ShadingStyles.Interpolate; m_lines.Properties.Width = 2; m_lines.Properties.Antialiasing = true; m_lines.Label.Text = ""; ArrowHeadAngle = 10 * Math.PI / 180; Invalidate(); Add(m_lines); }
protected override void CreateVertices() { ILColormap colormap = m_panel.Colormap; if (m_vertices == null) { m_vertices = ILMemoryPool.Pool.New <float>(m_Vertcount * 40); } float val = 0.0f; float minZ = m_globalClipping.ZMin, minC = (m_colors == null)? 0.0f : m_colors.MinValue; float maxZ = m_globalClipping.ZMax; bool useColorArray = !object.Equals(m_colors, null); float a; if (useColorArray) { a = colormap.Length / (m_colors.MaxValue - minC); } else { if (maxZ - minZ != 0.0f) { a = colormap.Length / (maxZ - minZ); } else { a = 0.0f; } } int curVertPos = 0, curVecPos = 0; if (m_shading == ShadingStyles.Interpolate) { #region shading interpolate for (int r = 0; r < m_rows; r++) { for (int c = 0; c < m_cols; c++) { curVecPos = r + c * m_rows; val = m_sourceArray.GetValue(r, c); // set color values if (useColorArray) { colormap.Map((m_colors.GetValue(curVecPos) - minC) * a, m_vertices, ref curVertPos); } else { if (a != 0) { colormap.Map((val - minZ) * a, m_vertices, ref curVertPos); } else { // plane: minz == maxz colormap.Map(colormap.Length / 2, m_vertices, ref curVertPos); } } m_vertices[curVertPos++] = m_opacity; curVertPos += 3; m_vertices[curVertPos++] = m_xCoords[curVecPos]; m_vertices[curVertPos++] = m_yCoords[curVecPos]; m_vertices[curVertPos++] = val; } } #endregion } else if (m_shading == ShadingStyles.Flat) { #region shading flat /** Consider a surface area like this: * * 8 - 9 -10 -11 * | / | / | / | * 4 - 5 - 6 - 7 * | / | / | / | * 0 - 1 - 2 - 3 * * The rectangle surrounded by 0-1-4-5 is than colored by the * vertex 5. This rectangle will be assembled by 2 triangles: * 0-1-5 and 0-4-5. Therefore the color for both rectangles * is the same and must be stored in the vertex No.5. * The vertices can be assembled in natural order, beginning * with 0 and approching m_vertexCount-1. The color for flat * shading is averaged over the neighbor corners of each * rectangle. In our Example the color stored in 5 is averaged * over the values of the vertices 0,1,4 and 5. The first row * and the first column are not used for the surface. However * it may _be_ used for the wireframe grid if that is drawn with * interpolated colors (Wireframe.Color.IsEmpty). So we must * prepare the color for it -> here we just take the value itself. */ // first row: no color average for (int c = 0; c < m_cols; c++) { val = m_sourceArray.GetValue(0, c); if (useColorArray) { colormap.Map((m_colors.GetValue(0, c) - minC) * a, m_vertices, ref curVertPos); } else { colormap.Map((val - minZ) * a, m_vertices, ref curVertPos); } m_vertices[curVertPos++] = m_opacity; curVertPos += 3; m_vertices[curVertPos++] = m_xCoords[m_rows * c]; m_vertices[curVertPos++] = m_yCoords[m_rows * c]; m_vertices[curVertPos++] = val; } for (int r = 1; r < m_rows; r++) { val = m_sourceArray.GetValue(r, 0); if (useColorArray) { colormap.Map((m_colors.GetValue(r) - minC) * a, m_vertices, ref curVertPos); } else { colormap.Map((val - minZ) * a, m_vertices, ref curVertPos); } m_vertices[curVertPos++] = m_opacity; curVertPos += 3; m_vertices[curVertPos++] = m_xCoords[r]; m_vertices[curVertPos++] = m_yCoords[r]; m_vertices[curVertPos++] = val; // next columns: average color over precomputed corners for (int c = 1; c < m_cols; c++) { curVecPos = r + c * m_rows; val = m_sourceArray.GetValue(r, c); val += m_sourceArray.GetValue(r - 1, c); val += m_sourceArray.GetValue(r, c - 1); val += m_sourceArray.GetValue(r - 1, c - 1); val /= 4; if (useColorArray) { colormap.Map((m_colors.GetValue(curVecPos) - minC) * a, m_vertices, ref curVertPos); } else { colormap.Map((val - minZ) * a, m_vertices, ref curVertPos); } m_vertices[curVertPos++] = m_opacity; curVertPos += 3; m_vertices[curVertPos++] = m_xCoords[curVecPos]; m_vertices[curVertPos++] = m_yCoords[curVecPos]; m_vertices[curVertPos++] = m_sourceArray.GetValue(r, c); } } #endregion m_oldColormap = colormap; } #region create normals // todo: depends on lighting enabled or not...! // reset vertices pointer and start all over curVertPos = 0; float nx, ny, nz; for (int r = 0; r < m_rows; r++) { for (int c = 0; c < m_cols; c++) { nx = m_vertices[curVertPos + 7]; ny = m_vertices[curVertPos + 8]; nz = m_vertices[curVertPos + 9]; if (c > 0) { nx += m_vertices[curVertPos - 3]; ny += m_vertices[curVertPos - 2]; nz += m_vertices[curVertPos - 1]; } if (c < m_cols - 1) { nx += m_vertices[curVertPos + 17]; ny += m_vertices[curVertPos + 18]; nz += m_vertices[curVertPos + 19]; } if (r > 0 && r < m_rows) { nx += m_vertices[curVertPos - m_cols * 10 + 10]; ny += m_vertices[curVertPos - m_cols * 10 + 11]; nz += m_vertices[curVertPos - m_cols * 10 + 12]; } if (r < m_rows - 1) { nx += m_vertices[curVertPos + m_cols * 10 + 10]; ny += m_vertices[curVertPos + m_cols * 10 + 11]; nz += m_vertices[curVertPos + m_cols * 10 + 12]; } // normalize float len = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz); m_vertices[curVertPos + 4] = nx / len; m_vertices[curVertPos + 5] = ny / len; m_vertices[curVertPos + 6] = nz / len; curVertPos += 10; } } #endregion m_oldShading = m_shading; m_vertexReady = true; }
private void UpdateTrackerPlot() { ilPanelTracker.Scene.Children.Clear(); var scene = new ILScene(); // add plot cube tracker = scene.Add(new ILPlotCube()); // meterialize new colormap ILColormap m = new ILColormap(Colormaps.Lines); //// create a line plot for each entry in the colormap var legendas = tracker.Add( new ILLegend { Location = new PointF(1, 0.02f), Anchor = new PointF(1, 0) }); //foreach (var data in datas) foreach (var node in Designer.TrackingNodes) { double[] data = node.GetAllEZs().ToArray(); ILArray<float> d = ILMath.tosingle((ILArray<double>)data); d = d.Reshape(new int[] { 1, d.Count() }); var lp = tracker.Add(new ILLinePlot(d)); legendas.Items.Add(new ILLegendItem(lp, String.Format("Node: {0}:{1}", node.i, node.j))); //legendas.Add(); } ilPanelTracker.Scene.Add(scene); }
/// <summary> /// update range for color bar, supply color provider /// </summary> /// <param name="minValue">min value</param> /// <param name="maxValue">max value</param> /// <param name="colorProvider">color provider (not implemented)</param> public void Update(float minValue, float maxValue, ILColormap colormap) { m_minValue = minValue; m_maxValue = maxValue; m_colormap = colormap; }