public static Grain[,] ReadFromTextFile(Image mainImage) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Txt file|*.txt"; if (openFileDialog.ShowDialog() == true) { using (StreamReader sr = new StreamReader(openFileDialog.FileName)) { // Read the stream to a string, and write the string to the console. var tab = sr.ReadLine().Split(); MainWindow.XNumOfCells = int.Parse(tab[0]); MainWindow.YNumOfCells = int.Parse(tab[1]); MainWindow.GrainTable = new Grain[MainWindow.XNumOfCells, MainWindow.YNumOfCells]; MainWindow.TempGrainTable = new Grain[MainWindow.XNumOfCells, MainWindow.YNumOfCells]; String line; while ((line = sr.ReadLine()) != null) { var parsedline = line.Split(); int x = int.Parse(parsedline[0]); int y = int.Parse(parsedline[1]); int state = int.Parse(parsedline[2]); Color color = (Color)ColorConverter.ConvertFromString(parsedline[3]); MainWindow.GrainTable[x, y] = new Grain(x, y, (int)mainImage.Width / MainWindow.XNumOfCells, (int)mainImage.Height / MainWindow.YNumOfCells, color); MainWindow.GrainTable[x, y].State = state; MainWindow.TempGrainTable[x, y] = new Grain(x, y, (int)mainImage.Width / MainWindow.XNumOfCells, (int)mainImage.Height / MainWindow.YNumOfCells, color); if (color == Color.FromRgb(0, 0, 0)) { MainWindow.GrainTable[x, y].Inclusion = true; } } Growth.Replace(MainWindow.TempGrainTable, MainWindow.GrainTable, MainWindow.XNumOfCells, MainWindow.YNumOfCells); } } return(null); }
private void Update(object sender, EventArgs e) { if (!monteCarlo && !SRXMC) { for (int i = 0; i < XNumOfCells; i++) { for (int j = 0; j < YNumOfCells; j++) { if (!Growth.Moore(i, j, XNumOfCells, YNumOfCells)) { if (!Growth.NearestMoore(i, j, XNumOfCells, YNumOfCells)) { if (!Growth.FutherMoore(i, j, XNumOfCells, YNumOfCells)) { Growth.RuleFour(i, j, XNumOfCells, YNumOfCells); } } } } } Growth.Replace(GrainTable, TempGrainTable, XNumOfCells, YNumOfCells); } else if(monteCarlo) { while (grainMCList.Any()) { MonteCarlo.ChangeGrains(); } grainMCList = MonteCarlo.GetNewMCList(); NumberOfMCIterations++; NumberOfIterationsTextBox.Text = (NumberOfIterationFromGUI - NumberOfMCIterations).ToString(); if (NumberOfMCIterations >= NumberOfIterationFromGUI) { monteCarlo = false; StartMCBtn.Content = "START MC"; timer.Stop(); NumberOfMCIterations = 0; } } else { while (RSXMCList.Any()) { MonteCarlo.ChangeRSXGrains(); } RSXMCList = RSXMC.NewRSXMCList(); NumberOfMCIterations++; NumberOfIterationsTextBox.Text = (NumberOfIterationFromGUI - NumberOfMCIterations).ToString(); if (NumberOfMCIterations >= NumberOfIterationFromGUI) { monteCarlo = false; StartMCBtn.Content = "START MC"; timer.Stop(); NumberOfMCIterations = 0; } } PaintPane(); }