From 2405a27b29abf5382da56e67cc46cc338d2d0f89 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 20 Jul 2020 15:33:37 +0300 Subject: Refactored total liquid volume exceeds the max calc to nl/cm based. Fixed notes for New Environment. Applied possible fix for PPC power up message stuck. --- .../Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs index f583fa15e..d9ba419e0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorConversionViewVM.cs @@ -314,11 +314,11 @@ namespace Tango.MachineStudio.RML.ViewModels try { var tables = RML.GetActiveProcessGroup().ProcessParametersTables.OrderBy(x => x.TableIndex).ToList(); - return (tables[1].MaxInkUptake / tables[0].MaxInkUptake) * 100; + return tables.Max(x => x.MaxInkUptake); } catch { - return BrushStop.MAX_TOTAL_LIQUID_VOLUME; + return BrushStop.MAX_INK_UPTAKE; } } -- cgit v1.3.1 From 384ccdc90a77d1b099ace3245163f24883bd60ee Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Mon, 20 Jul 2020 16:48:12 +0300 Subject: New Linearization graph. Related Work Items: #2957 --- .../PMR/Messages/ColorLab/LinearizationInput.proto | 16 ++ .../ColorLab/LinearizationMeasurement.proto | 12 + .../Messages/ColorLab/LinearizationOutput.proto | 13 + .../ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp | 318 ++++++++++++++++++++- .../ColorLib/Tango.ColorLib_v4/ColorCalibrator.h | 31 +- .../ColorLib/Tango.ColorLib_v4/Exports.cpp | 6 + .../PMR/ColorLab/LinearizationInput.pb-c.c | 144 ++++++++++ .../PMR/ColorLab/LinearizationInput.pb-c.h | 82 ++++++ .../PMR/ColorLab/LinearizationMeasurement.pb-c.c | 131 +++++++++ .../PMR/ColorLab/LinearizationMeasurement.pb-c.h | 78 +++++ .../PMR/ColorLab/LinearizationOutput.pb-c.c | 119 ++++++++ .../PMR/ColorLab/LinearizationOutput.pb-c.h | 75 +++++ .../Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj | 6 + .../Tango.ColorLib_v4.vcxproj.filters | 18 ++ .../Models/ColorLinearizationModel.cs | 10 +- .../ViewModels/ColorCalibrationViewVM.cs | 143 ++++++--- .../Views/ColorCalibrationView.xaml | 278 +++++++++--------- .../Tango.MachineStudio.RML/Views/RmlView.xaml | 2 +- .../DefaultColorCalibrator.cs | 30 +- .../ILinearizationMeasurements.cs | 14 + .../Tango.ColorCalibration.csproj | 1 + .../Tango.PMR/ColorLab/LinearizationInput.cs | 268 +++++++++++++++++ .../Tango.PMR/ColorLab/LinearizationMeasurement.cs | 244 ++++++++++++++++ .../Tango.PMR/ColorLab/LinearizationOutput.cs | 209 ++++++++++++++ Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj | 5 +- 25 files changed, 2072 insertions(+), 181 deletions(-) create mode 100644 Software/PMR/Messages/ColorLab/LinearizationInput.proto create mode 100644 Software/PMR/Messages/ColorLab/LinearizationMeasurement.proto create mode 100644 Software/PMR/Messages/ColorLab/LinearizationOutput.proto create mode 100644 Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationInput.pb-c.c create mode 100644 Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationInput.pb-c.h create mode 100644 Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationMeasurement.pb-c.c create mode 100644 Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationMeasurement.pb-c.h create mode 100644 Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationOutput.pb-c.c create mode 100644 Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationOutput.pb-c.h create mode 100644 Software/Visual_Studio/Tango.ColorCalibration/ILinearizationMeasurements.cs create mode 100644 Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationInput.cs create mode 100644 Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationMeasurement.cs create mode 100644 Software/Visual_Studio/Tango.PMR/ColorLab/LinearizationOutput.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/PMR/Messages/ColorLab/LinearizationInput.proto b/Software/PMR/Messages/ColorLab/LinearizationInput.proto new file mode 100644 index 000000000..ff6ba489e --- /dev/null +++ b/Software/PMR/Messages/ColorLab/LinearizationInput.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +import "LinearizationMeasurement.proto"; +import "LiquidType.proto"; + +package Tango.PMR.ColorLab; +option java_package = "com.twine.tango.pmr.colorlab"; + +message LinearizationInput +{ + LiquidType LiquidType = 1; + double TargetL = 2; + double TargetA = 3; + double TargetB = 4; + repeated LinearizationMeasurement Measurements = 5; +} \ No newline at end of file diff --git a/Software/PMR/Messages/ColorLab/LinearizationMeasurement.proto b/Software/PMR/Messages/ColorLab/LinearizationMeasurement.proto new file mode 100644 index 000000000..57f5eb2f5 --- /dev/null +++ b/Software/PMR/Messages/ColorLab/LinearizationMeasurement.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package Tango.PMR.ColorLab; +option java_package = "com.twine.tango.pmr.colorlab"; + +message LinearizationMeasurement +{ + double InkPercentage = 1; + double L = 2; + double A = 3; + double B = 4; +} \ No newline at end of file diff --git a/Software/PMR/Messages/ColorLab/LinearizationOutput.proto b/Software/PMR/Messages/ColorLab/LinearizationOutput.proto new file mode 100644 index 000000000..ee043f6b4 --- /dev/null +++ b/Software/PMR/Messages/ColorLab/LinearizationOutput.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package Tango.PMR.ColorLab; +option java_package = "com.twine.tango.pmr.colorlab"; + +message LinearizationOutput +{ + repeated double InkPercentage = 1; + + + bool HasError = 20; + string ErrorMessage = 21; +} \ No newline at end of file diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp index a0e44c95c..9d51062c2 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp @@ -2,9 +2,14 @@ #include "CalibrationInput.pb-c.h" #include "CalibrationOutput.pb-c.h" #include "CalibrationMeasurement.pb-c.h" +#include "LinearizationInput.pb-c.h" +#include "LinearizationOutput.pb-c.h" +#include "LinearizationMeasurement.pb-c.h" + #include #include #include +#include using namespace std; #define MDRThr 1.0 @@ -13,7 +18,7 @@ using namespace std; #define dEThr 1.0 -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(): m_nsize(0), m_nlcm(NULL), m_LabData(NULL), m_inkChannel(0), m_targetVal(NULL), m_CalIndex(0), m_inkpercentage(NULL) { } @@ -42,6 +47,11 @@ void Tango::ColorLib::ColorCalibrator::ClearData() delete[] m_targetVal; m_targetVal = NULL; } + if (m_inkpercentage != NULL) + { + delete[] m_inkpercentage; + m_inkpercentage = NULL; + } } size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, size_t input_buffer_size, uint8_t *& output_buffer) @@ -99,6 +109,68 @@ size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, return size; } +size_t Tango::ColorLib::ColorCalibrator::GetLinearizationMeasurements(uint8_t * input_buffer, size_t input_buffer_size, uint8_t *& output_buffer) +{ + try + { + //Get Input + LinearizationInput* linearizationInput = (LinearizationInput*)malloc(sizeof(LinearizationInput)); + linearizationInput = linearization_input__unpack(NULL, input_buffer_size, input_buffer); + + //Investigate Input + LinearizationInitData((const LinearizationMeasurement**)linearizationInput->measurements, linearizationInput->n_measurements, linearizationInput->liquidtype, linearizationInput->targetl, linearizationInput->targeta, linearizationInput->targetb); + + //Init Output + LinearizationOutput *linearizationOutput = (LinearizationOutput*)malloc(sizeof(LinearizationOutput)); + linearization_output__init(linearizationOutput); + + std:string error_message; + linearizationOutput->n_inkpercentage = m_nsize; + linearizationOutput->inkpercentage = new double[m_nsize]; + Linearizaton(m_inkpercentage, linearizationOutput->inkpercentage, error_message); + const char* c_error = error_message.c_str(); + int nErrorLength = strlen(c_error); + if (nErrorLength > 0) + { + linearizationOutput->has_haserror = true; + linearizationOutput->haserror = true; + linearizationOutput->errormessage = (char*)malloc(nErrorLength); + for (int i = 0; i < nErrorLength; ++i) + linearizationOutput->errormessage[i] = c_error[i]; + + } + //Pack Output + output_buffer = (uint8_t*)malloc(linearization_output__get_packed_size(linearizationOutput)); + int size = linearization_output__pack(linearizationOutput, output_buffer); + + //Free Resources + linearization_input__free_unpacked(linearizationInput, NULL); + linearization_output__free_unpacked(linearizationOutput, NULL); + + return size; + } + catch (const std::exception& e) + { + //Notify Error... + LinearizationOutput *linearizationOutput = (LinearizationOutput*)malloc(sizeof(LinearizationOutput)); + linearization_output__init(linearizationOutput); + + linearizationOutput->has_haserror = true; + linearizationOutput->haserror = true; + + const char* what = e.what(); + int nWhat = strlen(what); + linearizationOutput->errormessage = (char*)malloc(nWhat); + for (int i = 0; i < nWhat; ++i) + linearizationOutput->errormessage[i] = what[i]; + + output_buffer = (uint8_t*)malloc(linearization_output__get_packed_size(linearizationOutput)); + int size = linearization_output__pack(linearizationOutput, output_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(); @@ -312,3 +384,247 @@ void Tango::ColorLib::ColorCalibrator::dEcmc(double *refX, double *samX, double dECMC = sqrt(pow(dL / (2 * refX_SL), 2) + pow(dC / refX_SC, 2) + pow(dH / refX_SH, 2)); } + +void Tango::ColorLib::ColorCalibrator::LinearizationInitData(const LinearizationMeasurement** 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_inkpercentage = 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_inkpercentage[i] = m[i]->inkpercentage; + + } + 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::Linearizaton(double *InkVals, double *&LinearInkVal, std::string &error) +{ + double maxVal = -1000; + double minVal = 1000; + double * yVal = new double[m_nsize]; + + for (int i = 0; i < m_nsize; ++i) + { + yVal[i] = m_LabData[i][m_CalIndex]; + } + bool res = SortValues(InkVals, yVal); + + if (CheckDuplicates(InkVals, error)) + return; + if (CheckLimits(InkVals, error)) + return; + + //Values are sorted and unique + SmoothCurveData(yVal, 3); + if (CheckMonotonicity(yVal, error)) + return; + //Values are monotonic, therefore can be inverted + int Kconst = 1; + if (yVal[0] > yVal[m_nsize - 1]) + Kconst = -1; + for (int i = 0; i < m_nsize; ++i) + { + yVal[i] *= Kconst; + } + + if (false == Linearize(yVal, LinearInkVal, error)) + { + return; + } +} +bool Tango::ColorLib::ColorCalibrator::SortValues(double *InkVals, double *yVal) +{ + //prepare data + std::vector IndVal; + + //fill up first vector pair + + double *tmpLab = new double[m_nsize]; + double *tmpInk = new double[m_nsize]; + int *tmpSort = new int[m_nsize]; + int *SortIndex = new int[m_nsize]; + //init index + IndVal.resize(m_nsize); + for (int i = 0; i < m_nsize; ++i) + { + IndVal[i].m_ID = i; + SortIndex[i] = i; + IndVal[i].m_val = m_inkpercentage[i]; + yVal[i] = m_LabData[i][m_CalIndex]; + } + + std::stable_sort(IndVal.begin(), IndVal.end(), ByDouble()); + //arrange all sorted values + for (int i = 0; i < m_nsize; ++i) + { + tmpLab[i] = yVal[IndVal[i].m_ID]; + tmpInk[i] = InkVals[IndVal[i].m_ID]; + tmpSort[i] = SortIndex[IndVal[i].m_ID]; + } + for (int i = 0; i < m_nsize; ++i) + { + yVal[i] = tmpLab[i]; + m_inkpercentage[i] = tmpInk[i]; + InkVals[i] = tmpInk[i]; + SortIndex[i] = tmpSort[i]; + } + if (tmpSort != NULL) + { + delete[] tmpSort; + tmpSort = NULL; + } + if (tmpLab != NULL) + { + delete[] tmpLab; + tmpLab = NULL; + } + if (tmpInk != NULL) + { + delete[] tmpInk; + tmpInk = NULL; + } + IndVal.resize(0); + return(true); +} +bool Tango::ColorLib::ColorCalibrator::CheckDuplicates(double *InkVals, std::string &error) +{ + double diff; + for (int i = 0; i < m_nsize - 1; ++i) + { + diff = InkVals[i + 1] - InkVals[i]; + if (diff == 0.0) + { + error = "Ink Percentages have to be unique"; + return true; + //throw std::exception("Ink Percentages have to be unique"); + } + + } + return false; +} + +bool Tango::ColorLib::ColorCalibrator::CheckLimits(double *InkVals, std::string &error) +{ + double maxVal = -1000.0; + double minVal = 1000.0; + for (int i = 0; i < m_nsize; ++i) + { + maxVal = fmax(maxVal, InkVals[i]); + minVal = fmin(minVal, InkVals[i]); + } + if (maxVal != 100.0) + { + error ="Maximal value has to be 100%"; + return true; + } + + if (minVal != 0.0) + { + error = "Minimal value has to be 0"; + return true; + } + return false; +} + +void Tango::ColorLib::ColorCalibrator::SmoothCurveData(double *YVal, int FilterWidth) +{ + int NumIter = max(FilterWidth, 3) - 2; + //Smooth the data with repeated applications of a[1 1 1] filter + double *tmpyVal = new double[m_nsize]; + for (int i = 0; i < NumIter; ++i) + { + for (int j = 0; j < m_nsize; ++j) + tmpyVal[j] = YVal[j]; + for (int j = 1; j < m_nsize - 1; ++j) + YVal[j] = (tmpyVal[j - 1] + tmpyVal[j] + tmpyVal[j + 1]) / 3; + } + delete[] tmpyVal; + tmpyVal = NULL; +} + +bool Tango::ColorLib::ColorCalibrator::CheckMonotonicity(double *yVal, std::string &error) +{ + //Check Monotonicity of Smooth Lab Channel + + double diff; + diff = yVal[m_nsize - 1] - yVal[0]; + int CF = 1; + if (diff < 0) + CF = -1; + + for (int i = 0; i < m_nsize - 1; ++i) + { + diff = CF * (yVal[i + 1] - yVal[i]); + if (diff <= 0.0) + { + error = "Non monotonic behavior, please remeasure"; + return true; + } + } + return false; +} +bool Tango::ColorLib::ColorCalibrator::Linearize(double *yVal, double*LinearInkVal, std::string &error) +{ + double Gain = (yVal[m_nsize - 1] - yVal[0]) / (m_inkpercentage[m_nsize - 1] - m_inkpercentage[0]); + double Offset = yVal[0] - Gain * m_inkpercentage[0]; + double *LabLinear = new double[m_nsize]; + for (int i = 0; i < m_nsize; i++) + LabLinear[i] = Gain * m_inkpercentage[i] + Offset; + double outVal = 0.0; + for (int i = 0; i < m_nsize; i++) + { + if (false == Interp1D(LabLinear, m_inkpercentage, yVal[i], outVal, error)) + return false; + LinearInkVal[i] = outVal; + } + return true; +} +bool Tango::ColorLib::ColorCalibrator::Interp1D(double* xx, double *yy, double InValue, double &OutValue, std::string &error) +{ + int m, ind; + int errType = 0; + + ind = -1; + + //Check Bounds + if ((InValue < xx[0] - epsTol) || (InValue > xx[m_nsize - 1] + epsTol)) + { + error = "Interp1D: In Value out of Bounds"; + return false; + } + + if ((InValue > xx[0] - epsTol) && (InValue < xx[0])) + InValue = xx[0]; + + if ((InValue > xx[m_nsize - 1]) && (InValue < xx[m_nsize - 1] + epsTol)) + InValue = xx[m_nsize - 1]; + + for (m = 0; m < m_nsize - 1; ++m) + { + if (xx[m] <= InValue && xx[m + 1] >= InValue) + { + ind = m; + break; + } + } + if (ind == -1) + { + error = "Could not find interpolation interval"; + return false; + } + OutValue = ((InValue - xx[m])*yy[m + 1] + (xx[m + 1] - InValue)*yy[m]) / (xx[m + 1] - xx[m]); +} diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h index 131241ccb..8d2ff664b 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h @@ -4,6 +4,7 @@ #include "CalibrationInput.pb-c.h" #include "CalibrationOutput.pb-c.h" #include "CalibrationMeasurement.pb-c.h" +#include "LinearizationMeasurement.pb-c.h" #pragma once @@ -17,11 +18,37 @@ namespace Tango ColorCalibrator(); ~ColorCalibrator(); size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, size_t input_buffer_size, uint8_t *& output_buffer); + size_t Tango::ColorLib::ColorCalibrator::GetLinearizationMeasurements(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 InitData(const CalibrationMeasurement** m, + const size_t &nsize, const int &inkChannel, const double& targetl, const double& targeta, const double& targetb); void MaximalDispensingRate(double &MDispRate, std::string &outputmessage); void dEcmc(double *refX, double *samX, double &dECMC); + void LinearizationInitData(const LinearizationMeasurement** m, + const size_t &nsize, const int &inkChannel, const double& targetl, const double& targeta, const double& targetb); + void Linearizaton(double *InkVals, double*& LinearInkVal, std::string &error); + bool SortValues(double *InkVals, double *yVal); + bool CheckLimits(double *InkVals, std::string &error); + void SmoothCurveData(double *YVal, int FilterWidth); + bool CheckMonotonicity(double *yVal, std::string &error); + bool CheckDuplicates(double *InkVals, std::string &error); + bool Linearize(double *yVal, double*LinearInkVal, std::string &error); + bool Interp1D(double* xx, double *yy, double InValue, double &OutValue, std::string &error); + + protected: + struct VectorPair + { + int m_ID; + double m_val; + }; + struct ByDouble : public std::binary_function + { + bool operator()(const VectorPair& lhs, const VectorPair& rhs) const + { + return lhs.m_val < rhs.m_val; + } + }; private: void ClearData(); @@ -32,6 +59,8 @@ namespace Tango int m_inkChannel; double *m_targetVal; int m_CalIndex; + + double *m_inkpercentage; }; } } diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Exports.cpp b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Exports.cpp index ed32be0b3..24e156640 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Exports.cpp +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Exports.cpp @@ -47,3 +47,9 @@ extern "C" EXPORT_API size_t __cdecl GenerateGradient(uint8_t* input_buffer, siz return converter.GenerateGradient(input_buffer, input_buffer_size, output_buffer); } +extern "C" EXPORT_API size_t __cdecl GetLinearizationMeasurements(uint8_t* input_buffer, size_t input_buffer_size, uint8_t*& output_buffer) +{ + ColorCalibrator calibrator; + return calibrator.GetLinearizationMeasurements(input_buffer, input_buffer_size, output_buffer); +} + diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationInput.pb-c.c b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationInput.pb-c.c new file mode 100644 index 000000000..5d30f6cd5 --- /dev/null +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationInput.pb-c.c @@ -0,0 +1,144 @@ +/* Generated by the protocol buffer compiler. DO NOT EDIT! */ +/* Generated from: LinearizationInput.proto */ + +/* Do not generate deprecated warnings for self */ +#ifndef PROTOBUF_C__NO_DEPRECATED +#define PROTOBUF_C__NO_DEPRECATED +#endif + +#include "LinearizationInput.pb-c.h" +void linearization_input__init + (LinearizationInput *message) +{ + static const LinearizationInput init_value = LINEARIZATION_INPUT__INIT; + *message = init_value; +} +size_t linearization_input__get_packed_size + (const LinearizationInput *message) +{ + assert(message->base.descriptor == &linearization_input__descriptor); + return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); +} +size_t linearization_input__pack + (const LinearizationInput *message, + uint8_t *out) +{ + assert(message->base.descriptor == &linearization_input__descriptor); + return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); +} +size_t linearization_input__pack_to_buffer + (const LinearizationInput *message, + ProtobufCBuffer *buffer) +{ + assert(message->base.descriptor == &linearization_input__descriptor); + return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); +} +LinearizationInput * + linearization_input__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) +{ + return (LinearizationInput *) + protobuf_c_message_unpack (&linearization_input__descriptor, + allocator, len, data); +} +void linearization_input__free_unpacked + (LinearizationInput *message, + ProtobufCAllocator *allocator) +{ + if(!message) + return; + assert(message->base.descriptor == &linearization_input__descriptor); + protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); +} +static const ProtobufCFieldDescriptor linearization_input__field_descriptors[5] = +{ + { + "LiquidType", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_ENUM, + offsetof(LinearizationInput, has_liquidtype), + offsetof(LinearizationInput, liquidtype), + &liquid_type__descriptor, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "TargetL", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_DOUBLE, + offsetof(LinearizationInput, has_targetl), + offsetof(LinearizationInput, targetl), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "TargetA", + 3, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_DOUBLE, + offsetof(LinearizationInput, has_targeta), + offsetof(LinearizationInput, targeta), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "TargetB", + 4, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_DOUBLE, + offsetof(LinearizationInput, has_targetb), + offsetof(LinearizationInput, targetb), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "Measurements", + 5, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_MESSAGE, + offsetof(LinearizationInput, n_measurements), + offsetof(LinearizationInput, measurements), + &linearization_measurement__descriptor, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned linearization_input__field_indices_by_name[] = { + 0, /* field[0] = LiquidType */ + 4, /* field[4] = Measurements */ + 2, /* field[2] = TargetA */ + 3, /* field[3] = TargetB */ + 1, /* field[1] = TargetL */ +}; +static const ProtobufCIntRange linearization_input__number_ranges[1 + 1] = +{ + { 1, 0 }, + { 0, 5 } +}; +const ProtobufCMessageDescriptor linearization_input__descriptor = +{ + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "LinearizationInput", + "LinearizationInput", + "LinearizationInput", + "", + sizeof(LinearizationInput), + 5, + linearization_input__field_descriptors, + linearization_input__field_indices_by_name, + 1, linearization_input__number_ranges, + (ProtobufCMessageInit) linearization_input__init, + NULL,NULL,NULL /* reserved[123] */ +}; diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationInput.pb-c.h b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationInput.pb-c.h new file mode 100644 index 000000000..9cab974c5 --- /dev/null +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationInput.pb-c.h @@ -0,0 +1,82 @@ +/* Generated by the protocol buffer compiler. DO NOT EDIT! */ +/* Generated from: LinearizationInput.proto */ + +#ifndef PROTOBUF_C_LinearizationInput_2eproto__INCLUDED +#define PROTOBUF_C_LinearizationInput_2eproto__INCLUDED + +#include + +PROTOBUF_C__BEGIN_DECLS + +#if PROTOBUF_C_VERSION_NUMBER < 1003000 +# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. +#elif 1003000 < PROTOBUF_C_MIN_COMPILER_VERSION +# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. +#endif + +#include "LinearizationMeasurement.pb-c.h" +#include "LiquidType.pb-c.h" + +typedef struct _LinearizationInput LinearizationInput; + + +/* --- enums --- */ + + +/* --- messages --- */ + +struct _LinearizationInput +{ + ProtobufCMessage base; + protobuf_c_boolean has_liquidtype; + LiquidType liquidtype; + protobuf_c_boolean has_targetl; + double targetl; + protobuf_c_boolean has_targeta; + double targeta; + protobuf_c_boolean has_targetb; + double targetb; + size_t n_measurements; + LinearizationMeasurement **measurements; +}; +#define LINEARIZATION_INPUT__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&linearization_input__descriptor) \ + , 0, LIQUID_TYPE__Cyan, 0, 0, 0, 0, 0, 0, 0,NULL } + + +/* LinearizationInput methods */ +void linearization_input__init + (LinearizationInput *message); +size_t linearization_input__get_packed_size + (const LinearizationInput *message); +size_t linearization_input__pack + (const LinearizationInput *message, + uint8_t *out); +size_t linearization_input__pack_to_buffer + (const LinearizationInput *message, + ProtobufCBuffer *buffer); +LinearizationInput * + linearization_input__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +void linearization_input__free_unpacked + (LinearizationInput *message, + ProtobufCAllocator *allocator); +/* --- per-message closures --- */ + +typedef void (*LinearizationInput_Closure) + (const LinearizationInput *message, + void *closure_data); + +/* --- services --- */ + + +/* --- descriptors --- */ + +extern const ProtobufCMessageDescriptor linearization_input__descriptor; + +PROTOBUF_C__END_DECLS + + +#endif /* PROTOBUF_C_LinearizationInput_2eproto__INCLUDED */ diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationMeasurement.pb-c.c b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationMeasurement.pb-c.c new file mode 100644 index 000000000..0a242ee0f --- /dev/null +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationMeasurement.pb-c.c @@ -0,0 +1,131 @@ +/* Generated by the protocol buffer compiler. DO NOT EDIT! */ +/* Generated from: LinearizationMeasurement.proto */ + +/* Do not generate deprecated warnings for self */ +#ifndef PROTOBUF_C__NO_DEPRECATED +#define PROTOBUF_C__NO_DEPRECATED +#endif + +#include "LinearizationMeasurement.pb-c.h" +void linearization_measurement__init + (LinearizationMeasurement *message) +{ + static const LinearizationMeasurement init_value = LINEARIZATION_MEASUREMENT__INIT; + *message = init_value; +} +size_t linearization_measurement__get_packed_size + (const LinearizationMeasurement *message) +{ + assert(message->base.descriptor == &linearization_measurement__descriptor); + return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); +} +size_t linearization_measurement__pack + (const LinearizationMeasurement *message, + uint8_t *out) +{ + assert(message->base.descriptor == &linearization_measurement__descriptor); + return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); +} +size_t linearization_measurement__pack_to_buffer + (const LinearizationMeasurement *message, + ProtobufCBuffer *buffer) +{ + assert(message->base.descriptor == &linearization_measurement__descriptor); + return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); +} +LinearizationMeasurement * + linearization_measurement__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) +{ + return (LinearizationMeasurement *) + protobuf_c_message_unpack (&linearization_measurement__descriptor, + allocator, len, data); +} +void linearization_measurement__free_unpacked + (LinearizationMeasurement *message, + ProtobufCAllocator *allocator) +{ + if(!message) + return; + assert(message->base.descriptor == &linearization_measurement__descriptor); + protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); +} +static const ProtobufCFieldDescriptor linearization_measurement__field_descriptors[4] = +{ + { + "InkPercentage", + 1, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_DOUBLE, + offsetof(LinearizationMeasurement, has_inkpercentage), + offsetof(LinearizationMeasurement, inkpercentage), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "L", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_DOUBLE, + offsetof(LinearizationMeasurement, has_l), + offsetof(LinearizationMeasurement, l), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "A", + 3, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_DOUBLE, + offsetof(LinearizationMeasurement, has_a), + offsetof(LinearizationMeasurement, a), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "B", + 4, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_DOUBLE, + offsetof(LinearizationMeasurement, has_b), + offsetof(LinearizationMeasurement, b), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned linearization_measurement__field_indices_by_name[] = { + 2, /* field[2] = A */ + 3, /* field[3] = B */ + 0, /* field[0] = InkPercentage */ + 1, /* field[1] = L */ +}; +static const ProtobufCIntRange linearization_measurement__number_ranges[1 + 1] = +{ + { 1, 0 }, + { 0, 4 } +}; +const ProtobufCMessageDescriptor linearization_measurement__descriptor = +{ + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "LinearizationMeasurement", + "LinearizationMeasurement", + "LinearizationMeasurement", + "", + sizeof(LinearizationMeasurement), + 4, + linearization_measurement__field_descriptors, + linearization_measurement__field_indices_by_name, + 1, linearization_measurement__number_ranges, + (ProtobufCMessageInit) linearization_measurement__init, + NULL,NULL,NULL /* reserved[123] */ +}; diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationMeasurement.pb-c.h b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationMeasurement.pb-c.h new file mode 100644 index 000000000..b4f17f87e --- /dev/null +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationMeasurement.pb-c.h @@ -0,0 +1,78 @@ +/* Generated by the protocol buffer compiler. DO NOT EDIT! */ +/* Generated from: LinearizationMeasurement.proto */ + +#ifndef PROTOBUF_C_LinearizationMeasurement_2eproto__INCLUDED +#define PROTOBUF_C_LinearizationMeasurement_2eproto__INCLUDED + +#include + +PROTOBUF_C__BEGIN_DECLS + +#if PROTOBUF_C_VERSION_NUMBER < 1003000 +# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. +#elif 1003000 < PROTOBUF_C_MIN_COMPILER_VERSION +# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. +#endif + + +typedef struct _LinearizationMeasurement LinearizationMeasurement; + + +/* --- enums --- */ + + +/* --- messages --- */ + +struct _LinearizationMeasurement +{ + ProtobufCMessage base; + protobuf_c_boolean has_inkpercentage; + double inkpercentage; + protobuf_c_boolean has_l; + double l; + protobuf_c_boolean has_a; + double a; + protobuf_c_boolean has_b; + double b; +}; +#define LINEARIZATION_MEASUREMENT__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&linearization_measurement__descriptor) \ + , 0, 0, 0, 0, 0, 0, 0, 0 } + + +/* LinearizationMeasurement methods */ +void linearization_measurement__init + (LinearizationMeasurement *message); +size_t linearization_measurement__get_packed_size + (const LinearizationMeasurement *message); +size_t linearization_measurement__pack + (const LinearizationMeasurement *message, + uint8_t *out); +size_t linearization_measurement__pack_to_buffer + (const LinearizationMeasurement *message, + ProtobufCBuffer *buffer); +LinearizationMeasurement * + linearization_measurement__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +void linearization_measurement__free_unpacked + (LinearizationMeasurement *message, + ProtobufCAllocator *allocator); +/* --- per-message closures --- */ + +typedef void (*LinearizationMeasurement_Closure) + (const LinearizationMeasurement *message, + void *closure_data); + +/* --- services --- */ + + +/* --- descriptors --- */ + +extern const ProtobufCMessageDescriptor linearization_measurement__descriptor; + +PROTOBUF_C__END_DECLS + + +#endif /* PROTOBUF_C_LinearizationMeasurement_2eproto__INCLUDED */ diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationOutput.pb-c.c b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationOutput.pb-c.c new file mode 100644 index 000000000..5bd04b218 --- /dev/null +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationOutput.pb-c.c @@ -0,0 +1,119 @@ +/* Generated by the protocol buffer compiler. DO NOT EDIT! */ +/* Generated from: LinearizationOutput.proto */ + +/* Do not generate deprecated warnings for self */ +#ifndef PROTOBUF_C__NO_DEPRECATED +#define PROTOBUF_C__NO_DEPRECATED +#endif + +#include "LinearizationOutput.pb-c.h" +void linearization_output__init + (LinearizationOutput *message) +{ + static const LinearizationOutput init_value = LINEARIZATION_OUTPUT__INIT; + *message = init_value; +} +size_t linearization_output__get_packed_size + (const LinearizationOutput *message) +{ + assert(message->base.descriptor == &linearization_output__descriptor); + return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); +} +size_t linearization_output__pack + (const LinearizationOutput *message, + uint8_t *out) +{ + assert(message->base.descriptor == &linearization_output__descriptor); + return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); +} +size_t linearization_output__pack_to_buffer + (const LinearizationOutput *message, + ProtobufCBuffer *buffer) +{ + assert(message->base.descriptor == &linearization_output__descriptor); + return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); +} +LinearizationOutput * + linearization_output__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) +{ + return (LinearizationOutput *) + protobuf_c_message_unpack (&linearization_output__descriptor, + allocator, len, data); +} +void linearization_output__free_unpacked + (LinearizationOutput *message, + ProtobufCAllocator *allocator) +{ + if(!message) + return; + assert(message->base.descriptor == &linearization_output__descriptor); + protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); +} +static const ProtobufCFieldDescriptor linearization_output__field_descriptors[3] = +{ + { + "InkPercentage", + 1, + PROTOBUF_C_LABEL_REPEATED, + PROTOBUF_C_TYPE_DOUBLE, + offsetof(LinearizationOutput, n_inkpercentage), + offsetof(LinearizationOutput, inkpercentage), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "HasError", + 20, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_BOOL, + offsetof(LinearizationOutput, has_haserror), + offsetof(LinearizationOutput, 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(LinearizationOutput, errormessage), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned linearization_output__field_indices_by_name[] = { + 2, /* field[2] = ErrorMessage */ + 1, /* field[1] = HasError */ + 0, /* field[0] = InkPercentage */ +}; +static const ProtobufCIntRange linearization_output__number_ranges[2 + 1] = +{ + { 1, 0 }, + { 20, 1 }, + { 0, 3 } +}; +const ProtobufCMessageDescriptor linearization_output__descriptor = +{ + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "LinearizationOutput", + "LinearizationOutput", + "LinearizationOutput", + "", + sizeof(LinearizationOutput), + 3, + linearization_output__field_descriptors, + linearization_output__field_indices_by_name, + 2, linearization_output__number_ranges, + (ProtobufCMessageInit) linearization_output__init, + NULL,NULL,NULL /* reserved[123] */ +}; diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationOutput.pb-c.h b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationOutput.pb-c.h new file mode 100644 index 000000000..b0ab54e12 --- /dev/null +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/PMR/ColorLab/LinearizationOutput.pb-c.h @@ -0,0 +1,75 @@ +/* Generated by the protocol buffer compiler. DO NOT EDIT! */ +/* Generated from: LinearizationOutput.proto */ + +#ifndef PROTOBUF_C_LinearizationOutput_2eproto__INCLUDED +#define PROTOBUF_C_LinearizationOutput_2eproto__INCLUDED + +#include + +PROTOBUF_C__BEGIN_DECLS + +#if PROTOBUF_C_VERSION_NUMBER < 1003000 +# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. +#elif 1003000 < PROTOBUF_C_MIN_COMPILER_VERSION +# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. +#endif + + +typedef struct _LinearizationOutput LinearizationOutput; + + +/* --- enums --- */ + + +/* --- messages --- */ + +struct _LinearizationOutput +{ + ProtobufCMessage base; + size_t n_inkpercentage; + double *inkpercentage; + protobuf_c_boolean has_haserror; + protobuf_c_boolean haserror; + char *errormessage; +}; +#define LINEARIZATION_OUTPUT__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&linearization_output__descriptor) \ + , 0,NULL, 0, 0, NULL } + + +/* LinearizationOutput methods */ +void linearization_output__init + (LinearizationOutput *message); +size_t linearization_output__get_packed_size + (const LinearizationOutput *message); +size_t linearization_output__pack + (const LinearizationOutput *message, + uint8_t *out); +size_t linearization_output__pack_to_buffer + (const LinearizationOutput *message, + ProtobufCBuffer *buffer); +LinearizationOutput * + linearization_output__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +void linearization_output__free_unpacked + (LinearizationOutput *message, + ProtobufCAllocator *allocator); +/* --- per-message closures --- */ + +typedef void (*LinearizationOutput_Closure) + (const LinearizationOutput *message, + void *closure_data); + +/* --- services --- */ + + +/* --- descriptors --- */ + +extern const ProtobufCMessageDescriptor linearization_output__descriptor; + +PROTOBUF_C__END_DECLS + + +#endif /* PROTOBUF_C_LinearizationOutput_2eproto__INCLUDED */ diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj index a0dc368bf..5c9365f84 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj @@ -178,6 +178,9 @@ + + + @@ -215,6 +218,9 @@ + + + diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj.filters b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj.filters index f78b6daee..3c6c1330d 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj.filters +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/Tango.ColorLib_v4.vcxproj.filters @@ -132,6 +132,15 @@ PMR + + PMR + + + PMR + + + PMR + @@ -230,5 +239,14 @@ PMR + + PMR + + + PMR + + + PMR + \ No newline at end of file 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 fe9ec7e37..8a24a9702 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 @@ -9,7 +9,7 @@ namespace Tango.MachineStudio.RML.Models { public class ColorLinearizationModel { - private class LinearizationDataItem + public class LinearizationDataItem { public double L { get; set; } public double A { get; set; } @@ -22,14 +22,10 @@ namespace Tango.MachineStudio.RML.Models } - public void GetDataFromFile(string fileName) + public void GetDataFromFile(string fileName, out List items) { - ExcelReader reader = new ExcelReader(fileName); - var items = reader.GetDataByIndex("Sheet1", 2); - foreach (var item in items) - { - } + items = reader.GetDataByIndex("Sheet1", 2); reader.Dispose(); } } 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 f118ce77a..d065b58c5 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 @@ -17,12 +17,14 @@ using Tango.PMR.ColorLab; using Tango.Logging; using Tango.MachineStudio.Common.Notifications; using System.Text.RegularExpressions; +using Microsoft.Win32; namespace Tango.MachineStudio.RML.ViewModels { public class ColorCalibrationViewVM : ExtendedObject { private IColorCalibrator _calibrator; + private ILinearizationMeasurements _linearizationMeasurementscalibrator; private INotificationProvider _notification; #region Properties @@ -41,15 +43,7 @@ namespace Tango.MachineStudio.RML.ViewModels get { return _liquidType; } 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 @@ -98,18 +92,14 @@ namespace Tango.MachineStudio.RML.ViewModels public RelayCommand CreateGraphCommand { get; set; } public RelayCommand CreateLinearizationGraphCommand { get; set; } + public RelayCommand ExportGraphCommand { get; set; } - public string CalibrationLiquidTypeName + public string LiquidTypeName { get { return LiquidType == null ?"" : LiquidType.Name; } } - - public string LinearizationLiquidTypeName - { - get { return SelectedLinearizationLiquidType == null ? "" : SelectedLinearizationLiquidType.Name; } - } - + public Plot PlotControl { get; set; } private IList _points; /// @@ -201,14 +191,17 @@ namespace Tango.MachineStudio.RML.ViewModels HasError = false; CreateGraphCommand = new RelayCommand(CreateGraph); CreateLinearizationGraphCommand = new RelayCommand(CreateLinearizationGraph); + ExportGraphCommand = new RelayCommand(ExportGraph); this.Points = new List(); TargetPoints = new List(); + LinearizationPoints = new List(); } public void Loading() { LiquidType = LiquidTypes.Count > 0 ? LiquidTypes[0] : null; _calibrator = new DefaultColorCalibrator(); + _linearizationMeasurementscalibrator = new DefaultColorCalibrator(); } @@ -281,33 +274,117 @@ namespace Tango.MachineStudio.RML.ViewModels #endregion #region CreateLinearizationGraph - private void CreateLinearizationGraph(object obj) + private async void CreateLinearizationGraph(object obj) { - if (_selectedLinearizationliquidType == null) + if (_liquidType == null ) return; - string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_selectedLinearizationliquidType.Type]; + string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type]; ColorLinearizationModel model = new ColorLinearizationModel(); - string fileName = @"C:\Test\Test Input Lineration.xlsx"; - model.GetDataFromFile(fileName); - //await Task.Factory.StartNew(() => - //{ - // Factor = GetLiquidFactor(); - //}); + string fileName = GetInkDataFileOpen();// @"C:\Test\Test Input Lineration.xlsx";//dialog to open file + if (fileName == null) + return; - LinearizationPoints.Clear(); - - Measurements.ToList().ForEach(x => { - LinearizationPoints.Add(new DataPoint(x.Ink, x.L)); + List items; + model.GetDataFromFile(fileName, out items); + if (items.Count == 0) + return; + + List outputPoints = new List(); + await Task.Factory.StartNew(() => + { + outputPoints = GetLinearizationMeasurements(items); }); - RaisePropertyChanged("To"); - RaisePropertyChanged("From"); - XStep = (int)(Points.Count / 6); + LinearizationPoints.Clear(); + + if (outputPoints == null || outputPoints.Count != items.Count) + return; + + foreach (var nw in items.Zip(outputPoints, Tuple.Create)) + { + LinearizationPoints.Add(new DataPoint(nw.Item1.InkPercentage, nw.Item2)); + } + LinearizationPlotControl.InvalidatePlot(true); } + private String GetInkDataFileOpen() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select Ink data file"; + dlg.Filter = "Excel |*.xlsx"; + if (dlg.ShowDialogCenter()) + { + return dlg.FileName; + } + + return null; + } + private List GetLinearizationMeasurements(List items) + { + try + { + LinearizationInput linearizationInput = new LinearizationInput(); + items.ForEach(x => linearizationInput.Measurements.Add(new LinearizationMeasurement { L = x.L, A = x.A, B = x.B, InkPercentage = x.InkPercentage })); + linearizationInput.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)) + { + linearizationInput.TargetL = lab.L; + linearizationInput.TargetA = lab.A; + linearizationInput.TargetB = lab.B; + } + LinearizationOutput result = _linearizationMeasurementscalibrator.GetLinearizationMeasurements(linearizationInput); + + ErrorMessage = Regex.Replace(result.ErrorMessage, "[^A-Za-z0-9_., ]+", ""); + + HasError = false == String.IsNullOrEmpty(ErrorMessage); + return result.InkPercentage.ToList(); + } + catch (Exception ex) + { + HasError = true; + ErrorMessage = "Error occurred while trying to call GetLiquidFactor."; + LogManager.Log(ex, "Error occurred while trying to call GetLiquidFactor."); + } + return null; + } + #endregion + + #region Export graph + + protected void ExportGraph() + { + SaveFileDialog dlg = new SaveFileDialog(); + try + { + dlg.Title = $"Export excel calibration file for {LiquidType.Name}"; + dlg.Filter = "Excel Files|*.xlsx"; + dlg.DefaultExt = ".xlsx"; + dlg.FileName = $"CData_{LiquidType.Name}_v{LiquidType.Version}.xlsx"; + if (dlg.ShowDialog().Value) + { + List points = new List(); + LinearizationPoints.ToList().ForEach(x=> points.Add(ToCalibrationPoint(x))); + BL.Calibration.CalibrationHelper.ExportCalibrationDataToExcel(points, dlg.FileName); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting excel file " + dlg.FileName); + _notification.ShowError("An error occurred while trying to export the calibration data."); + } + } + public CalibrationPoint ToCalibrationPoint(DataPoint point) + { + return new CalibrationPoint() + { + X = point.X, + Y = point.Y, + }; + } #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 32d467cba..291d335de 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 @@ -20,160 +20,166 @@ - - - - - - - Color Calibrations - - - - + + + Liquid Type: + + + - - + - - - - - - + + + + + + + LIQUID FACTOR + + + - - + + - - 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 fcce49aec07952eeb60cc6b33b90a8e493c85254 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Tue, 21 Jul 2020 16:37:15 +0300 Subject: Deleted unnecessary allocation memory, handle error message Related Work Items: #2957 --- .../ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp | 34 +++++++--------------- .../ViewModels/ColorCalibrationViewVM.cs | 29 +++++++++++------- 2 files changed, 29 insertions(+), 34 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp index 9d51062c2..82fb60ac4 100644 --- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp +++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp @@ -57,9 +57,7 @@ void Tango::ColorLib::ColorCalibrator::ClearData() size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, size_t input_buffer_size, uint8_t *& output_buffer) { //Get Input - CalibrationInput* calibrationInput = NULL; - calibrationInput = (CalibrationInput*)malloc(sizeof(CalibrationInput)); - calibrationInput = calibration_input__unpack(NULL, input_buffer_size, input_buffer); + CalibrationInput* calibrationInput = calibration_input__unpack(NULL, input_buffer_size, input_buffer); //Investigate Input InitData((const CalibrationMeasurement**)calibrationInput->measurements, calibrationInput->n_measurements, calibrationInput->liquidtype, calibrationInput->targetl, calibrationInput->targeta, calibrationInput->targetb); @@ -89,13 +87,9 @@ size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, std:string error_message; MaximalDispensingRate(calibrationOutput->liquidfactor, error_message); const char* c_error = error_message.c_str(); - int nErrorLength = strlen(c_error); - if (nErrorLength > 0) + if (strlen(c_error) > 0) { - calibrationOutput->errormessage = (char*)malloc(nErrorLength); - for (int i = 0; i < nErrorLength; ++i) - calibrationOutput->errormessage[i] = c_error[i]; - + calibrationOutput->errormessage = strdup(c_error); } //Pack Output @@ -111,12 +105,10 @@ size_t Tango::ColorLib::ColorCalibrator::GetLiquidFactor(uint8_t * input_buffer, size_t Tango::ColorLib::ColorCalibrator::GetLinearizationMeasurements(uint8_t * input_buffer, size_t input_buffer_size, uint8_t *& output_buffer) { + //Get Input + LinearizationInput* linearizationInput = linearization_input__unpack(NULL, input_buffer_size, input_buffer); try { - //Get Input - LinearizationInput* linearizationInput = (LinearizationInput*)malloc(sizeof(LinearizationInput)); - linearizationInput = linearization_input__unpack(NULL, input_buffer_size, input_buffer); - //Investigate Input LinearizationInitData((const LinearizationMeasurement**)linearizationInput->measurements, linearizationInput->n_measurements, linearizationInput->liquidtype, linearizationInput->targetl, linearizationInput->targeta, linearizationInput->targetb); @@ -129,15 +121,11 @@ size_t Tango::ColorLib::ColorCalibrator::GetLinearizationMeasurements(uint8_t * linearizationOutput->inkpercentage = new double[m_nsize]; Linearizaton(m_inkpercentage, linearizationOutput->inkpercentage, error_message); const char* c_error = error_message.c_str(); - int nErrorLength = strlen(c_error); - if (nErrorLength > 0) + if (strlen(c_error) > 0) { linearizationOutput->has_haserror = true; linearizationOutput->haserror = true; - linearizationOutput->errormessage = (char*)malloc(nErrorLength); - for (int i = 0; i < nErrorLength; ++i) - linearizationOutput->errormessage[i] = c_error[i]; - + linearizationOutput->errormessage = strdup(c_error); } //Pack Output output_buffer = (uint8_t*)malloc(linearization_output__get_packed_size(linearizationOutput)); @@ -159,13 +147,13 @@ size_t Tango::ColorLib::ColorCalibrator::GetLinearizationMeasurements(uint8_t * linearizationOutput->haserror = true; const char* what = e.what(); - int nWhat = strlen(what); - linearizationOutput->errormessage = (char*)malloc(nWhat); - for (int i = 0; i < nWhat; ++i) - linearizationOutput->errormessage[i] = what[i]; + linearizationOutput->errormessage = strdup(what); output_buffer = (uint8_t*)malloc(linearization_output__get_packed_size(linearizationOutput)); int size = linearization_output__pack(linearizationOutput, output_buffer); + //Free Resources + linearization_input__free_unpacked(linearizationInput, NULL); + linearization_output__free_unpacked(linearizationOutput, NULL); return (size); } 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 d065b58c5..7d05897d5 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 @@ -222,10 +222,10 @@ namespace Tango.MachineStudio.RML.ViewModels conversionInput.TargetB = lab.B; } CalibrationOutput result = _calibrator.GetLiquidFactor(conversionInput); - - ErrorMessage = Regex.Replace(result.ErrorMessage, "[^A-Za-z0-9_., ]+", ""); - + + ErrorMessage = result.ErrorMessage; HasError = false == String.IsNullOrEmpty(ErrorMessage); + return result.LiquidFactor; } catch (Exception ex ) @@ -309,6 +309,11 @@ namespace Tango.MachineStudio.RML.ViewModels LinearizationPlotControl.InvalidatePlot(true); } + + /// + /// Open file dialog and get name of file + /// + /// private String GetInkDataFileOpen() { OpenFileDialog dlg = new OpenFileDialog(); @@ -321,6 +326,7 @@ namespace Tango.MachineStudio.RML.ViewModels return null; } + private List GetLinearizationMeasurements(List items) { try @@ -338,23 +344,24 @@ namespace Tango.MachineStudio.RML.ViewModels } LinearizationOutput result = _linearizationMeasurementscalibrator.GetLinearizationMeasurements(linearizationInput); - ErrorMessage = Regex.Replace(result.ErrorMessage, "[^A-Za-z0-9_., ]+", ""); - - HasError = false == String.IsNullOrEmpty(ErrorMessage); + if(!String.IsNullOrEmpty(result.ErrorMessage)) + { + LogManager.Log(result.ErrorMessage, "Error occurred while trying to call GetLinearizationMeasurements."); + } return result.InkPercentage.ToList(); } catch (Exception ex) { - HasError = true; - ErrorMessage = "Error occurred while trying to call GetLiquidFactor."; - LogManager.Log(ex, "Error occurred while trying to call GetLiquidFactor."); + LogManager.Log(ex, "Error occurred while trying to call GetLinearizationMeasurements."); } return null; } #endregion - #region Export graph - + #region Export graph + /// + /// Exports the graph point to Excel file. + /// protected void ExportGraph() { SaveFileDialog dlg = new SaveFileDialog(); -- cgit v1.3.1