Browse Source

done = improved normal spread; was inverted pore inspection direction; some stability imrpovements

master
Nikita Romanenko 5 years ago
parent
commit
408b072389
  1. 16
      Pores/Bootstrap.cs
  2. 1
      Pores/MODELING-DEF-DES-MI-VI.csproj
  3. 37
      Pores/Models/Spreads/ImprovedNormalSpread.cs
  4. 10
      Pores/Modules/ModelCreationUnit/ModelCreationView.xaml
  5. 64
      Pores/Modules/PoreInspectionUnit/PoreInspectionView.xaml
  6. 181
      Pores/Modules/PoreInspectionUnit/PoreInspectionViewModel.cs

16
Pores/Bootstrap.cs

@ -16,13 +16,27 @@ namespace MODELING_DEF_DES_MI_VI
{
ContainerBuilder build = new ContainerBuilder();
var camera = new Camera2D()
{
Speed = 1.0,
CutDepth = 10.0,
DepthVisibility = 2.0,
Scale = 40,
StartPosition = new Point2D(0 * 40, 0 * 40),
};
build
.RegisterInstance(camera)
.AsSelf()
.SingleInstance();
build
.Register(c => new MaterialModel())
.As<MaterialModel>()
.SingleInstance();
build
.Register(c => new ObservableCollection<IPoreSpread>() { new NormalSpread(c.Resolve<MaterialModel>()) })
.Register(c => new ObservableCollection<IPoreSpread>() { new NormalSpread(c.Resolve<MaterialModel>()), new ImprovedNormalSpread(c.Resolve<MaterialModel>()) })
.As<IEnumerable<IPoreSpread>>()
.SingleInstance();

1
Pores/MODELING-DEF-DES-MI-VI.csproj

@ -100,6 +100,7 @@
<Compile Include="Models\Point2D.cs" />
<Compile Include="Models\Point3D.cs" />
<Compile Include="Models\Spreads\BaseSpread.cs" />
<Compile Include="Models\Spreads\ImprovedNormalSpread.cs" />
<Compile Include="Models\Spreads\NormalSpread.cs" />
<Compile Include="Models\Material.cs" />
<Compile Include="Models\Pore.cs" />

37
Pores/Models/Spreads/ImprovedNormalSpread.cs

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace MODELING_DEF_DES_MI_VI.Models.Spreads
{
public class ImprovedNormalSpread : BaseSpread
{
public MaterialModel Material { get; set; }
public NormalSpread NormalSpread { get; set; }
public override IList<Pore> GetSpread()
{
var r = new Random();
var pores = NormalSpread.GetSpread();
pores.ToList().ForEach(p =>
{
p.Point.X = p.Point.X + r.NextDouble() * 2 - 1;
p.Point.Y = p.Point.Y + r.NextDouble() * 2 - 1;
p.Point.Z = p.Point.Z + r.NextDouble() * 2 - 1;
});
return pores;
}
public override void LoadRecommendParams()
{
NormalSpread.LoadRecommendParams();
}
public ImprovedNormalSpread(MaterialModel material)
{
NormalSpread = new NormalSpread(material);
Material = material;
}
public override string ToString()
=> "Улучшенное нормальное распределение";
}
}

10
Pores/Modules/ModelCreationUnit/ModelCreationView.xaml

@ -40,7 +40,7 @@
<TextBlock Text="Параметры модели материала: " />
<TextBlock Text="Ширина: " />
<TextBox Text="{Binding CurrentMaterial.Width}" />
<TextBlock Text="Глубина: " />
<TextBlock Text="Длина: " />
<TextBox Text="{Binding CurrentMaterial.Depth}" />
<TextBlock Text="Высота: " />
<TextBox Text="{Binding CurrentMaterial.Height}" />
@ -68,6 +68,14 @@
<TextBox Text="{Binding Mu}" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type spreads:ImprovedNormalSpread}">
<StackPanel>
<TextBlock Text="Сигма: " />
<TextBox Text="{Binding NormalSpread.Sigma}" />
<TextBlock Text="Мю: " />
<TextBox Text="{Binding NormalSpread.Mu}" />
</StackPanel>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
<TextBlock Text="Параметры распределения радиуса пор: " />

64
Pores/Modules/PoreInspectionUnit/PoreInspectionView.xaml

