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. --- .../Models/CalibrationMeasurementModel.cs | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs new file mode 100644 index 000000000..74c6bba3e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.BL.Enumerations; +using Tango.PMR.Printing; + +namespace Tango.MachineStudio.RML.Models +{ + public static class ColorCalibrationExt + { + public static Dictionary TargetLiquidTypeToLAB = new Dictionary + { + {LiquidTypes.Cyan, new LAB(51.94591,-18.3438,-39.0577)}, + {LiquidTypes.Magenta, new LAB(47.46248, 65.84478, 3.922838)}, + {LiquidTypes.Yellow, new LAB(84.41956,-0.27005, 94.05445)}, + {LiquidTypes.Black, new LAB(26.57986, -0.13567, 0.948574)}, + }; + public static Dictionary DisplayLiquidTypeToLABType = new Dictionary + { + {LiquidTypes.Cyan, "L"}, + {LiquidTypes.Magenta, "L"}, + {LiquidTypes.Yellow, "B"}, + {LiquidTypes.Black, "L"}, + }; + }; + + public class LAB + { + public double L { get; set; } + public double A { get; set; } + public double B { get; set; } + + public LAB( double l, double a, double b) + { + L = l; B = b; A = a; + } + }; + + public class CalibrationMeasurementModel : ExtendedObject + { + #region properties + private int _l; + + public int L + { + get { return _l; } + set { _l = value; RaisePropertyChangedAuto(); } + } + + private int _a; + + public int A + { + get { return _a; } + set { _a = value; RaisePropertyChangedAuto(); } + } + + private int _b; + + public int B + { + get { return _b; } + set { _b = value; RaisePropertyChangedAuto(); } + } + + private int _ink; + + public int Ink + { + get { return _ink; } + set { _ink = value; RaisePropertyChangedAuto(); } + } + #endregion + + public CalibrationMeasurementModel() + { + _ink = 0; + L = 0; + A = 0; + B = 0; + } + } +} -- cgit v1.3.1 From bdce9ac6cda523781bae61e08587df974974ea98 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 21 Jun 2020 15:19:41 +0300 Subject: Color Calibrator . Added C++ functions. MaximalDispensingRate. --- .../ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp | 259 +++++++++++++++++++-- .../ColorLib/Tango.ColorLib_v4/ColorCalibrator.h | 18 ++ .../PMR/ColorLab/CalibrationOutput.pb-c.c | 37 ++- .../PMR/ColorLab/CalibrationOutput.pb-c.h | 5 +- .../Models/CalibrationMeasurementModel.cs | 21 +- .../ViewModels/ColorCalibrationViewVM.cs | 99 +++++++- .../ViewModels/MainViewVM.cs | 2 +- .../Views/ColorCalibrationView.xaml | 2 +- 8 files changed, 408 insertions(+), 35 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models') diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp index 8d49acf74..90c023060 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp @@ -2,15 +2,46 @@ #include "CalibrationInput.pb-c.h" #include "CalibrationOutput.pb-c.h" #include "CalibrationMeasurement.pb-c.h" +#include +#include +#include +using namespace std; +#define MDRThr 1.0 +#define epsTol 0.05 +#define PI 4*atan(1.0) +#define dEThr 1.0 -Tango::ColorLib::ColorCalibrator::ColorCalibrator() + +Tango::ColorLib::ColorCalibrator::ColorCalibrator(): m_nsize(0), m_nlcm(NULL), m_LabData(NULL), m_inkChannel(0), m_targetVal(NULL), m_CalIndex(0) { } -Tango::ColorLib::ColorCalibrator::~ColorCalibrator() +Tango::ColorLib::ColorCalibrator::~ColorCalibrator() { + ClearData(); +} + +void Tango::ColorLib::ColorCalibrator::ClearData() +{ + if (m_LabData != NULL) + { + for (int i = 0; i < m_nsize; ++i) + delete[] m_LabData[i]; + delete[] m_LabData; + m_LabData = NULL; + } + if (m_nlcm != NULL) + { + delete[] m_nlcm; + m_nlcm = NULL; + } + if (m_targetVal != NULL) + { + delete[] m_targetVal; + m_targetVal = NULL; + } } size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, size_t input_buffer_size, uint8_t *& output_buffer) @@ -21,27 +52,29 @@ size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, calibrationInput = calibration_input__unpack(NULL, input_buffer_size, input_buffer); //Call Mirta with input - + InitData((const CalibrationMeasurement**)calibrationInput->measurements, calibrationInput->n_measurements, calibrationInput->liquidtype, calibrationInput->targetl, calibrationInput->targeta, calibrationInput->targetb); + //Init Output CalibrationOutput *calibrationOutput = (CalibrationOutput*)malloc(sizeof(CalibrationOutput)); calibration_output__init(calibrationOutput); //Investigate Input - double targetL = calibrationInput->has_targetl; //Get Target LAB... + //double targetL = calibrationInput->has_targetl; //Get Target LAB... - for (size_t i = 0; i < calibrationInput->n_measurements; i++) //Iterate measurements... - { - CalibrationMeasurement* m = calibrationInput->measurements[i]; + //for (size_t i = 0; i < calibrationInput->n_measurements; i++) //Iterate measurements... + //{ + // CalibrationMeasurement* m = calibrationInput->measurements[i]; - m->nanoliterpercentimeter; //NL PER CM.. - m->l; //L - m->a; //A - m->b; //B - } + // m->nanoliterpercentimeter; //NL PER CM.. + // m->l; //L + // m->a; //A + // m->b; //B + //} //Set Output calibrationOutput->has_liquidfactor = true; - calibrationOutput->liquidfactor = 5.0; + MaximalDispensingRate(calibrationOutput->liquidfactor); + //calibrationOutput->liquidfactor = 5.0; //Pack Output output_buffer = (uint8_t*)malloc(calibration_output__get_packed_size(calibrationOutput)); @@ -53,3 +86,203 @@ size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, return size; } + +void Tango::ColorLib::ColorCalibrator::InitData(const CalibrationMeasurement** m, const size_t &nsize, const int &inkChannel, const double& targetl, const double& targeta, const double& targetb) +{ + ClearData(); + + m_nsize = nsize; + m_LabData = new double*[m_nsize]; + m_nlcm = new double[m_nsize]; + + for (int i = 0; i < m_nsize; ++i) + { + m_LabData[i] = new double[3]; + m_LabData[i][0] = m[i]->l; + m_LabData[i][1] = m[i]->a; + m_LabData[i][2] = m[i]->b; + m_nlcm[i] = m[i]->nanoliterpercentimeter; + + } + m_inkChannel = inkChannel; + m_targetVal = new double[3]; + m_targetVal[0] = targetl; + m_targetVal[1] = targeta; + m_targetVal[2] = targetb; + + int m_CalIndex = 0; + if (m_inkChannel == 2) + m_CalIndex = 2; +} +void Tango::ColorLib::ColorCalibrator::MaximalDispensingRate(double &MDispRate) +{ + MDispRate = -1000; + double *yVal = new double[m_nsize]; + + double maxVal = -1000; + double minVal = 1000; + int maxInd = -1; + int minInd = -1; + for (int i = 0; i < m_nsize; ++i) + { + yVal[i] = m_LabData[i][m_CalIndex]; + if (maxVal < yVal[i]) + { + maxVal = yVal[i]; + maxInd = i; + } + if (minVal > yVal[i]) + { + minVal = yVal[i]; + minInd = i; + } + } + if (maxVal - minVal < MDRThr) + { + delete[] yVal; + yVal = NULL; + throw std::exception("Maximal and Minimal Values are too close"); + } + + //increasing or decreasing + int KC = 0; + if (yVal[0] < yVal[m_nsize - 1]) + KC = 1; // increasing + else if (yVal[0] > yVal[m_nsize - 1]) + KC = -1; // decreasing + int indLab = 0; + if (m_inkChannel == 2) //Yellow + indLab = 2; + double dE = 0.0; + if ((m_targetVal[indLab] < minVal) | (m_targetVal[indLab] > maxVal)) + { + //Advice + if (KC == 1) + { + if (m_targetVal[indLab] < minVal) + { + //Increasing Function, dispensing rate above values + dEcmc(m_targetVal, m_LabData[minInd], dE); + if (dE < dEThr) + MDispRate = m_nlcm[minInd]; + else + { + if (yVal != NULL) + { + delete[] yVal; + yVal = NULL; + } + throw std::exception("Target Value does not fall in data interval,decrease dispensing rate"); + } + } + else if (m_targetVal[indLab] > maxVal) + { + //Increasing Function, dispensing rate below values + dEcmc(m_targetVal, m_LabData[maxInd], dE); + if (dE < dEThr) + MDispRate = m_nlcm[maxInd]; + else + { + if (yVal != NULL) + { + delete[] yVal; + yVal = NULL; + } + throw std::exception("Target Value does not fall in data interval,increase dispensing rate"); + } + } + } + else //decreasing //KC = -1 + { + if (m_targetVal[indLab] < minVal) + { + //decreasing Function, dispensing rate above values + dEcmc(m_targetVal, m_LabData[minInd], dE); + if (dE < dEThr) + MDispRate = m_nlcm[minInd]; + else + { + if (yVal != NULL) + { + delete[] yVal; + yVal = NULL; + } + throw std::exception("Target Value does not fall in data interval,increase dispensing rate"); + } + } + else if (m_targetVal[indLab] > maxVal) + { + //Increasing Function, dispensing rate below values + dEcmc(m_targetVal, m_LabData[maxInd], dE); + if (dE < dEThr) + MDispRate = m_nlcm[maxInd]; + else + throw std::exception("Target Value does not fall in data interval,decrease dispensing rate"); + } + } + } + else + { + for (int i = 0; i < m_nsize; ++i) + yVal[i] *= KC; + double targetVal = KC * m_targetVal[indLab]; + for (int i = 0; i < m_nsize - 1; ++i) + { + if ((yVal[i] <= targetVal) & (targetVal < yVal[i + 1])) + MDispRate = ((targetVal - yVal[i])*m_nlcm[i + 1] + (yVal[i + 1] - targetVal)*m_nlcm[i]) / (yVal[i + 1] - yVal[i]); + } + } + +} +void Tango::ColorLib::ColorCalibrator::dEcmc(double *refX, double *samX, double &dECMC) +{ + //dEcmc(refX, samX) calculates color difference CMC(2:1) in + //CIE - L*a*b* colorspace between references(refX) and + // samples(samX) + +// reference parameter calculations + // hue calculation + double h1 = atan2(refX[2], refX[1])*(180 / PI); + if (h1 < 0) + h1 = h1 + 360; + double h2 = atan2(samX[2], samX[1])*(180 / PI); + if (h2 < 0) + h2 = h2 + 360; + double refX_H = h1; + //chroma calculation + double refX_C = sqrt(refX[1] * refX[1] + refX[2] * refX[2]); + //reference SL parameter + double refX_SL; + if (refX[1] <= 16) + refX_SL = 0.511; + else + refX_SL = refX[1] * 0.040975 / (1 + 0.01765*refX[1]); + //reference SC parameter + double refX_SC = (0.638 + 0.0638*refX_C / (1 + 0.0131*refX_C)); + //reference CQ parameter + double refX_CQ = pow(refX_C, 4); + //reference F parameter + double refX_F = sqrt(refX_CQ / (refX_CQ + 1900)); + // reference T parameter + double refX_T = 0; + if ((refX_H > 164) & (refX_H < 345)) + refX_T = 0.56 + abs(0.2*cos(PI*(refX_H + 168) / 180)); + else if ((refX_H >= 345) | (refX_H <= 164)) + refX_T = 0.36 + abs(0.4*cos(PI*(refX_H + 35) / 180)); + // reference SH parameter + double refX_SH = refX_SC * (refX_T*refX_F + 1 - refX_F); + + //sample parameter calculations + //hue calculation + double samX_H = h2; + //chroma calculation + double samX_C = sqrt(samX[1] * samX[1] + samX[2] * samX[2]); + + double dL = refX[0] - samX[0]; + double dC = samX_C - refX_C; + double da = refX[1] - samX[1]; + double db = refX[2] - samX[2]; + double dH = sqrt(max(da*da + db * db - dC * dC, 0.0)); + + dECMC = sqrt(pow(dL / (2 * refX_SL), 2) + pow(dC / refX_SC, 2) + pow(dH / refX_SH, 2)); +} diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h index 652be03f1..711462e2a 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h @@ -1,5 +1,8 @@ #include #include +#include "CalibrationInput.pb-c.h" +#include "CalibrationOutput.pb-c.h" +#include "CalibrationMeasurement.pb-c.h" #pragma once @@ -13,6 +16,21 @@ namespace Tango ColorCalibrator(); ~ColorCalibrator(); size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, size_t input_buffer_size, uint8_t *& output_buffer); + protected: + void InitData(const CalibrationMeasurement** m, const size_t &nsize, const int &inkChannel, const double& targetl, const double& targeta, const double& targetb); + void MaximalDispensingRate(double &MDispRate); + void dEcmc(double *refX, double *samX, double &dECMC); + + private: + void ClearData(); + + private: + int m_nsize; + double *m_nlcm; + double **m_LabData; + int m_inkChannel; + double *m_targetVal; + int m_CalIndex; }; } } diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/CalibrationOutput.pb-c.c b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/CalibrationOutput.pb-c.c index ab79bc168..dca0c112b 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/CalibrationOutput.pb-c.c +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/CalibrationOutput.pb-c.c @@ -52,7 +52,7 @@ void calibration_output__free_unpacked assert(message->base.descriptor == &calibration_output__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } -static const ProtobufCFieldDescriptor calibration_output__field_descriptors[1] = +static const ProtobufCFieldDescriptor calibration_output__field_descriptors[3] = { { "LiquidFactor", @@ -66,14 +66,41 @@ static const ProtobufCFieldDescriptor calibration_output__field_descriptors[1] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "HasError", + 20, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_BOOL, + offsetof(CalibrationOutput, has_haserror), + offsetof(CalibrationOutput, haserror), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "ErrorMessage", + 21, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_STRING, + 0, /* quantifier_offset */ + offsetof(CalibrationOutput, errormessage), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned calibration_output__field_indices_by_name[] = { + 2, /* field[2] = ErrorMessage */ + 1, /* field[1] = HasError */ 0, /* field[0] = LiquidFactor */ }; -static const ProtobufCIntRange calibration_output__number_ranges[1 + 1] = +static const ProtobufCIntRange calibration_output__number_ranges[2 + 1] = { { 1, 0 }, - { 0, 1 } + { 20, 1 }, + { 0, 3 } }; const ProtobufCMessageDescriptor calibration_output__descriptor = { @@ -83,10 +110,10 @@ const ProtobufCMessageDescriptor calibration_output__descriptor = "CalibrationOutput", "", sizeof(CalibrationOutput), - 1, + 3, calibration_output__field_descriptors, calibration_output__field_indices_by_name, - 1, calibration_output__number_ranges, + 2, calibration_output__number_ranges, (ProtobufCMessageInit) calibration_output__init, NULL,NULL,NULL /* reserved[123] */ }; diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/CalibrationOutput.pb-c.h b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/CalibrationOutput.pb-c.h index 160f894db..c60f4f3c8 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/CalibrationOutput.pb-c.h +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/CalibrationOutput.pb-c.h @@ -28,10 +28,13 @@ struct _CalibrationOutput ProtobufCMessage base; protobuf_c_boolean has_liquidfactor; double liquidfactor; + protobuf_c_boolean has_haserror; + protobuf_c_boolean haserror; + char *errormessage; }; #define CALIBRATION_OUTPUT__INIT \ { PROTOBUF_C_MESSAGE_INIT (&calibration_output__descriptor) \ - , 0, 0 } + , 0, 0, 0, 0, NULL } /* CalibrationOutput methods */ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs index 74c6bba3e..87eba8ba2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs @@ -42,33 +42,33 @@ namespace Tango.MachineStudio.RML.Models public class CalibrationMeasurementModel : ExtendedObject { #region properties - private int _l; + private double _l; - public int L + public double L { get { return _l; } set { _l = value; RaisePropertyChangedAuto(); } } - private int _a; + private double _a; - public int A + public double A { get { return _a; } set { _a = value; RaisePropertyChangedAuto(); } } - private int _b; + private double _b; - public int B + public double B { get { return _b; } set { _b = value; RaisePropertyChangedAuto(); } } - private int _ink; + private double _ink; - public int Ink + public double Ink { get { return _ink; } set { _ink = value; RaisePropertyChangedAuto(); } @@ -77,10 +77,7 @@ namespace Tango.MachineStudio.RML.Models public CalibrationMeasurementModel() { - _ink = 0; - L = 0; - A = 0; - B = 0; + } } } 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..dd0c66c58 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,16 @@ using OxyPlot.Wpf; using OxyPlot.Annotations; using Tango.ColorCalibration; using Tango.PMR.ColorLab; +using Tango.Logging; +using Tango.MachineStudio.Common.Notifications; namespace Tango.MachineStudio.RML.ViewModels { public class ColorCalibrationViewVM : ExtendedObject { private IColorCalibrator _calibrator; + private INotificationProvider _notification; + #region Properties private Rml _rml; @@ -138,8 +142,9 @@ namespace Tango.MachineStudio.RML.ViewModels #endregion - public ColorCalibrationViewVM() + public ColorCalibrationViewVM(INotificationProvider notification) { + _notification = notification; Measurements = new ObservableCollection() { new CalibrationMeasurementModel(), @@ -165,7 +170,8 @@ namespace Tango.MachineStudio.RML.ViewModels 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)) { @@ -183,6 +189,8 @@ namespace Tango.MachineStudio.RML.ViewModels return 0.0; } + #region CreateGraph + private async void CreateGraph(object obj) { if (_liquidType == null) @@ -213,6 +221,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(), 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 815e7a5f9..02cef3c0d 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 @@ -106,7 +106,7 @@ - + -- 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/Models') 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 - + + - - - - - + - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - Factor: - - - - Warning: + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + Factor: + + + + + + + Warning: + + + - - - + + + + + + + + LINEARIZATION + + + - + - - - - - - - Liquid Type - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + - - + - - - + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml index 7d050a29a..152797bec 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml @@ -226,7 +226,7 @@ - + diff --git a/Software/Visual_Studio/Tango.ColorCalibration/DefaultColorCalibrator.cs b/Software/Visual_Studio/Tango.ColorCalibration/DefaultColorCalibrator.cs index 98a558f8e..98162dc78 100644 --- a/Software/Visual_Studio/Tango.ColorCalibration/DefaultColorCalibrator.cs +++ b/Software/Visual_Studio/Tango.ColorCalibration/DefaultColorCalibrator.cs @@ -11,7 +11,7 @@ using Tango.PMR.ColorLab; namespace Tango.ColorCalibration { - public class DefaultColorCalibrator : IColorCalibrator + public class DefaultColorCalibrator : IColorCalibrator, ILinearizationMeasurements { static class NativeMethods { @@ -52,5 +52,33 @@ namespace Tango.ColorCalibration return output; } + + public LinearizationOutput GetLinearizationMeasurements(LinearizationInput input) + { + String fileName = $"{AssemblyHelper.GetCurrentAssemblyFolder()}\\Tango.ColorLib_v4.dll"; + + if (!File.Exists(fileName)) + { + throw new FileNotFoundException($"Could not find color calibration library '{fileName}'."); + } + + IntPtr pDll = NativeMethods.LoadLibrary(fileName); + IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "GetLinearizationMeasurements"); + NativeMethodDelegate getLinearizationMeasurements = (NativeMethodDelegate)Marshal.GetDelegateForFunctionPointer( + pAddressOfFunctionToCall, + typeof(NativeMethodDelegate)); + + NativePMR nativePMR = new NativePMR(getLinearizationMeasurements); + LinearizationOutput output = nativePMR.Invoke(input); + + bool result = NativeMethods.FreeLibrary(pDll); + + if (output.HasError) + { + throw new ExternalException($"Linearization Measurements Error: {output.ErrorMessage}!"); + } + + return output; + } } } diff --git a/Software/Visual_Studio/Tango.ColorCalibration/ILinearizationMeasurements.cs b/Software/Visual_Studio/Tango.ColorCalibration/ILinearizationMeasurements.cs new file mode 100644 index 000000000..2966b104b --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorCalibration/ILinearizationMeasurements.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.ColorLab; + +namespace Tango.ColorCalibration +{ + public interface ILinearizationMeasurements + { + LinearizationOutput GetLinearizationMeasurements( LinearizationInput input); + } +} diff --git a/Software/Visual_Studio/Tango.ColorCalibration/Tango.ColorCalibration.csproj b/Software/Visual_Studio/Tango.ColorCalibration/Tango.ColorCalibration.csproj index fe90c9bc2..9e0e438af 100644 --- a/Software/Visual_Studio/Tango.ColorCalibration/Tango.ColorCalibration.csproj +++ b/Software/Visual_Studio/Tango.ColorCalibration/Tango.ColorCalibration.csproj @@ -43,6 +43,7 @@ + diff --git a/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationInput.cs b/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationInput.cs new file mode 100644 index 000000000..a127a8546 --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationInput.cs @@ -0,0 +1,268 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: LinearizationInput.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.ColorLab { + + /// Holder for reflection information generated from LinearizationInput.proto + public static partial class LinearizationInputReflection { + + #region Descriptor + /// File descriptor for LinearizationInput.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static LinearizationInputReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChhMaW5lYXJpemF0aW9uSW5wdXQucHJvdG8SElRhbmdvLlBNUi5Db2xvckxh", + "YhoeTGluZWFyaXphdGlvbk1lYXN1cmVtZW50LnByb3RvGhBMaXF1aWRUeXBl", + "LnByb3RvIr8BChJMaW5lYXJpemF0aW9uSW5wdXQSMgoKTGlxdWlkVHlwZRgB", + "IAEoDjIeLlRhbmdvLlBNUi5Db2xvckxhYi5MaXF1aWRUeXBlEg8KB1Rhcmdl", + "dEwYAiABKAESDwoHVGFyZ2V0QRgDIAEoARIPCgdUYXJnZXRCGAQgASgBEkIK", + "DE1lYXN1cmVtZW50cxgFIAMoCzIsLlRhbmdvLlBNUi5Db2xvckxhYi5MaW5l", + "YXJpemF0aW9uTWVhc3VyZW1lbnRCHgocY29tLnR3aW5lLnRhbmdvLnBtci5j", + "b2xvcmxhYmIGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::Tango.PMR.ColorLab.LinearizationMeasurementReflection.Descriptor, global::Tango.PMR.ColorLab.LiquidTypeReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.ColorLab.LinearizationInput), global::Tango.PMR.ColorLab.LinearizationInput.Parser, new[]{ "LiquidType", "TargetL", "TargetA", "TargetB", "Measurements" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class LinearizationInput : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new LinearizationInput()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.ColorLab.LinearizationInputReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationInput() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationInput(LinearizationInput other) : this() { + liquidType_ = other.liquidType_; + targetL_ = other.targetL_; + targetA_ = other.targetA_; + targetB_ = other.targetB_; + measurements_ = other.measurements_.Clone(); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationInput Clone() { + return new LinearizationInput(this); + } + + /// Field number for the "LiquidType" field. + public const int LiquidTypeFieldNumber = 1; + private global::Tango.PMR.ColorLab.LiquidType liquidType_ = 0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Tango.PMR.ColorLab.LiquidType LiquidType { + get { return liquidType_; } + set { + liquidType_ = value; + } + } + + /// Field number for the "TargetL" field. + public const int TargetLFieldNumber = 2; + private double targetL_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double TargetL { + get { return targetL_; } + set { + targetL_ = value; + } + } + + /// Field number for the "TargetA" field. + public const int TargetAFieldNumber = 3; + private double targetA_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double TargetA { + get { return targetA_; } + set { + targetA_ = value; + } + } + + /// Field number for the "TargetB" field. + public const int TargetBFieldNumber = 4; + private double targetB_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double TargetB { + get { return targetB_; } + set { + targetB_ = value; + } + } + + /// Field number for the "Measurements" field. + public const int MeasurementsFieldNumber = 5; + private static readonly pb::FieldCodec _repeated_measurements_codec + = pb::FieldCodec.ForMessage(42, global::Tango.PMR.ColorLab.LinearizationMeasurement.Parser); + private readonly pbc::RepeatedField measurements_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Measurements { + get { return measurements_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as LinearizationInput); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(LinearizationInput other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (LiquidType != other.LiquidType) return false; + if (TargetL != other.TargetL) return false; + if (TargetA != other.TargetA) return false; + if (TargetB != other.TargetB) return false; + if(!measurements_.Equals(other.measurements_)) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (LiquidType != 0) hash ^= LiquidType.GetHashCode(); + if (TargetL != 0D) hash ^= TargetL.GetHashCode(); + if (TargetA != 0D) hash ^= TargetA.GetHashCode(); + if (TargetB != 0D) hash ^= TargetB.GetHashCode(); + hash ^= measurements_.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (LiquidType != 0) { + output.WriteRawTag(8); + output.WriteEnum((int) LiquidType); + } + if (TargetL != 0D) { + output.WriteRawTag(17); + output.WriteDouble(TargetL); + } + if (TargetA != 0D) { + output.WriteRawTag(25); + output.WriteDouble(TargetA); + } + if (TargetB != 0D) { + output.WriteRawTag(33); + output.WriteDouble(TargetB); + } + measurements_.WriteTo(output, _repeated_measurements_codec); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (LiquidType != 0) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) LiquidType); + } + if (TargetL != 0D) { + size += 1 + 8; + } + if (TargetA != 0D) { + size += 1 + 8; + } + if (TargetB != 0D) { + size += 1 + 8; + } + size += measurements_.CalculateSize(_repeated_measurements_codec); + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(LinearizationInput other) { + if (other == null) { + return; + } + if (other.LiquidType != 0) { + LiquidType = other.LiquidType; + } + if (other.TargetL != 0D) { + TargetL = other.TargetL; + } + if (other.TargetA != 0D) { + TargetA = other.TargetA; + } + if (other.TargetB != 0D) { + TargetB = other.TargetB; + } + measurements_.Add(other.measurements_); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 8: { + liquidType_ = (global::Tango.PMR.ColorLab.LiquidType) input.ReadEnum(); + break; + } + case 17: { + TargetL = input.ReadDouble(); + break; + } + case 25: { + TargetA = input.ReadDouble(); + break; + } + case 33: { + TargetB = input.ReadDouble(); + break; + } + case 42: { + measurements_.AddEntriesFrom(input, _repeated_measurements_codec); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationMeasurement.cs b/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationMeasurement.cs new file mode 100644 index 000000000..fb83ca1c2 --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationMeasurement.cs @@ -0,0 +1,244 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: LinearizationMeasurement.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.ColorLab { + + /// Holder for reflection information generated from LinearizationMeasurement.proto + public static partial class LinearizationMeasurementReflection { + + #region Descriptor + /// File descriptor for LinearizationMeasurement.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static LinearizationMeasurementReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Ch5MaW5lYXJpemF0aW9uTWVhc3VyZW1lbnQucHJvdG8SElRhbmdvLlBNUi5D", + "b2xvckxhYiJSChhMaW5lYXJpemF0aW9uTWVhc3VyZW1lbnQSFQoNSW5rUGVy", + "Y2VudGFnZRgBIAEoARIJCgFMGAIgASgBEgkKAUEYAyABKAESCQoBQhgEIAEo", + "AUIeChxjb20udHdpbmUudGFuZ28ucG1yLmNvbG9ybGFiYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.ColorLab.LinearizationMeasurement), global::Tango.PMR.ColorLab.LinearizationMeasurement.Parser, new[]{ "InkPercentage", "L", "A", "B" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class LinearizationMeasurement : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new LinearizationMeasurement()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.ColorLab.LinearizationMeasurementReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationMeasurement() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationMeasurement(LinearizationMeasurement other) : this() { + inkPercentage_ = other.inkPercentage_; + l_ = other.l_; + a_ = other.a_; + b_ = other.b_; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationMeasurement Clone() { + return new LinearizationMeasurement(this); + } + + /// Field number for the "InkPercentage" field. + public const int InkPercentageFieldNumber = 1; + private double inkPercentage_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double InkPercentage { + get { return inkPercentage_; } + set { + inkPercentage_ = value; + } + } + + /// Field number for the "L" field. + public const int LFieldNumber = 2; + private double l_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double L { + get { return l_; } + set { + l_ = value; + } + } + + /// Field number for the "A" field. + public const int AFieldNumber = 3; + private double a_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double A { + get { return a_; } + set { + a_ = value; + } + } + + /// Field number for the "B" field. + public const int BFieldNumber = 4; + private double b_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double B { + get { return b_; } + set { + b_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as LinearizationMeasurement); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(LinearizationMeasurement other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (InkPercentage != other.InkPercentage) return false; + if (L != other.L) return false; + if (A != other.A) return false; + if (B != other.B) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (InkPercentage != 0D) hash ^= InkPercentage.GetHashCode(); + if (L != 0D) hash ^= L.GetHashCode(); + if (A != 0D) hash ^= A.GetHashCode(); + if (B != 0D) hash ^= B.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (InkPercentage != 0D) { + output.WriteRawTag(9); + output.WriteDouble(InkPercentage); + } + if (L != 0D) { + output.WriteRawTag(17); + output.WriteDouble(L); + } + if (A != 0D) { + output.WriteRawTag(25); + output.WriteDouble(A); + } + if (B != 0D) { + output.WriteRawTag(33); + output.WriteDouble(B); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (InkPercentage != 0D) { + size += 1 + 8; + } + if (L != 0D) { + size += 1 + 8; + } + if (A != 0D) { + size += 1 + 8; + } + if (B != 0D) { + size += 1 + 8; + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(LinearizationMeasurement other) { + if (other == null) { + return; + } + if (other.InkPercentage != 0D) { + InkPercentage = other.InkPercentage; + } + if (other.L != 0D) { + L = other.L; + } + if (other.A != 0D) { + A = other.A; + } + if (other.B != 0D) { + B = other.B; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 9: { + InkPercentage = input.ReadDouble(); + break; + } + case 17: { + L = input.ReadDouble(); + break; + } + case 25: { + A = input.ReadDouble(); + break; + } + case 33: { + B = input.ReadDouble(); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationOutput.cs b/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationOutput.cs new file mode 100644 index 000000000..3c402aa10 --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationOutput.cs @@ -0,0 +1,209 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: LinearizationOutput.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.ColorLab { + + /// Holder for reflection information generated from LinearizationOutput.proto + public static partial class LinearizationOutputReflection { + + #region Descriptor + /// File descriptor for LinearizationOutput.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static LinearizationOutputReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChlMaW5lYXJpemF0aW9uT3V0cHV0LnByb3RvEhJUYW5nby5QTVIuQ29sb3JM", + "YWIiVAoTTGluZWFyaXphdGlvbk91dHB1dBIVCg1JbmtQZXJjZW50YWdlGAEg", + "AygBEhAKCEhhc0Vycm9yGBQgASgIEhQKDEVycm9yTWVzc2FnZRgVIAEoCUIe", + "Chxjb20udHdpbmUudGFuZ28ucG1yLmNvbG9ybGFiYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.ColorLab.LinearizationOutput), global::Tango.PMR.ColorLab.LinearizationOutput.Parser, new[]{ "InkPercentage", "HasError", "ErrorMessage" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class LinearizationOutput : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new LinearizationOutput()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.ColorLab.LinearizationOutputReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationOutput() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationOutput(LinearizationOutput other) : this() { + inkPercentage_ = other.inkPercentage_.Clone(); + hasError_ = other.hasError_; + errorMessage_ = other.errorMessage_; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LinearizationOutput Clone() { + return new LinearizationOutput(this); + } + + /// Field number for the "InkPercentage" field. + public const int InkPercentageFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_inkPercentage_codec + = pb::FieldCodec.ForDouble(10); + private readonly pbc::RepeatedField inkPercentage_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField InkPercentage { + get { return inkPercentage_; } + } + + /// Field number for the "HasError" field. + public const int HasErrorFieldNumber = 20; + private bool hasError_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool HasError { + get { return hasError_; } + set { + hasError_ = value; + } + } + + /// Field number for the "ErrorMessage" field. + public const int ErrorMessageFieldNumber = 21; + private string errorMessage_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ErrorMessage { + get { return errorMessage_; } + set { + errorMessage_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as LinearizationOutput); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(LinearizationOutput other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!inkPercentage_.Equals(other.inkPercentage_)) return false; + if (HasError != other.HasError) return false; + if (ErrorMessage != other.ErrorMessage) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= inkPercentage_.GetHashCode(); + if (HasError != false) hash ^= HasError.GetHashCode(); + if (ErrorMessage.Length != 0) hash ^= ErrorMessage.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + inkPercentage_.WriteTo(output, _repeated_inkPercentage_codec); + if (HasError != false) { + output.WriteRawTag(160, 1); + output.WriteBool(HasError); + } + if (ErrorMessage.Length != 0) { + output.WriteRawTag(170, 1); + output.WriteString(ErrorMessage); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += inkPercentage_.CalculateSize(_repeated_inkPercentage_codec); + if (HasError != false) { + size += 2 + 1; + } + if (ErrorMessage.Length != 0) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(ErrorMessage); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(LinearizationOutput other) { + if (other == null) { + return; + } + inkPercentage_.Add(other.inkPercentage_); + if (other.HasError != false) { + HasError = other.HasError; + } + if (other.ErrorMessage.Length != 0) { + ErrorMessage = other.ErrorMessage; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: + case 9: { + inkPercentage_.AddEntriesFrom(input, _repeated_inkPercentage_codec); + break; + } + case 160: { + HasError = input.ReadBool(); + break; + } + case 170: { + ErrorMessage = input.ReadString(); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj index 048e92900..66c84cb0d 100644 --- a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj +++ b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj @@ -62,6 +62,9 @@ + + + @@ -461,7 +464,7 @@ - + \ No newline at end of file -- cgit v1.3.1 From f18636711f5cdf36f561dfe4da93335a08000877 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Thu, 23 Jul 2020 16:34:59 +0300 Subject: Color Calibration. Change order items in input Ink file of linearization. --- .../Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs | 2 +- .../Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models') 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 index 8a24a9702..53e15f976 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/ColorLinearizationModel.cs @@ -11,10 +11,10 @@ namespace Tango.MachineStudio.RML.Models { public class LinearizationDataItem { + public double InkPercentage { get; set; } public double L { get; set; } public double A { get; set; } public double B { get; set; } - public int InkPercentage { get; set; } } public ColorLinearizationModel() 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 291d335de..b9077d365 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 @@ -103,7 +103,7 @@ - + -- cgit v1.3.1 From 8e2e60ef069776aa6c3aab6a12e03ba1b228eea0 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 30 Aug 2020 10:54:09 +0300 Subject: Color Calibrations. Applied buttons to import data from file and save data in to the current RML calibration tables. Added shadow effect to popup search combobox. --- .../Models/CalibrationMeasurementModel.cs | 7 ++ .../ViewModels/CalibrationDataViewVM.cs | 10 +++ .../ViewModels/ColorCalibrationViewVM.cs | 44 ++++++++- .../Views/ColorCalibrationView.xaml | 100 +++++++++++---------- .../Resources/MaterialDesign.xaml | 25 +++--- 5 files changed, 129 insertions(+), 57 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs index 87eba8ba2..6345d5f59 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs @@ -79,5 +79,12 @@ namespace Tango.MachineStudio.RML.Models { } + public CalibrationMeasurementModel(Tango.MachineStudio.RML.Models.ColorLinearizationModel.LinearizationDataItem model) + { + L = model.L; + A = model.A; + B = model.B; + Ink = model.InkPercentage; + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs index b34ef83bc..fd69fef35 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/CalibrationDataViewVM.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Calibration; +using Tango.BL.Entities; using Tango.Core.Commands; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Notifications; @@ -106,5 +107,14 @@ namespace Tango.MachineStudio.RML.ViewModels _notification.ShowError("An error occurred while trying to export the calibration data."); } } + + public void ApplyCalibrationData(LiquidType liquidType, List newpoints) + { + CalibrationDataVM vm = LiquidsCalibrationData.FirstOrDefault(x => x.LiquidType == liquidType); + if(vm != null) + { + newpoints.ForEach(x => vm.CalibrationPoints.Add(x)); + } + } } } 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 4a6895df3..f7e93a4e6 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 @@ -89,10 +89,12 @@ namespace Tango.MachineStudio.RML.ViewModels get { return _hasError; } set { _hasError = value; RaisePropertyChangedAuto(); } } - + + public RelayCommand ImportDataCommand { get; set; } public RelayCommand CreateGraphCommand { get; set; } public RelayCommand CreateLinearizationGraphCommand { get; set; } public RelayCommand ExportGraphCommand { get; set; } + public RelayCommand ApplyCalibrationDataCommand { get; set; } public string LiquidTypeName @@ -189,9 +191,11 @@ namespace Tango.MachineStudio.RML.ViewModels }; Factor = 0; HasError = false; + ImportDataCommand = new RelayCommand(ImportDataForCalcFactorExcel); CreateGraphCommand = new RelayCommand(CreateGraph); CreateLinearizationGraphCommand = new RelayCommand(CreateLinearizationGraph); ExportGraphCommand = new RelayCommand(ExportGraph); + ApplyCalibrationDataCommand = new RelayCommand(ApplyCalibrationData); this.Points = new List(); TargetPoints = new List(); LinearizationPoints = new List(); @@ -236,7 +240,32 @@ namespace Tango.MachineStudio.RML.ViewModels } return 0.0; } + + private void ImportDataForCalcFactorExcel() + { + OpenFileDialog dlg = new OpenFileDialog(); + try + { + dlg.Title = $"Import excel file for calculate Factor"; + dlg.Filter = "Excel Files|*.xlsx"; + if (dlg.ShowDialog().Value) + { + List items;//List items + ColorLinearizationModel model = new ColorLinearizationModel(); + model.GetDataFromFile(dlg.FileName, out items); + if (items.Count == 0) + return; + Measurements.Clear(); + items.ForEach(x => Measurements.Add(new CalibrationMeasurementModel(x))); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error importing excel file " + dlg.FileName); + _notification.ShowError("An error occurred while trying to import the selected excel file. Please check the file format if valid and is available to read."); + } + } #region CreateGraph private async void CreateGraph(object obj) @@ -420,6 +449,19 @@ namespace Tango.MachineStudio.RML.ViewModels Y = point.Y, }; } + + /// + /// Applies the calibration data. + /// + protected void ApplyCalibrationData() + { + if (LinearizationPoints.Count == 0) + return; + + List points = new List(); + LinearizationPoints.ToList().ForEach(x => points.Add(new CalibrationDataPointVM(x.X, x.Y))); + ViewModelLocator.MainViewVM.CalibrationDataViewVM.ApplyCalibrationData(LiquidType, points); + } #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 b9077d365..d05959f9a 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 @@ -11,7 +11,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="450" d:DesignWidth="1200" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> @@ -52,50 +52,55 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -168,8 +173,11 @@ - +