diff options
| author | Avi Levkovich <avi@twine-s.com> | 2020-06-23 09:42:30 +0300 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2020-06-23 09:42:30 +0300 |
| commit | 6138caa64d75f6580790095e1cdbbb00ed58d795 (patch) | |
| tree | bb8eccbc637d7e133ade69238ff64f790e2efdd9 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels | |
| parent | d215fe8f95a8522ff8ef915d5666087a2f271f2e (diff) | |
| parent | da3c540b1b9079a3357a7a9b7f37d07127ce0b09 (diff) | |
| download | Tango-6138caa64d75f6580790095e1cdbbb00ed58d795.tar.gz Tango-6138caa64d75f6580790095e1cdbbb00ed58d795.zip | |
merge conflicts
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels')
2 files changed, 137 insertions, 19 deletions
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 24867122e..d44ef7a0c 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 @@ -14,12 +14,17 @@ using OxyPlot.Wpf; using OxyPlot.Annotations; using Tango.ColorCalibration; using Tango.PMR.ColorLab; +using Tango.Logging; +using Tango.MachineStudio.Common.Notifications; +using System.Text.RegularExpressions; namespace Tango.MachineStudio.RML.ViewModels { public class ColorCalibrationViewVM : ExtendedObject { private IColorCalibrator _calibrator; + private INotificationProvider _notification; + #region Properties private Rml _rml; @@ -65,9 +70,24 @@ namespace Tango.MachineStudio.RML.ViewModels public double Factor { get { return _factor; } - set { _factor = value; } + set { _factor = value; RaisePropertyChangedAuto(); } + } + + private string _errorMessage; + + public string ErrorMessage + { + get { return _errorMessage; } + set { _errorMessage = value; RaisePropertyChangedAuto(); } } + private bool _hasError; + public bool HasError + { + get { return _hasError; } + set { _hasError = value; RaisePropertyChangedAuto(); } + } + public RelayCommand CreateGraphCommand { get; set; } @@ -138,8 +158,9 @@ namespace Tango.MachineStudio.RML.ViewModels #endregion - public ColorCalibrationViewVM() + public ColorCalibrationViewVM(INotificationProvider notification) { + _notification = notification; Measurements = new ObservableCollection<CalibrationMeasurementModel>() { new CalibrationMeasurementModel(), @@ -147,6 +168,7 @@ namespace Tango.MachineStudio.RML.ViewModels new CalibrationMeasurementModel(), }; Factor = 0; + HasError = false; CreateGraphCommand = new RelayCommand(CreateGraph); this.Points = new List<DataPoint>(); TargetPoints = new List<DataPoint>(); @@ -161,38 +183,47 @@ namespace Tango.MachineStudio.RML.ViewModels 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; + 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); + + ErrorMessage = Regex.Replace(result.ErrorMessage, "[^A-Za-z0-9_., ]+", ""); + + HasError = false == String.IsNullOrEmpty(ErrorMessage); + return result.LiquidFactor; } catch (Exception ex ) { + HasError = true; + ErrorMessage = "Error occurred while trying to call GetLiquidFactor."; LogManager.Log(ex, "Error occurred while trying to call GetLiquidFactor."); } return 0.0; } + #region CreateGraph + private async void CreateGraph(object obj) { if (_liquidType == null) return; - LAB lab; string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type]; await Task.Factory.StartNew(() => { - Factor = GetLiquidFactor(); + Factor = GetLiquidFactor( ); }); Points.Clear(); @@ -213,6 +244,93 @@ namespace Tango.MachineStudio.RML.ViewModels XStep = (int)(Points.Count / 6); 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 Intersect + + public DataPoint? FindIntersection(DataPoint[] line1, DataPoint[] line2) + { + for (int i = 0; i < line1.Length; i++) + { + int nextI = i; + nextI++; + if (nextI == line1.Length) break; + + 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; + + } + } + 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); + + double determinant = a1 * b2 - a2 * b1; + + 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; + } + + #endregion + } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs index 4939cbb48..36398a593 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs @@ -380,7 +380,7 @@ namespace Tango.MachineStudio.RML.ViewModels LiquidTypesRmls = LiquidTypesRmls, }; - ColorCalibrationVM = new ColorCalibrationViewVM() + ColorCalibrationVM = new ColorCalibrationViewVM(_notification) { RML = ActiveRML, LiquidTypes = LiquidTypesRmls.Where(x => x.LiquidType.HasPigment).ToList().Select(y => y.LiquidType).ToList(), |
