Browse Source

Added a lot of small edits, as visual and as feature sides.

master
Nikita Romanenko 6 years ago
parent
commit
3b7c0783d7
  1. 6
      Pores/Bootstrap.cs
  2. 12
      Pores/Controllers/BatchGenerator.cs
  3. 4
      Pores/Controllers/ConnectedPoreReportGenerator.cs
  4. 4
      Pores/Controllers/PoreGenerator.cs
  5. 1
      Pores/Interfaces/IPoreSpread.cs
  6. 34
      Pores/MainWindow.xaml
  7. 68
      Pores/MainWindowViewModel.cs
  8. 5
      Pores/Models/Material.cs
  9. 1
      Pores/Models/Spreads/BaseSpread.cs
  10. 50
      Pores/Models/Spreads/NormalSpread.cs

6
Pores/Bootstrap.cs

@ -19,12 +19,12 @@ namespace Pores
ContainerBuilder build = new ContainerBuilder();
build
.Register(c => new Material())
.As<Material>()
.Register(c => new MaterialModel())
.As<MaterialModel>()
.SingleInstance();
build
.Register(c => new ObservableCollection<IPoreSpread>() { new NormalSpread(c.Resolve<Material>()) })
.Register(c => new ObservableCollection<IPoreSpread>() { new NormalSpread(c.Resolve<MaterialModel>()) })
.As<IEnumerable<IPoreSpread>>()
.SingleInstance();

12
Pores/Controllers/BatchGenerator.cs

