private void OpenCA() { if (File.Exists(_savePathCA)) { BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fs = new FileStream(_savePathCA, FileMode.OpenOrCreate)) { CA = (CA_Model)formatter.Deserialize(fs); } } else { CA = new CA_Model(); SaveCA(); } }
private void NextStep() { CA.Next(); if (_isDynamicPaint) { GetUpdating = true; Dispatcher.BeginInvoke((Action)(() => { Paint(); })); } else { Dispatcher.BeginInvoke((Action)(() => { switch (_selectChart) { case Chart.PointChart3D: SetName("Клеточный автомат; Итерация =" + CA.Iterator); break; case Chart.MeshChart: SetName("Осреднение по оси " + CA_Model.GetNameAxis(_selectAxis) + "; Слой = " + _selectIndex + "; Итерация =" + CA.Iterator); break; case Chart.PointChart2D: SetName("Клеточный автомат; Разрез по оси " + CA_Model.GetNameAxis(_selectAxis) + "; Слой = " + _selectIndex + "; Итерация =" + CA.Iterator); break; } })); } while (GetUpdating) { } _manualResetEvent.WaitOne(); }
public MainWindow() { InitializeComponent(); StyleButton.Checked += StyleButtonToggle; StyleButton.Unchecked += StyleButtonToggle; _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(139, 0, 0), 1)); _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 0.8)); _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(255, 255, 0), 0.5)); _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(173, 255, 47), 0.2)); _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 255), 0.09)); _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 255), 0.05)); _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(29, 44, 107), 0.009)); _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(53, 29, 107), 0.001)); _gradientColor.GradientStops.Add(new GradientStop(Color.FromRgb(92, 29, 107), 0)); SciChart3D = new SciChart3DSurface { ChartModifier = new ModifierGroup3D(new MouseWheelZoomModifier3D(), new OrbitModifier3D()) }; SciChart2D = new SciChartSurface() { ChartModifier = new ModifierGroup(new MouseWheelZoomModifier(), new ZoomPanModifier()) }; string pathXML = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Source\AppConfig.xml"); _savePathCA = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Source\AppCA.dat"); if (!File.Exists(pathXML)) { string dataDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Source"); if (!Directory.Exists(dataDirectory)) { Directory.CreateDirectory(dataDirectory); } FileStream fs = new FileStream(pathXML, FileMode.Create); XmlTextWriter xmlOut = new XmlTextWriter(fs, Encoding.Unicode) { Formatting = Formatting.Indented }; xmlOut.WriteStartDocument(); xmlOut.WriteStartElement("root"); xmlOut.WriteEndElement(); xmlOut.WriteEndDocument(); xmlOut.Close(); fs.Close(); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(pathXML); XmlElement xroot = xmlDocument.DocumentElement; XmlElement element = xmlDocument.CreateElement("style"); element.InnerText = "Dark"; xroot.AppendChild(element); element = xmlDocument.CreateElement("saveProperty"); element.InnerText = _saveCA.ToString(); xroot.AppendChild(element); xmlDocument.Save(pathXML); CA = new CA_Model(); SaveCA(); } else { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(pathXML); XmlElement xroot = xmlDocument.DocumentElement; try { _saveCA = bool.Parse(xroot.SelectSingleNode("saveProperty").InnerText); } catch { _saveCA = true; } try { _styleType = !(xroot.SelectSingleNode("style").InnerText == "Light"); } catch { _styleType = true; } if (_saveCA) { OpenCA(); } else { CA = new CA_Model(); } } _selectIndex = CA.Length / 2; SetAxis(); AddCharting(); Paint(); }
private void Paint() { switch (_selectChart) { case (int)Chart.PointChart3D: var grath_3D = new XyzDataSeries3D <int>(); for (int x = 0; x < CA.Length; x++) { for (int y = 0; y < CA.Length; y++) { for (int z = 0; z < CA.Length; z++) { if (CA[x, y, z]) { grath_3D.Append(x, y, z); } } } } var scatterSeries3D = new ScatterRenderableSeries3D { DataSeries = grath_3D, PointMarker = _selectPointMarker }; scatterSeries3D.PointMarker.Fill = Color.FromArgb(_selectAlpha, _selectColor.R, _selectColor.G, _selectColor.B); SciChart3D.RenderableSeries.Clear(); SciChart3D.RenderableSeries.Add(scatterSeries3D); SetName("Клеточный автомат; Итерация =" + CA.Iterator); break; case Chart.MeshChart: var meshGrath_3D = new UniformGridDataSeries3D <double>(CA.Length, CA.Length); double[,] pollution = CA.GetPollution(_selectIndex, _selectAxis); for (int i = 0; i < CA.Length; i++) { for (int j = 0; j < CA.Length; j++) { meshGrath_3D[i, j] = pollution[i, j]; } } var meshRenderableSeries = new SurfaceMeshRenderableSeries3D() { MeshColorPalette = _gradientColor, DrawMeshAs = DrawMeshAs.SolidWithContours, DataSeries = meshGrath_3D }; SciChart3D.RenderableSeries.Clear(); SciChart3D.RenderableSeries.Add(meshRenderableSeries); SetName("Осреднение по плоскости " + CA_Model.GetNameAxis(_selectAxis) + "; Слой = " + _selectIndex + "; Итерация =" + CA.Iterator); break; case Chart.PointChart2D: var dataGraph_2D = new XyDataSeries <int, int>(); for (int i = 0; i < CA.Length; i++) { for (int j = 0; j < CA.Length; j++) { if (CA.GetPointPollution(_selectAxis, _selectIndex, i, j)) { dataGraph_2D.Append(i, j); } } } var xyScatter = new XyScatterRenderableSeries() { DataSeries = dataGraph_2D, PointMarker = _selectPointMarker2D }; xyScatter.PointMarker.Fill = Color.FromArgb(_selectAlpha, _selectColor.R, _selectColor.G, _selectColor.B); SciChart2D.RenderableSeries.Clear(); SciChart2D.RenderableSeries.Add(xyScatter); SetName("Клеточный автомат; Плоскость " + CA_Model.GetNameAxis(_selectAxis) + "; Слой = " + _selectIndex + "; Итерация =" + CA.Iterator); break; } GetUpdating = false; }