Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'UVtools.Core/Operations/OperationFlip.cs')
-rw-r--r--UVtools.Core/Operations/OperationFlip.cs64
1 files changed, 57 insertions, 7 deletions
diff --git a/UVtools.Core/Operations/OperationFlip.cs b/UVtools.Core/Operations/OperationFlip.cs
index 7a63814..5381d1b 100644
--- a/UVtools.Core/Operations/OperationFlip.cs
+++ b/UVtools.Core/Operations/OperationFlip.cs
@@ -7,16 +7,22 @@
*/
using System;
+using System.Threading.Tasks;
+using Emgu.CV;
using Emgu.CV.CvEnum;
+using UVtools.Core.FileFormats;
namespace UVtools.Core.Operations
{
[Serializable]
public class OperationFlip : Operation
{
+ #region Members
private bool _makeCopy;
private Enumerations.FlipDirection _flipDirection = Enumerations.FlipDirection.Horizontally;
+ #endregion
+ #region Overrides
public override string Title => "Flip";
public override string Description =>
"Flip the layers of the model vertically and/or horizontally.\n" +
@@ -34,6 +40,16 @@ namespace UVtools.Core.Operations
public override string ProgressAction => "Flipped layers";
+ public override string ToString()
+ {
+ var result = $"[{_flipDirection}] [Blend: {_makeCopy}]" + LayerRangeString;
+ if (!string.IsNullOrEmpty(ProfileName)) result = $"{ProfileName}: {result}";
+ return result;
+ }
+ #endregion
+
+ #region Properties
+
public Enumerations.FlipDirection FlipDirection
{
get => _flipDirection;
@@ -69,13 +85,7 @@ namespace UVtools.Core.Operations
return flipType;
}
}
-
- public override string ToString()
- {
- var result = $"[{_flipDirection}] [Blend: {_makeCopy}]" + LayerRangeString;
- if (!string.IsNullOrEmpty(ProfileName)) result = $"{ProfileName}: {result}";
- return result;
- }
+ #endregion
#region Equality
@@ -101,5 +111,45 @@ namespace UVtools.Core.Operations
}
#endregion
+
+ #region Methods
+ public override bool Execute(FileFormat slicerFile, OperationProgress progress = null)
+ {
+ progress ??= new OperationProgress();
+ progress.Reset(ProgressAction, LayerRangeCount);
+ Parallel.For(LayerIndexStart, LayerIndexEnd + 1, layerIndex =>
+ {
+ if (progress.Token.IsCancellationRequested) return;
+ using var mat = slicerFile[layerIndex].LayerMat;
+ Execute(mat);
+ slicerFile[layerIndex].LayerMat = mat;
+
+ lock (progress.Mutex)
+ {
+ progress++;
+ }
+ });
+ progress.Token.ThrowIfCancellationRequested();
+ return true;
+ }
+
+ public override bool Execute(Mat mat, params object[] arguments)
+ {
+ var target = GetRoiOrDefault(mat);
+
+ if (MakeCopy)
+ {
+ using Mat dst = new Mat();
+ CvInvoke.Flip(target, dst, FlipTypeOpenCV);
+ CvInvoke.Add(target, dst, target);
+ }
+ else
+ {
+ CvInvoke.Flip(target, target, FlipTypeOpenCV);
+ }
+
+ return true;
+ }
+ #endregion
}
}