mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-08 17:42:31 +02:00
816898836b
- **File formats:** - (Add) File extension: .gktwo.ctb to `ChituboxFile` to be able to convert files for UniFormation GKtwo under special CTB format - (Add) UniFormation GKtwo compatibility under CTB format, if exporting JXS rename to CTB before open - (Fix) CTB, CBDDLP, PHOTON, FDG, PHZ: Read and write files larger then 4GB (#608) - **PCB Exposure:** - (Add) Offset X/Y to offset the PCB from it origin - (Add) Allow to toggle between "Show preview image cropped by it bounds" and "Show full preview image (The final result)" - (Improvement) Use rectangle instead of line for center line primitive (#607) - (Fix) Implement rotation to polygon and center line primitives (#607) - (Fix) Macros in a single line was not being parsed (#607) - (Fix) Invert color per file was not affecting primitives - **Network printers:** - (Add) Socket requests with TCP and UDP - (Add) AnyCubic printer preset (However it can't upload a file) - (Add) Scripts in request path to allow a first request to fetch data to the final request: - A script starts with **<\?** and ends with **?>** - First parameter is the first request to get response content from - Second parameter is the regex pattern to match content with - Third parameter is the final request that supports a parameter from regex matching group, eg: **{#1}** is match Group[1] value - **Example:** <\? getfiles > {0}\/(\d+\.[\da-zA-Z]+), > printfile,{#1} ?> - (Change) Allow to print a filename without send it when upload request path is empty - (Fix) Do not show printers with empty requests - (Change) Default layer compression to Lz4 instead of Png - (Improvement) Application is now culture aware but set part of `NumberFormat` to the `InvariantCulture.NumberFormat` - (Improvement) Material cost now show with the current culture currency symbol due previous change - (Improvement) Better submit of bug reports using sections and forms - (Improvement) Linux: AppImage now have a help manual with possible arguments and parameters - (Improvement) macOS: Codesign app on auto-installer and auto-upgrade to bypass arm64 run restriction (#431) - (Improvement) macOS: Rebuilt arm64 libcvextern.dylib to run with less dependencies (#431) - (Improvement) macOS: Try to show missing dependencies from openCV (if any) on the error message - (Fix) UI: layers sorted lexicographically instead of numerically in the issues list view (#611) - (Fix) PrusaSlicer printer parameters: UniFormation GKtwo
95 lines
3.9 KiB
C#
95 lines
3.9 KiB
C#
/*
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE
|
|
* Version 3, 19 November 2007
|
|
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
* of this license document, but changing it is not allowed.
|
|
*/
|
|
|
|
namespace UVtools.Core.Slicer;
|
|
|
|
public static class LinAlgUtils
|
|
{
|
|
/*#region Find Facets
|
|
public static List<Facet> FindFacetsIntersectingZIndex(STLDocument stl, float z)
|
|
{
|
|
return stl.Facets.Where(f => f.Vertices.Any(v => v.Z <= z) && f.Vertices.Any(v => v.Z >= z) && Math.Abs(f.Normal.Z) != 1).ToList();
|
|
}
|
|
|
|
public static List<Facet> FindFlatFacetsAtZIndex(STLDocument stl, float z)
|
|
{
|
|
return stl.Facets.Where(f => f.Vertices.All(v => v.Z == z)).ToList();
|
|
}
|
|
|
|
public static List<Facet> FindTopFlatFacetsAtZIndex(STLDocument stl, float z)
|
|
{
|
|
return stl.Facets.Where(f => f.Vertices.Any(v => v.Z == z) && f.Normal.Z == 1).ToList();
|
|
}
|
|
public static List<Facet> FindBottomFlatFacetsAtZIndex(STLDocument stl, float z)
|
|
{
|
|
return stl.Facets.Where(f => f.Vertices.Any(v => v.Z == z) && f.Normal.Z == -1).ToList();
|
|
}
|
|
#endregion
|
|
|
|
public static SliceLine CreateLineFromFacetAtZIndex(Facet facet, float z)
|
|
{
|
|
// This won't work for flat horizontal plane vertices, so throw if that's what we've got
|
|
if (Math.Abs(facet.Normal.Z) == 1)
|
|
throw new Exception("Cannot create lines for flat horizontal planes");
|
|
var verts = facet.Vertices;
|
|
var returnLine = new SliceLine();
|
|
// If any vertices are ON the z-index, just return that line
|
|
returnLine.AddRange(verts.Where(v => v.Z == z).Select(v => new PointF(v.X, v.Y)));
|
|
// For uniformity, I'm representing a point as a "line" between two of the same point
|
|
// It's janky, I'll refactor later
|
|
if (returnLine.Count == 1)
|
|
{
|
|
returnLine.Add(returnLine[0]);
|
|
}
|
|
if (returnLine.Count == 2)
|
|
{
|
|
returnLine.Normal = new PointF(facet.Normal.X, facet.Normal.Y);
|
|
return returnLine;
|
|
}
|
|
// If no vertices are ON the z-index, find the two points where they CROSS it
|
|
if ((verts[0].Z - z) / (verts[1].Z - z) < 0)
|
|
returnLine.Add(CalculateZIntercept(verts[0], verts[1], z));
|
|
if ((verts[2].Z - z) / (verts[1].Z - z) < 0)
|
|
returnLine.Add(CalculateZIntercept(verts[2], verts[1], z));
|
|
|
|
if (returnLine.Count < 2)
|
|
returnLine.Add(CalculateZIntercept(verts[0], verts[2], z));
|
|
|
|
returnLine.Normal = new PointF(facet.Normal.X, facet.Normal.Y);
|
|
|
|
if (!returnLine.Validate())
|
|
throw new InvalidOperationException("Invalid Point Data");
|
|
|
|
return returnLine;
|
|
}
|
|
|
|
public static PointF CalculateZIntercept(Vector3 v1, Vector3 v2, float z)
|
|
{
|
|
var returnX = CalculateDimensionalValueAtIndex(new PointF(v1.Z, v1.X), new PointF(v2.Z, v2.X), z);
|
|
var returnY = CalculateDimensionalValueAtIndex(new PointF(v1.Z, v1.Y), new PointF(v2.Z, v2.Y), z);
|
|
return new PointF
|
|
{
|
|
X = returnX,
|
|
Y = returnY
|
|
};
|
|
}
|
|
|
|
public static float CalculateDimensionalValueAtIndex(PointF p1, PointF p2, float z, byte precision = 4)
|
|
{
|
|
var slope = (p1.Y - p2.Y) / (p1.X - p2.X);
|
|
var intercept = p1.Y - (slope * p1.X);
|
|
var rawVal = slope * z + intercept;
|
|
return (float)Math.Round(rawVal, precision);
|
|
// using floats we end up with some infinitesimal rounding errors,
|
|
// so we need to set the precision to something reasonable. Default is 1/100th of a micron
|
|
// I'm sure there's a better way than converting it to a string and then back to a float,
|
|
// but that's what I've got right now, so that's what I'm doing.
|
|
//var strVal = rawVal.ToString($"0.{precision}");
|
|
//return float.Parse(strVal, CultureInfo.InvariantCulture);
|
|
}*/
|
|
} |