Browse Source

Added special connected pores reporter, which save connected pore pairs in file report...

master
Nikita Romanenko 6 years ago
parent
commit
424d28bce6
  1. 5
      Pores/Bootstrap.cs
  2. 2
      Pores/Controllers/BatchGenerator.cs
  3. 47
      Pores/Controllers/ConnectedPoreReportGenerator.cs
  4. 2
      Pores/Controllers/ReportGenerator.cs
  5. 11
      Pores/MainWindowViewModel.cs
  6. 6
      Pores/Models/Localizations/NormalLocalization.cs
  7. 1
      Pores/Models/Pore.cs
  8. 1
      Pores/Pores.csproj

5
Pores/Bootstrap.cs

@ -41,6 +41,11 @@ namespace Pores
.RegisterType<ReportGenerator>()
.AsSelf();
build
.RegisterType<ConnectedPoreReportGenerator>()
.AsSelf()
.SingleInstance();
build
.RegisterType<MainWindowViewModel>()
.AsSelf()

2
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)

47
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<Pore> pores, int index)
{
IList<Tuple<Pore,Pore>> report = new List<Tuple<Pore, Pore>>();
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;
}
}
}

2
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\\"

11
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<IPoreLocalization> 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;
});

6
Pores/Models/Localizations/NormalLocalization.cs

@ -27,6 +27,7 @@ namespace Pores.Models.Localizations
public override ObservableCollection<Pore> GetLocalization()
{
var r = new Random();
var id = 0;
GetMaxRadius();
var result = new ObservableCollection<Pore>();
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;
}

1
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; }
}
}

1
Pores/Pores.csproj

@ -82,6 +82,7 @@
<Compile Include="Bootstrap.cs" />
<Compile Include="Controllers\BaseSaveLoadController.cs" />
<Compile Include="Controllers\BatchGenerator.cs" />
<Compile Include="Controllers\ConnectedPoreReportGenerator.cs" />
<Compile Include="Controllers\ReportGenerator.cs" />
<Compile Include="Controllers\PoreGenerator.cs" />
<Compile Include="Helpers\PropertyChanged.cs" />

Loading…
Cancel
Save