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. 52
      Pores/MainWindowViewModel.cs
  8. 5
      Pores/Models/Material.cs
  9. 1
      Pores/Models/Spreads/BaseSpread.cs
  10. 48
      Pores/Models/Spreads/NormalSpread.cs

6
Pores/Bootstrap.cs

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

12
Pores/Controllers/BatchGenerator.cs

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

4
Pores/Controllers/PoreGenerator.cs

@ -8,9 +8,9 @@ namespace Pores.Controllers
public class PoreGenerator : PropertyChangedClass, IPoreGenerator public class PoreGenerator : PropertyChangedClass, IPoreGenerator
{ {
public IPoreSpread PoresLocalization { get; set; } 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; CurrentMaterial = currentMaterial;
} }

1
Pores/Interfaces/IPoreSpread.cs

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

34
Pores/MainWindow.xaml

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

52
Pores/MainWindowViewModel.cs

@ -5,15 +5,15 @@ using Pores.Helpers;
using System.Windows.Input; using System.Windows.Input;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.Collections.ObjectModel;
namespace Pores namespace Pores
{ {
public class MainWindowViewModel : PropertyChangedClass public class MainWindowViewModel : PropertyChangedClass
{ {
public Material CurrentMaterial { get; set; } public MaterialModel CurrentMaterial { get; set; }
public ObservableCollection<Pore> Pores { get; set; } = new ObservableCollection<Pore>(); public ObservableCollection<Pore> Pores { get; set; } = new ObservableCollection<Pore>();
public IEnumerable<IPoreSpread> Spreads { get; set; } public IEnumerable<IPoreSpread> Spreads { get; set; }
@ -24,9 +24,15 @@ namespace Pores
private ReportGenerator ReportSaver; private ReportGenerator ReportSaver;
public bool GenerateBatchForEachModelFlag { get; set; } = true; private bool _disableGenerateAllFlag;
public bool EnableControlsFlag { get; set; } = true; public bool DisableGenerateAllFlag
public bool GenerateConnectedPoresReportFlag { get; set; } = true; {
get => !_disableGenerateAllFlag && SelectedSpread != null;
set
{
_disableGenerateAllFlag = value;
}
}
public int NumberOfPores { get; set; } public int NumberOfPores { get; set; }
public int ModelAndBatchNumber { get; set; } = 1; public int ModelAndBatchNumber { get; set; } = 1;
@ -36,21 +42,22 @@ namespace Pores
public ICommand GenAndSaveBatchCommand { get; set; } public ICommand GenAndSaveBatchCommand { get; set; }
public ICommand GenerateAllCommand { get; set; } public ICommand GenerateAllCommand { get; set; }
public ICommand OpenModelDirectoryCommand { get; set; } public ICommand OpenModelDirectoryCommand { get; set; }
public ICommand LoadRecommendParamsCommand { get; set; }
public BatchPoint BatchPoint { get; set; } = new BatchPoint(); public BatchPoint BatchPoint { get; set; } = new BatchPoint();
public Thread AllSavingThread { get; set; } public Thread AllSavingThread { get; set; }
public MainWindowViewModel( public MainWindowViewModel(
Material material, MaterialModel material,
IEnumerable<IPoreSpread> localizations, IEnumerable<IPoreSpread> spreads,
IPoreGenerator poreGenerator, IPoreGenerator poreGenerator,
ReportGenerator reportSaver, ReportGenerator reportSaver,
BatchGenerator batchGenerator, BatchGenerator batchGenerator,
ConnectedPoreReportGenerator connectedPoreReportGenerator) ConnectedPoreReportGenerator connectedPoreReportGenerator)
{ {
CurrentMaterial = material; CurrentMaterial = material;
Spreads = localizations; Spreads = spreads;
PoreGeneratorInstance = poreGenerator; PoreGeneratorInstance = poreGenerator;
ReportSaver = reportSaver; ReportSaver = reportSaver;
BatchGenerator = batchGenerator; BatchGenerator = batchGenerator;
@ -59,17 +66,12 @@ namespace Pores
GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedSpread != null); GeneratePoresCommand = new RelayCommand(GeneratePoresToForm, () => SelectedSpread != null);
SaveToFileCommand = new RelayCommand(Save, () => Pores?.Count > 0); SaveToFileCommand = new RelayCommand(Save, () => Pores?.Count > 0);
GenAndSaveBatchCommand = new RelayCommand(SaveBatch, () => Pores?.Count > 0); GenAndSaveBatchCommand = new RelayCommand(SaveBatch, () => Pores?.Count > 0);
GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c), () => GenerateAllCommand = new RelayCommand(c => GenAndSaveAll((int)c));
{
if (SelectedSpread != null)
if (AllSavingThread?.IsAlive != true)
return true;
return false;
});
OpenModelDirectoryCommand = new RelayCommand( OpenModelDirectoryCommand = new RelayCommand(
() => Process.Start(@".\results\"), () => Process.Start(@".\results\"),
() => Directory.Exists(@".\results\") () => Directory.Exists(@".\results\")
); );
LoadRecommendParamsCommand = new RelayCommand(() => SelectedSpread.LoadRecommendParams(), () => SelectedSpread != null);
} }
public void GeneratePoresToForm() public void GeneratePoresToForm()
@ -97,24 +99,28 @@ namespace Pores
public void SaveBatch() public void SaveBatch()
=> SaveBatch(Pores); => SaveBatch(Pores);
public void SaveBatch(IList<Pore> pores, int i = 0) public IEnumerable<Pore> SaveBatch(IEnumerable<Pore> pores, int i = -1)
=> BatchGenerator.GenerateBatch(BatchPoint, pores, i); {
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) public void GenAndSaveAll(int num)
{ {
AllSavingThread = new Thread(() => AllSavingThread = new Thread(() =>
{ {
EnableControlsFlag = false; DisableGenerateAllFlag = true;
for (int i = 0; i < num; i++) for (int i = 0; i < num; i++)
{ {
List<Pore> list2;
var list = GeneratePores(); var list = GeneratePores();
Save(list, i); Save(list, i);
if (GenerateBatchForEachModelFlag) list2 = new List<Pore>(SaveBatch(list, i));
SaveBatch(list, i); ConnectedPoreReportGenerator.CreateReport(list2, i);
if (GenerateConnectedPoresReportFlag)
ConnectedPoreReportGenerator.CreateReport(list, i);
} }
EnableControlsFlag = true; DisableGenerateAllFlag = false;
}); });
AllSavingThread.Start(); AllSavingThread.Start();
} }

5
Pores/Models/Material.cs

@ -2,11 +2,14 @@
namespace Pores.Models namespace Pores.Models
{ {
public class Material : PropertyChangedClass public class MaterialModel : PropertyChangedClass
{ {
public double Height { get; set; } public double Height { get; set; }
public double Width { get; set; } public double Width { get; set; }
public double Depth { get; set; } public double Depth { get; set; }
public int NumberOfPores { 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 class BaseSpread : PropertyChangedClass, IPoreSpread
{ {
public abstract ObservableCollection<Pore> GetSpread(); public abstract ObservableCollection<Pore> GetSpread();
public virtual void LoadRecommendParams() { }
} }
} }

48
Pores/Models/Spreads/NormalSpread.cs

@ -5,10 +5,9 @@ namespace Pores.Models.Spreads
{ {
public class NormalSpread : BaseSpread public class NormalSpread : BaseSpread
{ {
public double mu { get; set; } public double Mu { get; set; }
public double sigma { get; set; } public double Sigma { get; set; }
public double maxR { get; set; } private MaterialModel Material { get; set; }
private Material Material { get; }
public double GaussFunction (double x, double sigma, double mu) public double GaussFunction (double x, double sigma, double mu)
{ {
@ -17,16 +16,14 @@ namespace Pores.Models.Spreads
return part1 * part2; return part1 * part2;
} }
public double GaussFunctionByHeight (Point3D c) public double GaussFunctionByHeight(Point3D c)
{ => GaussFunction(c.Z, Sigma, Mu);
return GaussFunction(c.Z, sigma, mu);
}
public override ObservableCollection<Pore> GetSpread() public override ObservableCollection<Pore> GetSpread()
{ {
var r = new Random(); var r = new Random();
var id = 0; var id = 0;
GetMaxRadius(); GetOptimalRadius();
var result = new ObservableCollection<Pore>(); var result = new ObservableCollection<Pore>();
for (int i = 0; i <= Material.NumberOfPores; i++) for (int i = 0; i <= Material.NumberOfPores; i++)
for (int j = 0; j <= Material.NumberOfPores; j++) for (int j = 0; j <= Material.NumberOfPores; j++)
@ -42,25 +39,44 @@ namespace Pores.Models.Spreads
var gaussResult = GaussFunctionByHeight(c); var gaussResult = GaussFunctionByHeight(c);
if (randomDouble < gaussResult) 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++; id++;
} }
} }
return result; return result;
} }
private void GetMaxRadius() private double GetOptimalRadius()
{ {
var m = Material; var m = Material;
var volume = m.Height * m.Width * m.Depth; 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; if (Material.Width == 0 || Material.Height == 0 || Material.Depth == 0)
sigma = 4; {
mu = Material.Height - Material.Height / 4; 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