@ -27,31 +27,43 @@
</Style>
</TextBlock.Style>
</TextBlock>
<ItemsControl Focusable="True" ItemsSource="{Binding Ellipses}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas
Width="{Binding Camera.Width, Mode=OneWayToSource}"
Height="{Binding Camera.Height, Mode=OneWayToSource}"
IsItemsHost="True">
<Canvas.Style>
<Style TargetType="Canvas">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding Ellipses.Count}" Value="0">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Canvas.Style>
</Canvas>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">
<TextBlock Foreground="White" Text="{Binding Camera.Scale, StringFormat={}Масштаб отрисовки: 1 к {0}}" />
<TextBlock Foreground="White" Text="{Binding Camera.Speed, StringFormat={}Скорость камеры: {0}}" />
<TextBlock Foreground="White" Text="{Binding Camera.CutDepth, StringFormat={}Глубина среза: {0}}" />
</StackPanel>
<Grid>
<ItemsControl Focusable="True" ItemsSource="{Binding Ellipses}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas
Width="{Binding Camera.Width, Mode=OneWay}"
Height="{Binding Camera.Height, Mode=OneWay}"
IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<UniformGrid Columns="2">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">
<TextBlock Foreground="White" Text="Смещение вдоль плоскости: W A S D" />
<TextBlock Foreground="White" Text="Изменение глубины: R F" />
<TextBlock Foreground="White" Text="Изменение масштаба: + -" />
<TextBlock Foreground="White" Text="Изменение скорости камеры: 9 0" />
<TextBlock Foreground="White" Text="Изменение дальности прорисовки: T G" />
</StackPanel>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">
<TextBlock Foreground="White" Text="{Binding Camera.Scale, StringFormat={}Масштаб отрисовки: 1 к {0}}" />
<TextBlock Foreground="White" Text="{Binding Camera.Speed, StringFormat={}Скорость камеры: {0}}" />
<TextBlock Foreground="White" Text="{Binding Camera.CutDepth, StringFormat={}Глубина среза: {0}}" />
<TextBlock Foreground="White" Text="{Binding Camera.DepthVisibility, StringFormat={}Дистанция прорисовки: {0}}" />
<TextBlock Foreground="White" Text="{Binding Ellipses.Count, StringFormat={}Отрисованно объектов: {0}, Mode=OneWay}" />
</StackPanel>
</UniformGrid>
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding Ellipses.Count, Mode=OneWay}" Value="0">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
</Grid>
</Grid>
</UserControl>

181
Pores/Modules/PoreInspectionUnit/PoreInspectionViewModel.cs

