From 5de93f3dca8a7aa227a397652771f70ae78bb5ac Mon Sep 17 00:00:00 2001 From: Adrian Kennard Date: Sat, 10 Sep 2011 15:55:04 +0100 Subject: [PATCH] General improvements to filling --- e3d-fill.c | 38 +++++++++++++++++++++++--------------- e3d-fill.h | 2 +- e3d-gcode.c | 15 ++++++++++----- e3d-gcode.h | 2 +- e3d.c | 7 +++++-- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/e3d-fill.c b/e3d-fill.c index d79feb4..d571bf0 100644 --- a/e3d-fill.c +++ b/e3d-fill.c @@ -85,7 +85,7 @@ fill_perimeter (slice_t * slice, poly_dim_t width, int loops, int fast) p[l] = q; q = poly_inset (q, (l + 1 < loops) ? width : width / 2); if (fast) - poly_tidy (q, width / 8); // inner surfaces need way less detail + poly_tidy (q, width / 10); // inner surfaces need way less detail } slice->fill = q; // process loops in reverse order @@ -202,31 +202,39 @@ fill_area (stl_t * stl, poly_dim_t width, int layers) } static void -fill (int e, stl_t * s, slice_t * a, polygon_t * p, int dir, poly_dim_t width, double density) +fill (int e, stl_t * s, slice_t * a, polygon_t * p, int dir, poly_dim_t width, double density, double fillflow) { if (density <= 0) return; if (!p || !p->contours) return; polygon_t *q = poly_inset (p, width / 2); - poly_dim_t w = s->max.x - s->min.x, y, d = width * sqrtl (2.0), dy = d * (2.0 / density), iy = dy - d; + poly_dim_t w = s->max.x - s->min.x, y, d = width * sqrtl (2.0), dy = d * 2.0, iy = dy - d; + int flag = 0; + if (density < 1) + { // sparse fill + dy = d * (2.0 * fillflow / density); + //iy = dy - d; + iy = dy / 2; + flag = 1; + } for (y = s->min.y - w; y < s->max.y + dy; y += dy) { polygon_t *n = poly_new (); - poly_dim_t oy = y + (d * dir / 4) % dy; + poly_dim_t oy = y + (d * dir / 4 + ((dir / 2 % 2) * dy / 2)) % dy; if (dir & 1) { - poly_add (n, s->min.x, oy, 0); - poly_add (n, s->min.x, oy + iy, 0); - poly_add (n, s->max.x, oy + w + iy, 0); - poly_add (n, s->max.x, oy + w, 0); + poly_add (n, s->min.x, oy, flag); + poly_add (n, s->min.x, oy + iy, flag); + poly_add (n, s->max.x, oy + w + iy, flag); + poly_add (n, s->max.x, oy + w, flag); } else { - poly_add (n, s->max.x, oy + iy, 0); - poly_add (n, s->max.x, oy, 0); - poly_add (n, s->min.x, oy + w, 0); - poly_add (n, s->min.x, oy + w + iy, 0); + poly_add (n, s->max.x, oy + iy, flag); + poly_add (n, s->max.x, oy, flag); + poly_add (n, s->min.x, oy + w, flag); + poly_add (n, s->min.x, oy + w + iy, flag); } prefix_extrude (&a->extrude[e], poly_clip (POLY_INTERSECT, 2, n, q)); poly_free (n); @@ -235,14 +243,14 @@ fill (int e, stl_t * s, slice_t * a, polygon_t * p, int dir, poly_dim_t width, d } void -fill_extrude (stl_t * s, poly_dim_t width, double density) +fill_extrude (stl_t * s, poly_dim_t width, double density, double fillflow) { // Generate extrude path for fills int layer = 0; slice_t *a; for (a = s->slices; a; a = a->next) { - fill (EXTRUDE_FILL, s, a, a->infill, layer, width, density); - fill (EXTRUDE_FILL, s, a, a->solid, layer, width, 1); + fill (EXTRUDE_FILL, s, a, a->infill, layer, width, density, fillflow); + fill (EXTRUDE_FILL, s, a, a->solid, layer, width, 1, 1); // flying layer done differently - outside in plot polygon_t *q = poly_inset (a->flying, width / 2); while (q && q->contours) diff --git a/e3d-fill.h b/e3d-fill.h index a0715de..76f4e25 100644 --- a/e3d-fill.h +++ b/e3d-fill.h @@ -18,5 +18,5 @@ void fill_perimeter (slice_t *, poly_dim_t width, int loops, int fast); // create perimeter and remaining fill area void fill_area (stl_t * stl, poly_dim_t width, int layers); // Break down fill areas based on layers -void fill_extrude (stl_t * stl, poly_dim_t width, double density); // Generate extrude path for fills +void fill_extrude (stl_t * stl, poly_dim_t width, double density,double fillflow); // Generate extrude path for fills void fill_anchor (stl_t * stl, int loops, poly_dim_t width, poly_dim_t offset, poly_dim_t step); // Add anchor to layer 0 diff --git a/e3d-gcode.c b/e3d-gcode.c index 3228504..c577ac8 100644 --- a/e3d-gcode.c +++ b/e3d-gcode.c @@ -24,7 +24,7 @@ unsigned int gcode_out (const char *filename, stl_t * stl, double flowrate, poly_dim_t layer, poly_dim_t speed0, poly_dim_t speed, poly_dim_t zspeed, double back, - poly_dim_t hop, int mirror, double anchorflow, int eplaces, int tempbed, int temp0, int temp, int quiet) + poly_dim_t hop, int mirror, double anchorflow, double fillflow, int eplaces, int tempbed, int temp0, int temp, int quiet) { // returns time estimate in seconds FILE *o = fopen (filename, "w"); if (!o) @@ -119,10 +119,14 @@ gcode_out (const char *filename, stl_t * stl, double flowrate, poly_dim_t layer, move (v->x, v->y, z + hop, back); } move (v->x, v->y, z, 0); + double flow = (c->vertices->flag ? fillflow : 1); for (v = c->vertices->next; v; v = v->next) - extrude (v->x, v->y, z, speed, flowrate); + { + extrude (v->x, v->y, z, speed, flowrate * flow); + flow = (v->flag ? fillflow : 1); + } v = c->vertices; - extrude (v->x, v->y, z, speed, flowrate); + extrude (v->x, v->y, z, speed, flowrate * flow); } } // layers @@ -149,8 +153,9 @@ gcode_out (const char *filename, stl_t * stl, double flowrate, poly_dim_t layer, plot_loops (s->extrude[e], speed0, flowrate, 1); // flying layer - in order it was made if (s == stl->slices && temp && temp0 != temp) { - move (cx, cy, z + hop * 2, back); - fprintf (o, "M109 S%d\n", temp); + //move (cx, cy, z + hop * 2, back); + //fprintf (o, "M109 S%d\n", temp); + fprintf (o, "M108 S%d\n", temp); } z += layer; s = s->next; diff --git a/e3d-gcode.h b/e3d-gcode.h index 52b2c20..34e5bb9 100644 --- a/e3d-gcode.h +++ b/e3d-gcode.h @@ -17,4 +17,4 @@ #include "e3d.h" unsigned int gcode_out (const char *filename, stl_t * stl, double feedrate, poly_dim_t layer, poly_dim_t speed0, poly_dim_t speed, poly_dim_t zspeed, - double back, poly_dim_t hop, int mirror, double anchorflow, int eplaces,int tempbed,int temp0,int temp,int quiet); + double back, poly_dim_t hop, int mirror, double anchorflow, double fillflow,int eplaces,int tempbed,int temp0,int temp,int quiet); diff --git a/e3d.c b/e3d.c index 927cb1f..eb796d1 100644 --- a/e3d.c +++ b/e3d.c @@ -53,6 +53,7 @@ main (int argc, const char *argv[]) double anchorgap = 2; double anchorstep = 5; double anchorflow = 2; + double infillflow = 1.5; double filament = 2.9; double packing = 1; double speed = 50; @@ -89,13 +90,14 @@ main (int argc, const char *argv[]) {"anchor-gap", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &anchorgap, 0, "Gap between perimeter and anchor in widths", "Widths"}, {"anchor-step", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &anchorstep, 0, "Spacing of joins between perimeter and anchor in widths", "Widths"}, {"anchor-flow", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &anchorflow, 0, "Extrude multiplier for anchor join loop", "Ratio"}, + {"infill-flow", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &infillflow, 0, "Extrude multiplier for sparse infill", "Ratio"}, {"filament", 'f', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &filament, 0, "Filament diameter", "Units"}, {"packing", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &packing, 0, "Multiplier for feed rate", "Ratio"}, {"speed", 'S', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &speed, 0, "Speed", "Units/sec"}, {"speed0", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &speed0, 0, "Speed (layer0)", "Units/sec"}, {"z-speed", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &zspeed, 0, "Max Z Speed", "Units/sec"}, {"temp0", 0, POPT_ARG_INT, &temp0, 0, "Set layer 0 temp (M109)", "C"}, - {"temp", 0, POPT_ARG_INT, &temp, 0, "Set temp (M109)", "C"}, + {"temp", 0, POPT_ARG_INT, &temp, 0, "Set temp", "C"}, {"bed", 0, POPT_ARG_INT, &tempbed, 0, "Set temp of bed (M140)", "C"}, {"hop", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &hop, 0, "Hop up when moving and not extruding", "Units"}, {"back", 0, POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_DOUBLE, &back, 0, "Pull back extrude when not extruding", "Units"}, @@ -214,7 +216,7 @@ main (int argc, const char *argv[]) for (; s; s = s->next) fill_perimeter (s, width, skins + (((count++) & 1) ? altskins : 0), fast); fill_area (stl, width, layers); - fill_extrude (stl, width, density); + fill_extrude (stl, width, density, infillflow); } if (anchorloops) @@ -238,6 +240,7 @@ main (int argc, const char *argv[]) { unsigned int t = gcode_out (gcodefile, stl, layer * layer * widthratio / filament / filament * packing, l, speed0s, speeds, zspeeds, back, hops, mirror, anchorflow, + infillflow, eplaces, tempbed, temp0, temp, quiet); if (!quiet) {