public static double[,] Gauss(Data.Condition condition, int dpi, ref int iterate, double omega = 0, double[,] grid = null, double conv = 0) { if (grid == null) { grid = new double[condition.X_LMax * dpi, condition.Y_LMax *dpi]; } double[,] temp = new double[condition.X_LMax * dpi, condition.Y_LMax *dpi]; int cnt = 0; Parallel.For(0, iterate, (i, loopState) => { double[,] gridOld = grid; double max = 0; for (int x = 1; x + 1 < condition.X_LMax * dpi; x++) { for (int y = 1; y + 1 < condition.Y_LMax * dpi; y++) { if (x >= condition.X_Pos * dpi && y >= condition.Y_Pos * dpi) { if (x <= (condition.X_Pos + condition.X_LRec) * dpi && y <= (condition.Y_Pos + condition.y_LRec) * dpi) { grid[x, y] = 1; temp[x, y] = 1; continue; } } double data = grid[x, y]; if (omega == 0) { grid[x, y] = 0.25 * (temp[x + 1, y] + grid[x - 1, y] + temp[x, y + 1] + grid[x, y - 1]); max = Math.Abs(data - grid[x, y]) > max ? Math.Abs(data - grid[x, y]) : max; continue; } grid[x, y] = temp[x, y] + omega * (0.25 * (temp[x + 1, y] + grid[x - 1, y] + temp[x, y + 1] + grid[x, y - 1]) - temp[x, y]); max = Math.Abs(data - grid[x, y]) > max ? Math.Abs(data - grid[x, y]) : max; } } temp = gridOld; if (conv != 0) { if (conv > max) { loopState.Stop(); } } //cnt++; lock ((object)cnt) { cnt++; } }); iterate = cnt; return(grid); }
private bool Filter() { if (fform == null) { fform = new BaseFilter(); } fform.FilterInfos = this.FilterInfos; fform.DefaultCondition = this.DefaultCondition; DialogResult rst = fform.ShowDialog(this);; if (rst == DialogResult.OK) { this.CurCondition = fform.GetCondition(); this.RefreshData(); return(true); } else { return(false); } }
private void Filter() { try { if (fform == null) { fform = new BaseFilter(); } fform.FilterInfos = this.FilterInfos; fform.DefaultCondition = this.DefaultCondition; DialogResult rst = fform.ShowDialog(this);; if (rst == DialogResult.OK) { this.CurCondition = fform.GetCondition(); this.RefreshData(); } } catch (Exception e) { MessageBox.Show(e.Message); } }
public static Bitmap CreateImage(Data.Condition con, int dpi, double[,] data) { Bitmap image = new Bitmap(con.X_LMax * dpi, con.Y_LMax * dpi); for (int x = 0; x < con.X_LMax * dpi; x++) { for (int y = 0; y < con.Y_LMax * dpi; y++) { var color = Color.FromArgb(GetColor(data[x, y])); if (x >= con.X_Pos * dpi && y >= con.Y_Pos * dpi) { if (x <= (con.X_Pos + con.X_LRec) * dpi && y <= (con.Y_Pos + con.y_LRec) * dpi) { color = Color.White; } } image.SetPixel(x, y, color); } } return(image); }