@ -10,16 +10,14 @@ namespace Pores.Controllers
{
public class BatchGenerator
{
public ReportGenerator BatchSaver { get; set; }
public Material Material { get; set; }
public MaterialModel Material { get; set; }
public BatchGenerator(Material material, ReportGenerator batchSaver)
public BatchGenerator(MaterialModel material, ReportGenerator batchSaver)
{
Material = material;
BatchSaver = batchSaver;
}
public void GenerateBatch(BatchPoint bp, IList<Pore> pores, int index = 0)
public IEnumerable<Pore> GenerateBatch(BatchPoint bp, IEnumerable<Pore> pores)
{
var p1 = new Point3D()
{
@ -33,9 +31,7 @@ namespace Pores.Controllers
Y = bp.Center.Y + bp.Width / 2,
Z = bp.Center.Z
};
BatchSaver.Save(
pores.Where(p => IsPointInsideOfCube(p.Point, p1, p2)),
BatchSaver.AddOther(string.Format("batch_{0}", index)));
return pores.Where(p => IsPointInsideOfCube(p.Point, p1, p2)).ToList();
}
public bool IsPointInsideOfCube(Point3D p, Point3D vertex1, Point3D vertex2)

4
Pores/Controllers/ConnectedPoreReportGenerator.cs

@ -7,10 +7,10 @@ namespace Pores.Controllers
{
public class ConnectedPoreReportGenerator
{
public Material Material { get; }
public MaterialModel Material { get; }
public ReportGenerator ReportGenerator { get; }
public ConnectedPoreReportGenerator(Material material, ReportGenerator reportGenerator)
public ConnectedPoreReportGenerator(MaterialModel material, ReportGenerator reportGenerator)
{
Material = material;
ReportGenerator = reportGenerator;

4
Pores/Controllers/PoreGenerator.cs

@ -8,9 +8,9 @@ namespace Pores.Controllers
public class PoreGenerator : PropertyChangedClass, IPoreGenerator
{
public IPoreSpread PoresLocalization { get; set; }
public Material CurrentMaterial { get; set; }
public MaterialModel CurrentMaterial { get; set; }
public PoreGenerator(Material currentMaterial)
public PoreGenerator(MaterialModel currentMaterial)
{
CurrentMaterial = currentMaterial;
}

1
Pores/Interfaces/IPoreSpread.cs

@ -6,5 +6,6 @@ namespace Pores.Interfaces
public interface IPoreSpread
{
ObservableCollection<Pore> GetSpread();
void LoadRecommendParams();
}
}

34
Pores/MainWindow.xaml

@ -6,7 +6,7 @@
xmlns:spreads="clr-namespace:Pores.Models.Spreads"
mc:Ignorable="d"
Title="Pores" Height="600" Width="1000">
<Grid IsEnabled="{Binding EnableControlsFlag}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
@ -24,7 +24,6 @@
</StackPanel>
</DockPanel>
<DockPanel Grid.Column="1" Grid.RowSpan="3" VerticalAlignment="Stretch" Margin="5 0">
<StackPanel DockPanel.Dock="Top" Margin="5 0">
<TextBlock Text="Настройки моделирования" HorizontalAlignment="Center" FontWeight="SemiBold" Margin="0 5"/>
@ -44,16 +43,22 @@
<DataTemplate DataType="{x:Type spreads:NormalSpread}">
<StackPanel>
<TextBlock Text="Сигма: "/>
<TextBox Text="{Binding sigma}"/>
<TextBox Text="{Binding Sigma}"/>
<TextBlock Text="Мю: "/>
<TextBox Text="{Binding mu}"/>
<TextBox Text="{Binding Mu}"/>
</StackPanel>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
<TextBlock Text="Параметры распределения радиуса пор: "/>
<TextBlock Text="Минимальный: "/>
<TextBox Text="{Binding CurrentMaterial.MinRadius}"/>
<TextBlock Text="Максимальный: "/>
<TextBox Text="{Binding CurrentMaterial.MaxRadius}"/>
</StackPanel>
<StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Margin="5 10">
<Button Content="[Рекомендуемые параметры]" Command="{Binding LoadRecommendParamsCommand}"/>
<TextBlock Text="Результаты работы"/>
<TextBlock Text="Количество пор: "/>
<TextBox Text="{Binding Pores.Count, Mode=OneWay}" IsEnabled="False"/>
@ -63,12 +68,12 @@
<DockPanel Grid.Column="2" Grid.RowSpan="3" Margin="5 0">
<StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
<Button Content="Сгенерировать модель" Command="{Binding GeneratePoresCommand}"/>
<Button Content="Сохранить выборку из модели в файл" Command="{Binding GenAndSaveBatchCommand}"/>
<!--<Button Content="Сохранить выборку из модели в файл" Command="{Binding GenAndSaveBatchCommand}"/>-->
<Button Content="Сохранить модель в файл" Command="{Binding SaveToFileCommand}"/>
<Button Command="{Binding GenerateAllCommand}" CommandParameter="{Binding ModelAndBatchNumber}">
<Button Command="{Binding GenerateAllCommand}" IsEnabled="{Binding DisableGenerateAllFlag, UpdateSourceTrigger=PropertyChanged}" CommandParameter="{Binding ModelAndBatchNumber}">
<Button.Content>
<TextBlock>
<Run Text="Сгенерировать модели+выборки ["/>
<Run Text="Сгенерировать все данные ["/>
<Run><Binding Path="ModelAndBatchNumber" UpdateSourceTrigger="PropertyChanged"/></Run>
<Run Text="]"/>
</TextBlock>
@ -90,17 +95,14 @@
<TextBox Text="{Binding BatchPoint.Width}"/>
<TextBlock Text="Глубина:"/>
<TextBox Text="{Binding BatchPoint.Depth}"/>
<CheckBox Margin="0 5" IsChecked="{Binding RandomBatchPointFlag}" IsEnabled="False">
<!--<CheckBox Margin="0 5" IsChecked="{Binding RandomBatchPointFlag}" IsEnabled="False">
<TextBlock TextWrapping="Wrap" Text="Случайное координаты для выборки"/>
</CheckBox>
</CheckBox>-->
<TextBlock Text="Количество моделей/моделей и выборок генерируемое за один раз:" TextWrapping="Wrap"/>
<TextBox Text="{Binding ModelAndBatchNumber}"/>
<CheckBox Margin="0 5" IsChecked="{Binding GenerateBatchForEachModelFlag}">
<TextBlock TextWrapping="Wrap" Text="Генерировать для каждой модели по выборке"/>
</CheckBox>
<CheckBox Margin="0 5" IsChecked="{Binding GenerateConnectedPoresReportFlag}">
<TextBlock TextWrapping="Wrap" Text="Предоставить отчет по количеству пор, соединенных между собой"/>
</CheckBox>
<TextBox Text="{Binding ModelAndBatchNumber, UpdateSourceTrigger=PropertyChanged}"/>
<!--<CheckBox Margin="0 5" IsChecked="{Binding GenerateConPoresReportFlag}">
<TextBlock TextWrapping="Wrap" Text="Создавать отчет [выборки : соединенные поры в выборке]"/>
</CheckBox>-->
</StackPanel>
</DockPanel>
</Grid>

68
Pores/MainWindowViewModel.cs

@ -5,15 +5,15 @@ using Pores.Helpers;
using System.Windows.Input;
using System.Collections.Generic;
using System.Threading;
using System.Collections.ObjectModel;
using System.IO;
using System.Diagnostics;
using System.Collections.ObjectModel;
namespace Pores
{
public class MainWindowViewModel : PropertyChangedClass
{
public Material CurrentMaterial { get; set; }
public MaterialModel CurrentMaterial { get; set; }
public ObservableCollection<Pore> Pores { get; set; } = new ObservableCollection<Pore>();
public IEnumerable<IPoreSpread> Spreads { get; set; }
@ -24,9 +24,15 @@ namespace Pores
private ReportGenerator ReportSaver;
public bool GenerateBatchForEachModelFlag { get; set; } = true;
public bool EnableControlsFlag { get; set; } = true;
public bool GenerateConnectedPoresReportFlag { get; set; } = true;
private bool _disableGenerateAllFlag;
public bool DisableGenerateAllFlag
{
get => !_disableGenerateAllFlag && SelectedSpread != null;
set
{
_disableGenerateAllFlag = value;
}
}
public int NumberOfPores { get; set; }
public int ModelAndBatchNumber { get; set; } = 1;
@ -34,23 +40,24 @@ namespace Pores
public ICommand GeneratePoresCommand { get; set; }
public ICommand SaveToFileCommand { get; set; }
public ICommand GenAndSaveBatchCommand { get; set; }
public ICommand GenerateAllCommand { get; set; }
public ICommand GenerateAllCommand { get; set; }
public ICommand OpenModelDirectoryCommand { get; set; }
public ICommand LoadRecommendParamsCommand { get; set; }
public BatchPoint BatchPoint { get; set; } = new BatchPoint();
public Thread AllSavingThread { get; set; }
public MainWindowViewModel(
Material material,
IEnumerable<IPoreSpread> localizations,
MaterialModel material,
IEnumerable<IPoreSpread> spreads,
IPoreGenerator poreGenerator,
ReportGenerator reportSaver,
BatchGenerator batchGenerator,
ConnectedPoreReportGenerator connectedPoreReportGenerator)
{
CurrentMaterial = material;
Spreads = localizations;
Spreads = spreads;
PoreGeneratorInstance = poreGenerator;
ReportSaver = reportSaver;
BatchGenerator = batchGenerator;
@ -59,26 +66,21 @@ namespace Pores
GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedSpread != null);
SaveToFileCommand = new RelayCommand(Save, () => Pores?.Count > 0);
GenAndSaveBatchCommand = new RelayCommand(SaveBatch, () => Pores?.Count > 0);
GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c), () =>
{
if (SelectedSpread != null)
if (AllSavingThread?.IsAlive != true)
return true;
return false;
});
GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c));
OpenModelDirectoryCommand = new RelayCommand(
() => Process.Start(@".\results\"),
() => Process.Start(@".\results\"),
() => Directory.Exists(@".\results\")
);
LoadRecommendParamsCommand = new RelayCommand(() => SelectedSpread.LoadRecommendParams(), () => SelectedSpread != null);
}
public void GeneratePoresToForm()
public void GeneratePoresToForm()
=> Pores = new ObservableCollection<Pore>(PoreGeneratorInstance.Generate(SelectedSpread));
public IList<Pore> GeneratePores()
public IList<Pore> GeneratePores()
=> PoreGeneratorInstance.Generate(SelectedSpread);
public void Save()
public void Save()
=> Save(Pores);
public void Save(IList<Pore> pores, int i = 0)
@ -86,35 +88,39 @@ namespace Pores
var n = string.Format(
"model_{0}_w{1}_d{2}_h{3}_n{4}",
i,
CurrentMaterial.Width,
CurrentMaterial.Depth,
CurrentMaterial.Width,
CurrentMaterial.Depth,
CurrentMaterial.Height,
pores.Count);
ReportSaver.Save(pores, ReportSaver.AddOther(n));
}
public void SaveBatch()
public void SaveBatch()
=> SaveBatch(Pores);
public void SaveBatch(IList<Pore> pores, int i = 0)
=> BatchGenerator.GenerateBatch(BatchPoint, pores, i);
public IEnumerable<Pore> SaveBatch(IEnumerable<Pore> pores, int i = -1)
{
var batch = BatchGenerator.GenerateBatch(BatchPoint, pores);
if (i != -1)
ReportSaver.Save(batch, ReportSaver.AddOther(string.Format("batch_{0}", i)));
return batch;
}
public void GenAndSaveAll(int num)
{
AllSavingThread = new Thread(() =>
{
EnableControlsFlag = false;
DisableGenerateAllFlag = true;
for (int i = 0; i < num; i++)
{
List<Pore> list2;
var list = GeneratePores();
Save(list, i);
if (GenerateBatchForEachModelFlag)
SaveBatch(list, i);
if (GenerateConnectedPoresReportFlag)
ConnectedPoreReportGenerator.CreateReport(list, i);
list2 = new List<Pore>(SaveBatch(list, i));
ConnectedPoreReportGenerator.CreateReport(list2, i);
}
EnableControlsFlag = true;
DisableGenerateAllFlag = false;
});
AllSavingThread.Start();
}

5
Pores/Models/Material.cs

@ -2,11 +2,14 @@
namespace Pores.Models
{
public class Material : PropertyChangedClass
public class MaterialModel : PropertyChangedClass
{
public double Height { get; set; }
public double Width { get; set; }
public double Depth { get; set; }
public int NumberOfPores { get; set; }
public double MinRadius { get; set; }
public double MaxRadius { get; set; }
}
}

1
Pores/Models/Spreads/BaseSpread.cs

@ -7,5 +7,6 @@ namespace Pores.Models.Spreads
public abstract class BaseSpread : PropertyChangedClass, IPoreSpread
{
public abstract ObservableCollection<Pore> GetSpread();
public virtual void LoadRecommendParams() { }
}
}

50
Pores/Models/Spreads/NormalSpread.cs

@ -5,10 +5,9 @@ namespace Pores.Models.Spreads
{
public class NormalSpread : BaseSpread
{
public double mu { get; set; }
public double sigma { get; set; }
public double maxR { get; set; }
private Material Material { get; }
public double Mu { get; set; }
public double Sigma { get; set; }
private MaterialModel Material { get; set; }
public double GaussFunction (double x, double sigma, double mu)
{
@ -17,16 +16,14 @@ namespace Pores.Models.Spreads
return part1 * part2;
}
public double GaussFunctionByHeight (Point3D c)
{
return GaussFunction(c.Z, sigma, mu);
}
public double GaussFunctionByHeight(Point3D c)
=> GaussFunction(c.Z, Sigma, Mu);
public override ObservableCollection<Pore> GetSpread()
{
var r = new Random();
var id = 0;
GetMaxRadius();
GetOptimalRadius();
var result = new ObservableCollection<Pore>();
for (int i = 0; i <= Material.NumberOfPores; i++)
for (int j = 0; j <= Material.NumberOfPores; j++)
@ -42,25 +39,44 @@ namespace Pores.Models.Spreads
var gaussResult = GaussFunctionByHeight(c);
if (randomDouble < gaussResult)
{
result.Add(new Pore() { Point = c, Radius = maxR, Id = id });
var randomRadius
= r.NextDouble()
* (Material.MaxRadius - Material.MinRadius)
+ Material.MinRadius;
result.Add(new Pore() { Point = c, Radius = randomRadius, Id = id });
id++;
}
}
return result;
}
private void GetMaxRadius()
private double GetOptimalRadius()
{
var m = Material;
var volume = m.Height * m.Width * m.Depth;
maxR = Math.Round(Math.Pow((3.0 / 4.0) * volume / (3.14 * Math.Pow(m.NumberOfPores, 3)), 1.0 / 3.0), 3);
return Math.Round(Math.Pow((3.0 / 4.0) * volume / (3.14 * Math.Pow(m.NumberOfPores, 3)), 1.0 / 3.0), 3);
}
public NormalSpread(Material material)
public override void LoadRecommendParams()
{
Material = material;
sigma = 4;
mu = Material.Height - Material.Height / 4;
if (Material.Width == 0 || Material.Height == 0 || Material.Depth == 0)
{
Material.Width = 10;
Material.Height = 10;
Material.Depth = 10;
Material.NumberOfPores = 20;
}
Sigma = 4;
Mu = Material.Height - Material.Height / 4;
var r = GetOptimalRadius();
Material.MinRadius = r / 2;
Material.MaxRadius = 3 * r / 2;
}
public NormalSpread(MaterialModel material)
=> Material = material;
public override string ToString()
=> "Нормальное распределение";
}
}

Loading…
Cancel
Save