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:
authorTiago Conceição <Tiago_caza@hotmail.com>2021-09-09 17:47:17 +0300
committerTiago Conceição <Tiago_caza@hotmail.com>2021-09-09 17:47:17 +0300
commit8948724835655097aad011b95e036532a200bb3f (patch)
tree92b8303734b27abeab63394785f659886c33b9dd /UVtools.ScriptSample
parent08a5797f36867c9b4c9b58da94e61bbea6258ae1 (diff)
pre v2.21.2
- (Add) Allow to choose custom locations for "Send to" - (Improvement) Better random generation for benchmark - (Fix) Outline - Hollow areas: Not outlining the second closing contour for contours with child - (Fix) Pixel editor - Eraser: It was selecting the whole blob even if have inner parents
Diffstat (limited to 'UVtools.ScriptSample')
-rw-r--r--UVtools.ScriptSample/ScriptInsetSample.cs7
-rw-r--r--UVtools.ScriptSample/ScriptTester.cs63
-rw-r--r--UVtools.ScriptSample/UVtools.ScriptSample.csproj1
3 files changed, 59 insertions, 12 deletions
diff --git a/UVtools.ScriptSample/ScriptInsetSample.cs b/UVtools.ScriptSample/ScriptInsetSample.cs
index 9b6de73..60d5dec 100644
--- a/UVtools.ScriptSample/ScriptInsetSample.cs
+++ b/UVtools.ScriptSample/ScriptInsetSample.cs
@@ -7,13 +7,16 @@
*/
using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using UVtools.Core.Scripting;
using Emgu.CV;
using Emgu.CV.CvEnum;
+using Emgu.CV.Util;
using UVtools.Core;
+using UVtools.Core.Extensions;
namespace UVtools.ScriptSample
{
@@ -87,9 +90,11 @@ namespace UVtools.ScriptSample
public bool ScriptExecute()
{
var anchor = new Point(-1, -1); // Kernel anchor, -1, -1 = center
- var kernel = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), anchor); // Rectangle 3x3 kernel
+ var kernel =
+ CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), anchor); // Rectangle 3x3 kernel
Progress.Reset("Inset layers", Operation.LayerRangeCount); // Sets the progress name and number of items to process
+
// Loop user selected layers in parallel, this will put each core of CPU working here on parallel
Parallel.For(Operation.LayerIndexStart, Operation.LayerIndexEnd+1, CoreSettings.ParallelOptions, layerIndex =>
{
diff --git a/UVtools.ScriptSample/ScriptTester.cs b/UVtools.ScriptSample/ScriptTester.cs
index 2027740..5ea3789 100644
--- a/UVtools.ScriptSample/ScriptTester.cs
+++ b/UVtools.ScriptSample/ScriptTester.cs
@@ -7,8 +7,16 @@
*/
using System;
+using System.Collections.Generic;
+using System.Drawing;
using UVtools.Core.Scripting;
using System.IO;
+using System.Threading.Tasks;
+using Emgu.CV;
+using Emgu.CV.CvEnum;
+using Emgu.CV.Util;
+using UVtools.Core;
+using UVtools.Core.EmguCV;
using UVtools.Core.Extensions;
namespace UVtools.ScriptSample
@@ -44,22 +52,55 @@ namespace UVtools.ScriptSample
/// <returns>True if executes successfully to the end, otherwise false.</returns>
public bool ScriptExecute()
{
- string path = @"c:\temp\UVToolAreaExp_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
+ var dict = new Dictionary<uint, List<(Point[] points, Rectangle rect)>>();
+ Parallel.For(Operation.LayerIndexStart, Operation.LayerIndexEnd + 1, CoreSettings.ParallelOptions, layerIndex =>
+ {
+ using var mat = SlicerFile[layerIndex].LayerMat;
+ using var contours = mat.FindContours(out var hierarchy, RetrType.Tree);
+
+ var hollowContours = new List<(Point[] points, Rectangle rect)>();
+ dict.Add((uint)layerIndex, hollowContours);
- Progress.Reset("Changing layers", Operation.LayerRangeCount); // Sets the progress name and number of items to process
+ for (int i = 0; i < contours.Size; i++)
+ {
+ // Only hollow areas inside model
+ if (hierarchy[i, EmguContour.HierarchyParent] == -1) continue;
- using var sw = File.CreateText(path);
- for (uint layerIndex = Operation.LayerIndexStart; layerIndex <= Operation.LayerIndexEnd; layerIndex++)
+ hollowContours.Add((contours[i].ToArray(), CvInvoke.BoundingRectangle(contours[i])));
+ }
+ });
+
+ foreach (var (layerIndex, contours) in dict)
{
- Progress.Token.ThrowIfCancellationRequested(); // Abort operation, user requested cancellation
- var layer = SlicerFile[layerIndex]; // Unpack and expose layer variable for easier use
+ if (!dict.TryGetValue(layerIndex + 1, out var nextContours)) continue; // No next layer with results
+
+ foreach (var tuple in contours)
+ {
+ Mat thisContourMat = null;
+ foreach (var nextTuple in nextContours)
+ {
+ if (!tuple.rect.IntersectsWith(nextTuple.rect)) continue;
+ if (thisContourMat is null)
+ {
+ thisContourMat = EmguExtensions.InitMat(SlicerFile.Resolution);
+ using var vec = new VectorOfPoint(tuple.points);
+ CvInvoke.DrawContours(thisContourMat, vec, -1, EmguExtensions.WhiteColor, -1);
+ }
- sw.WriteLine($@"{layerIndex}\{layer.NonZeroPixelCount}\{layer.BoundingRectangleMillimeters.Area()}");
- //sw.WriteLine(SlicerFile.GetName);
-
- Progress++; // Increment progress bar by 1
+ using var nextContourMat = thisContourMat.NewBlank();
+ using var vecNext = new VectorOfPoint(nextTuple.points);
+ CvInvoke.DrawContours(nextContourMat, vecNext, -1, EmguExtensions.WhiteColor, -1);
+
+ CvInvoke.BitwiseAnd(thisContourMat, nextContourMat, nextContourMat);
+ if (CvInvoke.CountNonZero(nextContourMat) == 0) continue; // Does not intersect!
+
+ // Intersecting here!
+ }
+
+ thisContourMat?.Dispose();
+ }
}
- sw.Close();
+
// return true if not cancelled by user
return !Progress.Token.IsCancellationRequested;
diff --git a/UVtools.ScriptSample/UVtools.ScriptSample.csproj b/UVtools.ScriptSample/UVtools.ScriptSample.csproj
index 6c0dcf5..cf79ecd 100644
--- a/UVtools.ScriptSample/UVtools.ScriptSample.csproj
+++ b/UVtools.ScriptSample/UVtools.ScriptSample.csproj
@@ -10,6 +10,7 @@
<RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<Copyright>Copyright © 2020 PTRTECH</Copyright>
+ <Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>