diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-05-12 08:52:51 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-05-12 08:52:51 +0300 |
| commit | d66c5e376f12aff4cd69e09dbe629a5a069392cc (patch) | |
| tree | a4ef8062195249612d4353d8880991cb9666fc33 /Software/Visual_Studio | |
| parent | 04078aa1cce858187cd4c87fd1472b3c816597df (diff) | |
| download | Tango-d66c5e376f12aff4cd69e09dbe629a5a069392cc.tar.gz Tango-d66c5e376f12aff4cd69e09dbe629a5a069392cc.zip | |
Implemented About screens on TCC.
Implemented 2D and 3D card emulations on color capture module.
Diffstat (limited to 'Software/Visual_Studio')
14 files changed, 454 insertions, 84 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/CaptureMode.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/CaptureMode.cs new file mode 100644 index 000000000..389bff178 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/CaptureMode.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.ColorCapture +{ + public enum CaptureMode + { + Camera, + Emulated2D, + Emulated3D + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Contracts/IMainView.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Contracts/IMainView.cs new file mode 100644 index 000000000..3c0a5ecca --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Contracts/IMainView.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using Tango.SharedUI; + +namespace Tango.MachineStudio.ColorCapture.Contracts +{ + public interface IMainView : IView + { + void SetCardSource(BitmapSource source); + BitmapSource GetViewportImage(); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Converters/CaptureModeToVisibilityConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Converters/CaptureModeToVisibilityConverter.cs new file mode 100644 index 000000000..8a134eb35 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Converters/CaptureModeToVisibilityConverter.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace Tango.MachineStudio.ColorCapture.Converters +{ + public class CaptureModeToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var mode1 = (CaptureMode)value; + var mode2 = (CaptureMode)parameter; + return mode1 == mode2 ? Visibility.Visible : Visibility.Hidden; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj index a38db1b53..1c04917c0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Tango.MachineStudio.ColorCapture.csproj @@ -32,6 +32,15 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="AForge"> + <HintPath>..\..\..\Referenced Assemblies\AForge\AForge.dll</HintPath> + </Reference> + <Reference Include="AForge.Imaging"> + <HintPath>..\..\..\Referenced Assemblies\AForge\AForge.Imaging.dll</HintPath> + </Reference> + <Reference Include="AForge.Math"> + <HintPath>..\..\..\Referenced Assemblies\AForge\AForge.Math.dll</HintPath> + </Reference> <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> <HintPath>..\..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath> </Reference> @@ -41,6 +50,15 @@ <Reference Include="Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> <HintPath>..\..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll</HintPath> </Reference> + <Reference Include="HelixToolkit"> + <HintPath>..\..\..\Referenced Assemblies\Helix\HelixToolkit.dll</HintPath> + </Reference> + <Reference Include="HelixToolkit.Wpf"> + <HintPath>..\..\..\Referenced Assemblies\Helix\HelixToolkit.Wpf.dll</HintPath> + </Reference> + <Reference Include="HelixToolkit.Wpf.Input"> + <HintPath>..\..\..\Referenced Assemblies\Helix\HelixToolkit.Wpf.Input.dll</HintPath> + </Reference> <Reference Include="MahApps.Metro, Version=1.5.0.23, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL"> <HintPath>..\..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath> </Reference> @@ -96,10 +114,13 @@ <Compile Include="..\..\..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Compile Include="CaptureMode.cs" /> <Compile Include="ColorCaptureSettings.cs" /> <Compile Include="ColorCaptureModule.cs" /> + <Compile Include="Contracts\IMainView.cs" /> <Compile Include="Controls\ColorMatrixControl.cs" /> <Compile Include="Controls\IndexedUniformGrid.cs" /> + <Compile Include="Converters\CaptureModeToVisibilityConverter.cs" /> <Compile Include="Models\BenchmarkItem.cs" /> <Compile Include="Models\CaptureConfig.cs" /> <Compile Include="Models\CaptureItem.cs" /> @@ -150,6 +171,10 @@ <Project>{f441feee-322a-4943-b566-110e12fd3b72}</Project> <Name>Tango.BL</Name> </ProjectReference> + <ProjectReference Include="..\..\..\Tango.BrushPicker\Tango.BrushPicker.csproj"> + <Project>{40085232-aced-4cbe-945b-90ba8153c151}</Project> + <Name>Tango.BrushPicker</Name> + </ProjectReference> <ProjectReference Include="..\..\..\Tango.CircularGauge\Tango.CircularGauge.csproj"> <Project>{6efd5895-177b-4bbb-af52-29f4d53b3fbd}</Project> <Name>Tango.CircularGauge</Name> @@ -182,6 +207,10 @@ <Project>{9652f972-2bd1-4283-99cb-fc6240434c17}</Project> <Name>Tango.Video</Name> </ProjectReference> + <ProjectReference Include="..\..\..\Tango.Visuals\Tango.Visuals.csproj"> + <Project>{cf7c0ff4-9440-42cf-83b8-c060772792d4}</Project> + <Name>Tango.Visuals</Name> + </ProjectReference> <ProjectReference Include="..\..\..\TCC\Tango.TCC.BL\Tango.TCC.BL.csproj"> <Project>{f209fae8-73f9-441b-97f4-0844a0279390}</Project> <Name>Tango.TCC.BL</Name> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs index 2f8d421cd..38c86c297 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs @@ -1,4 +1,7 @@ -using ColorMine.ColorSpaces; +using AForge; +using AForge.Imaging.Filters; +using AForge.Math.Random; +using ColorMine.ColorSpaces; using ColorMine.ColorSpaces.Comparisons; using Microsoft.Win32; using Microsoft.WindowsAPICodePack.Dialogs; @@ -14,11 +17,15 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Windows.Media.Imaging; +using System.Windows.Threading; using Tango.Core; using Tango.Core.Commands; +using Tango.Core.Threading; using Tango.CSV; using Tango.Logging; +using Tango.MachineStudio.ColorCapture.Contracts; using Tango.MachineStudio.ColorCapture.Models; +using Tango.MachineStudio.ColorCapture.Views; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.Video; @@ -29,7 +36,7 @@ using Tango.Video.DirectCapture; namespace Tango.MachineStudio.ColorCapture.ViewModels { - public class MainViewVM : StudioViewModel + public class MainViewVM : StudioViewModel<IMainView> { private INotificationProvider _notification; private CardDetector _cardDetector; @@ -40,6 +47,8 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels private byte[] templateBitmap; private DeltaEComparisons _lastDeltaEComparison; private IColorSpaceComparison _deltaEComparison; + private ActionTimer _emulatedActionTimer; + private DispatcherTimer _timer3D; public IVideoCaptureProvider VideoProvider { get; set; } @@ -155,11 +164,11 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels set { _barcode = value; RaisePropertyChangedAuto(); } } - private bool _isEmulated; - public bool IsEmulated + private CaptureMode _captureMode; + public CaptureMode CaptureMode { - get { return _isEmulated; } - set { _isEmulated = value; RaisePropertyChangedAuto(); } + get { return _captureMode; } + set { _captureMode = value; RaisePropertyChangedAuto(); OnCaptureModeChanged(); } } private int emulatedR; @@ -183,6 +192,58 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels set { emulatedB = value; RaisePropertyChangedAuto(); OnEmulatedColorChanged(); } } + private Color _emulatedColor; + public Color EmulatedColor + { + get { return _emulatedColor; } + set + { + _emulatedColor = value; RaisePropertyChangedAuto(); + emulatedR = _emulatedColor.R; + emulatedG = _emulatedColor.G; + emulatedB = _emulatedColor.B; + RaisePropertyChanged(nameof(EmulatedR)); + RaisePropertyChanged(nameof(EmulatedG)); + RaisePropertyChanged(nameof(EmulatedB)); + OnEmulatedColorChanged(); + } + } + + private double _brightness; + public double Brightness + { + get { return _brightness; } + set { _brightness = value; RaisePropertyChangedAuto(); OnEmulatedColorChanged(); } + } + + private double _contrast; + public double Contrast + { + get { return _contrast; } + set { _contrast = value; RaisePropertyChangedAuto(); OnEmulatedColorChanged(); } + } + + private double _saturation; + public double Saturation + { + get { return _saturation; } + set { _saturation = value; RaisePropertyChangedAuto(); OnEmulatedColorChanged(); } + } + + private double _noise; + public double Noise + { + get { return _noise; } + set { _noise = value; RaisePropertyChangedAuto(); OnEmulatedColorChanged(); } + } + + private BitmapSource _emulatedImage; + public BitmapSource EmulatedImage + { + get { return _emulatedImage; } + set { _emulatedImage = value; RaisePropertyChangedAuto(); } + } + public RelayCommand ImportBenchmarksCommand { get; set; } public RelayCommand ExportBenchmarksCommand { get; set; } @@ -197,9 +258,7 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels public RelayCommand SelectTemplateFileCommand { get; set; } - public RelayCommand LiveCommand { get; set; } - - public RelayCommand EmulatedCommand { get; set; } + public RelayCommand<CaptureMode> CaptureModeCommand { get; set; } public MainViewVM() { @@ -223,8 +282,13 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels SelectSamplesFolderCommand = new RelayCommand(SelectSamplesFolder); SelectBenchmarksFileCommand = new RelayCommand(SelectBenchmarkFile); SelectTemplateFileCommand = new RelayCommand(SelectTemplateFile); - LiveCommand = new RelayCommand(() => IsEmulated = false); - EmulatedCommand = new RelayCommand(() => IsEmulated = true); + CaptureModeCommand = new RelayCommand<CaptureMode>((mode) => CaptureMode = mode); + _emulatedActionTimer = new ActionTimer(TimeSpan.FromMilliseconds(100)); + + _timer3D = new DispatcherTimer(); + _timer3D.Interval = TimeSpan.FromSeconds(1); + _timer3D.Tick += _timer3D_Tick; + _timer3D.Start(); } public MainViewVM(IVideoCaptureProvider videoProvider, INotificationProvider notificationProvider) : this() @@ -234,6 +298,14 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels SelectedVideoDevice = videoProvider.AvailableCaptureDevices.FirstOrDefault(); } + private void OnCaptureModeChanged() + { + if (CaptureMode == CaptureMode.Emulated2D || CaptureMode == CaptureMode.Emulated3D) + { + OnEmulatedColorChanged(); + } + } + private void SelectTemplateFile() { OpenFileDialog dlg = new OpenFileDialog(); @@ -445,7 +517,7 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels private void OnVideoFrameReceived(object sender, Video.DirectShow.EventArguments.FrameReceivedEventArgs args) { - if (_abort || IsPaused || IsEmulated) return; + if (_abort || IsPaused || CaptureMode != CaptureMode.Camera) return; PerformDetection(args.BitmapSource); } @@ -604,57 +676,106 @@ namespace Tango.MachineStudio.ColorCapture.ViewModels { if (EmulatedColors != null && EmulatedColors.Count > Config.TargetIndex) { + var colors = EmulatedColors.ToList(); + Color color = Color.FromRgb((byte)EmulatedR, (byte)EmulatedG, (byte)EmulatedB); - EmulatedColors[Config.TargetIndex] = color; + colors[Config.TargetIndex] = color; - if (IsEmulated) + if (CaptureMode == CaptureMode.Emulated2D) { - DetectionOutput output = new DetectionOutput(); - output.ColorMatrix.AddRange(EmulatedColors.Select(x => new DetectionColor() + _emulatedActionTimer.ResetReplace(() => { - R = x.R, - G = x.G, - B = x.B, - })); - output.ProcessedColor = new DetectionColor() - { - R = EmulatedR, - G = EmulatedG, - B = EmulatedB, - }; + DetectionOutput output = new DetectionOutput(); + output.ColorMatrix.AddRange(colors.ToList().Select(x => new DetectionColor() + { + R = x.R, + G = x.G, + B = x.B, + })); + output.ProcessedColor = new DetectionColor() + { + R = EmulatedR, + G = EmulatedG, + B = EmulatedB, + }; - var bitmap = ColorDetector.DetectionOutputToImage(new DetectionInput() - { - Columns = Config.Columns, - Rows = Config.Rows, - TargetIndex = Config.TargetIndex + var bitmap = ColorDetector.DetectionOutputToImage(new DetectionInput() + { + Columns = Config.Columns, + Rows = Config.Rows, + TargetIndex = Config.TargetIndex - }, output, Config.SampleWidth, Config.SampleHeight, true, true, false); + }, output, Config.SampleWidth, Config.SampleHeight, true, true, false); - float rectWidth = (bitmap.Width / Config.Columns) - 4; - float rectHeight = (bitmap.Height / Config.Rows) - 4; + bitmap = bitmap.ConvertTo24Bit(); - using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) - { - g.DrawImage(Properties.Resources.topleft, new System.Drawing.RectangleF(0, 0, rectWidth, rectHeight)); - g.DrawImage(Properties.Resources.topRight, new System.Drawing.RectangleF(bitmap.Width - rectWidth, 0, rectWidth, rectHeight)); + //Apply filters. - g.DrawImage(Properties.Resources.bottomLeft, new System.Drawing.RectangleF(0, bitmap.Height - rectHeight, rectWidth, rectHeight)); - g.DrawImage(Properties.Resources.bottomRight, new System.Drawing.RectangleF(bitmap.Width - rectWidth, bitmap.Height - rectHeight, rectWidth, rectHeight)); - } + if (Brightness != 0) + { + BrightnessCorrection brightness = new BrightnessCorrection((int)Brightness); + brightness.ApplyInPlace(bitmap); + } + if (Contrast > 0) + { + ContrastCorrection contrast = new ContrastCorrection((int)Contrast); + contrast.ApplyInPlace(bitmap); + } + if (Saturation != 0) + { + SaturationCorrection saturation = new SaturationCorrection((float)Saturation); + saturation.ApplyInPlace(bitmap); + } + if (Noise > 0) + { + IRandomNumberGenerator generator = new UniformGenerator(new Range((int)-Noise, (int)Noise)); + AdditiveNoise noise = new AdditiveNoise(generator); + noise.ApplyInPlace(bitmap); + } - var bitmapContainer = new System.Drawing.Bitmap(640, 480); - using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmapContainer)) - { - g.Clear(System.Drawing.Color.White); - g.DrawImageUnscaled(bitmap, (bitmapContainer.Width / 2) - bitmap.Width / 2, (bitmapContainer.Height / 2) - bitmap.Height / 2); - } - bitmap.Dispose(); + float rectWidth = (bitmap.Width / Config.Columns) - 4; + float rectHeight = (bitmap.Height / Config.Rows) - 4; + + using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) + { + g.DrawImage(Properties.Resources.topleft, new System.Drawing.RectangleF(0, 0, rectWidth, rectHeight)); + g.DrawImage(Properties.Resources.topRight, new System.Drawing.RectangleF(bitmap.Width - rectWidth, 0, rectWidth, rectHeight)); + + g.DrawImage(Properties.Resources.bottomLeft, new System.Drawing.RectangleF(0, bitmap.Height - rectHeight, rectWidth, rectHeight)); + g.DrawImage(Properties.Resources.bottomRight, new System.Drawing.RectangleF(bitmap.Width - rectWidth, bitmap.Height - rectHeight, rectWidth, rectHeight)); + } + + var bitmapContainer = new System.Drawing.Bitmap(640, 480); + using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmapContainer)) + { + g.Clear(System.Drawing.Color.White); + g.DrawImageUnscaled(bitmap, (bitmapContainer.Width / 2) - bitmap.Width / 2, (bitmapContainer.Height / 2) - bitmap.Height / 2); + } + + InvokeUI(() => + { + EmulatedImage = bitmap.ToBitmapSource(); + bitmap.Dispose(); + View.SetCardSource(EmulatedImage); + }); - PerformDetection(bitmapContainer.ToBitmapSource()); + PerformDetection(bitmapContainer.ToBitmapSource()); - bitmapContainer.Dispose(); + bitmapContainer.Dispose(); + }); + } + } + } + + private void _timer3D_Tick(object sender, EventArgs e) + { + if (CaptureMode == CaptureMode.Emulated3D) + { + if (EmulatedColors != null) + { + var source = View.GetViewportImage(); + PerformDetection(source); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml index 616bdcfed..e11ae3fa3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml @@ -8,13 +8,17 @@ xmlns:gauge="clr-namespace:Tango.CircularGauge;assembly=Tango.CircularGauge" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:vm="clr-namespace:Tango.MachineStudio.ColorCapture.ViewModels" + xmlns:visuals="clr-namespace:Tango.Visuals;assembly=Tango.Visuals" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" xmlns:controls="clr-namespace:Tango.MachineStudio.ColorCapture.Controls" + xmlns:localConverters="clr-namespace:Tango.MachineStudio.ColorCapture.Converters" xmlns:sharedControls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:tcc="clr-namespace:Tango.TCC.BL;assembly=Tango.TCC.BL" xmlns:realtimeGraphX="clr-namespace:RealTimeGraphX.WPF;assembly=RealTimeGraphX.WPF" xmlns:global="clr-namespace:Tango.MachineStudio.ColorCapture" + xmlns:helix="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" + xmlns:brushPicker="clr-namespace:Tango.BrushPicker;assembly=Tango.BrushPicker" xmlns:local="clr-namespace:Tango.MachineStudio.ColorCapture.Views" mc:Ignorable="d" d:DesignHeight="1080" d:DesignWidth="1920" Background="#202020" Foreground="#BBBBBB" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> @@ -39,6 +43,7 @@ <SolidColorBrush x:Key="LightBackground" Color="#303030" /> <converters:EnumToItemsSourceConverter x:Key="EnumToItemsSourceConverter" /> + <localConverters:CaptureModeToVisibilityConverter x:Key="CaptureModeToVisibilityConverter" /> </ResourceDictionary> </UserControl.Resources> @@ -165,7 +170,7 @@ </DockPanel> </Grid> - <Grid Visibility="{Binding IsEmulated,Converter={StaticResource BoolToVisConverter}}"> + <Grid Visibility="{Binding CaptureMode,Converter={StaticResource CaptureModeToVisibilityConverter},ConverterParameter={x:Static global:CaptureMode.Emulated2D}}"> <Grid.RowDefinitions> <RowDefinition Height="60"/> <RowDefinition Height="1*"/> @@ -177,33 +182,112 @@ <Grid Background="{StaticResource LightBackground}" Grid.Row="1" Margin="1"> <Border HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="1" BorderBrush="{StaticResource Accent}" Padding="20" Background="{StaticResource Background}"> - <StackPanel Orientation="Horizontal"> - <Border BorderThickness="1" BorderBrush="{StaticResource Accent}"> - <controls:ColorMatrixControl Colors="{Binding EmulatedColors,Mode=OneWay}" Width="200" Height="210" Columns="10" Rows="11" Background="{StaticResource LightBackground}" /> - </Border> + <StackPanel> + <StackPanel + Orientation="Horizontal"> + <Border BorderThickness="1" BorderBrush="{StaticResource Accent}" Width="200" Height="210"> + <!--<controls:ColorMatrixControl Colors="{Binding EmulatedColors,Mode=OneWay}" Columns="10" Rows="11" Background="{StaticResource LightBackground}" />--> + <Image Source="{Binding EmulatedImage}" Stretch="Fill" /> + </Border> - <UniformGrid Columns="3" Width="150" Height="200" Margin="40 0 0 0"> - <DockPanel> - <TextBlock Foreground="{StaticResource Red}" DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0 0 0 5" Text="{Binding EmulatedR,FallbackValue=0}"></TextBlock> - <TextBlock Foreground="{StaticResource Red}" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Margin="0 5 0 0">R</TextBlock> - <Slider Foreground="{StaticResource Red}" Orientation="Vertical" HorizontalAlignment="Center" Minimum="0" IsSnapToTickEnabled="True" TickFrequency="1" Maximum="255" Value="{Binding EmulatedR,Mode=TwoWay}"></Slider> - </DockPanel> - <DockPanel> - <TextBlock Foreground="{StaticResource Green}" DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0 0 0 5" Text="{Binding EmulatedG,FallbackValue=0}"></TextBlock> - <TextBlock Foreground="{StaticResource Green}" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Margin="0 5 0 0">G</TextBlock> - <Slider Foreground="{StaticResource Green}" Orientation="Vertical" HorizontalAlignment="Center" Minimum="0" IsSnapToTickEnabled="True" TickFrequency="1" Maximum="255" Value="{Binding EmulatedG,Mode=TwoWay}"></Slider> - </DockPanel> - <DockPanel> - <TextBlock Foreground="{StaticResource Blue}" DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0 0 0 5" Text="{Binding EmulatedB,FallbackValue=0}"></TextBlock> - <TextBlock Foreground="{StaticResource Blue}" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Margin="0 5 0 0">B</TextBlock> - <Slider Foreground="{StaticResource Blue}" Orientation="Vertical" HorizontalAlignment="Center" Minimum="0" IsSnapToTickEnabled="True" TickFrequency="1" Maximum="255" Value="{Binding EmulatedB,Mode=TwoWay}"></Slider> - </DockPanel> - </UniformGrid> + <UniformGrid Columns="3" Width="150" Height="200" Margin="40 0 0 0"> + <DockPanel> + <TextBlock Foreground="{StaticResource Red}" DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0 0 0 5" Text="{Binding EmulatedR,FallbackValue=0}"></TextBlock> + <TextBlock Foreground="{StaticResource Red}" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Margin="0 5 0 0">R</TextBlock> + <Slider Foreground="{StaticResource Red}" Orientation="Vertical" HorizontalAlignment="Center" Minimum="0" IsSnapToTickEnabled="True" TickFrequency="1" Maximum="255" Value="{Binding EmulatedR,Mode=TwoWay}"></Slider> + </DockPanel> + <DockPanel> + <TextBlock Foreground="{StaticResource Green}" DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0 0 0 5" Text="{Binding EmulatedG,FallbackValue=0}"></TextBlock> + <TextBlock Foreground="{StaticResource Green}" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Margin="0 5 0 0">G</TextBlock> + <Slider Foreground="{StaticResource Green}" Orientation="Vertical" HorizontalAlignment="Center" Minimum="0" IsSnapToTickEnabled="True" TickFrequency="1" Maximum="255" Value="{Binding EmulatedG,Mode=TwoWay}"></Slider> + </DockPanel> + <DockPanel> + <TextBlock Foreground="{StaticResource Blue}" DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0 0 0 5" Text="{Binding EmulatedB,FallbackValue=0}"></TextBlock> + <TextBlock Foreground="{StaticResource Blue}" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Margin="0 5 0 0">B</TextBlock> + <Slider Foreground="{StaticResource Blue}" Orientation="Vertical" HorizontalAlignment="Center" Minimum="0" IsSnapToTickEnabled="True" TickFrequency="1" Maximum="255" Value="{Binding EmulatedB,Mode=TwoWay}"></Slider> + </DockPanel> + </UniformGrid> + + <brushPicker:BrushPicker BrushTypeVisibility="Collapsed" Height="220" Margin="20 8 0 0" Width="240" Background="Transparent" BorderThickness="0" Color="{Binding EmulatedColor,Mode=TwoWay}" /> + </StackPanel> + + <UniformGrid Columns="4" Margin="0 10 0 0"> + <StackPanel> + <visuals:Knob x:Name="knobBrightness" ToolTip="{Binding Brightness}" PreviewMouseDoubleClick="OnResetBrightness" Value="{Binding Brightness,Mode=TwoWay}" Minimum="-100" Maximum="100" Width="80" TicksHeight="5" TicksHighlightBrush="{StaticResource Accent}" /> + <TextBlock HorizontalAlignment="Center" Margin="0 5 0 0">Brightness</TextBlock> + </StackPanel> + + <StackPanel> + <visuals:Knob x:Name="knobContrast" ToolTip="{Binding Contrast}" PreviewMouseDoubleClick="knobContrast_PreviewMouseDoubleClick" Value="{Binding Contrast,Mode=TwoWay}" Minimum="0" Maximum="100" Width="80" TicksHeight="5" TicksHighlightBrush="{StaticResource Accent}" /> + <TextBlock HorizontalAlignment="Center" Margin="0 5 0 0">Contrast</TextBlock> + </StackPanel> + <StackPanel> + <visuals:Knob x:Name="knobSaturation" ToolTip="{Binding Saturation}" PreviewMouseDoubleClick="knobSaturation_PreviewMouseDoubleClick" Value="{Binding Saturation,Mode=TwoWay}" Minimum="-1" Maximum="1" Width="80" TicksHeight="5" TicksHighlightBrush="{StaticResource Accent}" /> + <TextBlock HorizontalAlignment="Center" Margin="0 5 0 0">Saturation</TextBlock> + </StackPanel> + + <StackPanel> + <visuals:Knob x:Name="knobNoise" ToolTip="{Binding Noise}" PreviewMouseDoubleClick="knobNoise_PreviewMouseDoubleClick" Value="{Binding Noise,Mode=TwoWay}" Minimum="0" Maximum="100" Width="80" TicksHeight="5" TicksHighlightBrush="{StaticResource Accent}" /> + <TextBlock HorizontalAlignment="Center" Margin="0 5 0 0">Noise</TextBlock> + </StackPanel> + </UniformGrid> </StackPanel> </Border> </Grid> </Grid> + + <Grid Visibility="{Binding CaptureMode,Converter={StaticResource CaptureModeToVisibilityConverter},ConverterParameter={x:Static global:CaptureMode.Emulated3D}}"> + <Grid.RowDefinitions> + <RowDefinition Height="60"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + + <Grid Background="{StaticResource Background}"> + + </Grid> + + <Grid Grid.Row="1" Background="{StaticResource Background}" Margin="1"> + <helix:HelixViewport3D x:Name="viewport" ShowCoordinateSystem="True" ShowViewCube="False"> + <helix:DefaultLights ShowLights="True" /> + <helix:RectangleVisual3D DivWidth="30" DivLength="30"> + <helix:RectangleVisual3D.BackMaterial> + <DiffuseMaterial Brush="Gray"></DiffuseMaterial> + </helix:RectangleVisual3D.BackMaterial> + <helix:RectangleVisual3D.Material> + <MaterialGroup x:Name="material"> + <DiffuseMaterial> + <DiffuseMaterial.Brush> + <VisualBrush> + <VisualBrush.Visual> + <Border Padding="40" Background="White"> + <Image Stretch="Fill" /> + </Border> + </VisualBrush.Visual> + </VisualBrush> + </DiffuseMaterial.Brush> + </DiffuseMaterial> + <SpecularMaterial Brush="White" SpecularPower="30"></SpecularMaterial> + </MaterialGroup> + </helix:RectangleVisual3D.Material> + </helix:RectangleVisual3D> + </helix:HelixViewport3D> + + <Grid> + <UniformGrid Rows="4" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20"> + <StackPanel> + <visuals:Knob Minimum="-100" Maximum="100" Width="40" TicksHeight="2" TicksHighlightBrush="{StaticResource Accent}" /> + <TextBlock HorizontalAlignment="Center" Margin="0 5 0 0">Light</TextBlock> + </StackPanel> + + <StackPanel Margin="0 10 0 0"> + <visuals:Knob Minimum="0" Maximum="100" Width="40" TicksHeight="2" TicksHighlightBrush="{StaticResource Accent}" /> + <TextBlock HorizontalAlignment="Center" Margin="0 5 0 0">Spectural</TextBlock> + </StackPanel> + </UniformGrid> + </Grid> + </Grid> + </Grid> </Grid> </Border> @@ -496,15 +580,15 @@ </Grid> </Grid> - <UniformGrid VerticalAlignment="Top" HorizontalAlignment="Left" Width="200" Columns="2" Margin="300 -35 0 0"> - <Button Command="{Binding LiveCommand}" Height="35" Style="{StaticResource MaterialDesignFlatButton}" BorderThickness="0" Padding="5"> + <UniformGrid VerticalAlignment="Top" HorizontalAlignment="Left" Width="340" Columns="3" Margin="200 -35 0 0"> + <Button Command="{Binding CaptureModeCommand}" CommandParameter="{x:Static global:CaptureMode.Camera}" Height="35" Style="{StaticResource MaterialDesignFlatButton}" BorderThickness="0" Padding="5"> <StackPanel Orientation="Horizontal"> <StackPanel.Style> <Style TargetType="StackPanel"> - <Setter Property="TextElement.Foreground" Value="{StaticResource Accent}"></Setter> + <Setter Property="TextElement.Foreground" Value="#808080"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding IsEmulated}" Value="True"> - <Setter Property="TextElement.Foreground" Value="#808080"></Setter> + <DataTrigger Binding="{Binding CaptureMode}" Value="{x:Static global:CaptureMode.Camera}"> + <Setter Property="TextElement.Foreground" Value="{StaticResource Accent}"></Setter> </DataTrigger> </Style.Triggers> </Style> @@ -513,20 +597,36 @@ <TextBlock Margin="5 0 0 0">Camera</TextBlock> </StackPanel> </Button> - <Button Command="{Binding EmulatedCommand}" Height="35" Style="{StaticResource MaterialDesignFlatButton}" BorderThickness="0" Padding="5"> + <Button Command="{Binding CaptureModeCommand}" CommandParameter="{x:Static global:CaptureMode.Emulated2D}" Height="35" Style="{StaticResource MaterialDesignFlatButton}" BorderThickness="0" Padding="5"> <StackPanel Orientation="Horizontal"> <StackPanel.Style> <Style TargetType="StackPanel"> <Setter Property="TextElement.Foreground" Value="#808080"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding IsEmulated}" Value="True"> + <DataTrigger Binding="{Binding CaptureMode}" Value="{x:Static global:CaptureMode.Emulated2D}"> <Setter Property="TextElement.Foreground" Value="{StaticResource Accent}"></Setter> </DataTrigger> </Style.Triggers> </Style> </StackPanel.Style> <materialDesign:PackIcon Kind="Image" VerticalAlignment="Center" /> - <TextBlock Margin="5 0 0 0">Emulated</TextBlock> + <TextBlock Margin="5 0 0 0">Emulated 2D</TextBlock> + </StackPanel> + </Button> + <Button Command="{Binding CaptureModeCommand}" CommandParameter="{x:Static global:CaptureMode.Emulated3D}" Height="35" Style="{StaticResource MaterialDesignFlatButton}" BorderThickness="0" Padding="5"> + <StackPanel Orientation="Horizontal"> + <StackPanel.Style> + <Style TargetType="StackPanel"> + <Setter Property="TextElement.Foreground" Value="#808080"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding CaptureMode}" Value="{x:Static global:CaptureMode.Emulated3D}"> + <Setter Property="TextElement.Foreground" Value="{StaticResource Accent}"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </StackPanel.Style> + <materialDesign:PackIcon Kind="Cube" VerticalAlignment="Center" /> + <TextBlock Margin="5 0 0 0">Emulated 3D</TextBlock> </StackPanel> </Button> </UniformGrid> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml.cs index aa7ff5d49..0bd0efe31 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/Views/MainView.xaml.cs @@ -1,5 +1,7 @@ -using System; +using HelixToolkit.Wpf; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,8 +12,11 @@ using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; +using System.Windows.Media.Media3D; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.Core.DI; +using Tango.MachineStudio.ColorCapture.Contracts; using Tango.MachineStudio.ColorCapture.ViewModels; namespace Tango.MachineStudio.ColorCapture.Views @@ -19,17 +24,75 @@ namespace Tango.MachineStudio.ColorCapture.Views /// <summary> /// Interaction logic for MainView.xaml /// </summary> - public partial class MainView : UserControl + public partial class MainView : UserControl, IMainView { private MainViewVM _vm; public MainView() { InitializeComponent(); - Loaded += (_, __) => + Loaded += (_, __) => { _vm = DataContext as MainViewVM; + + //viewport.CameraController.ShowGridLines = true; }; + + viewport.RotateGesture = new MouseGesture(MouseAction.LeftClick); + viewport.PanGesture = new MouseGesture(MouseAction.LeftClick, ModifierKeys.Control); + viewport.ChangeFieldOfViewGesture = new MouseGesture(MouseAction.LeftClick, ModifierKeys.Shift); + + TangoIOC.Default.Register<IMainView>(this); + } + + private void OnResetBrightness(object sender, MouseButtonEventArgs e) + { + knobBrightness.Value = 0; + } + + private void knobContrast_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) + { + knobContrast.Value = 0; + } + + private void knobSaturation_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) + { + knobSaturation.Value = 0; + } + + private void knobNoise_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) + { + knobNoise.Value = 0; + } + + public void SetCardSource(BitmapSource source) + { + material.Children[0] = new DiffuseMaterial() + { + Brush = new VisualBrush() + { + Visual = new Border() + { + Padding = new Thickness(40), + Background = new SolidColorBrush(Colors.White), + Child = new Image() + { + Source = source, + Stretch = Stretch.Fill, + }, + }, + }, + }; + } + + public BitmapSource GetViewportImage() + { + MemoryStream ms = new MemoryStream(); + Viewport3DHelper.SaveBitmap(viewport.Viewport, ms, null, 1, BitmapExporter.OutputFormat.Bmp); + ms.Position = 0; + var source = ms.ToArray().ToBitmapSource(); + ms.Dispose(); + return source; } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj index 8a6c16067..b1e6c05da 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj @@ -192,7 +192,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.Imaging.dll b/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.Imaging.dll Binary files differnew file mode 100644 index 000000000..150e87d42 --- /dev/null +++ b/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.Imaging.dll diff --git a/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.Math.dll b/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.Math.dll Binary files differnew file mode 100644 index 000000000..bdc5e5ba6 --- /dev/null +++ b/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.Math.dll diff --git a/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.dll b/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.dll Binary files differnew file mode 100644 index 000000000..311cfe5a9 --- /dev/null +++ b/Software/Visual_Studio/Referenced Assemblies/AForge/AForge.dll diff --git a/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.Wpf.Input.dll b/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.Wpf.Input.dll Binary files differnew file mode 100644 index 000000000..c4e551b44 --- /dev/null +++ b/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.Wpf.Input.dll diff --git a/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.Wpf.dll b/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.Wpf.dll Binary files differnew file mode 100644 index 000000000..e270fe951 --- /dev/null +++ b/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.Wpf.dll diff --git a/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.dll b/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.dll Binary files differnew file mode 100644 index 000000000..47d5bab7d --- /dev/null +++ b/Software/Visual_Studio/Referenced Assemblies/Helix/HelixToolkit.dll |
