public void Transform(Matrix3 m, Chart3D chart3d, Axes ax, ChartStyle cs, ChartLabels cl) { // Normalize the point: float x1 = (X - ax.XMin) / (ax.XMax - ax.XMin) - 0.5f; float y1 = (Y - ax.YMin) / (ax.YMax - ax.YMin) - 0.5f; float z1 = (Z - ax.ZMin) / (ax.ZMax - ax.ZMin) - 0.5f; // Perform transformation on the point using matrix m: float[] result = m.VectorMultiply(new float[4] { x1, y1, z1, W }); X = result[0]; Y = result[1]; // Coordinate transformation from World to Device system: float xShift = 1.05f; float xScale = 1; float yShift = 1.05f; float yScale = 0.9f; if (cl.Title == "No Title") { yShift = 0.95f; yScale = 1; } if (cs.IsColorBar) { xShift = 0.95f; xScale = 0.9f; } X = (xShift + xScale * X) * chart3d.Width / 2; Y = (yShift - yScale * Y) * chart3d.Height / 2; }
public void AddChartStyle2D(Graphics g, ChartStyle cs3d, Axes ax, Grid gd, ChartLabels cl) { SetPlotArea(g, cs3d, cl, ax); Pen aPen = new Pen(Color.Black, 1f); SizeF tickFontSize = g.MeasureString("A", cl.TickFont); // Create vertical gridlines: float fX, fY; if (gd.IsYGrid == true) { aPen = new Pen(gd.GridStyle.LineColor, 1f); aPen.DashStyle = gd.GridStyle.Pattern; for (fX = ax.XMin + ax.XTick; fX < ax.XMax; fX += ax.XTick) { g.DrawLine(aPen, Point2D(new PointF(fX, ax.YMin), ax), Point2D(new PointF(fX, ax.YMax), ax)); } } // Create horizontal gridlines: if (gd.IsXGrid == true) { aPen = new Pen(gd.GridStyle.LineColor, 1f); aPen.DashStyle = gd.GridStyle.Pattern; for (fY = ax.YMin + ax.YTick; fY < ax.YMax; fY += ax.YTick) { g.DrawLine(aPen, Point2D(new PointF(ax.XMin, fY),ax), Point2D(new PointF(ax.XMax, fY),ax)); } } // Create the x-axis tick marks: for (fX = ax.XMin; fX <= ax.XMax; fX += ax.XTick) { PointF yAxisPoint = Point2D(new PointF(fX, ax.YMin), ax); g.DrawLine(Pens.Black, yAxisPoint, new PointF(yAxisPoint.X, yAxisPoint.Y - 5f)); } // Create the y-axis tick marks: for (fY = ax.YMin; fY <= ax.YMax; fY += ax.YTick) { PointF xAxisPoint = Point2D(new PointF(ax.XMin, fY), ax); g.DrawLine(Pens.Black, xAxisPoint, new PointF(xAxisPoint.X + 5f, xAxisPoint.Y)); } aPen.Dispose(); }
public Chart3D() { InitializeComponent(); this.SetStyle(ControlStyles.ResizeRedraw, true); cs = new ChartStyle(this); cs2d = new ChartStyle2D(this); dc = new DrawChart(this); ds = new DataSeries(); ax = new Axes(this); va = new ViewAngle(this); gd = new Grid(this); cl = new ChartLabels(this); gd.GridStyle.LineColor = Color.LightGray; this.BackColor = Color.White; cm = new ColorMap(); dc.CMap = cm.Jet(); }
private void AddSlice(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.Black); Point4[, ,] pts = ds.Point4Array; PointF[] pta = new PointF[4]; Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); // Find the minumum and maximum v values: float vmin = ds.VDataMin(); float vmax = ds.VDataMax(); // Perform transformation on points: for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { for (int k = 0; k < pts.GetLength(2); k++) { pts[i, j, k].point3.Transform(m, chart3d, ax, cs, cl); pts[i, j, k].point3.Z = pts[i, j, k].V; } } } // Select slice: if (XYZSlice == SliceEnum.XSlice) { if (SliceLocation < ax.XMin) SliceLocation = ax.XMin; if (SliceLocation > ax.XMax) SliceLocation = ax.XMax; int nfix = (int)((SliceLocation - ds.XDataMin) / ds.XSpacing) + 1; for (int j = 0; j < pts.GetLength(1) - 1; j++) { for (int k = 0; k < pts.GetLength(2) - 1; k++) { pta[0] = new PointF(pts[nfix, j, k].point3.X, pts[nfix, j, k].point3.Y); pta[1] = new PointF(pts[nfix, j + 1, k].point3.X, pts[nfix, j + 1, k].point3.Y); pta[2] = new PointF(pts[nfix, j + 1, k + 1].point3.X, pts[nfix, j + 1, k + 1].point3.Y); pta[3] = new PointF(pts[nfix, j, k + 1].point3.X, pts[nfix, j, k + 1].point3.Y); Color color = AddColor(cs, pts[nfix, j, k].point3, vmin, vmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } else if (XYZSlice == SliceEnum.YSlice) { if (SliceLocation < ax.YMin) SliceLocation = ax.YMin; if (SliceLocation > ax.YMax) SliceLocation = ax.YMax; int nfix = (int)((SliceLocation - ds.YDataMin) / ds.YSpacing) + 1; for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int k = 0; k < pts.GetLength(2) - 1; k++) { pta[0] = new PointF(pts[i, nfix, k].point3.X, pts[i, nfix, k].point3.Y); pta[1] = new PointF(pts[i + 1, nfix, k].point3.X, pts[i + 1, nfix, k].point3.Y); pta[2] = new PointF(pts[i + 1, nfix, k + 1].point3.X, pts[i + 1, nfix, k + 1].point3.Y); pta[3] = new PointF(pts[i, nfix, k + 1].point3.X, pts[i, nfix, k + 1].point3.Y); Color color = AddColor(cs, pts[i, nfix, k].point3, vmin, vmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } else if (XYZSlice == SliceEnum.ZSlice) { if (SliceLocation < ax.ZMin) SliceLocation = ax.ZMin; if (SliceLocation > ax.ZMax) SliceLocation = ax.ZMax; int nfix = (int)((SliceLocation - ds.ZZDataMin) / ds.ZSpacing) + 1; for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { pta[0] = new PointF(pts[i, j, nfix].point3.X, pts[i, j, nfix].point3.Y); pta[1] = new PointF(pts[i + 1, j, nfix].point3.X, pts[i + 1, j, nfix].point3.Y); pta[2] = new PointF(pts[i + 1, j + 1, nfix].point3.X, pts[i + 1, j + 1, nfix].point3.Y); pta[3] = new PointF(pts[i, j + 1, nfix].point3.X, pts[i, j + 1, nfix].point3.Y); Color color = AddColor(cs, pts[i, j, nfix].point3, vmin, vmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } aPen.Dispose(); aBrush.Dispose(); }
private void AddXYColor(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; Matrix3 m = new Matrix3(); // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Draw surface on the XY plane: if (!IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { pta[0] = cs2d.Point2D(new PointF(pts[i, j].X, pts[i, j].Y), ax); pta[1] = cs2d.Point2D(new PointF(pts[i, j + 1].X, pts[i, j + 1].Y), ax); pta[2] = cs2d.Point2D(new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y), ax); pta[3] = cs2d.Point2D(new PointF(pts[i + 1, j].X, pts[i + 1, j].Y), ax); Color color = AddColor(cs, pts[i, j], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } // Draw refined surface: else if (IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { Point3[] points = new Point3[4]; points[0] = pts[i, j]; points[1] = pts[i, j + 1]; points[2] = pts[i + 1, j + 1]; points[3] = pts[i + 1, j]; Interp(g, cs, cs2d, m, points, zmin, zmax, 2, ax, va, cl); pta[0] = cs2d.Point2D(new PointF(pts[i, j].X, pts[i, j].Y), ax); pta[1] = cs2d.Point2D(new PointF(pts[i, j + 1].X, pts[i, j + 1].Y), ax); pta[2] = cs2d.Point2D(new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y), ax); pta[3] = cs2d.Point2D(new PointF(pts[i + 1, j].X, pts[i + 1, j].Y), ax); if (ds.LineStyle.IsVisible) { g.DrawPolygon(aPen, pta); } } } } }
private void SetPlotArea(Graphics g, ChartStyle cs3d, ChartLabels cl, Axes ax) { // Draw chart area: SolidBrush aBrush = new SolidBrush(ChartBackColor); Pen aPen = new Pen(ChartBorderColor, 2); g.FillRectangle(aBrush, ChartArea); g.DrawRectangle(aPen, ChartArea); // Set PlotArea: float xOffset = ChartArea.Width / 30.0f; float yOffset = ChartArea.Height / 30.0f; SizeF labelFontSize = g.MeasureString("A", cl.LabelFont); SizeF titleFontSize = g.MeasureString("A", cl.TitleFont); if (cl.Title.ToUpper() == "NO TITLE") { titleFontSize.Width = 8f; titleFontSize.Height = 8f; } float xSpacing = xOffset / 3.0f; float ySpacing = yOffset / 3.0f; SizeF tickFontSize = g.MeasureString("A", cl.TickFont); float tickSpacing = 2f; SizeF yTickSize = g.MeasureString(ax.YMin.ToString(), cl.TickFont); for (float yTick = ax.YMin; yTick <= ax.YMax; yTick += ax.YTick) { SizeF tempSize = g.MeasureString(yTick.ToString(), cl.TickFont); if (yTickSize.Width < tempSize.Width) { yTickSize = tempSize; } } float leftMargin = xOffset + labelFontSize.Width + xSpacing + yTickSize.Width + tickSpacing; float rightMargin = 2 * xOffset; float topMargin = yOffset + titleFontSize.Height + ySpacing; float bottomMargin = yOffset + labelFontSize.Height + ySpacing + tickSpacing + tickFontSize.Height; // Define the plot area: int plotX = ChartArea.X + (int)leftMargin; int plotY = ChartArea.Y + (int)topMargin; int plotWidth = ChartArea.Width - (int)leftMargin - (int)rightMargin; int plotHeight = ChartArea.Height - (int)topMargin - (int)bottomMargin; plotArea.X = plotX; plotArea.Y = plotY; if (cs3d.IsColorBar) plotArea.Width = 25 * plotWidth / 30; else plotArea.Width = plotWidth; plotArea.Height = plotHeight; // Draw plot area: aBrush = new SolidBrush(PlotBackColor); aPen = new Pen(PlotBorderColor, 1); g.FillRectangle(aBrush, PlotArea); g.DrawRectangle(aPen, PlotArea); AddLabels(g, cs3d, cl, ax); }
private void AddTicks(Graphics g, Axes ax, ViewAngle va, ChartLabels cl) { Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); Point3[] pta = new Point3[2]; Point3[] pts = CoordinatesOfChartBox(ax, va); ; Pen aPen = new Pen(ax.AxisStyle.LineColor, ax.AxisStyle.Thickness); aPen.DashStyle = ax.AxisStyle.Pattern; // Add x ticks: float offset = (ax.YMax - ax.YMin) / 30.0f; float ticklength = offset; for (float x = ax.XMin; x <= ax.XMax; x = x + ax.XTick) { if (va.Elevation >= 0) { if (va.Azimuth >= -90 && va.Azimuth < 90) ticklength = -offset; } else if (va.Elevation < 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || va.Azimuth >= 90 && va.Azimuth <= 180) ticklength = -(ax.YMax - ax.YMin) / 30; } pta[0] = new Point3(x, pts[1].Y + ticklength, pts[1].Z, pts[1].W); pta[1] = new Point3(x, pts[1].Y, pts[1].Z, pts[1].W); for (int i = 0; i < pta.Length; i++) { pta[i].Transform(m, chart3d, ax, this, cl); } g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } // Add y ticks: offset = (ax.XMax - ax.XMin) / 30.0f; ticklength = offset; for (float y = ax.YMin; y <= ax.YMax; y = y + ax.YTick) { pts = CoordinatesOfChartBox(ax, va); ; if (va.Elevation >= 0) { if (va.Azimuth >= -180 && va.Azimuth < 0) ticklength = -offset; } else if (va.Elevation < 0) { if (va.Azimuth >= 0 && va.Azimuth < 180) ticklength = -offset; } pta[0] = new Point3(pts[1].X + ticklength, y, pts[1].Z, pts[1].W); pta[1] = new Point3(pts[1].X, y, pts[1].Z, pts[1].W); for (int i = 0; i < pta.Length; i++) { pta[i].Transform(m, chart3d, ax, this, cl); } g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } float xoffset = (ax.XMax - ax.XMin) / 45.0f; float yoffset = (ax.YMax - ax.YMin) / 20.0f; float xticklength = xoffset; float yticklength = yoffset; for (float z = ax.ZMin; z <= ax.ZMax; z = z + ax.ZTick) { if (va.Elevation >= 0) { if (va.Azimuth >= -180 && va.Azimuth < -90) { xticklength = 0; yticklength = yoffset; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { xticklength = xoffset; yticklength = 0; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { xticklength = 0; yticklength = -yoffset; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { xticklength = -xoffset; yticklength = 0; } } else if (va.Elevation < 0) { if (va.Azimuth >= -180 && va.Azimuth < -90) { yticklength = 0; xticklength = xoffset; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { yticklength = -yoffset; xticklength = 0; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { yticklength = 0; xticklength = -xoffset; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { yticklength = yoffset; xticklength = 0; } } pta[0] = new Point3(pts[2].X, pts[2].Y, z, pts[2].W); pta[1] = new Point3(pts[2].X + yticklength, pts[2].Y + xticklength, z, pts[2].W); for (int i = 0; i < pta.Length; i++) { pta[i].Transform(m, chart3d, ax, this, cl); } g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } aPen.Dispose(); }
private void AddGrids(Graphics g, Axes ax, ViewAngle va, Grid gd, ChartLabels cl) { Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); Point3[] pta = new Point3[3]; Point3[] pts = CoordinatesOfChartBox(ax, va); Pen aPen = new Pen(gd.GridStyle.LineColor, gd.GridStyle.Thickness); aPen.DashStyle = gd.GridStyle.Pattern; // Draw x gridlines: if (gd.IsXGrid) { for (float x = ax.XMin; x <= ax.XMax; x = x + ax.XTick) { pts = CoordinatesOfChartBox(ax, va); pta[0] = new Point3(x, pts[1].Y, pts[1].Z, pts[1].W); if (va.Elevation >= 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || (va.Azimuth >= 0 && va.Azimuth < 90)) { pta[1] = new Point3(x, pts[0].Y, pts[1].Z, pts[1].W); pta[2] = new Point3(x, pts[0].Y, pts[3].Z, pts[1].W); } else { pta[1] = new Point3(x, pts[2].Y, pts[1].Z, pts[1].W); pta[2] = new Point3(x, pts[2].Y, pts[3].Z, pts[1].W); } } else if (va.Elevation < 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || (va.Azimuth >= 0 && va.Azimuth < 90)) { pta[1] = new Point3(x, pts[2].Y, pts[1].Z, pts[1].W); pta[2] = new Point3(x, pts[2].Y, pts[3].Z, pts[1].W); } else { pta[1] = new Point3(x, pts[0].Y, pts[1].Z, pts[1].W); pta[2] = new Point3(x, pts[0].Y, pts[3].Z, pts[1].W); } } for (int i = 0; i < pta.Length; i++) { pta[i].Transform(m, chart3d, ax, this, cl); } g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); g.DrawLine(aPen, pta[1].X, pta[1].Y, pta[2].X, pta[2].Y); } } // Draw y gridlines: if (gd.IsYGrid) { for (float y = ax.YMin; y <= ax.YMax; y = y + ax.YTick) { pts = CoordinatesOfChartBox(ax, va); pta[0] = new Point3(pts[1].X, y, pts[1].Z, pts[1].W); if (va.Elevation >= 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || (va.Azimuth >= 0 && va.Azimuth < 90)) { pta[1] = new Point3(pts[2].X, y, pts[1].Z, pts[1].W); pta[2] = new Point3(pts[2].X, y, pts[3].Z, pts[1].W); } else { pta[1] = new Point3(pts[0].X, y, pts[1].Z, pts[1].W); pta[2] = new Point3(pts[0].X, y, pts[3].Z, pts[1].W); } } if (va.Elevation < 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || (va.Azimuth >= 0 && va.Azimuth < 90)) { pta[1] = new Point3(pts[0].X, y, pts[1].Z, pts[1].W); pta[2] = new Point3(pts[0].X, y, pts[3].Z, pts[1].W); } else { pta[1] = new Point3(pts[2].X, y, pts[1].Z, pts[1].W); pta[2] = new Point3(pts[2].X, y, pts[3].Z, pts[1].W); } } for (int i = 0; i < pta.Length; i++) { pta[i].Transform(m, chart3d, ax, this, cl); } g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); g.DrawLine(aPen, pta[1].X, pta[1].Y, pta[2].X, pta[2].Y); } } // Draw Z gridlines: if (gd.IsZGrid) { for (float z = ax.ZMin; z <= ax.ZMax; z = z + ax.ZTick) { pts = CoordinatesOfChartBox(ax, va); pta[0] = new Point3(pts[2].X, pts[2].Y, z, pts[2].W); if (va.Elevation >= 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || (va.Azimuth >= 0 && va.Azimuth < 90)) { pta[1] = new Point3(pts[2].X, pts[0].Y, z, pts[1].W); pta[2] = new Point3(pts[0].X, pts[0].Y, z, pts[1].W); } else { pta[1] = new Point3(pts[0].X, pts[2].Y, z, pts[1].W); pta[2] = new Point3(pts[0].X, pts[1].Y, z, pts[1].W); } } if (va.Elevation < 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || (va.Azimuth >= 0 && va.Azimuth < 90)) { pta[1] = new Point3(pts[0].X, pts[2].Y, z, pts[1].W); pta[2] = new Point3(pts[0].X, pts[0].Y, z, pts[1].W); } else { pta[1] = new Point3(pts[2].X, pts[0].Y, z, pts[1].W); pta[2] = new Point3(pts[0].X, pts[0].Y, z, pts[1].W); } } for (int i = 0; i < pta.Length; i++) { pta[i].Transform(m, chart3d, ax, this, cl); } g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); g.DrawLine(aPen, pta[1].X, pta[1].Y, pta[2].X, pta[2].Y); } } }
private Color AddColor(ChartStyle cs, Point3 pt, float zmin, float zmax, Axes ax, ViewAngle va, ChartLabels cl) { int colorLength = CMap.GetLength(0); int cindex = (int)Math.Round((colorLength * (pt.Z - zmin) + (zmax - pt.Z)) / (zmax - zmin)); if (cindex < 1) cindex = 1; if (cindex > colorLength) cindex = colorLength; Color color = Color.FromArgb(CMap[cindex - 1, 0], CMap[cindex - 1, 1], CMap[cindex - 1, 2], CMap[cindex - 1, 3]); return color; }
private void AddBar3D(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); PointF[] pt = new PointF[4]; Point3[,] pts = ds.PointArray; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Check parameters: float xlength = ds.BarStyle.XLength; if (xlength <= 0) xlength = 0.1f * ds.XSpacing; else if (xlength > 0.5f) xlength = 0.5f * ds.XSpacing; else xlength = ds.BarStyle.XLength * ds.XSpacing; float ylength = ds.BarStyle.YLength; if (ylength <= 0) ylength = 0.1f * ds.YSpacing; else if (ylength > 0.5f) ylength = 0.5f * ds.YSpacing; else ylength = ds.BarStyle.YLength * ds.YSpacing; float zorigin = ds.BarStyle.ZOrigin; // Draw 3D bars: for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { int ii = i; int jj = j; if (va.Azimuth >= -180 && va.Azimuth < -90) { ii = pts.GetLength(0) - 2 - i; jj = j; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; jj = pts.GetLength(1) - 2 - j; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { ii = i; jj = pts.GetLength(1) - 2 - j; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { ii = i; jj = j; } DrawBar(g, ds, cs, m, pts[ii, jj], xlength, ylength, zorigin, zmax, zmin, ax, va, cl); } } }
public void AddColorBar(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { if (cs.IsColorBar && IsColorMap) { Pen aPen = new Pen(Color.Black, 1); SolidBrush aBrush = new SolidBrush(cl.TickFontColor); StringFormat sFormat = new StringFormat(); sFormat.Alignment = StringAlignment.Near; SizeF size = g.MeasureString("A", cl.TickFont); int x, y, width, height; Point3[] pts = new Point3[64]; PointF[] pta = new PointF[4]; float zmin, zmax; if (ChartType == ChartTypeEnum.Slice) { zmin = ds.VDataMin(); zmax = ds.VDataMax(); } else { zmin = ds.ZDataMin(); zmax = ds.ZDataMax(); } float dz = (zmax - zmin) / 63; if (ChartType == ChartTypeEnum.Contour || ChartType == ChartTypeEnum.FillContour || ChartType == ChartTypeEnum.XYColor) { x = 5 * cs2d.ChartArea.Width / 6; y = cs2d.PlotArea.Y; width = cs2d.ChartArea.Width / 25; height = cs2d.PlotArea.Height; // Add color bar: for (int i = 0; i < 64; i++) { pts[i] = new Point3(x, y, zmin + i * dz, 1); } for (int i = 0; i < 63; i++) { Color color = AddColor(cs, pts[i], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); float y1 = y + height - (pts[i].Z - zmin) * height / (zmax - zmin); float y2 = y + height - (pts[i + 1].Z - zmin) * height / (zmax - zmin); pta[0] = new PointF(x, y2); pta[1] = new PointF(x + width, y2); pta[2] = new PointF(x + width, y1); pta[3] = new PointF(x, y1); g.FillPolygon(aBrush, pta); } g.DrawRectangle(aPen, x, y, width, height); // Add ticks and labels to the color bar: float ticklength = 0.1f * width; for (float z = zmin; z <= zmax; z = z + (zmax - zmin) / 6) { float yy = y + height - (z - zmin) * height / (zmax - zmin); g.DrawLine(aPen, x, yy, x + ticklength, yy); g.DrawLine(aPen, x + width, yy, x + width - ticklength, yy); g.DrawString((Math.Round(z, 2)).ToString(), cl.TickFont, Brushes.Black, new PointF(x + width + 5, yy - size.Height / 2), sFormat); } } else { x = 5 * cs2d.ChartArea.Width / 6; y = cs2d.ChartArea.Height / 10; width = cs2d.ChartArea.Width / 25; height = 8 * cs2d.ChartArea.Height / 10; // Add color bar: for (int i = 0; i < 64; i++) { pts[i] = new Point3(x, y, zmin + i * dz, 1); } for (int i = 0; i < 63; i++) { Color color = AddColor(cs, pts[i], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); float y1 = y + height - (pts[i].Z - zmin) * height / (zmax - zmin); float y2 = y + height - (pts[i + 1].Z - zmin) * height / (zmax - zmin); pta[0] = new PointF(x, y2); pta[1] = new PointF(x + width, y2); pta[2] = new PointF(x + width, y1); pta[3] = new PointF(x, y1); g.FillPolygon(aBrush, pta); } g.DrawRectangle(aPen, x, y, width, height); // Add ticks and labels to the color bar: float ticklength = 0.1f * width; for (float z = zmin; z <= zmax; z = z + (zmax - zmin) / 6) { float yy = y + height - (z - zmin) * height / (zmax - zmin); g.DrawLine(aPen, x, yy, x + ticklength, yy); g.DrawLine(aPen, x + width, yy, x + width - ticklength, yy); g.DrawString((Math.Round(z, 2)).ToString(), cl.TickFont, Brushes.Black, new PointF(x + width + 5, yy - size.Height / 2), sFormat); } } } }
public void AddChart(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { switch (ChartType) { case ChartTypeEnum.Line: AddLine(g, ds, cs, ax, va, cl); break; case ChartTypeEnum.Mesh: AddMesh(g, ds, cs, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.MeshZ: AddMeshZ(g, ds, cs, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Waterfall: AddWaterfall(g, ds, cs, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Surface: AddSurface(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.XYColor: AddXYColor(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Contour: AddContour(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.FillContour: AddXYColor(g, ds, cs, cs2d, ax, va, cl); AddContour(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.MeshContour: AddContour3D(g, ds, cs, cs2d, ax, va, cl); AddMesh(g, ds, cs, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.SurfaceContour: AddContour3D(g, ds, cs, cs2d, ax, va, cl); AddSurface(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.SurfaceFillContour: AddXYColor3D(g, ds, cs, cs2d, ax, va, cl); AddContour3D(g, ds, cs, cs2d, ax, va, cl); AddSurface(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Slice: AddSlice(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; case ChartTypeEnum.Bar3D: AddBar3D(g, ds, cs, cs2d, ax, va, cl); AddColorBar(g, ds, cs, cs2d, ax, va, cl); break; } }
private void Interp(Graphics g, ChartStyle cs, ChartStyle2D cs2d, Matrix3 m, Point3[] pta, float zmin, float zmax, int flag, Axes ax, ViewAngle va, ChartLabels cl) { SolidBrush aBrush = new SolidBrush(Color.Black); PointF[] points = new PointF[4]; int npoints = NumberInterp; Point3[,] pts = new Point3[npoints + 1, npoints + 1]; Point3[,] pts1 = new Point3[npoints + 1, npoints + 1]; float x0 = pta[0].X; float y0 = pta[0].Y; float x1 = pta[2].X; float y1 = pta[2].Y; float dx = (x1 - x0) / npoints; float dy = (y1 - y0) / npoints; float C00 = pta[0].Z; float C10 = pta[3].Z; float C11 = pta[2].Z; float C01 = pta[1].Z; float x, y, C; Color color; if (flag == 1) // For Surface chart { for (int i = 0; i <= npoints; i++) { x = x0 + i * dx; for (int j = 0; j <= npoints; j++) { y = y0 + j * dy; C = (y1 - y) * ((x1 - x) * C00 + (x - x0) * C10) / (x1 - x0) / (y1 - y0) + (y - y0) * ((x1 - x) * C01 + (x - x0) * C11) / (x1 - x0) / (y1 - y0); pts[i, j] = new Point3(x, y, C, 1); pts[i, j].Transform(m, chart3d, ax, cs, cl); } } for (int i = 0; i < npoints; i++) { for (int j = 0; j < npoints; j++) { color = AddColor(cs, pts[i, j], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); points[0] = new PointF(pts[i, j].X, pts[i, j].Y); points[1] = new PointF(pts[i + 1, j].X, pts[i + 1, j].Y); points[2] = new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y); points[3] = new PointF(pts[i, j + 1].X, pts[i, j + 1].Y); g.FillPolygon(aBrush, points); aBrush.Dispose(); } } } else if (flag == 2) // For XYColor chart { for (int i = 0; i <= npoints; i++) { x = x0 + i * dx; for (int j = 0; j <= npoints; j++) { y = y0 + j * dy; C = (y1 - y) * ((x1 - x) * C00 + (x - x0) * C10) / (x1 - x0) / (y1 - y0) + (y - y0) * ((x1 - x) * C01 + (x - x0) * C11) / (x1 - x0) / (y1 - y0); pts[i, j] = new Point3(x, y, C, 1); } } for (int i = 0; i < npoints; i++) { for (int j = 0; j < npoints; j++) { color = AddColor(cs, pts[i, j], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); points[0] = cs2d.Point2D(new PointF(pts[i, j].X, pts[i, j].Y), ax); points[1] = cs2d.Point2D(new PointF(pts[i + 1, j].X, pts[i + 1, j].Y), ax); points[2] = cs2d.Point2D(new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y), ax); points[3] = cs2d.Point2D(new PointF(pts[i, j + 1].X, pts[i, j + 1].Y), ax); g.FillPolygon(aBrush, points); aBrush.Dispose(); } } } else if (flag == 3) // For XYColor3D chart { for (int i = 0; i <= npoints; i++) { x = x0 + i * dx; for (int j = 0; j <= npoints; j++) { y = y0 + j * dy; C = (y1 - y) * ((x1 - x) * C00 + (x - x0) * C10) / (x1 - x0) / (y1 - y0) + (y - y0) * ((x1 - x) * C01 + (x - x0) * C11) / (x1 - x0) / (y1 - y0); pts1[i, j] = new Point3(x, y, C, 1); pts[i, j] = new Point3(x, y, ax.ZMin, 1); pts[i, j].Transform(m, chart3d, ax, cs, cl); } } for (int i = 0; i < npoints; i++) { for (int j = 0; j < npoints; j++) { color = AddColor(cs, pts1[i, j], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); points[0] = new PointF(pts[i, j].X, pts[i, j].Y); points[1] = new PointF(pts[i + 1, j].X, pts[i + 1, j].Y); points[2] = new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y); points[3] = new PointF(pts[i, j + 1].X, pts[i, j + 1].Y); g.FillPolygon(aBrush, points); aBrush.Dispose(); } } } }
private void DrawBar(Graphics g, DataSeries ds, ChartStyle cs, Matrix3 m, Point3 pt, float xlength, float ylength, float zorign, float zmax, float zmin, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; Color color = AddColor(cs, pt, zmin, zmax, ax, va, cl); SolidBrush aBrush = new SolidBrush(color); Point3[] pts = new Point3[8]; Point3[] pts1 = new Point3[8]; Point3[] pt3 = new Point3[4]; PointF[] pta = new PointF[4]; pts[0] = new Point3(pt.X - xlength, pt.Y - ylength, zorign, 1); pts[1] = new Point3(pt.X - xlength, pt.Y + ylength, zorign, 1); pts[2] = new Point3(pt.X + xlength, pt.Y + ylength, zorign, 1); pts[3] = new Point3(pt.X + xlength, pt.Y - ylength, zorign, 1); pts[4] = new Point3(pt.X + xlength, pt.Y - ylength, pt.Z, 1); pts[5] = new Point3(pt.X + xlength, pt.Y + ylength, pt.Z, 1); pts[6] = new Point3(pt.X - xlength, pt.Y + ylength, pt.Z, 1); pts[7] = new Point3(pt.X - xlength, pt.Y - ylength, pt.Z, 1); for (int i = 0; i < pts.Length; i++) { pts1[i] = new Point3(pts[i].X, pts[i].Y, pts[i].Z, 1); pts[i].Transform(m, chart3d, ax, cs, cl); } int[] nconfigs = new int[8]; if (ds.BarStyle.IsBarSingleColor) { pta[0] = new PointF(pts[4].X, pts[4].Y); pta[1] = new PointF(pts[5].X, pts[5].Y); pta[2] = new PointF(pts[6].X, pts[6].Y); pta[3] = new PointF(pts[7].X, pts[7].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); pta[0] = new PointF(pts[0].X, pts[0].Y); pta[1] = new PointF(pts[1].X, pts[1].Y); pta[2] = new PointF(pts[2].X, pts[2].Y); pta[3] = new PointF(pts[3].X, pts[3].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); if (va.Azimuth >= -180 && va.Azimuth < -90) { nconfigs = new int[8] { 1, 2, 5, 6, 1, 0, 7, 6 }; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { nconfigs = new int[8] { 1, 0, 7, 6, 0, 3, 4, 7 }; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { nconfigs = new int[8] { 0, 3, 4, 7, 2, 3, 4, 5 }; } else if (va.Azimuth >= 90 && va.Azimuth < 180) { nconfigs = new int[8] { 2, 3, 4, 5, 1, 2, 5, 6 }; } pta[0] = new PointF(pts[nconfigs[0]].X, pts[nconfigs[0]].Y); pta[1] = new PointF(pts[nconfigs[1]].X, pts[nconfigs[1]].Y); pta[2] = new PointF(pts[nconfigs[2]].X, pts[nconfigs[2]].Y); pta[3] = new PointF(pts[nconfigs[3]].X, pts[nconfigs[3]].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); pta[0] = new PointF(pts[nconfigs[4]].X, pts[nconfigs[4]].Y); pta[1] = new PointF(pts[nconfigs[5]].X, pts[nconfigs[5]].Y); pta[2] = new PointF(pts[nconfigs[6]].X, pts[nconfigs[6]].Y); pta[3] = new PointF(pts[nconfigs[7]].X, pts[nconfigs[7]].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); } else if (!ds.BarStyle.IsBarSingleColor && IsColorMap) { pta[0] = new PointF(pts[4].X, pts[4].Y); pta[1] = new PointF(pts[5].X, pts[5].Y); pta[2] = new PointF(pts[6].X, pts[6].Y); pta[3] = new PointF(pts[7].X, pts[7].Y); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); pta[0] = new PointF(pts[0].X, pts[0].Y); pta[1] = new PointF(pts[1].X, pts[1].Y); pta[2] = new PointF(pts[2].X, pts[2].Y); pta[3] = new PointF(pts[3].X, pts[3].Y); color = AddColor(cs, pts[0], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); g.DrawPolygon(aPen, pta); float dz = (zmax - zmin) / 63; if (pt.Z < zorign) dz = -dz; int nz = (int)((pt.Z - zorign) / dz) + 1; if (nz < 1) nz = 1; float z = zorign; if (va.Azimuth >= -180 && va.Azimuth < -90) { nconfigs = new int[4] { 1, 2, 1, 0 }; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { nconfigs = new int[4] { 1, 0, 0, 3 }; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { nconfigs = new int[4] { 0, 3, 2, 3 }; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { nconfigs = new int[4] { 2, 3, 1, 2 }; } for (int i = 0; i < nz; i++) { z = zorign + i * dz; pt3[0] = new Point3(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, z, 1); pt3[1] = new Point3(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, z, 1); pt3[2] = new Point3(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, z + dz, 1); pt3[3] = new Point3(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, z + dz, 1); for (int j = 0; j < pt3.Length; j++) { pt3[j].Transform(m, chart3d, ax, cs, cl); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); color = AddColor(cs, pt3[0], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); } pt3[0] = new Point3(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, zorign, 1); pt3[1] = new Point3(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, zorign, 1); pt3[2] = new Point3(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, pt.Z, 1); pt3[3] = new Point3(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, pt.Z, 1); for (int j = 0; j < pt3.Length; j++) { pt3[j].Transform(m, chart3d, ax, cs, cl); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.DrawPolygon(aPen, pta); for (int i = 0; i < nz; i++) { z = zorign + i * dz; pt3[0] = new Point3(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, z, 1); pt3[1] = new Point3(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, z, 1); pt3[2] = new Point3(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, z + dz, 1); pt3[3] = new Point3(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, z + dz, 1); for (int j = 0; j < pt3.Length; j++) { pt3[j].Transform(m, chart3d, ax, cs, cl); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); color = AddColor(cs, pt3[0], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); } pt3[0] = new Point3(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, zorign, 1); pt3[1] = new Point3(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, zorign, 1); pt3[2] = new Point3(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, pt.Z, 1); pt3[3] = new Point3(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, pt.Z, 1); for (int j = 0; j < pt3.Length; j++) { pt3[j].Transform(m, chart3d, ax, cs, cl); } pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.DrawPolygon(aPen, pta); } aPen.Dispose(); aBrush.Dispose(); }
private void AddXYColor3D(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; Point3[,] pts1 = new Point3[pts.GetLength(0), pts.GetLength(1)]; Point3[,] pts2 = new Point3[pts.GetLength(0), pts.GetLength(1)]; Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Perform transformation on points: for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { // Make a deep copy the points array: pts1[i, j] = new Point3(pts[i, j].X, pts[i, j].Y, ax.ZMin, 1); pts2[i, j] = new Point3(pts[i, j].X, pts[i, j].Y, ax.ZMin, 1); pts1[i, j].Transform(m, chart3d, ax, cs, cl); } } // Draw surface on the XY plane: if (!IsInterp) { for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { pta[0] = new PointF(pts1[i, j].X, pts1[i, j].Y); pta[1] = new PointF(pts1[i, j + 1].X, pts1[i, j + 1].Y); pta[2] = new PointF(pts1[i + 1, j + 1].X, pts1[i + 1, j + 1].Y); pta[3] = new PointF(pts1[i + 1, j].X, pts1[i + 1, j].Y); Color color = AddColor(cs, pts[i, j], zmin, zmax, ax, va, cl); aBrush = new SolidBrush(color); g.FillPolygon(aBrush, pta); if (ds.LineStyle.IsVisible) { //g.DrawPolygon(aPen, pta); } } } } // Draw refined surface: else if (IsInterp) { for (int i = 0; i < pts1.GetLength(0) - 1; i++) { for (int j = 0; j < pts1.GetLength(1) - 1; j++) { Point3[] points = new Point3[4]; points[0] = pts[i, j]; points[1] = pts[i, j + 1]; points[2] = pts[i + 1, j + 1]; points[3] = pts[i + 1, j]; Interp(g, cs, cs2d, m, points, zmin, zmax, 3, ax, va, cl); } } } }
public void AddChartStyle(Graphics g, Axes ax, ViewAngle va, Grid gd, ChartLabels cl) { AddTicks(g, ax, va, cl); AddGrids(g, ax, va, gd, cl); AddAxes(g, ax, va, cl); AddLabels(g, ax, va, cl); }
private void AddAxes(Graphics g, Axes ax, ViewAngle va, ChartLabels cl) { Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); Point3[] pts = CoordinatesOfChartBox(ax, va); Pen aPen = new Pen(ax.AxisStyle.LineColor, ax.AxisStyle.Thickness); aPen.DashStyle = ax.AxisStyle.Pattern; for (int i = 0; i < pts.Length; i++) { pts[i].Transform(m, chart3d, ax, this, cl); } g.DrawLine(aPen, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y); g.DrawLine(aPen, pts[1].X, pts[1].Y, pts[2].X, pts[2].Y); g.DrawLine(aPen, pts[2].X, pts[2].Y, pts[3].X, pts[3].Y); aPen.Dispose(); }
private void AddContour3D(Graphics g, DataSeries ds, ChartStyle cs, ChartStyle2D cs2d, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; Point3[] pta = new Point3[2]; Point3[,] pts = ds.PointArray; Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); float[] zlevels = new float[numberContours]; for (int i = 0; i < numberContours; i++) { zlevels[i] = zmin + i * (zmax - zmin) / (numberContours - 1); } int i0, i1, i2, j0, j1, j2; float zratio = 1; // Draw contour on the XY plane: for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { for (int k = 0; k < numberContours; k++) { if (IsColorMap && ChartType != ChartTypeEnum.FillContour && ChartType != ChartTypeEnum.SurfaceFillContour) { Color color = AddColor(cs, pts[i, j], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } // Left triangle: i0 = i; j0 = j; i1 = i; j1 = j + 1; i2 = i + 1; j2 = j + 1; if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i1, j1].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i1, j1].Z) && (zlevels[k] >= pts[i1, j1].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i1, j1].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i1, j1].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X, (1 - zratio) * pts[i0, j0].Y + zratio * pts[i1, j1].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i1, j1].Z) / (pts[i2, j2].Z - pts[i1, j1].Z); pta[1] = new Point3((1 - zratio) * pts[i1, j1].X + zratio * pts[i2, j2].X, pts[i1, j1].Y, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } else if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i2, j2].Z) && (zlevels[k] >= pts[i1, j1].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i1, j1].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i2, j2].Z - pts[i0, j0].Z); pta[0] = new Point3((1 - zratio) * pts[i0, j0].X + zratio * pts[i2, j2].X, (1 - zratio) * pts[i0, j0].Y + zratio * pts[i2, j2].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i1, j1].Z) / (pts[i2, j2].Z - pts[i1, j1].Z); pta[1] = new Point3((1 - zratio) * pts[i1, j1].X + zratio * pts[i2, j2].X, pts[i1, j1].Y, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } else if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i1, j1].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i1, j1].Z) && (zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i1, j1].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X, (1 - zratio) * pts[i0, j0].Y + zratio * pts[i1, j1].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i2, j2].Z - pts[i0, j0].Z); pta[1] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i2, j2].X * zratio, pts[i0, j0].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } // right triangle: i0 = i; j0 = j; i1 = i + 1; j1 = j; i2 = i + 1; j2 = j + 1; if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i1, j1].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i1, j1].Z) && (zlevels[k] >= pts[i1, j1].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i1, j1].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i1, j1].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i1, j1].X * zratio, pts[i0, j0].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i1, j1].Z) / (pts[i2, j2].Z - pts[i1, j1].Z); pta[1] = new Point3(pts[i1, j1].X, pts[i1, j1].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } else if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i2, j2].Z) && (zlevels[k] >= pts[i1, j1].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i1, j1].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i2, j2].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i2, j2].X * zratio, pts[i0, j0].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); zratio = (zlevels[k] - pts[i1, j1].Z) / (pts[i2, j2].Z - pts[i1, j1].Z); pta[1] = new Point3(pts[i1, j1].X, pts[i1, j1].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } else if ((zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i1, j1].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i1, j1].Z) && (zlevels[k] >= pts[i0, j0].Z && zlevels[k] < pts[i2, j2].Z || zlevels[k] < pts[i0, j0].Z && zlevels[k] >= pts[i2, j2].Z)) { zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i1, j1].Z - pts[i0, j0].Z); pta[0] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i1, j1].X * zratio, pts[i0, j0].Y, ax.ZMin, 1); zratio = (zlevels[k] - pts[i0, j0].Z) / (pts[i2, j2].Z - pts[i0, j0].Z); pta[1] = new Point3(pts[i0, j0].X * (1 - zratio) + pts[i2, j2].X * zratio, pts[i0, j0].Y * (1 - zratio) + pts[i2, j2].Y * zratio, ax.ZMin, 1); pta[0].Transform(m, chart3d, ax, cs, cl); pta[1].Transform(m, chart3d, ax, cs, cl); g.DrawLine(aPen, pta[0].X, pta[0].Y, pta[1].X, pta[1].Y); } } } } aPen.Dispose(); }
private void AddLabels(Graphics g, Axes ax, ViewAngle va, ChartLabels cl) { Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); Point3 pt = new Point3(); Point3[] pts = CoordinatesOfChartBox(ax, va); SolidBrush aBrush = new SolidBrush(cl.LabelFontColor); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; // Add x tick labels: float offset = (ax.YMax - ax.YMin) / 20; float labelSpace = offset; for (float x = ax.XMin + ax.XTick; x < ax.XMax; x = x + ax.XTick) { if (va.Elevation >= 0) { if (va.Azimuth >= -90 && va.Azimuth < 90) labelSpace = -offset; } else if (va.Elevation < 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || va.Azimuth >= 90 && va.Azimuth <= 180) labelSpace = -offset; } pt = new Point3(x, pts[1].Y + labelSpace, pts[1].Z, pts[1].W); pt.Transform(m, chart3d, ax, this, cl); g.DrawString(x.ToString(), cl.TickFont, aBrush, new PointF(pt.X, pt.Y), sf); } // Add y tick labels: offset = (ax.XMax - ax.XMin) / 20; labelSpace = offset; for (float y = ax.YMin + ax.YTick; y < ax.YMax; y = y + ax.YTick) { pts = CoordinatesOfChartBox(ax, va); if (va.Elevation >= 0) { if (va.Azimuth >= -180 && va.Azimuth < 0) labelSpace = -offset; } else if (va.Elevation < 0) { if (va.Azimuth >= 0 && va.Azimuth < 180) labelSpace = -offset; } pt = new Point3(pts[1].X + labelSpace, y, pts[1].Z, pts[1].W); pt.Transform(m, chart3d, ax, this, cl); g.DrawString(y.ToString(), cl.TickFont, aBrush, new PointF(pt.X, pt.Y), sf); } // Add z tick labels: float xoffset = (ax.XMax - ax.XMin) / 30.0f; float yoffset = (ax.YMax - ax.YMin) / 15.0f; float xlabelSpace = xoffset; float ylabelSpace = yoffset; SizeF s = g.MeasureString("A", cl.TickFont); for (float z = ax.ZMin; z <= ax.ZMax; z = z + ax.ZTick) { sf.Alignment = StringAlignment.Far; pts = CoordinatesOfChartBox(ax, va); if (va.Elevation >= 0) { if (va.Azimuth >= -180 && va.Azimuth < -90) { xlabelSpace = 0; ylabelSpace = yoffset; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { xlabelSpace = xoffset; ylabelSpace = 0; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { xlabelSpace = 0; ylabelSpace = -yoffset; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { xlabelSpace = -xoffset; ylabelSpace = 0; } } else if (va.Elevation < 0) { if (va.Azimuth >= -180 && va.Azimuth < -90) { ylabelSpace = 0; xlabelSpace = xoffset; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { ylabelSpace = -yoffset; xlabelSpace = 0; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { ylabelSpace = 0; xlabelSpace = -xoffset; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { ylabelSpace = yoffset; xlabelSpace = 0; } } pt = new Point3(pts[2].X + ylabelSpace, pts[2].Y + xlabelSpace, z, pts[2].W); pt.Transform(m, chart3d, ax, this, cl); g.DrawString(z.ToString(), cl.TickFont, aBrush, new PointF(pt.X - labelSpace, pt.Y - s.Height / 2), sf); } // Add Title: sf.Alignment = StringAlignment.Center; aBrush = new SolidBrush(cl.TitleColor); if (cl.Title != "No Title") { g.DrawString(cl.Title, cl.TitleFont, aBrush, new PointF(chart3d.Width / 2, chart3d.Height / 30), sf); } aBrush.Dispose(); // Add x axis label: offset = (ax.YMax - ax.YMin) / 3; labelSpace = offset; sf.Alignment = StringAlignment.Center; aBrush = new SolidBrush(cl.LabelFontColor); float offset1 = (ax.XMax - ax.XMin) / 10; float xc = offset1; if (va.Elevation >= 0) { if (va.Azimuth >= -90 && va.Azimuth < 90) labelSpace = -offset; if (va.Azimuth >= 0 && va.Azimuth <= 180) xc = -offset1; } else if (va.Elevation < 0) { if ((va.Azimuth >= -180 && va.Azimuth < -90) || va.Azimuth >= 90 && va.Azimuth <= 180) labelSpace = -offset; if (va.Azimuth >= -180 && va.Azimuth <= 0) xc = -offset1; } Point3[] pta = new Point3[2]; pta[0] = new Point3(ax.XMin, pts[1].Y + labelSpace, pts[1].Z, pts[1].W); pta[1] = new Point3((ax.XMin + ax.XMax) / 2 - xc, pts[1].Y + labelSpace, pts[1].Z, pts[1].W); pta[0].Transform(m, chart3d, ax, this, cl); pta[1].Transform(m, chart3d, ax, this, cl); float theta = (float)Math.Atan((pta[1].Y - pta[0].Y) / (pta[1].X - pta[0].X)); theta = theta * 180 / (float)Math.PI; GraphicsState gs = g.Save(); g.TranslateTransform(pta[1].X, pta[1].Y); g.RotateTransform(theta); g.DrawString(cl.XLabel, cl.LabelFont, aBrush, new PointF(0, 0), sf); g.Restore(gs); // Add y axis label: offset = (ax.XMax - ax.XMin) / 3; offset1 = (ax.YMax - ax.YMin) / 5; labelSpace = offset; float yc = ax.YTick; if (va.Elevation >= 0) { if (va.Azimuth >= -180 && va.Azimuth < 0) labelSpace = -offset; if (va.Azimuth >= -90 && va.Azimuth <= 90) yc = -offset1; } else if (va.Elevation < 0) { yc = -offset1; if (va.Azimuth >= 0 && va.Azimuth < 180) labelSpace = -offset; if (va.Azimuth >= -90 && va.Azimuth <= 90) yc = offset1; } pta[0] = new Point3(pts[1].X + labelSpace, ax.YMin, pts[1].Z, pts[1].W); pta[1] = new Point3(pts[1].X + labelSpace, (ax.YMin + ax.YMax) / 2 + yc, pts[1].Z, pts[1].W); pta[0].Transform(m, chart3d, ax, this, cl); pta[1].Transform(m, chart3d, ax, this, cl); theta = (float)Math.Atan((pta[1].Y - pta[0].Y) / (pta[1].X - pta[0].X)); theta = theta * 180 / (float)Math.PI; gs = g.Save(); g.TranslateTransform(pta[1].X, pta[1].Y); g.RotateTransform(theta); g.DrawString(cl.YLabel, cl.LabelFont, aBrush, new PointF(0, 0), sf); g.Restore(gs); // Add z axis labels: float zticklength = 10; labelSpace = -1.3f * offset; offset1 = (ax.ZMax - ax.ZMin) / 8; float zc = -offset1; for (float z = ax.ZMin; z < ax.ZMax; z = z + ax.ZTick) { SizeF size = g.MeasureString(z.ToString(), cl.TickFont); if (zticklength < size.Width) zticklength = size.Width; } float zlength = -zticklength; if (va.Elevation >= 0) { if (va.Azimuth >= -180 && va.Azimuth < -90) { zlength = -zticklength; labelSpace = -1.3f * offset; zc = -offset1; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { zlength = zticklength; labelSpace = 2 * offset / 3; zc = offset1; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { zlength = zticklength; labelSpace = 2 * offset / 3; zc = -offset1; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { zlength = -zticklength; labelSpace = -1.3f * offset; zc = offset1; } } else if (va.Elevation < 0) { if (va.Azimuth >= -180 && va.Azimuth < -90) { zlength = -zticklength; labelSpace = -1.3f * offset; zc = offset1; } else if (va.Azimuth >= -90 && va.Azimuth < 0) { zlength = zticklength; labelSpace = 2 * offset / 3; zc = -offset1; } else if (va.Azimuth >= 0 && va.Azimuth < 90) { zlength = zticklength; labelSpace = 2 * offset / 3; zc = offset1; } else if (va.Azimuth >= 90 && va.Azimuth <= 180) { zlength = -zticklength; labelSpace = -1.3f * offset; zc = -offset1; } } pta[0] = new Point3(pts[2].X - labelSpace, pts[2].Y, (ax.ZMin + ax.ZMax) / 2 + zc, pts[2].W); pta[0].Transform(m, chart3d, ax, this, cl); gs = g.Save(); g.TranslateTransform(pta[0].X - zlength, pta[0].Y); g.RotateTransform(270); g.DrawString(cl.ZLabel, cl.LabelFont, aBrush, new PointF(0, 0), sf); g.Restore(gs); }
private void AddLine(Graphics g, DataSeries ds, ChartStyle cs, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); Point3[] pts = new Point3[ds.PointList.Count]; // Find zmin and zmax values, then perform transformation on points: float zmin = 0; float zmax = 0; for (int i = 0; i < pts.Length; i++) { pts[i] = (Point3)ds.PointList[i]; zmin = Math.Min(zmin, pts[i].Z); zmax = Math.Max(zmax, pts[i].Z); pts[i].Transform(m, chart3d, ax, cs, cl); } // Draw line: if (ds.LineStyle.IsVisible == true) { for (int i = 1; i < pts.Length; i++) { if (IsColorMap) { Color color = AddColor(cs, pts[i], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawLine(aPen, pts[i - 1].X, pts[i - 1].Y, pts[i].X, pts[i].Y); } } aPen.Dispose(); }
private void AddLabels(Graphics g, ChartStyle cs3d, ChartLabels cl, Axes ax) { float xOffset = ChartArea.Width / 30.0f; float yOffset = ChartArea.Height / 30.0f; SizeF labelFontSize = g.MeasureString("A", cl.LabelFont); SizeF titleFontSize = g.MeasureString("A", cl.TitleFont); SizeF tickFontSize = g.MeasureString("A", cl.TickFont); SolidBrush aBrush = new SolidBrush(cl.TickFontColor); StringFormat sFormat = new StringFormat(); // Create the x-axis tick marks: aBrush = new SolidBrush(cl.TickFontColor); for (float fX = ax.XMin; fX <= ax.XMax; fX += ax.XTick) { PointF yAxisPoint = Point2D(new PointF(fX, ax.YMin), ax); sFormat.Alignment = StringAlignment.Far; SizeF sizeXTick = g.MeasureString(fX.ToString(), cl.TickFont); g.DrawString(fX.ToString(), cl.TickFont, aBrush, new PointF(yAxisPoint.X + sizeXTick.Width / 2, yAxisPoint.Y + 4f), sFormat); } // Create the y-axis tick marks: for (float fY = ax.YMin; fY <= ax.YMax; fY += ax.YTick) { PointF xAxisPoint = Point2D(new PointF(ax.XMin, fY), ax); sFormat.Alignment = StringAlignment.Far; g.DrawString(fY.ToString(), cl.TickFont, aBrush, new PointF(xAxisPoint.X - 3f, xAxisPoint.Y - tickFontSize.Height / 2), sFormat); } // Add horizontal axis label: aBrush = new SolidBrush(cl.LabelFontColor); SizeF stringSize = g.MeasureString(cl.XLabel, cl.LabelFont); g.DrawString(cl.XLabel, cl.LabelFont, aBrush, new Point(PlotArea.X + PlotArea.Width / 2 - (int)stringSize.Width / 2, ChartArea.Bottom - (int)yOffset - (int)labelFontSize.Height)); // Add y-axis label: sFormat.Alignment = StringAlignment.Center; stringSize = g.MeasureString(cl.YLabel, cl.LabelFont); // Save the state of the current Graphics object GraphicsState gState = g.Save(); g.TranslateTransform(xOffset, yOffset + titleFontSize.Height + yOffset / 3 + PlotArea.Height / 2); g.RotateTransform(-90); g.DrawString(cl.YLabel, cl.LabelFont, aBrush, 0, 0, sFormat); // Restore it: g.Restore(gState); // Add title: aBrush = new SolidBrush(cl.TitleColor); stringSize = g.MeasureString(cl.Title, cl.TitleFont); if (cl.Title.ToUpper() != "NO TITLE") { g.DrawString(cl.Title, cl.TitleFont, aBrush, new Point(PlotArea.X + PlotArea.Width / 2 - (int)stringSize.Width / 2, ChartArea.Top + (int)yOffset)); } aBrush.Dispose(); }
private void AddMesh(Graphics g, DataSeries ds, ChartStyle cs, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); // Perform transformations on points: for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { pts[i, j].Transform(m, chart3d, ax, cs, cl); } } // Draw color mesh: for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { int ii = i; if (va.Azimuth >= -180 && va.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } pta[0] = new PointF(pts[ii, j].X, pts[ii, j].Y); pta[1] = new PointF(pts[ii, j + 1].X, pts[ii, j + 1].Y); pta[2] = new PointF(pts[ii + 1, j + 1].X, pts[ii + 1, j + 1].Y); pta[3] = new PointF(pts[ii + 1, j].X, pts[ii + 1, j].Y); if (!IsHiddenLine) { g.FillPolygon(aBrush, pta); } if (IsColorMap) { Color color = AddColor(cs, pts[ii, j], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } aPen.Dispose(); aBrush.Dispose(); }
private void AddMeshZ(Graphics g, DataSeries ds, ChartStyle cs, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); PointF[] pta = new PointF[4]; Point3[,] pts = ds.PointArray; Point3[,] pts1 = new Point3[pts.GetLength(0), pts.GetLength(1)]; Color color; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); for (int i = 0; i < pts.GetLength(0); i++) { for (int j = 0; j < pts.GetLength(1); j++) { // Make a deep copy the points array: pts1[i, j] = new Point3(pts[i, j].X, pts[i, j].Y, pts[i, j].Z, 1); // Perform transformations on points: pts[i, j].Transform(m, chart3d, ax, cs, cl); } } for (int i = 0; i < pts.GetLength(0) - 1; i++) { for (int j = 0; j < pts.GetLength(1) - 1; j++) { int ii = i; if (va.Azimuth >= -180 && va.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; } pta[0] = new PointF(pts[ii, j].X, pts[ii, j].Y); pta[1] = new PointF(pts[ii, j + 1].X, pts[ii, j + 1].Y); pta[2] = new PointF(pts[ii + 1, j + 1].X, pts[ii + 1, j + 1].Y); pta[3] = new PointF(pts[ii + 1, j].X, pts[ii + 1, j].Y); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pts[ii, j], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } Point3[] pt3 = new Point3[4]; for (int i = 0; i < pts1.GetLength(0); i++) { int jj = pts1.GetLength(0) - 1; if (va.Elevation >= 0) { if (va.Azimuth >= -90 && va.Azimuth <= 90) jj = 0; } else if (va.Elevation < 0) { jj = 0; if (va.Azimuth >= -90 && va.Azimuth <= 90) jj = pts1.GetLength(0) - 1; } if (i < pts1.GetLength(0) - 1) { pt3[0] = new Point3(pts1[i, jj].X, pts1[i, jj].Y, pts1[i, jj].Z, 1); pt3[1] = new Point3(pts1[i + 1, jj].X, pts1[i + 1, jj].Y, pts1[i + 1, jj].Z, 1); pt3[2] = new Point3(pts1[i + 1, jj].X, pts1[i + 1, jj].Y, ax.ZMin, 1); pt3[3] = new Point3(pts1[i, jj].X, pts1[i, jj].Y, ax.ZMin, 1); for (int k = 0; k < 4; k++) pt3[k].Transform(m, chart3d, ax, cs, cl); pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pt3[0], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } for (int j = 0; j < pts1.GetLength(1); j++) { int ii = 0; if (va.Elevation >= 0) { if (va.Azimuth >= 0 && va.Azimuth <= 180) ii = pts1.GetLength(1) - 1; } else if (va.Elevation < 0) { if (va.Azimuth >= -180 && va.Azimuth <= 0) ii = pts1.GetLength(1) - 1; } if (j < pts1.GetLength(1) - 1) { pt3[0] = new Point3(pts1[ii, j].X, pts1[ii, j].Y, pts1[ii, j].Z, 1); pt3[1] = new Point3(pts1[ii, j + 1].X, pts1[ii, j + 1].Y, pts1[ii, j + 1].Z, 1); pt3[2] = new Point3(pts1[ii, j + 1].X, pts1[ii, j + 1].Y, ax.ZMin, 1); pt3[3] = new Point3(pts1[ii, j].X, pts1[ii, j].Y, ax.ZMin, 1); for (int k = 0; k < 4; k++) pt3[k].Transform(m, chart3d, ax, cs, cl); pta[0] = new PointF(pt3[0].X, pt3[0].Y); pta[1] = new PointF(pt3[1].X, pt3[1].Y); pta[2] = new PointF(pt3[2].X, pt3[2].Y); pta[3] = new PointF(pt3[3].X, pt3[3].Y); g.FillPolygon(aBrush, pta); if (IsColorMap) { color = AddColor(cs, pt3[0], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawPolygon(aPen, pta); } } aPen.Dispose(); aBrush.Dispose(); }
private void AddWaterfall(Graphics g, DataSeries ds, ChartStyle cs, Axes ax, ViewAngle va, ChartLabels cl) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(Color.White); Matrix3 m = Matrix3.AzimuthElevation(va.Elevation, va.Azimuth); Point3[,] pts = ds.PointArray; Point3[] pt3 = new Point3[pts.GetLength(0) + 2]; PointF[] pta = new PointF[pts.GetLength(0) + 2]; Color color; // Find the minumum and maximum z values: float zmin = ds.ZDataMin(); float zmax = ds.ZDataMax(); for (int j = 0; j < pts.GetLength(1); j++) { int jj = j; if (va.Elevation >= 0) { if (va.Azimuth >= -90 && va.Azimuth < 90) { jj = pts.GetLength(1) - 1 - j; } } else if (va.Elevation < 0) { jj = pts.GetLength(1) - 1 - j; if (va.Azimuth >= -90 && va.Azimuth < 90) { jj = j; } } for (int i = 0; i < pts.GetLength(0); i++) { pt3[i + 1] = pts[i, jj]; if (i == 0) { pt3[0] = new Point3(pt3[i + 1].X, pt3[i + 1].Y, ax.ZMin, 1); } if (i == pts.GetLength(0) - 1) { pt3[pts.GetLength(0) + 1] = new Point3(pt3[i + 1].X, pt3[i + 1].Y, ax.ZMin, 1); } } for (int i = 0; i < pt3.Length; i++) { pt3[i].Transform(m, chart3d, ax, cs, cl); pta[i] = new PointF(pt3[i].X, pt3[i].Y); } g.FillPolygon(aBrush, pta); for (int i = 1; i < pt3.Length; i++) { if (IsColorMap) { color = AddColor(cs, pt3[i], zmin, zmax, ax, va, cl); aPen = new Pen(color, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; } g.DrawLine(aPen, pta[i - 1], pta[i]); } } aPen.Dispose(); aBrush.Dispose(); }