protected virtual void precompute_shells() { int nLayers = Slices.Count; LayerShells = new List <ShellsFillPolygon> [nLayers]; gParallel.ForEach(Interval1i.Range(nLayers), (layeri) => { PlanarSlice slice = Slices[layeri]; LayerShells[layeri] = new List <ShellsFillPolygon>(); List <GeneralPolygon2d> solids = slice.Solids; foreach (GeneralPolygon2d shape in solids) { ShellsFillPolygon shells_gen = new ShellsFillPolygon(shape); shells_gen.PathSpacing = Settings.SolidFillPathSpacingMM(); shells_gen.ToolWidth = Settings.Machine.NozzleDiamMM; shells_gen.Layers = Settings.Shells; shells_gen.InsetInnerPolygons = false; shells_gen.Compute(); LayerShells[layeri].Add(shells_gen); if (slice.Tags.Has(shape)) { ShellTags.Add(shells_gen, slice.Tags.Get(shape)); } } }); }
/// <summary> /// Fill polygon with solid fill strategy. /// If bIsInfillAdjacent, then we optionally add one or more shells around the solid /// fill, to give the solid fill something to stick to (imagine dense linear fill adjacent /// to sparse infill area - when the extruder zigs, most of the time there is nothing /// for the filament to attach to, so it pulls back. ugly!) /// </summary> protected virtual void fill_solid_region(int layer_i, GeneralPolygon2d solid_poly, IFillPathScheduler2d scheduler, bool bIsInfillAdjacent = false) { List <GeneralPolygon2d> fillPolys = new List <GeneralPolygon2d>() { solid_poly }; // if we are on an infill layer, and this shell has some infill region, // then we are going to draw contours around solid fill so it has // something to stick to // [TODO] should only be doing this if solid-fill is adjecent to infill region. // But how to determine this? not easly because we don't know which polys // came from where. Would need to do loop above per-polygon if (bIsInfillAdjacent && Settings.Part.InteriorSolidRegionShells > 0) { ShellsFillPolygon interior_shells = new ShellsFillPolygon(solid_poly, Settings.FillTypeFactory.Solid()); interior_shells.PathSpacing = Settings.SolidFillPathSpacingMM(); interior_shells.ToolWidth = Settings.Machine.NozzleDiamMM; interior_shells.Layers = Settings.Part.InteriorSolidRegionShells; interior_shells.PreserveOuterShells = true; interior_shells.InsetFromInputPolygonX = 0; interior_shells.Compute(); scheduler.AppendCurveSets(interior_shells.Shells); fillPolys = interior_shells.InnerPolygons; } // now actually fill solid regions foreach (GeneralPolygon2d fillPoly in fillPolys) { var solidFillSpacing = Settings.SolidFillPathSpacingMM(); TiledFillPolygon tiled_fill = new TiledFillPolygon(fillPoly) { TileSize = 13.1 * solidFillSpacing, TileOverlap = 0.3 * solidFillSpacing }; tiled_fill.TileFillGeneratorF = (tilePoly, index) => { int odd = ((index.x + index.y) % 2 == 0) ? 1 : 0; RasterFillPolygon solid_gen = new RasterFillPolygon(tilePoly, Settings.FillTypeFactory.Solid()) { InsetFromInputPolygon = false, PathSpacing = solidFillSpacing, ToolWidth = Settings.Machine.NozzleDiamMM, AngleDeg = LayerFillAngleF(layer_i + odd) }; return(solid_gen); }; tiled_fill.Compute(); scheduler.AppendCurveSets(tiled_fill.FillCurves); } }
protected virtual void fill_bridge_region_decompose(GeneralPolygon2d poly, IFillPathScheduler2d scheduler, PrintLayerData layer_data) { poly.Simplify(0.1, 0.01, true); TriangulatedPolygonGenerator generator = new TriangulatedPolygonGenerator() { Polygon = poly, Subdivisions = 16 }; DMesh3 mesh = generator.Generate().MakeDMesh(); //Util.WriteDebugMesh(mesh, "/Users/rms/scratch/bridgemesh.obj"); //List<Polygon2d> polys = decompose_mesh_recursive(mesh); List <Polygon2d> polys = decompose_cluster_up(mesh); Util.WriteDebugMesh(mesh, "/Users/rms/scratch/bridgemesh_reduce.obj"); double spacing = Settings.BridgeFillPathSpacingMM(); foreach (Polygon2d polypart in polys) { Box2d box = polypart.MinimalBoundingBox(0.00001); Vector2d axis = (box.Extent.x > box.Extent.y) ? box.AxisY : box.AxisX; double angle = Math.Atan2(axis.y, axis.x) * MathUtil.Rad2Deg; GeneralPolygon2d gp = new GeneralPolygon2d(polypart); ShellsFillPolygon shells_fill = new ShellsFillPolygon(gp); shells_fill.PathSpacing = Settings.SolidFillPathSpacingMM(); shells_fill.ToolWidth = Settings.Machine.NozzleDiamMM; shells_fill.Layers = 1; shells_fill.InsetFromInputPolygonX = 0.25; shells_fill.ShellType = ShellsFillPolygon.ShellTypes.BridgeShell; shells_fill.FilterSelfOverlaps = false; shells_fill.Compute(); scheduler.AppendCurveSets(shells_fill.GetFillCurves()); var fillPolys = shells_fill.InnerPolygons; double offset = Settings.Machine.NozzleDiamMM * Settings.SolidFillBorderOverlapX; fillPolys = ClipperUtil.MiterOffset(fillPolys, offset); foreach (var fp in fillPolys) { BridgeLinesFillPolygon fill_gen = new BridgeLinesFillPolygon(fp) { InsetFromInputPolygon = false, PathSpacing = spacing, ToolWidth = Settings.Machine.NozzleDiamMM, AngleDeg = angle, }; fill_gen.Compute(); scheduler.AppendCurveSets(fill_gen.GetFillCurves()); } } // fit bbox to try to find fill angle that has shortest spans //Box2d box = poly.Outer.MinimalBoundingBox(0.00001); //Vector2d axis = (box.Extent.x > box.Extent.y) ? box.AxisY : box.AxisX; //double angle = Math.Atan2(axis.y, axis.x) * MathUtil.Rad2Deg; // [RMS] should we do something like this? //if (Settings.SolidFillBorderOverlapX > 0) { // double offset = Settings.Machine.NozzleDiamMM * Settings.SolidFillBorderOverlapX; // fillPolys = ClipperUtil.MiterOffset(fillPolys, offset); //} }