From 424d28bce643e25f0595ce903426fb2fee56cb93 Mon Sep 17 00:00:00 2001 From: Nikita Romanenko Date: Thu, 13 Dec 2018 02:46:32 +0300 Subject: [PATCH] Added special connected pores reporter, which save connected pore pairs in file report... --- Pores/Bootstrap.cs | 5 ++ Pores/Controllers/BatchGenerator.cs | 2 +- .../ConnectedPoreReportGenerator.cs | 47 +++++++++++++++++++ Pores/Controllers/ReportGenerator.cs | 2 +- Pores/MainWindowViewModel.cs | 11 +++-- .../Localizations/NormalLocalization.cs | 6 ++- Pores/Models/Pore.cs | 1 + Pores/Pores.csproj | 1 + 8 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 Pores/Controllers/ConnectedPoreReportGenerator.cs diff --git a/Pores/Bootstrap.cs b/Pores/Bootstrap.cs index 2d3e3ab..ecd0940 100644 --- a/Pores/Bootstrap.cs +++ b/Pores/Bootstrap.cs @@ -41,6 +41,11 @@ namespace Pores .RegisterType() .AsSelf(); + build + .RegisterType() + .AsSelf() + .SingleInstance(); + build .RegisterType() .AsSelf() diff --git a/Pores/Controllers/BatchGenerator.cs b/Pores/Controllers/BatchGenerator.cs index 854a94b..e31e44b 100644 --- a/Pores/Controllers/BatchGenerator.cs +++ b/Pores/Controllers/BatchGenerator.cs @@ -35,7 +35,7 @@ namespace Pores.Controllers }; BatchSaver.Save( pores.Where(p => IsPointInsideOfCube(p.Point, p1, p2)), - BatchSaver.FileNamer(string.Format("batch_{0}", index))); + BatchSaver.AddOther(string.Format("batch_{0}", index))); } public bool IsPointInsideOfCube(Point3D p, Point3D vertex1, Point3D vertex2) diff --git a/Pores/Controllers/ConnectedPoreReportGenerator.cs b/Pores/Controllers/ConnectedPoreReportGenerator.cs new file mode 100644 index 0000000..4088138 --- /dev/null +++ b/Pores/Controllers/ConnectedPoreReportGenerator.cs @@ -0,0 +1,47 @@ +using Pores.Models; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Pores.Controllers +{ + public class ConnectedPoreReportGenerator + { + public Material Material { get; } + public ReportGenerator ReportGenerator { get; } + + public ConnectedPoreReportGenerator(Material material, ReportGenerator reportGenerator) + { + Material = material; + ReportGenerator = reportGenerator; + } + + public void CreateReport(IList pores, int index) + { + IList> report = new List>(); + foreach(Pore p1 in pores) + foreach(Pore p2 in pores) + if (!p1.Equals(p2)) + if (!report.Any(a => a.Item1.Id == p2.Id && a.Item2.Id == p1.Id)) + if (IsTwoPoresConnecting(p1, p2)) + report.Add(Tuple.Create(p1, p2)); + ReportGenerator.Save(report, ReportGenerator.AddOther("report_connected_pores_" + index)); + } + + public double DistanceBetweenTwoPoints(Point3D point1, Point3D point2) + { + return Math.Sqrt( + Math.Pow(point2.X - point1.X, 2) + + Math.Pow(point2.Y - point1.Y, 2) + + Math.Pow(point2.Z - point1.Z, 2) + ); + } + + public bool IsTwoPoresConnecting(Pore pore1, Pore pore2) + { + if (DistanceBetweenTwoPoints(pore1.Point, pore2.Point) > pore1.Radius + pore2.Radius) + return false; + return true; + } + } +} diff --git a/Pores/Controllers/ReportGenerator.cs b/Pores/Controllers/ReportGenerator.cs index 3298c7d..d5f2257 100644 --- a/Pores/Controllers/ReportGenerator.cs +++ b/Pores/Controllers/ReportGenerator.cs @@ -12,7 +12,7 @@ namespace Pores.Controllers { public class ReportGenerator : BaseSaveLoadController { - public string FileNamer(string fileName) + public string AddOther(string fileName) { return ".\\results\\" diff --git a/Pores/MainWindowViewModel.cs b/Pores/MainWindowViewModel.cs index 8da5f7b..8ca9272 100644 --- a/Pores/MainWindowViewModel.cs +++ b/Pores/MainWindowViewModel.cs @@ -4,8 +4,6 @@ using Pores.Models; using Pores.Helpers; using System.Windows.Input; using System.Collections.Generic; -using System; -using System.Threading.Tasks; using System.Threading; using System.Collections.ObjectModel; using System.IO; @@ -22,6 +20,7 @@ namespace Pores public IPoreLocalization SelectedLocalization { get; set; } public IPoreGenerator PoreGeneratorInstance { get; set; } public BatchGenerator BatchGenerator { get; } + public ConnectedPoreReportGenerator ConnectedPoreReportGenerator { get; } private ReportGenerator ReportSaver; @@ -47,13 +46,15 @@ namespace Pores IEnumerable localizations, IPoreGenerator poreGenerator, ReportGenerator reportSaver, - BatchGenerator batchGenerator) + BatchGenerator batchGenerator, + ConnectedPoreReportGenerator connectedPoreReportGenerator) { CurrentMaterial = material; Localizations = localizations; PoreGeneratorInstance = poreGenerator; ReportSaver = reportSaver; BatchGenerator = batchGenerator; + ConnectedPoreReportGenerator = connectedPoreReportGenerator; GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedLocalization != null); SaveToFileCommand = new RelayCommand(Save, () => Pores?.Count > 0); @@ -90,7 +91,7 @@ namespace Pores CurrentMaterial.Height, pores.Count); - ReportSaver.Save(pores, ReportSaver.FileNamer(n)); + ReportSaver.Save(pores, ReportSaver.AddOther(n)); } public void SaveBatch() @@ -110,6 +111,8 @@ namespace Pores Save(list, i); if (GenerateBatchForEachModelFlag) SaveBatch(list, i); + if (GenerateConnectedPoresReportFlag) + ConnectedPoreReportGenerator.CreateReport(list, i); } EnableControlsFlag = true; }); diff --git a/Pores/Models/Localizations/NormalLocalization.cs b/Pores/Models/Localizations/NormalLocalization.cs index e4fda74..14565a9 100644 --- a/Pores/Models/Localizations/NormalLocalization.cs +++ b/Pores/Models/Localizations/NormalLocalization.cs @@ -27,6 +27,7 @@ namespace Pores.Models.Localizations public override ObservableCollection GetLocalization() { var r = new Random(); + var id = 0; GetMaxRadius(); var result = new ObservableCollection(); for (int i = 0; i <= Material.NumberOfPores; i++) @@ -42,7 +43,10 @@ namespace Pores.Models.Localizations var randomDouble = r.NextDouble(); var gaussResult = GaussFunctionByHeight(c); if (randomDouble < gaussResult) - result.Add(new Pore() { Point = c, Radius = maxR }); + { + result.Add(new Pore() { Point = c, Radius = maxR, Id = id }); + id++; + } } return result; } diff --git a/Pores/Models/Pore.cs b/Pores/Models/Pore.cs index c5a8450..0a93dfd 100644 --- a/Pores/Models/Pore.cs +++ b/Pores/Models/Pore.cs @@ -7,5 +7,6 @@ namespace Pores.Models { public Point3D Point { get; set; } public double Radius { get; set; } + public int Id { get; set; } } } diff --git a/Pores/Pores.csproj b/Pores/Pores.csproj index ddbdaee..be50d52 100644 --- a/Pores/Pores.csproj +++ b/Pores/Pores.csproj @@ -82,6 +82,7 @@ +