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. --- .../ViewModels/ColorCalibrationViewVM.cs | 133 +++++++++------------ 1 file changed, 55 insertions(+), 78 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels') 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 - + } } -- cgit v1.3.1