From 487fc03281c2dfde034e73ad99bd74ec4f63f69a Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 17 Jun 2020 14:43:46 +0300 Subject: RML color calibration. --- .../Tango.MachineStudio.RML.csproj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj index a413223c3..3e2dcc67c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj @@ -49,6 +49,12 @@ ..\..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + + ..\..\..\packages\OxyPlot.Core.2.0.0\lib\net45\OxyPlot.dll + + + ..\..\..\packages\OxyPlot.Wpf.2.0.0\lib\net45\OxyPlot.Wpf.dll + @@ -73,6 +79,7 @@ GlobalVersionInfo.cs + @@ -93,6 +100,7 @@ + @@ -103,6 +111,9 @@ CalibrationDataView.xaml + + ColorCalibrationView.xaml + ColorConversionView.xaml @@ -212,6 +223,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile -- cgit v1.3.1 From dd007b87b400427c02b57983ce3c1cce695bc960 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 17 Jun 2020 19:04:33 +0300 Subject: Color Calibration. Added calling Native method "GetLiquidFactor". --- .../ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp | 2 + .../Tango.MachineStudio.RML.csproj | 4 ++ .../ViewModels/ColorCalibrationViewVM.cs | 61 ++++++++++++++-------- 3 files changed, 46 insertions(+), 21 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj') diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp index f2c88f1cc..8d49acf74 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp @@ -20,6 +20,8 @@ size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, calibrationInput = (CalibrationInput*)malloc(sizeof(CalibrationInput)); calibrationInput = calibration_input__unpack(NULL, input_buffer_size, input_buffer); + //Call Mirta with input + //Init Output CalibrationOutput *calibrationOutput = (CalibrationOutput*)malloc(sizeof(CalibrationOutput)); calibration_output__init(calibrationOutput); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj index 3e2dcc67c..1f9d56f07 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj @@ -162,6 +162,10 @@ {40085232-aced-4cbe-945b-90ba8153c151} Tango.BrushPicker + + {b60c695c-61e8-4091-b506-4c45349c04aa} + Tango.ColorCalibration + {b4fe6485-4161-4b36-bc08-67e0b53d01b7} Tango.ColorConversion diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs index a6a2b3f7b..24867122e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs @@ -12,13 +12,14 @@ using Tango.SharedUI; using OxyPlot; using OxyPlot.Wpf; using OxyPlot.Annotations; - +using Tango.ColorCalibration; +using Tango.PMR.ColorLab; namespace Tango.MachineStudio.RML.ViewModels { public class ColorCalibrationViewVM : ExtendedObject { - + private IColorCalibrator _calibrator; #region Properties private Rml _rml; @@ -28,17 +29,17 @@ namespace Tango.MachineStudio.RML.ViewModels set { _rml = value; RaisePropertyChangedAuto(); } } - private LiquidType _liquidType; + private BL.Entities.LiquidType _liquidType; - public LiquidType LiquidType + public BL.Entities.LiquidType LiquidType { get { return _liquidType; } set { _liquidType = value; RaisePropertyChangedAuto(); } } - private List _liquidTypes; + private List _liquidTypes; - public List LiquidTypes + public List LiquidTypes { get { return _liquidTypes; } set { _liquidTypes = value; } @@ -154,27 +155,45 @@ namespace Tango.MachineStudio.RML.ViewModels public void Loading() { LiquidType = LiquidTypes.Count > 0 ? LiquidTypes[0] : null; + _calibrator = new DefaultColorCalibrator(); + } - private void CreateGraph(object obj) + private double GetLiquidFactor() + { + try{ + CalibrationInput conversionInput = new CalibrationInput(); + Measurements.ToList().ForEach(x => conversionInput.Measurements.Add(new CalibrationMeasurement{ L = x.L, A = x.A, B = x.B, NanoliterPerCentimeter = x.Ink })); + conversionInput.LiquidType = PMR.ColorLab.LiquidType.TryParse(_liquidType.Type.ToString(), out PMR.ColorLab.LiquidType outValue) ? outValue : PMR.ColorLab.LiquidType.Black; + + LAB lab; + if (ColorCalibrationExt.TargetLiquidTypeToLAB.TryGetValue(_liquidType.Type, out lab)) + { + conversionInput.TargetL = lab.L; + conversionInput.TargetA = lab.A; + conversionInput.TargetB = lab.B; + } + CalibrationOutput result = _calibrator.GetLiquidFactor(conversionInput); + return result.LiquidFactor; + } + catch (Exception ex ) + { + LogManager.Log(ex, "Error occurred while trying to call GetLiquidFactor."); + } + return 0.0; + } + + private async void CreateGraph(object obj) { if (_liquidType == null) return; LAB lab; - string color = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type]; - if( ColorCalibrationExt.TargetLiquidTypeToLAB.TryGetValue(_liquidType.Type, out lab)) + string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type]; + await Task.Factory.StartNew(() => { - var value = lab.GetType().GetProperty(color)?.GetValue(lab, null); - Factor = (double)value; - } - - - - //call color calibration function - //////////////////////// - /// - + Factor = GetLiquidFactor(); + }); Points.Clear(); TargetPoints.Clear(); @@ -186,8 +205,8 @@ namespace Tango.MachineStudio.RML.ViewModels Points.Add(new DataPoint(x.Ink, x.L)); TargetPoints.Add(new DataPoint(x.Ink,Factor)); }); - _to = color == "L"? 100 : 128; - _from = color == "L" ? 0 : -127; + _to = labType == "L"? 100 : 128; + _from = labType == "L" ? 0 : -127; RaisePropertyChanged("To"); RaisePropertyChanged("From"); -- cgit v1.3.1 From d5d9da51c01d7db8374d4bbf1f2416ae6f434347 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Tue, 30 Jun 2020 20:12:50 +0300 Subject: Color calibration. Changes in GUI. --- .../Models/ColorLinearizationModel.cs | 36 ++++++ .../Tango.MachineStudio.RML.csproj | 1 + .../ViewModels/ColorCalibrationViewVM.cs | 133 +++++++++------------ .../Views/ColorCalibrationView.xaml | 106 +++++++++++----- .../Views/ColorCalibrationView.xaml.cs | 1 + .../Visual_Studio/PPC/Tango.PPC.UI/app.manifest | 2 +- 6 files changed, 169 insertions(+), 110 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs new file mode 100644 index 000000000..fe9ec7e37 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Documents; + +namespace Tango.MachineStudio.RML.Models +{ + public class ColorLinearizationModel + { + private class LinearizationDataItem + { + public double L { get; set; } + public double A { get; set; } + public double B { get; set; } + public int InkPercentage { get; set; } + } + + public ColorLinearizationModel() + { + + } + + public void GetDataFromFile(string fileName) + { + + ExcelReader reader = new ExcelReader(fileName); + var items = reader.GetDataByIndex("Sheet1", 2); + foreach (var item in items) + { + } + reader.Dispose(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj index 1f9d56f07..145a0e06e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj @@ -81,6 +81,7 @@ + Code diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs index d44ef7a0c..f118ce77a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs @@ -42,6 +42,14 @@ namespace Tango.MachineStudio.RML.ViewModels set { _liquidType = value; RaisePropertyChangedAuto(); } } + private BL.Entities.LiquidType _selectedLinearizationliquidType; + + public BL.Entities.LiquidType SelectedLinearizationLiquidType + { + get { return _selectedLinearizationliquidType; } + set { _selectedLinearizationliquidType = value; RaisePropertyChangedAuto(); } + } + private List _liquidTypes; public List LiquidTypes @@ -89,13 +97,19 @@ namespace Tango.MachineStudio.RML.ViewModels } public RelayCommand CreateGraphCommand { get; set; } + public RelayCommand CreateLinearizationGraphCommand { get; set; } - - public string CalibrationType + + public string CalibrationLiquidTypeName { get { return LiquidType == null ?"" : LiquidType.Name; } } + public string LinearizationLiquidTypeName + { + get { return SelectedLinearizationLiquidType == null ? "" : SelectedLinearizationLiquidType.Name; } + } + public Plot PlotControl { get; set; } private IList _points; /// @@ -156,6 +170,22 @@ namespace Tango.MachineStudio.RML.ViewModels } } + + public Plot LinearizationPlotControl { get; set; } + private IList _linearizationPoints; + /// + /// Binding to ItemsSource of line chart. + /// + public IList LinearizationPoints + { + get { return _linearizationPoints; } + set + { + _linearizationPoints = value; + RaisePropertyChangedAuto(); + } + } + #endregion public ColorCalibrationViewVM(INotificationProvider notification) @@ -170,6 +200,7 @@ namespace Tango.MachineStudio.RML.ViewModels Factor = 0; HasError = false; CreateGraphCommand = new RelayCommand(CreateGraph); + CreateLinearizationGraphCommand = new RelayCommand(CreateLinearizationGraph); this.Points = new List(); TargetPoints = new List(); } @@ -245,92 +276,38 @@ namespace Tango.MachineStudio.RML.ViewModels RaisePropertyChanged("CalibrationType"); PlotControl.InvalidatePlot(true); - //await Task.Factory.StartNew(() => - //{ - // DataPoint ? intersectionpoints = FindIntersection(Points.ToArray(), TargetPoints.ToArray()); - // if(intersectionpoints == null) - // { - // InvokeUI(() => - // { - // _notification.ShowWarning(LogManager.Log($"No intersect target value with input values", LogCategory.Warning)); - // }); - // } - //}); - } #endregion + #region CreateLinearizationGraph - #region Intersect - - public DataPoint? FindIntersection(DataPoint[] line1, DataPoint[] line2) + private void CreateLinearizationGraph(object obj) { - for (int i = 0; i < line1.Length; i++) - { - int nextI = i; - nextI++; - if (nextI == line1.Length) break; + if (_selectedLinearizationliquidType == null) + return; - for (int j = 0; j < line2.Length; j++) - { - int nextJ = j; - nextJ++; - if (nextJ == line2.Length) break; - DataPoint? d = CheckIntersecting(line1[i], line1[nextI], line2[j], line2[nextJ]); - return d; + string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_selectedLinearizationliquidType.Type]; - } - } - return null; - } - - public DataPoint? CheckIntersecting(DataPoint A, DataPoint B, DataPoint C, DataPoint D) - { - // Line AB represented as a1x + b1y = c1 - double a1 = B.Y - A.Y; - double b1 = A.X - B.X; - double c1 = a1 * (A.X) + b1 * (A.Y); - - // Line CD represented as a2x + b2y = c2 - double a2 = D.Y - C.Y; - double b2 = C.X - D.X; - double c2 = a2 * (C.X) + b2 * (C.Y); + ColorLinearizationModel model = new ColorLinearizationModel(); + string fileName = @"C:\Test\Test Input Lineration.xlsx"; + model.GetDataFromFile(fileName); + //await Task.Factory.StartNew(() => + //{ + // Factor = GetLiquidFactor(); + //}); - double determinant = a1 * b2 - a2 * b1; + LinearizationPoints.Clear(); + + Measurements.ToList().ForEach(x => { + LinearizationPoints.Add(new DataPoint(x.Ink, x.L)); + }); - if (determinant == 0) - { - // The lines are parallel. This is simplified - } - else - { - double x = (b2 * c1 - b1 * c2) / determinant; - double y = (a1 * c2 - a2 * c1) / determinant; - - // check if the point lies on given line segment - /* To check if "x" is between "a" and "b"; - int m = (a+b)/2; - if(Math.abs(x-m) <= (Math.abs(a-m))) - { - } - */ - double mx1 = (A.X + B.X) / 2; - double mx2 = (C.X + D.X) / 2; - double my1 = (A.Y + B.Y) / 2; - double my2 = (C.Y + D.Y) / 2; - if (Math.Abs(x - mx1) <= Math.Abs(A.X - mx1) - && Math.Abs(x - mx2) <= Math.Abs(C.X - mx2) - && Math.Abs(y - my1) <= Math.Abs(A.Y - my1) - && Math.Abs(y - my2) <= Math.Abs(C.Y - my2)) - { - return new DataPoint(x, y); - } - - } - return null; + RaisePropertyChanged("To"); + RaisePropertyChanged("From"); + XStep = (int)(Points.Count / 6); + LinearizationPlotControl.InvalidatePlot(true); } - #endregion - + } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml index ffe3bf68e..de433b7e7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml @@ -36,26 +36,28 @@ - + - - + - - - Liquid Type + + + + + + + Liquid Type - + + - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml.cs new file mode 100644 index 000000000..96254c03a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.RML.Views +{ + /// + /// Interaction logic for RmlDeleteDialogView.xaml + /// + public partial class RmlDeleteDialogView : UserControl + { + public RmlDeleteDialogView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml index 7c7194554..777af7c52 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml @@ -18,7 +18,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml index 888f49d3f..c26fae591 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/MessageBoxWindow.xaml @@ -31,7 +31,7 @@ - + -- cgit v1.3.1