Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions gsCore/geometry3Sharp/curve/PolySimplification2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,24 @@ public class PolySimplification2
public List<Vector2d> Result;


public PolySimplification2(Polygon2d polygon)
public PolySimplification2(IEnumerable<Vector2d> vertices, bool loop)
{
Vertices = new List<Vector2d>(polygon.Vertices);
IsLoop = true;
Vertices = new List<Vector2d>(vertices);
IsLoop = loop;
}

public PolySimplification2(PolyLine2d polycurve)
{
Vertices = new List<Vector2d>(polycurve.Vertices);
IsLoop = false;
}



/// <summary>
/// simplify outer and holes of a polygon solid with same thresholds
/// </summary>
public static void Simplify(GeneralPolygon2d solid, double deviationThresh)
{
PolySimplification2 simp = new PolySimplification2(solid.Outer);
PolySimplification2 simp = new PolySimplification2(solid.Outer.Vertices, true);
simp.SimplifyDeviationThreshold = deviationThresh;
simp.Simplify();
solid.Outer.SetVertices(simp.Result, true);

foreach (var hole in solid.Holes) {
PolySimplification2 holesimp = new PolySimplification2(hole);
PolySimplification2 holesimp = new PolySimplification2(hole.Vertices, true);
holesimp.SimplifyDeviationThreshold = deviationThresh;
holesimp.Simplify();
hole.SetVertices(holesimp.Result, true);
Expand Down
8 changes: 0 additions & 8 deletions gsCore/gsSlicer/tests/CalculateExtrusion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,5 @@ public void Calculate(Vector3d vStartPos, double fStartA, bool alreadyInRetract
ExtrusionLength = curA;

} // Calculate()


bool is_connection(Index3i flags) {
return (flags.a & (int)TPVertexFlags.IsConnector) != 0;
}



}
}
43 changes: 23 additions & 20 deletions gsCore/gsSlicer/toolpathing/FillPathScheduler2d.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using g3;

namespace gs
Expand Down Expand Up @@ -84,7 +85,7 @@ public virtual void AppendPolygon2d(FillPolygon2d poly)
loopV.Add(poly[k]);
}

double useSpeed = select_speed(poly);
double useSpeed = select_speed(poly.TypeFlags);

Builder.AppendExtrude(loopV, useSpeed, poly.TypeFlags, null);
}
Expand Down Expand Up @@ -137,22 +138,20 @@ public virtual void AppendPolyline2d(FillPolyline2d curve)

List<Vector2d> loopV;
List<TPVertexFlags> flags = null;
if (bReverse) {
loopV = new List<Vector2d>(N);
for (int i = N - 1; i >= 0; --i)
loopV.Add(curve[i]);
if (curve.HasFlags) {
flags = new List<TPVertexFlags>(N);
for (int i = N - 1; i >= 0; --i)
flags.Add(curve.GetFlag(i));
}
} else {
loopV = new List<Vector2d>(curve);
if (curve.HasFlags)
flags = new List<TPVertexFlags>(curve.Flags());
}

double useSpeed = select_speed(curve);
loopV = new List<Vector2d>(N);
flags = new List<TPVertexFlags>(N);

var range = Enumerable.Range(0, N);
if (bReverse) range.Reverse();

foreach (int i in range)
{
var point = curve.GetPoint(i, bReverse);
loopV.Add(point.Vertex);
flags.Add(point.SegmentInfo != null && point.SegmentInfo.IsConnector ? TPVertexFlags.IsConnector : TPVertexFlags.None );
}
double useSpeed = select_speed(curve.TypeFlags);

Vector2d dimensions = GCodeUtil.UnspecifiedDimensions;
if (curve.CustomThickness > 0)
Expand All @@ -162,22 +161,26 @@ public virtual void AppendPolyline2d(FillPolyline2d curve)
}


bool HasTypeFlag(FillTypeFlags typeFlags, FillTypeFlags f)
{
return (typeFlags & f) != 0;
}