@ -16,48 +16,48 @@ namespace MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit
public class PoreInspectionViewModel : PropertyChangedClass
{
public MaterialModel GlobalMaterial { get; set; }
public ObservableCollection<Shape> Ellipses { get; set; } = new ObservableCollection<Shape>();
public List<FrameworkElement> Ellipses { get; set; } = new List<FrameworkElement>();
public Camera2D Camera { get; set; }
private CancellationTokenSource ctSource { get; set; }
private bool IsCanceled { get; set; }
private bool IsBusy { get; set; }
public PoreInspectionViewModel(MaterialModel material)
public PoreInspectionViewModel(MaterialModel material, Camera2D camera)
{
GlobalMaterial = material;
Camera = new Camera2D()
{
Speed = 1.0,
CutDepth = 1.0,
DepthVisibility = 2.0,
Scale = 40,
StartPosition = new Point2D(0 * 40, 0 * 40),
};
Camera = camera;
Application.Current.MainWindow.KeyDown += OnKeyDown;
}
public async Task UpdateModel()
{
await Task.Run(() =>
await Task.Run(async () =>
{
try
{
ctSource = new CancellationTokenSource();
Application.Current.Dispatcher.Invoke(() =>
while (IsBusy) await Task.Delay(40);
IsBusy = true;
IsCanceled = false;
await Application.Current.Dispatcher.Invoke(async () =>
{
List<Shape> bufferedShapes = new List<Shape>();
List<FrameworkElement> bufferedShapes = new List<FrameworkElement>();
bufferedShapes.Add(CreateMaterial());
var visibilityRange = Tuple.Create(Camera.CutDepth / Camera.Scale, (Camera.DepthVisibility + Camera.CutDepth) / Camera.Scale);
var visibilityRange =
Tuple.Create(
(Camera.CutDepth + Camera.DepthVisibility) / Camera.Scale,
(Camera.CutDepth - Camera.DepthVisibility) / Camera.Scale);
foreach (Pore pore in GlobalMaterial.Pores)
{
if (ctSource.IsCancellationRequested)
if (IsCanceled)
return;
if (visibilityRange.Item1 < pore.Point.Z && pore.Point.Z < visibilityRange.Item2)
if (visibilityRange.Item2 < pore.Point.Z && pore.Point.Z < visibilityRange.Item1)
bufferedShapes.Add(CreateEllipse(pore));
}
Ellipses.Clear();
bufferedShapes.ForEach(s => Ellipses.Add(s));
Ellipses = bufferedShapes;
await Task.Delay(20);
IsBusy = false;
});
}
catch (Exception e)
@ -70,21 +70,27 @@ namespace MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit
private Ellipse CreateEllipse(Pore pore)
{
var e = new Ellipse();
var cuttingHeight = Math.Abs(pore.Point.Z * Camera.Scale - Camera.CutDepth);
if (cuttingHeight < pore.Radius * Camera.Scale)
var scaledPoreRadius = pore.Radius * Camera.Scale;
var distanceFromCameraToPore = Camera.CutDepth - pore.Point.Z * Camera.Scale;
var cuttingHeight = Math.Abs(distanceFromCameraToPore);
if (cuttingHeight < scaledPoreRadius)
{
e.Fill = Brushes.Violet;
var cuttedDiameter = Math.Sqrt(Math.Pow(pore.Radius * Camera.Scale, 2) - Math.Pow(cuttingHeight, 2)) * 2;
var cuttedDiameter = Math.Sqrt(Math.Pow(scaledPoreRadius, 2) - Math.Pow(cuttingHeight, 2)) * 2;
e.Width = cuttedDiameter;
e.Height = cuttedDiameter;
}
else
else if (pore.Point.Z < Camera.CutDepth / Camera.Scale)
{
e.Opacity = 0.5;
byte colorDegree = Convert.ToByte(pore.Point.Z * Camera.Scale / (Camera.DepthVisibility + Camera.CutDepth) * 255);
byte colorDegree = Convert.ToByte((1 - distanceFromCameraToPore / Camera.DepthVisibility) * 255);
e.Fill = new SolidColorBrush(Color.FromRgb(colorDegree, colorDegree, colorDegree));
e.Width = pore.Radius * 2 * Camera.Scale;
e.Height = pore.Radius * 2 * Camera.Scale;
e.Width = scaledPoreRadius * 2;
e.Height = scaledPoreRadius * 2;
}
else
{
e.Opacity = 0;
}
var x = Camera.Scale * pore.Point.X + Camera.StartPosition.X - e.Width / 2;
@ -109,62 +115,73 @@ namespace MODELING_DEF_DES_MI_VI.Modules.PoreInspectionUnit
private void OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.A:
ctSource.Cancel();
Camera.StartPosition.X -= Camera.Speed;
UpdateModel();
break;
case Key.D:
ctSource.Cancel();
Camera.StartPosition.X += Camera.Speed;
UpdateModel();
break;
case Key.W:
ctSource.Cancel();
Camera.StartPosition.Y -= Camera.Speed;
UpdateModel();
break;
case Key.S:
ctSource.Cancel();
Camera.StartPosition.Y += Camera.Speed;
UpdateModel();
break;
case Key.OemMinus:
ctSource.Cancel();
Camera.Scale /= 2;
UpdateModel();
break;
case Key.OemPlus:
ctSource.Cancel();
Camera.Scale *= 2;
UpdateModel();
break;
case Key.R:
ctSource.Cancel();
Camera.CutDepth += Camera.Speed;
UpdateModel();
break;
case Key.F:
ctSource.Cancel();
Camera.CutDepth -= Camera.Speed;
UpdateModel();
break;
case Key.D9:
if (Camera.Speed > 1)
{
ctSource.Cancel();
Camera.Speed--;
if (!IsBusy)
switch (e.Key)
{
case Key.A:
IsCanceled = true;
Camera.StartPosition.X -= Camera.Speed;
UpdateModel();
}
break;
case Key.D0:
ctSource.Cancel();
Camera.Speed++;
UpdateModel();
break;
}
break;
case Key.D:
IsCanceled = true;
Camera.StartPosition.X += Camera.Speed;
UpdateModel();
break;
case Key.W:
IsCanceled = true;
Camera.StartPosition.Y -= Camera.Speed;
UpdateModel();
break;
case Key.S:
IsCanceled = true;
Camera.StartPosition.Y += Camera.Speed;
UpdateModel();
break;
case Key.OemMinus:
IsCanceled = true;
Camera.Scale /= 2;
UpdateModel();
break;
case Key.OemPlus:
IsCanceled = true;
Camera.Scale *= 2;
UpdateModel();
break;
case Key.R:
IsCanceled = true;
Camera.CutDepth += Camera.Speed;
UpdateModel();
break;
case Key.F:
IsCanceled = true;
Camera.CutDepth -= Camera.Speed;
UpdateModel();
break;
case Key.D9:
if (Camera.Speed > 1)
{
IsCanceled = true;
Camera.Speed--;
UpdateModel();
}
break;
case Key.D0:
IsCanceled = true;
Camera.Speed++;
UpdateModel();
break;
case Key.T:
IsCanceled = true;
Camera.DepthVisibility -= Camera.Speed;
UpdateModel();
break;
case Key.G:
IsCanceled = true;
Camera.DepthVisibility += Camera.Speed;
UpdateModel();
break;
}
}
}
}

Loading…
Cancel
Save