aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML
diff options
context:
space:
mode:
authorRoy <roy.mail.net@gmail.com>2022-05-30 17:11:19 +0300
committerRoy <roy.mail.net@gmail.com>2022-05-30 17:11:19 +0300
commite645e84144f312c8b26832f0a356a006bd8c0c2a (patch)
tree3b35c305790eb6807301a5b9b5d9ddfd4a48b8da /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML
parent10eb841cf1535f7bbab097e7cf0a3fd0cf2282fa (diff)
downloadTango-e645e84144f312c8b26832f0a356a006bd8c0c2a.tar.gz
Tango-e645e84144f312c8b26832f0a356a006bd8c0c2a.zip
Merged MS batch conversion branch.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/BatchConversionCsvModelIn.cs16
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/BatchConversionCsvModelOut.cs88
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj2
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs236
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml7
5 files changed, 349 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/BatchConversionCsvModelIn.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/BatchConversionCsvModelIn.cs
new file mode 100644
index 000000000..7dfab5d5c
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/BatchConversionCsvModelIn.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.MachineStudio.RML.Models
+{
+ public class BatchConversionCsvModelIn
+ {
+ public string Index { get; set; }
+ public double L { get; set; }
+ public double A { get; set; }
+ public double B { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/BatchConversionCsvModelOut.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/BatchConversionCsvModelOut.cs
new file mode 100644
index 000000000..f4881ce00
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/BatchConversionCsvModelOut.cs
@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.MachineStudio.RML.Models
+{
+ public class BatchConversionCsvModelOut
+ {
+ public string Index { get; set; }
+ public double L { get; set; }
+ public double A { get; set; }
+ public double B { get; set; }
+
+ public double SuggestionL { get; set; }
+ public double SuggestionA { get; set; }
+ public double SuggestionB { get; set; }
+ public double SuggestionDeltaE { get; set; }
+
+ public double OutputL { get; set; }
+ public double OutputA { get; set; }
+ public double OutputB { get; set; }
+ public double OutputDeltaE { get; set; }
+
+ public double Cyan { get; set; }
+ public double Magenta { get; set; }
+ public double Yellow { get; set; }
+ public double Black { get; set; }
+
+ public double LightCyan { get; set; }
+ public double LightMagenta { get; set; }
+ public double LightYellow { get; set; }
+
+ public bool OutOfGamut { get; set; }
+
+ public static double MirtaDeltaE(double L1, double a1, double b1, double L2, double a2, double b2)
+ {
+ double h1 = Math.Atan2(b1, a1) * (180 / Math.PI);
+ if (h1 < 0)
+ h1 = h1 + 360;
+ double h2 = Math.Atan2(b2, a2) * (180 / Math.PI);
+ if (h2 < 0)
+ h2 = h2 + 360;
+ double refX_H = h1;
+ //chroma calculation
+ double refX_C = Math.Sqrt(a1 * a1 + b1 * b1);
+ //reference SL parameter
+ double refX_SL;
+ if (L1 <= 16)
+ refX_SL = 0.511;
+ else
+ refX_SL = L1 * 0.040975 / (1 + 0.01765 * L1);
+ //reference SC parameter
+ double refX_SC = (0.638 + 0.0638 * refX_C / (1 + 0.0131 * refX_C));
+ //reference CQ parameter
+ double refX_CQ = Math.Pow(refX_C, 4);
+ //reference F parameter
+ double refX_F = Math.Sqrt(refX_CQ / (refX_CQ + 1900));
+ // reference T parameter
+ double refX_T = 0;
+ if ((refX_H > 164) & (refX_H < 345))
+ refX_T = 0.56 + Math.Abs(0.2 * Math.Cos(Math.PI * (refX_H + 168) / 180));
+ else if ((refX_H >= 345) | (refX_H <= 164))
+ refX_T = 0.36 + Math.Abs(0.4 * Math.Cos(Math.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 = Math.Sqrt(a2 * a2 + b2 * b2);
+
+ double dL = L1 - L2;
+ double dC = samX_C - refX_C;
+ double da = a1 - a2;
+ double db = b1 - b2;
+ double dH = Math.Sqrt(Math.Max(da * da + db * db - dC * dC, 0.0));
+
+ double dECMC = Math.Sqrt(Math.Pow(dL / (2 * refX_SL), 2) + Math.Pow(dC / refX_SC, 2) + Math.Pow(dH / refX_SH, 2));
+ return dECMC;
+
+ }
+ }
+
+
+}
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 05e95ccfb..c8b778cc7 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
@@ -79,6 +79,8 @@
<Link>GlobalVersionInfo.cs</Link>
</Compile>
<Compile Include="Contracts\IMainView.cs" />
+ <Compile Include="Models\BatchConversionCsvModelIn.cs" />
+ <Compile Include="Models\BatchConversionCsvModelOut.cs" />
<Compile Include="Models\CalibrationMeasurementModel.cs" />
<Compile Include="Models\CctModel.cs" />
<Compile Include="Models\ColorLinearizationModel.cs" />
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 bde174f07..deb162687 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
@@ -25,6 +25,9 @@ using Tango.MachineStudio.Common.Authentication;
using Tango.BL.ActionLogs;
using Tango.BL.DTO;
using Tango.BL.Enumerations;
+using Google.Protobuf;
+using Tango.ColorConversion;
+using Tango.CSV;
namespace Tango.MachineStudio.RML.ViewModels
{
@@ -257,6 +260,8 @@ namespace Tango.MachineStudio.RML.ViewModels
/// </summary>
public RelayCommand RemoveSpoolCommand { get; set; }
+ public RelayCommand BatchConversionCommand { get; set; }
+
public MainViewVM(INotificationProvider notificationProvider, IAuthenticationProvider authentication, IActionLogManager actionLogManager)
{
_notification = notificationProvider;
@@ -283,6 +288,8 @@ namespace Tango.MachineStudio.RML.ViewModels
AddSpoolCommand = new RelayCommand(AddNewSpool);
RemoveSpoolCommand = new RelayCommand(RemoveSpool, () => SelectedSpool != null);
+
+ BatchConversionCommand = new RelayCommand(BatchConversion);
}
public override void OnApplicationReady()
@@ -916,6 +923,235 @@ namespace Tango.MachineStudio.RML.ViewModels
LoadRmls();
}
+ #region Batch Conversion
+
+ private void BatchConversion()
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Title = "Select CSV file with LAB data";
+ dlg.Filter = "CSV Files|*.csv";
+ if (!dlg.ShowDialogCenter())
+ {
+ return;
+ }
+
+ String fileName = dlg.FileName;
+
+ try
+ {
+ ConversionInput input = new ConversionInput();
+ input.ColorSpace = PMR.ColorLab.ColorSpace.Lab;
+ input.ForwardData = ByteString.CopyFrom(SelectedCCT.Data);
+
+ input.InputCoordinates = new InputCoordinates();
+
+ input.ThreadL = ActiveRML.WhitePointL;
+ input.ThreadA = ActiveRML.WhitePointA;
+ input.ThreadB = ActiveRML.WhitePointB;
+
+ input.UseLightInks = ActiveRML.UseLightInks;
+ input.VMax = ActiveRML.VMax;
+
+ //Validate calibration data
+ foreach (var vm in CalibrationDataViewVM.LiquidsCalibrationData.Where(x => x.LiquidType.HasPigment))
+ {
+ if (vm.CalibrationPoints.Count == 0)
+ {
+ InvokeUI(() =>
+ {
+ _notification.ShowError($"No calibration data for liquid '{vm.LiquidType.Name}'. Could not convert source color.");
+ });
+ return;
+ }
+ else if (!(vm.CalibrationPoints.First().X == 0 && vm.CalibrationPoints.First().Y == 0 && vm.CalibrationPoints.Last().X >= 100 && vm.CalibrationPoints.Last().Y >= 100))
+ {
+ InvokeUI(() =>
+ {
+ _notification.ShowError($"Invalid calibration data for liquid '{vm.LiquidType.Name}'. Could not convert source color.");
+ });
+ return;
+ }
+ }
+
+ foreach (var vm in CalibrationDataViewVM.LiquidsCalibrationData)
+ {
+ InputLiquid inputLiquid = new InputLiquid();
+
+
+ CalibrationData calData = new CalibrationData();
+ calData.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code;
+ calData.CalibrationPoints.AddRange(vm.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y }));
+
+ inputLiquid.CalibrationData = calData;
+
+ inputLiquid.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code;
+ inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.LiquidType.Code).MaxNlPerCm;
+
+ input.InputCoordinates.InputLiquids.Add(inputLiquid);
+ }
+
+ foreach (var process in ActiveRML.GetActiveProcessGroup().ProcessParametersTables)
+ {
+ input.ProcessRanges.Add(new ProcessRange()
+ {
+ MinInkUptake = process.MinInkUptake,
+ MaxInkUptake = process.MaxInkUptake,
+ });
+ }
+
+ input.GenerateHive = false;
+
+ IColorConverter converter = new DefaultColorConverter();
+
+ List<BatchConversionCsvModelIn> labList = CsvFile.Read<BatchConversionCsvModelIn>(new CsvSource(fileName)).ToList();
+
+ List<BatchConversionCsvModelOut> resultsList = new List<BatchConversionCsvModelOut>();
+
+ using (_notification.PushTaskItem("Converting..."))
+ {
+ foreach (var lab in labList)
+ {
+ input.InputCoordinates.L = lab.L;
+ input.InputCoordinates.A = lab.A;
+ input.InputCoordinates.B = lab.B;
+ input.ColorSpace = PMR.ColorLab.ColorSpace.Lab;
+ var output = converter.Convert(input, ActiveRML.ColorConversionVersion);
+
+ BatchConversionCsvModelOut result = new BatchConversionCsvModelOut();
+
+ result.Index = lab.Index;
+ result.L = lab.L;
+ result.A = lab.A;
+ result.B = lab.B;
+ result.SuggestionL = output.CreateSingleSuggestion().Coordinates.L;
+ result.SuggestionA = output.CreateSingleSuggestion().Coordinates.A;
+ result.SuggestionB = output.CreateSingleSuggestion().Coordinates.B;
+ var cyanVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.Cyan);
+
+ if (cyanVolume != null)
+ {
+ result.Cyan = cyanVolume.Volume;
+ }
+
+ var magentaVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.Magenta);
+
+ if (magentaVolume != null)
+ {
+ result.Magenta = magentaVolume.Volume;
+ }
+
+ var yellowVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.Yellow);
+
+ if (yellowVolume != null)
+ {
+ result.Yellow = yellowVolume.Volume;
+ }
+
+ var blackVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.Black);
+
+ if (blackVolume != null)
+ {
+ result.Black = blackVolume.Volume;
+ }
+
+ var lightCyanVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.LightCyan);
+
+ if (lightCyanVolume != null)
+ {
+ result.LightCyan = lightCyanVolume.Volume;
+ }
+
+ var lightMagentaVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.LightMagenta);
+
+ if (lightMagentaVolume != null)
+ {
+ result.LightMagenta = lightMagentaVolume.Volume;
+ }
+
+ var lightYellowVolume = output.CreateSingleSuggestion().Coordinates.OutputLiquids.FirstOrDefault(x => x.LiquidType == PMR.ColorLab.LiquidType.LightYellow);
+
+ if (lightYellowVolume != null)
+ {
+ result.LightYellow = lightYellowVolume.Volume;
+ }
+ foreach (var item in input.InputCoordinates.InputLiquids)
+ {
+ switch (item.LiquidType)
+ {
+ case PMR.ColorLab.LiquidType.Cyan:
+ item.Volume = result.Cyan;
+ break;
+ case PMR.ColorLab.LiquidType.Magenta:
+ item.Volume = result.Magenta;
+ break;
+ case PMR.ColorLab.LiquidType.Yellow:
+ item.Volume = result.Yellow;
+ break;
+ case PMR.ColorLab.LiquidType.Black:
+ item.Volume = result.Black;
+ break;
+ case PMR.ColorLab.LiquidType.TransparentInk:
+ break;
+ case PMR.ColorLab.LiquidType.Lubricant:
+ break;
+ case PMR.ColorLab.LiquidType.Cleaner:
+ break;
+ case PMR.ColorLab.LiquidType.LightCyan:
+ item.Volume = result.LightCyan;
+ break;
+ case PMR.ColorLab.LiquidType.LightMagenta:
+ item.Volume= result.LightMagenta;
+ break;
+ case PMR.ColorLab.LiquidType.LightYellow:
+ item.Volume = result.LightYellow;
+ break;
+ default:
+ break;
+ }
+ }
+
+ result.OutOfGamut = output.OutOfGamut;
+ input.ColorSpace = PMR.ColorLab.ColorSpace.Volume;
+ output = converter.Convert(input, ActiveRML.ColorConversionVersion);
+ result.OutputL = output.CreateSingleSuggestion().Coordinates.L;
+ result.OutputA = output.CreateSingleSuggestion().Coordinates.A;
+ result.OutputB = output.CreateSingleSuggestion().Coordinates.B;
+ result.SuggestionDeltaE = BatchConversionCsvModelOut.MirtaDeltaE(result.L, result.A, result.B, result.SuggestionL, result.SuggestionA, result.SuggestionB);
+ result.OutputDeltaE = BatchConversionCsvModelOut.MirtaDeltaE(result.L, result.A, result.B, result.OutputL, result.OutputA, result.OutputB);
+
+
+ resultsList.Add(result);
+ }
+ }
+
+ SaveFileDialog dlgOut = new SaveFileDialog();
+ dlgOut.Title = "Select results CSV file";
+ dlgOut.Filter = "CSV Files|*.csv";
+ dlgOut.FileName = Path.GetFileNameWithoutExtension(fileName) + " - Results";
+ dlgOut.DefaultExt = ".csv";
+ if (!dlgOut.ShowDialogCenter())
+ {
+ return;
+ }
+
+ using (CsvFile<BatchConversionCsvModelOut> outFile = new CsvFile<BatchConversionCsvModelOut>(new CsvDestination(dlgOut.FileName)))
+ {
+ foreach (var result in resultsList)
+ {
+ outFile.Append(result);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _notification.ShowError($"Error converting the selected file. Please check all data is valid.\n{ex.FlattenMessage()}");
+ }
+
+ _notification.ShowInfo("Batch Conversion Completed.");
+ }
+
+ #endregion
+
#region Import / Export Color Conversion Data
private void ImportCCTData()
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 6a5c4de9b..a9b943525 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
@@ -179,6 +179,13 @@
</Border.Effect>
<Grid>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Margin="20 0 0 0" FontSize="16">COLOR CONVERSION</TextBlock>
+
+ <Button ToolTip="Import LAB data from CSV and export the conversion results to a new CSV file" FontSize="11" Foreground="{StaticResource DarkGrayBrush200}" HorizontalAlignment="Right" Style="{StaticResource MaterialDesignFlatButton}" Height="Auto" VerticalAlignment="Bottom" Padding="0" Command="{Binding BatchConversionCommand}" Margin="0 0 5 0">
+ <StackPanel Orientation="Horizontal">
+ <materialDesign:PackIcon Kind="FolderMultipleOutline" Foreground="{StaticResource DimGrayBrush}" Width="16" Height="26" />
+ <TextBlock VerticalAlignment="Center" Margin="5 0 0 0">Batch Conversion</TextBlock>
+ </StackPanel>
+ </Button>
</Grid>
</Border>
<local:ColorConversionView x:Name="colorConversionView" Margin="0 0 0 0" Grid.Column="0" DataContext="{Binding ColorConversionViewVM}"/>