diff options
Diffstat (limited to 'UVtools.Core/Operations/Operation.cs')
-rw-r--r-- | UVtools.Core/Operations/Operation.cs | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/UVtools.Core/Operations/Operation.cs b/UVtools.Core/Operations/Operation.cs index 54abe03..56e2d12 100644 --- a/UVtools.Core/Operations/Operation.cs +++ b/UVtools.Core/Operations/Operation.cs @@ -13,6 +13,7 @@ using Emgu.CV; using Emgu.CV.Util; using UVtools.Core.Extensions; using UVtools.Core.FileFormats; +using UVtools.Core.Managers; using UVtools.Core.Objects; namespace UVtools.Core.Operations @@ -341,21 +342,37 @@ namespace UVtools.Core.Operations /// </summary> public virtual void InitWithSlicerFile() { } + public void ClearROI() + { + ROI = Rectangle.Empty; + } + + public void ClearROIandMasks() + { + ClearROI(); + ClearMasks(); + } + public void SetROIIfEmpty(Rectangle roi) { if (HaveROI) return; ROI = roi; } - public void SetMasksIfEmpty(Point[][] points) + public Mat GetRoiOrDefault(Mat defaultMat) { - if (HaveMask) return; - MaskPoints = points; + return HaveROI && defaultMat.Size != _roi.Size ? new Mat(defaultMat, _roi) : defaultMat; } - public Mat GetRoiOrDefault(Mat defaultMat) + public void ClearMasks() { - return HaveROI && defaultMat.Size != _roi.Size ? new Mat(defaultMat, _roi) : defaultMat; + MaskPoints = null; + } + + public void SetMasksIfEmpty(Point[][] points) + { + if (HaveMask) return; + MaskPoints = points; } public Mat GetMask(Mat mat) => GetMask(_maskPoints, mat); @@ -379,8 +396,15 @@ namespace UVtools.Core.Operations { resultRoi = GetRoiOrDefault(result); } - resultRoi.CopyTo(originalRoi, mask); - originalRoi.CopyTo(resultRoi); + + if (mask.Size != resultRoi.Size) // Accept a full size mask + { + mask = GetRoiOrDefault(mask); + } + + using var tempMat = originalRoi.Clone(); + resultRoi.CopyTo(tempMat, mask); + tempMat.CopyTo(resultRoi); } /// <summary> @@ -390,7 +414,7 @@ namespace UVtools.Core.Operations /// <param name="result">Result image which will also be modified</param> public void ApplyMask(Mat original, Mat result) { - using var mask = GetMask(result); + using var mask = GetMask(original); ApplyMask(original, result, mask); } @@ -409,6 +433,8 @@ namespace UVtools.Core.Operations if(!string.IsNullOrWhiteSpace(msg)) throw new InvalidOperationException($"{Title} can't execute due some errors:\n{msg}"); } + + progress ??= new OperationProgress(); progress.Reset(ProgressAction, LayerRangeCount); HaveExecuted = true; |