private void AddSurface(Graphics g, DataSeries ds, Draw3DSkin skin3d) { SolidBrush abrush = new SolidBrush(Color.AliceBlue); Pen apen = new Pen(ds.DataLine.LineColor, ds.DataLine.Thickness); apen.DashStyle = ds.DataLine.LineStyle; Matrix3 m = Matrix3.AzimuthElevation(cs.Elevation, cs.Azimuth); Point3[,] pts = ds.CloneDataSet(); int len0 = pts.GetLength(0); int len1 = pts.GetLength(1); Point3[,] pts1 = new Point3[len0, len1]; PointF[] pta = new PointF[4]; for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { pts1[i, j] = new Point3(pts[i, j].X, pts[i, j].Y, pts[i, j].Z, 1); pts[i, j].Transform(m, panel.Size, cs); } } //Draw Surface for (int i = 0; i < len0 - 1; i++) { for (int j = 0; j < len1 - 1; j++) { int ii = i; if (cs.Azimuth >= -180 && cs.Azimuth < 0) { ii = len0 - 2 - i; } Point3[] p3 = new Point3[4]; p3[0] = pts1[ii, j]; p3[1] = pts1[ii, j + 1]; p3[2] = pts1[ii + 1, j + 1]; p3[3] = pts1[ii + 1, j]; Interp(g, skin3d, m, p3, ds.Zmin, ds.Zmax, 1); 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.DrawPolygon(apen, pta); } } if (cs.FullScale) { DrawCurtain(g, m, pts1, ds.Zmin, ds.Zmax); } apen.Dispose(); abrush.Dispose(); }
private void Interp(Graphics g, Draw3DSkin skin3d, Matrix3 m , Point3[] pta, float zmin, float zmax, int flag) { SolidBrush abrush = new SolidBrush(Color.Black); PointF[] pf = new PointF[4]; int nPoint = NumberInterp; Point3[,] pts = new Point3[nPoint + 1, nPoint + 1]; Point3[,] pts1 = new Point3[nPoint + 1, nPoint + 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) / nPoint; float dy = (y1 - y0) / nPoint; float C00 = pta[0].Z; float C01 = pta[1].Z; float C11 = pta[2].Z; float C10 = pta[3].Z; float x, y, C; Color color; if (flag == 1) //Surface chart { for (int i = 0; i <= nPoint; i++) { x = x0 + dx * i; for (int j = 0; j <= nPoint; j++) { y = y0 + dy * j; C = ((y1 - y) * ((x1 - x) * C00 + (x - x0) * C10) + (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, panel.Size, cs); } } for (int i = 0; i < nPoint; i++) { for (int j = 0; j < nPoint; j++) { color = AddColor(pts[i, j], zmin, zmax); abrush = new SolidBrush(color); pf[0] = new PointF(pts[i, j].X, pts[i, j].Y); pf[1] = new PointF(pts[i, j + 1].X, pts[i, j + 1].Y); pf[2] = new PointF(pts[i + 1, j + 1].X, pts[i + 1, j + 1].Y); pf[3] = new PointF(pts[i + 1, j].X, pts[i + 1, j].Y); g.FillPolygon(abrush, pf); } } } abrush.Dispose(); }
private void AddColorBar(Graphics g, DataSeries ds, Draw3DSkin skin3d) { SolidBrush abrush = new SolidBrush(cs.TickColor); using (Pen apen = new Pen(Color.Black, 1)) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; SizeF size = g.MeasureString("A", cs.TickFont); int x, y, w, h; Point3[] pts = new Point3[64]; PointF[] pta = new PointF[4]; float dz = ds.Zdistance / 63; x = 5 * panel.Width / 6 + 25; y = panel.Height / 10; w = panel.Width / 40; h = 3 * panel.Height / 5; //Add Color Bar for (int i = 0; i < 64; i++) { pts[i] = new Point3(x, y, ds.Zmin + i * dz, 1); } for (int i = 0; i < 63; i++) { Color color = AddColor(pts[i], ds.Zmin, ds.Zmax); abrush = new SolidBrush(color); float y1 = y + h - h * (pts[i].Z - ds.Zmin) / ds.Zdistance; float y2 = y + h - h * (pts[i + 1].Z - ds.Zmin) / ds.Zdistance; pta[0] = new PointF(x, y2); pta[1] = new PointF(x + w, y2); pta[2] = new PointF(x + w, y1); pta[3] = new PointF(x, y1); g.FillPolygon(abrush, pta); } g.DrawRectangle(apen, x, y, w, h); //Add ticks and label to color bar float tickLength = 0.1f * w; for (float z = ds.Zmin; z <= ds.Zmax; z += (ds.Zmax - ds.Zmin) / 6) { float yy = y + h - h * (z - ds.Zmin) / ds.Zdistance; g.DrawLine(apen, x, yy, x + tickLength, yy); g.DrawLine(apen, x + w, yy, x + w - tickLength, yy); g.DrawString(Math.Round(z, 2).ToString(), cs.TickFont , abrush, new PointF(x + w + 5, yy - size.Height / 2), sf); } } abrush.Dispose(); }
public void AddPartialChart(Graphics g, DataSeries ds, Draw3DSkin skin3d, int pos1, int pos2) { //Debug.WriteLine("Entering AddChart panel=" + panel.Width.ToString() //+ "," + panel.Height.ToString()); if (ds.XArray != null) { AddPartialSurface(g, ds, skin3d, pos1, pos2); //AddMesh(g, ds, cs); AddColorBar(g, ds, skin3d); } Debug.WriteLine("Exit AddChart panel=" + panel.Width.ToString() + "," + panel.Height.ToString()); }
public Form1() { InitializeComponent(); Screen myScreen = Screen.FromControl(this); Rectangle area = myScreen.WorkingArea; float ratio = area.Width / area.Height; int w, h; Point pos; if (ratio < 1.5) { h = (int)(area.Height * 0.9); w = (int)(h * 1.5); pos = new Point(w / 12, h / 12); } else { w = (int)(area.Width * 0.9); h = (int)(w / 1.5); pos = new Point(w / 12, h / 12); } this.Size = new Size(w, h); this.Location = pos; this.BackColor = Color.AliceBlue; cs3 = new ChartStyle(); drawBase3 = new Draw3DBase(panel3D, cs3); draw3 = new Draw3DChart(panel3D, cs3); draw3.NumberInterp = 5; ColorMap cm = new ColorMap(); draw3.CMap = cm.Jet(); skin3 = new Draw3DSkin(panel3D); skin3.PlotBackColor = this.BackColor; skin3.PlotBorderColor = this.BackColor; //Init trackBar PosMin = 0; PosMax = 50000; DrawTrackBar(); //Data Generation InitCSPara(); ds = new DataSeries(); //ds.Random3D(cs3); ds.DataLine.LineColor = Color.DarkBlue; ds.DataLine.Thickness = 1; panel3D.Paint += new PaintEventHandler(Plot3D); panel3D.BackColor = Color.Cornsilk; //ds.ZdataStat(); lbAvg.Text = ds.Zavg.ToString("0.000"); lbMax.Text = ds.Zmax.ToString("0.000"); lbMin.Text = ds.Zmin.ToString("0.000"); //2D view panel2D.Paint += new PaintEventHandler(Plot2D); panel2D.BackColor = Color.Azure; draw2 = new DrawSection(panel2D, cs3); //two sets of horizontal and vertical rulers dl_array = new DraggableLine[dl_num]; dl_array[0] = new DraggableLine(new Pen(Color.Navy, 2), 0, true); dl_array[1] = new DraggableLine(new Pen(Color.Navy, 2), 0, false); dl_array[2] = new DraggableLine(new Pen(Color.DarkGreen, 2), 15, true); dl_array[3] = new DraggableLine(new Pen(Color.DarkGreen, 2), 15, false); }