Skip to content

Commit

Permalink
v0.6.6.1
Browse files Browse the repository at this point in the history
* (Add) Elapsed time to the Log list
* (Add) Setting - Issues - Islands: Allow diagonal bonds with default to false (#22)
* (Change) Tool - Repair Layers: Allow set both iterations to 0 to skip closing and opening operations and allow remove islands independently
* (Change) Title - file open time from miliseconds to seconds
* (Improvement) Tool - Repair Layers: Layer image will only read/save if required and if current layer got modified
* (Fix) Setting - Issues - Islands: "Pixels below this value will turn black, otherwise white" (Threshold) was not using the set value and was forcing 1
* (Fix) Remove duplicated log for repair layers and issues
  • Loading branch information
sn4k3 committed Aug 17, 2020
1 parent 06598b7 commit fa5073e
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 152 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 17/08/2020 - v0.6.6.1

* (Add) Elapsed time to the Log list
* (Add) Setting - Issues - Islands: Allow diagonal bonds with default to false (#22)
* (Change) Tool - Repair Layers: Allow set both iterations to 0 to skip closing and opening operations and allow remove islands independently
* (Change) Title - file open time from miliseconds to seconds
* (Improvement) Tool - Repair Layers: Layer image will only read/save if required and if current layer got modified
* (Fix) Setting - Issues - Islands: "Pixels below this value will turn black, otherwise white" (Threshold) was not using the set value and was forcing 1
* (Fix) Remove duplicated log for repair layers and issues

## 11/08/2020 - v0.6.6.0

* (Add) Pixel Editor: Eraser - Right click over a white pixel to remove it whole linked area (Fill with black) (#7)
Expand Down
1 change: 0 additions & 1 deletion UVtools.Core/Layer/LayerIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class IslandDetectionConfiguration
/// individual components on the layer, if false only 4 neighbors (right, left, above, below)
/// will be considered..
/// </summary>
///
public bool AllowDiagonalBonds { get; set; } = false;
}

Expand Down
149 changes: 82 additions & 67 deletions UVtools.Core/Layer/LayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -844,25 +845,25 @@ public List<LayerIssue> GetAllIssues(
using (Mat stats = new Mat())
using (Mat centroids = new Mat())
{

int numLabels;

if (islandConfig.BinaryThreshold > 0)
{
using (var thresholdImage = new Mat())
CvInvoke.Threshold(image, image, islandConfig.BinaryThreshold, 255, ThresholdType.Binary);
/*using (var thresholdImage = new Mat())
{
CvInvoke.Threshold(image, thresholdImage, 1, 255, ThresholdType.Binary);
CvInvoke.Threshold(image, thresholdImage, islandConfig.BinaryThreshold, 255, ThresholdType.Binary);
// Evaluate number of connected components using the 4-connected neighbor approach
numLabels = CvInvoke.ConnectedComponentsWithStats(thresholdImage, labels, stats, centroids,
islandConfig.AllowDiagonalBonds ? LineType.EightConnected : LineType.FourConnected);
}
}*/
}
else
/*else
{
// Evaluate number of connected components 4-connected neighbor approach
numLabels = CvInvoke.ConnectedComponentsWithStats(image, labels, stats, centroids,
islandConfig.AllowDiagonalBonds?LineType.EightConnected:LineType.FourConnected);
}
islandConfig.AllowDiagonalBonds ? LineType.EightConnected : LineType.FourConnected);
}*/
var numLabels = CvInvoke.ConnectedComponentsWithStats(image, labels, stats, centroids,
islandConfig.AllowDiagonalBonds ? LineType.EightConnected : LineType.FourConnected);

// Get array that contains details of each connected component
var ccStats = stats.GetData();
Expand All @@ -872,7 +873,7 @@ public List<LayerIssue> GetAllIssues(
//stats[i][3]: Height of Connected Component
//stats[i][4]: Total Area (in pixels) in Connected Component

Span<int> labelSpan = MemoryMarshal.Cast<byte, int>(labels.GetPixelSpan<byte>());
Span<int> labelSpan = labels.GetPixelSpan<int>();
Mat previousImage = null;
Span<byte> previousSpan = null;

Expand Down Expand Up @@ -900,16 +901,14 @@ public List<LayerIssue> GetAllIssues(
for (int x = rect.X; x < rect.Right; x++)
{
int pixel = step * y + x;
if (span[pixel] < islandConfig.RequiredPixelBrightnessToProcessCheck)
continue; // Low brightness, ignore

if (labelSpan[pixel] != i)
continue; // Background pixel or a pixel from another component within the bounding rectangle
if (
labelSpan[pixel] != i || // Background pixel or a pixel from another component within the bounding rectangle
span[pixel] < islandConfig.RequiredPixelBrightnessToProcessCheck // Low brightness, ignore
) continue;

points.Add(new Point(x, y));

if (previousSpan[pixel] >=
islandConfig.RequiredPixelBrightnessToSupport)
if (previousSpan[pixel] >= islandConfig.RequiredPixelBrightnessToSupport)
{
pixelsSupportingIsland++;
}
Expand Down Expand Up @@ -1206,7 +1205,7 @@ in list
return result.OrderBy(issue => issue.Type).ThenBy(issue => issue.LayerIndex).ThenBy(issue => issue.PixelsCount).ToList();
}

public void RepairLayers(uint layerStart, uint layerEnd, uint closingIterations = 1, uint openingIterations = 1, byte removeIslandsBelowEqualPixels = 4,
public void RepairLayers(uint layerStart, uint layerEnd, uint closingIterations = 1, uint openingIterations = 0, byte removeIslandsBelowEqualPixels = 4,
bool repairIslands = true, bool removeEmptyLayers = true, bool repairResinTraps = true, List<LayerIssue> issues = null,
OperationProgress progress = null)
{
Expand All @@ -1219,79 +1218,95 @@ public void RepairLayers(uint layerStart, uint layerEnd, uint closingIterations
{
if (progress.Token.IsCancellationRequested) return;
Layer layer = this[layerIndex];
using (var image = layer.LayerMat)
Mat image = null;

void initImage()
{
if(ReferenceEquals(image, null))
image = layer.LayerMat;
}

if (!ReferenceEquals(issues, null))
{
if (!ReferenceEquals(issues, null))
if (repairIslands && removeIslandsBelowEqualPixels > 0)
{
if (repairIslands && removeIslandsBelowEqualPixels > 0)
Span<byte> bytes = null;
foreach (var issue in issues)
{
if (
issue.LayerIndex != layerIndex ||
issue.Type != LayerIssue.IssueType.Island ||
issue.Pixels.Length > removeIslandsBelowEqualPixels) continue;

initImage();
if(bytes == null)
bytes = image.GetPixelSpan<byte>();

foreach (var issuePixel in issue.Pixels)
{
bytes[image.GetPixelPos(issuePixel)] = 0;
}
}
/*if (issues.TryGetValue((uint)layerIndex, out var issueList))
{
var bytes = image.GetPixelSpan<byte>();
foreach (var issue in issues)
foreach (var issue in issueList.Where(issue =>
issue.Type == LayerIssue.IssueType.Island && issue.Pixels.Length <= removeIslandsBelowEqualPixels))
{
if (
issue.LayerIndex != layerIndex ||
issue.Type != LayerIssue.IssueType.Island ||
issue.Pixels.Length > removeIslandsBelowEqualPixels) continue;

foreach (var issuePixel in issue.Pixels)
{
bytes[image.GetPixelPos(issuePixel)] = 0;
}
}
/*if (issues.TryGetValue((uint)layerIndex, out var issueList))
{
var bytes = image.GetPixelSpan<byte>();
foreach (var issue in issueList.Where(issue =>
issue.Type == LayerIssue.IssueType.Island && issue.Pixels.Length <= removeIslandsBelowEqualPixels))
{
foreach (var issuePixel in issue.Pixels)
{
bytes[image.GetPixelPos(issuePixel)] = 0;
}
}
}*/
}
}*/
}

if (repairResinTraps)
if (repairResinTraps)
{
foreach (var issue in issues.Where(issue => issue.LayerIndex == layerIndex && issue.Type == LayerIssue.IssueType.ResinTrap))
{
foreach (var issue in issues.Where(issue => issue.LayerIndex == layerIndex && issue.Type == LayerIssue.IssueType.ResinTrap))
initImage();
using (var vec = new VectorOfVectorOfPoint(new VectorOfPoint(issue.Pixels)))
{
using (var vec = new VectorOfVectorOfPoint(new VectorOfPoint(issue.Pixels)))
{
CvInvoke.DrawContours(image,
vec,
-1,
new MCvScalar(255),
-1);
}
CvInvoke.DrawContours(image,
vec,
-1,
new MCvScalar(255),
-1);
}
}
}
}

if (repairIslands)
if (repairIslands && (closingIterations > 0 || openingIterations > 0))
{
initImage();
using (Mat kernel = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3),
new Point(-1, -1)))
{
using (Mat kernel = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3),
new Point(-1, -1)))
if (closingIterations > 0)
{
if (closingIterations > 0)
{
CvInvoke.MorphologyEx(image, image, MorphOp.Close, kernel, new Point(-1, -1),
(int) closingIterations, BorderType.Default, new MCvScalar());
}
CvInvoke.MorphologyEx(image, image, MorphOp.Close, kernel, new Point(-1, -1),
(int) closingIterations, BorderType.Default, new MCvScalar());
}

if (openingIterations > 0)
{
CvInvoke.MorphologyEx(image, image, MorphOp.Open, kernel, new Point(-1, -1),
(int) closingIterations, BorderType.Default, new MCvScalar());
}
if (openingIterations > 0)
{
CvInvoke.MorphologyEx(image, image, MorphOp.Open, kernel, new Point(-1, -1),
(int) closingIterations, BorderType.Default, new MCvScalar());
}
}
}

if (!ReferenceEquals(image, null))
{
layer.LayerMat = image;
lock (progress.Mutex)
{
progress++;
}
image.Dispose();
}

lock (progress.Mutex)
{
progress++;
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions UVtools.Core/UVtools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl>
<PackageProjectUrl>https://github.com/sn4k3/UVtools</PackageProjectUrl>
<Description>MSLA/DLP, file analysis, repair, conversion and manipulation</Description>
<Version>0.6.6.0</Version>
<Version>0.6.6.1</Version>
<Copyright>Copyright © 2020 PTRTECH</Copyright>
<PackageIcon>UVtools.png</PackageIcon>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyVersion>0.6.6.0</AssemblyVersion>
<FileVersion>0.6.6.0</FileVersion>
<AssemblyVersion>0.6.6.1</AssemblyVersion>
<FileVersion>0.6.6.1</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
3 changes: 3 additions & 0 deletions UVtools.GUI/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
<setting name="PartialUpdateIslandsOnEditing" serializeAs="String">
<value>True</value>
</setting>
<setting name="IslandAllowDiagonalBonds" serializeAs="String">
<value>False</value>
</setting>
</UVtools.GUI.Properties.Settings>
</userSettings>
</configuration>
30 changes: 21 additions & 9 deletions UVtools.GUI/Controls/Log.cs → UVtools.GUI/Controls/LogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,32 @@

namespace UVtools.GUI.Controls
{
public sealed class Log : INotifyPropertyChanged
public sealed class LogItem : INotifyPropertyChanged
{
private int _index;
private string _time;
private string _startTime;
private decimal _elapsedTime;
private string _description;

[OLVColumn(Width = 50, Title = "#")]
[OLVColumn(Width = 40, Title = "#")]
public int Index
{
get => _index;
set => SetField(ref _index, value);
}

[OLVColumn(Width = 90)]
public string Time
[OLVColumn(Width = 80, Title = "Started")]
public string StartTime
{
get => _time;
set => SetField(ref _time, value);
get => _startTime;
set => SetField(ref _startTime, value);
}

[OLVColumn(Width = 70, Title = "Time(s)")]
public decimal ElapsedTime
{
get => _elapsedTime;
set => SetField(ref _elapsedTime, Math.Round(value, 2));
}

[OLVColumn(Width = 0)]
Expand All @@ -33,13 +41,17 @@ public string Description
set => SetField(ref _description, value);
}

public Log(int index, string description)
public LogItem(int index, string description, decimal elapsedTime = 0)
{
_index = index;
_description = description;
_time = DateTime.Now.ToString("HH:mm:ss");
_elapsedTime = elapsedTime;
_startTime = DateTime.Now.ToString("HH:mm:ss");
}

public LogItem(string description, uint elapsedTime = 0) : this(0, description, elapsedTime)
{ }

public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged([CallerMemberName] string propertyName = null)
Expand Down
5 changes: 2 additions & 3 deletions UVtools.GUI/Forms/FrmInputBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/

using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Forms;
using UVtools.Core;
using UVtools.Core.FileFormats;
using UVtools.GUI.Controls;

namespace UVtools.GUI.Forms
{
Expand Down Expand Up @@ -41,6 +41,7 @@ public decimal CurrentValue
get => _currentValue;
set { _currentValue = value; tbCurrentValue.Text = value.ToString(CultureInfo.InvariantCulture)+ValueUint; }
}

#endregion

#region Constructors
Expand All @@ -49,8 +50,6 @@ public FrmInputBox()
InitializeComponent();
DialogResult = DialogResult.Cancel;
numNewValue.Select();


}

public FrmInputBox(FileFormat.PrintParameterModifier modifier, decimal currentValue) : this(modifier.Name,
Expand Down
Loading

0 comments on commit fa5073e

Please sign in to comment.