public Chart3DControlLib() { InitializeComponent(); this.cs = new ChartStyle2D(); this.ds = new Bar3DStyle(); this.d3c = new Draw3DChart(); this.cs.ChartCanvas = chartCanvas; }
private void DrawPolygon(ChartStyle2D cs, Bar3DStyle bs, Point[] pts, SolidColorBrush fillBrush, SolidColorBrush lineBrush) { Polygon plg = new Polygon(); plg.Stroke = lineBrush; plg.StrokeThickness = bs.LineThickness; plg.Fill = fillBrush; for (int i = 0; i < pts.Length; i++) { plg.Points.Add(pts[i]); } cs.ChartCanvas.Children.Add(plg); }
private void DrawBar(ChartStyle2D cs, Bar3DStyle bs, Matrix3D m, Point3D pt, double xlength, double ylength, double zorign, double zmax, double zmin) { SolidColorBrush lineBrush = (SolidColorBrush)bs.LineColor; SolidColorBrush fillBrush = GetBrush(pt.Z, zmin, zmax); Point3D[] pts = new Point3D[8]; Point3D[] pts1 = new Point3D[8]; Point3D[] pt3 = new Point3D[4]; Point[] pta = new Point[4]; pts[0] = new Point3D(pt.X - xlength, pt.Y - ylength, zorign); pts[1] = new Point3D(pt.X - xlength, pt.Y + ylength, zorign); pts[2] = new Point3D(pt.X + xlength, pt.Y + ylength, zorign); pts[3] = new Point3D(pt.X + xlength, pt.Y - ylength, zorign); pts[4] = new Point3D(pt.X + xlength, pt.Y - ylength, pt.Z); pts[5] = new Point3D(pt.X + xlength, pt.Y + ylength, pt.Z); pts[6] = new Point3D(pt.X - xlength, pt.Y + ylength, pt.Z); pts[7] = new Point3D(pt.X - xlength, pt.Y - ylength, pt.Z); for (int i = 0; i < pts.Length; i++) { pts1[i] = new Point3D(pts[i].X, pts[i].Y, pts[i].Z); pts[i] = cs.Normalize3D(m, pts[i]); } int[] nconfigs = new int[8]; if (IsBarSingleColor) { pta[0] = new Point(pts[4].X, pts[4].Y); pta[1] = new Point(pts[5].X, pts[5].Y); pta[2] = new Point(pts[6].X, pts[6].Y); pta[3] = new Point(pts[7].X, pts[7].Y); DrawPolygon(cs, bs, pta, fillBrush, lineBrush); if (cs.Azimuth >= -180 && cs.Azimuth < -90) { nconfigs = new int[8] { 1, 2, 5, 6, 1, 0, 7, 6 }; } else if (cs.Azimuth >= -90 && cs.Azimuth < 0) { nconfigs = new int[8] { 1, 0, 7, 6, 0, 3, 4, 7 }; } else if (cs.Azimuth >= 0 && cs.Azimuth < 90) { nconfigs = new int[8] { 0, 3, 4, 7, 2, 3, 4, 5 }; } else if (cs.Azimuth >= 90 && cs.Azimuth < 180) { nconfigs = new int[8] { 2, 3, 4, 5, 1, 2, 5, 6 }; } pta[0] = new Point(pts[nconfigs[0]].X, pts[nconfigs[0]].Y); pta[1] = new Point(pts[nconfigs[1]].X, pts[nconfigs[1]].Y); pta[2] = new Point(pts[nconfigs[2]].X, pts[nconfigs[2]].Y); pta[3] = new Point(pts[nconfigs[3]].X, pts[nconfigs[3]].Y); DrawPolygon(cs, bs, pta, fillBrush, lineBrush); pta[0] = new Point(pts[nconfigs[4]].X, pts[nconfigs[4]].Y); pta[1] = new Point(pts[nconfigs[5]].X, pts[nconfigs[5]].Y); pta[2] = new Point(pts[nconfigs[6]].X, pts[nconfigs[6]].Y); pta[3] = new Point(pts[nconfigs[7]].X, pts[nconfigs[7]].Y); DrawPolygon(cs, bs, pta, fillBrush, lineBrush); } else if (!IsBarSingleColor && IsColormap) { pta[0] = new Point(pts[4].X, pts[4].Y); pta[1] = new Point(pts[5].X, pts[5].Y); pta[2] = new Point(pts[6].X, pts[6].Y); pta[3] = new Point(pts[7].X, pts[7].Y); DrawPolygon(cs, bs, pta, fillBrush, lineBrush); pta[0] = new Point(pts[0].X, pts[0].Y); pta[1] = new Point(pts[1].X, pts[1].Y); pta[2] = new Point(pts[2].X, pts[2].Y); pta[3] = new Point(pts[3].X, pts[3].Y); fillBrush = GetBrush(pts1[0].Z, zmin, zmax); DrawPolygon(cs, bs, pta, fillBrush, lineBrush); double dz = (zmax - zmin) / 63; if (pt.Z < zorign) { dz = -dz; } int nz = (int)((pt.Z - zorign) / dz) + 1; if (nz < 1) { nz = 1; } double z = zorign; if (cs.Azimuth >= -180 && cs.Azimuth < -90) { nconfigs = new int[4] { 1, 2, 1, 0 }; } else if (cs.Azimuth >= -90 && cs.Azimuth < 0) { nconfigs = new int[4] { 1, 0, 0, 3 }; } else if (cs.Azimuth >= 0 && cs.Azimuth < 90) { nconfigs = new int[4] { 0, 3, 2, 3 }; } else if (cs.Azimuth >= 90 && cs.Azimuth <= 180) { nconfigs = new int[4] { 2, 3, 1, 2 }; } for (int i = 0; i < nz; i++) { z = zorign + i * dz; pt3[0] = new Point3D(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, z); pt3[1] = new Point3D(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, z); pt3[2] = new Point3D(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, z + dz); pt3[3] = new Point3D(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, z + dz); for (int j = 0; j < pt3.Length; j++) { pt3[j] = cs.Normalize3D(m, pt3[j]); } pta[0] = new Point(pt3[0].X, pt3[0].Y); pta[1] = new Point(pt3[1].X, pt3[1].Y); pta[2] = new Point(pt3[2].X, pt3[2].Y); pta[3] = new Point(pt3[3].X, pt3[3].Y); fillBrush = GetBrush(z, zmin, zmax); DrawPolygon(cs, bs, pta, fillBrush, fillBrush); } pt3[0] = new Point3D(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, zorign); pt3[1] = new Point3D(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, zorign); pt3[2] = new Point3D(pts1[nconfigs[1]].X, pts1[nconfigs[1]].Y, pt.Z); pt3[3] = new Point3D(pts1[nconfigs[0]].X, pts1[nconfigs[0]].Y, pt.Z); for (int j = 0; j < pt3.Length; j++) { pt3[j] = cs.Normalize3D(m, pt3[j]); } pta[0] = new Point(pt3[0].X, pt3[0].Y); pta[1] = new Point(pt3[1].X, pt3[1].Y); pta[2] = new Point(pt3[2].X, pt3[2].Y); pta[3] = new Point(pt3[3].X, pt3[3].Y); fillBrush = Brushes.Transparent; DrawPolygon(cs, bs, pta, fillBrush, lineBrush); for (int i = 0; i < nz; i++) { z = zorign + i * dz; pt3[0] = new Point3D(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, z); pt3[1] = new Point3D(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, z); pt3[2] = new Point3D(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, z + dz); pt3[3] = new Point3D(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, z + dz); for (int j = 0; j < pt3.Length; j++) { pt3[j] = cs.Normalize3D(m, pt3[j]); } pta[0] = new Point(pt3[0].X, pt3[0].Y); pta[1] = new Point(pt3[1].X, pt3[1].Y); pta[2] = new Point(pt3[2].X, pt3[2].Y); pta[3] = new Point(pt3[3].X, pt3[3].Y); fillBrush = GetBrush(z, zmin, zmax); DrawPolygon(cs, bs, pta, fillBrush, fillBrush); } pt3[0] = new Point3D(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, zorign); pt3[1] = new Point3D(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, zorign); pt3[2] = new Point3D(pts1[nconfigs[3]].X, pts1[nconfigs[3]].Y, pt.Z); pt3[3] = new Point3D(pts1[nconfigs[2]].X, pts1[nconfigs[2]].Y, pt.Z); for (int j = 0; j < pt3.Length; j++) { pt3[j] = cs.Normalize3D(m, pt3[j]); } pta[0] = new Point(pt3[0].X, pt3[0].Y); pta[1] = new Point(pt3[1].X, pt3[1].Y); pta[2] = new Point(pt3[2].X, pt3[2].Y); pta[3] = new Point(pt3[3].X, pt3[3].Y); fillBrush = Brushes.Transparent; DrawPolygon(cs, bs, pta, fillBrush, lineBrush); } }
private void AddBar3D(ChartStyle2D cs, Bar3DStyle bs) { Matrix3D m = Utility.AzimuthElevation(cs.Elevation, cs.Azimuth); Point[] pta = new Point[4]; Point3D[,] pts = bs.PointArray; // Find the minumum and maximum z values: double zmin = bs.ZDataMin(); double zmax = bs.ZDataMax(); // Check parameters: double xlength = bs.XLength; if (xlength <= 0) { xlength = 0.1 * bs.XSpacing; } else if (xlength > 0.5) { xlength = 0.5 * bs.XSpacing; } else { xlength = bs.XLength * bs.XSpacing; } double ylength = bs.YLength; if (ylength <= 0) { ylength = 0.1 * bs.YSpacing; } else if (ylength > 0.5) { ylength = 0.5 * bs.YSpacing; } else { ylength = bs.YLength * bs.YSpacing; } double zorigin = bs.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 (cs.Azimuth >= -180 && cs.Azimuth < -90) { ii = pts.GetLength(0) - 2 - i; jj = j; } else if (cs.Azimuth >= -90 && cs.Azimuth < 0) { ii = pts.GetLength(0) - 2 - i; jj = pts.GetLength(1) - 2 - j; } else if (cs.Azimuth >= 0 && cs.Azimuth < 90) { ii = i; jj = pts.GetLength(1) - 2 - j; } else if (cs.Azimuth >= 90 && cs.Azimuth <= 180) { ii = i; jj = j; } DrawBar(cs, bs, m, pts[ii, jj], xlength, ylength, zorigin, zmax, zmin); } } if (cs.IsColorBar && IsColormap) { AddColorBar(cs, bs, zmin, zmax); } }