From b658c0e2f65cf896eefc4eb2fa5f17577e3091b4 Mon Sep 17 00:00:00 2001 From: tslater2006 Date: Thu, 28 Oct 2021 15:29:52 -0500 Subject: [PATCH] Add method for merging layers that are at the same PositionZ --- UVtools.Core/Layers/LayerManager.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/UVtools.Core/Layers/LayerManager.cs b/UVtools.Core/Layers/LayerManager.cs index fdfe19b..80e8077 100644 --- a/UVtools.Core/Layers/LayerManager.cs +++ b/UVtools.Core/Layers/LayerManager.cs @@ -623,6 +623,23 @@ namespace UVtools.Core return layers; } + public Mat GetMergedMatForLayerAtIndex(uint startIndex) + { + /* This operates backwards because GetSamePositionedLayers returns the highest layer index with the same postion z, not the lowest */ + var startLayer = this[startIndex]; + + Mat layerMat = startLayer.LayerMat; + + for (var curIndex = startIndex + 1; curIndex < LayerCount && (this[curIndex].PositionZ == startLayer.PositionZ); curIndex++) + { + var nextLayer = this[curIndex].LayerMat; + CvInvoke.BitwiseOr(nextLayer, layerMat, layerMat); + nextLayer.Dispose(); + } + + return layerMat; + } + public Rectangle GetBoundingRectangle(OperationProgress progress = null) { if (!_boundingRectangle.IsEmpty || LayerCount == 0 || this[0] is null) return _boundingRectangle;