// 1) If we have "careful" speed hint set, use CarefulExtrudeSpeed
// (currently this is only set on first layer)
// 2) if this is an outer perimeter, scale by outer perimeter speed multiplier
// 3) if we are being "careful" and this is support, also use that multiplier
// (bit of a hack, currently means on first layer we do support extra slow)
double select_speed(FillCurve2d pathCurve)
double select_speed(FillTypeFlags flags)
{
bool bIsSupport = pathCurve.HasTypeFlag(FillTypeFlags.SupportMaterial);
bool bIsOuterPerimeter = pathCurve.HasTypeFlag(FillTypeFlags.OuterPerimeter);
bool bIsSupport = HasTypeFlag(flags, FillTypeFlags.SupportMaterial);
bool bIsOuterPerimeter = HasTypeFlag(flags, FillTypeFlags.OuterPerimeter);
bool bCareful = (SpeedHint == SchedulerSpeedHint.Careful);
double useSpeed = bCareful ? Settings.CarefulExtrudeSpeed : Settings.RapidExtrudeSpeed;
if (bIsOuterPerimeter || (bCareful && bIsSupport))
useSpeed *= Settings.OuterPerimeterSpeedX;

bool bIsBridgeSupport = pathCurve.HasTypeFlag(FillTypeFlags.BridgeSupport);
bool bIsBridgeSupport = HasTypeFlag(flags, FillTypeFlags.BridgeSupport);
if (bIsBridgeSupport)
useSpeed = Settings.CarefulExtrudeSpeed * Settings.BridgeExtrudeSpeedX;

Expand Down
14 changes: 8 additions & 6 deletions gsCore/gsSlicer/toolpathing/ParallelLinesFillPolygon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ protected FillCurveSet2d ComputeFillPaths(GeneralPolygon2d poly)
eid = next.a;
vid = next.b;
int gid = pathGraph.GetEdgeGroup(eid);
if (gid < 0) {
path.AppendVertex(pathGraph.GetVertex(vid), TPVertexFlags.IsConnector);
} else {
if (gid < 0)
{
path.AppendVertex(pathGraph.GetVertex(vid), new FillSegmentInfo() { IsConnector = true });
}
else
{
path.AppendVertex(pathGraph.GetVertex(vid));
}

Expand All @@ -161,13 +164,12 @@ protected FillCurveSet2d ComputeFillPaths(GeneralPolygon2d poly)
if (path.ArcLength < MinPathLengthMM)
continue;


// run polyline simplification to get rid of unneccesary detail in connectors
// [TODO] we could do this at graph level...)
// [TODO] maybe should be checkign for collisions? we could end up creating
// [TODO] maybe should be checking for collisions? we could end up creating
// non-trivial overlaps here...
if ( SimplifyAmount != SimplificationLevel.None && path.VertexCount > 2 ) {
PolySimplification2 simp = new PolySimplification2(path);
PolySimplification2 simp = new PolySimplification2(path.Vertices, false);
switch (SimplifyAmount) {
default:
case SimplificationLevel.Minor:
Expand Down
4 changes: 2 additions & 2 deletions gsCore/gsSlicer/toolpathing/SortingScheduler2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public void SortAndAppendTo(Vector2d startPoint, IFillPathScheduler2d scheduler)
}
o.TypeFlags = loop.curve.TypeFlags;
paths.Append(o);
OutPoint = o.Vertices[0];
OutPoint = o[0];
} else {
paths.Append(loop.curve);
OutPoint = loop.curve.Vertices[0];
OutPoint = loop.curve[0];
}

} else { // span
Expand Down
91 changes: 9 additions & 82 deletions gsCore/gsSlicer/toolpaths/FillCurveSet2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ namespace gs
/// </summary>
public class FillCurveSet2d
{
public List<FillPolygon2d> Loops = new List<FillPolygon2d>();
public List<FillPolyline2d> Curves = new List<FillPolyline2d>();
public List<IFillElementPolygon> Loops = new List<IFillElementPolygon>();
public List<IFillElementPolyline> Curves = new List<IFillElementPolyline>();

public FillCurveSet2d()
{
}


public void Append(GeneralPolygon2d poly, FillTypeFlags typeFlags) {
Loops.Add(new FillPolygon2d(poly.Outer) { TypeFlags = typeFlags });
Loops.Add(new FillPolygon2d(poly.Outer.VerticesItr(false)) { TypeFlags = typeFlags });
foreach (var h in poly.Holes)
Loops.Add(new FillPolygon2d(h) { TypeFlags = typeFlags });
Loops.Add(new FillPolygon2d(h.VerticesItr(false)) { TypeFlags = typeFlags });
}

public void Append(List<GeneralPolygon2d> polys, FillTypeFlags typeFlags) {
Expand All @@ -32,29 +31,29 @@ public void Append(List<GeneralPolygon2d> polys, FillTypeFlags typeFlags) {
}

public void Append(Polygon2d poly, FillTypeFlags typeFlags) {
Loops.Add(new FillPolygon2d(poly) { TypeFlags = typeFlags } );
Loops.Add(new FillPolygon2d(poly.VerticesItr(false)) { TypeFlags = typeFlags } );
}

public void Append(List<Polygon2d> polys, FillTypeFlags typeFlags) {
foreach (var p in polys)
Append(p, typeFlags);
}

public void Append(FillPolygon2d loop) {
public void Append(IFillElementPolygon loop) {
Loops.Add(loop);
}

public void Append(List<FillPolygon2d> loops) {
public void Append(List<IFillElementPolygon> loops) {
foreach ( var l in loops )
Loops.Add(l);
}


public void Append(FillPolyline2d curve) {
public void Append(IFillElementPolyline curve) {
Curves.Add(curve);
}

public void Append(List<FillPolyline2d> curves) {
public void Append(List<IFillElementPolyline> curves) {
foreach (var p in curves)
Append(p);
}
Expand Down Expand Up @@ -86,77 +85,5 @@ public double TotalLength()
len += curve.ArcLength;
return len;
}


// DEPRECATED - remove?
// this connects up the paths with small connectors? used in DenseLinesFillPolygon
public void OptimizeCurves(double max_dist, Func<Segment2d, bool> ValidateF) {
int[] which = new int[4];
double[] dists = new double[4];
for (int ci = 0; ci < Curves.Count; ++ci ) {
FillPolyline2d l0 = Curves[ci];

// find closest viable connection
int iClosest = -1;
int iClosestCase = -1;
for (int cj = ci + 1; cj < Curves.Count; ++cj) {
FillPolyline2d l1 = Curves[cj];
dists[0] = l0.Start.Distance(l1.Start); which[0] = 0;
dists[1] = l0.Start.Distance(l1.End); which[1] = 1;
dists[2] = l0.End.Distance(l1.Start); which[2] = 2;
dists[3] = l0.End.Distance(l1.End); which[3] = 3;
Array.Sort(dists, which);

for (int k = 0; k < 4 && iClosest != cj; ++k) {
if (dists[k] > max_dist)
continue;
Segment2d connector = get_case(l0, l1, which[k]);
if (ValidateF(connector) == false)
continue;
iClosest = cj;
iClosestCase = which[k];
}
}

if (iClosest == -1)
continue;

// [TODO] it would be better to preserve start/direction of
// longest path, if possible. Maybe make that an option?

// ok we will join ci w/ iClosest. May need reverse one
FillPolyline2d ljoin = Curves[iClosest];
if (iClosestCase == 0) {
l0.Reverse();
} else if (iClosestCase == 1) {
l0.Reverse();
ljoin.Reverse();
} else if (iClosestCase == 3) {
ljoin.Reverse();
}

// now we are in straight-append order
l0.AppendVertices(ljoin);
Curves.RemoveAt(iClosest);

// force check again w/ this curve
ci--;
}

}


static Segment2d get_case(FillPolyline2d l0, FillPolyline2d l1, int which) {
if (which == 0)
return new Segment2d(l0.Start, l1.Start);
else if (which == 1)
return new Segment2d(l0.Start, l1.End);
else if (which == 2)
return new Segment2d(l0.End, l1.Start);
else
return new Segment2d(l0.End, l1.End);
}


}
}
Loading