Date:2015-09-28 23:13:02 (8 years 4 days ago)
Author:Werner Almesberger
Commit:346899c34c2a3ca0c65b6d406a81190d1180ba03
Message:cameo/: new command "purge" to remove corners that add little or on area

Such corners are typically artefacts that can upset later processing stages.
Files: cameo/README (1 diff)
cameo/lang.l (1 diff)
cameo/lang.y (4 diffs)
cameo/ops.c (3 diffs)
cameo/ops.h (3 diffs)

Change Details

cameo/README
252252Note that this disturbs the order generated by "offset" and should thus
253253not be used on paths that are to be executed in a specific sequence.
254254
255  purge [<length>]
256
257Remove all corners where the area of the corresponding parallelogram is
258inferior to the square of the length parameter. This is particularly
259useful for removing artefacts that cold upset later processing steps.
260If the length omitted, a default of 1 um is used.
261
255262
256263Statistics:
257264
cameo/lang.l
5151<INITIAL>offset return TOK_OFFSET;
5252<INITIAL>optimize return TOK_OPTIMIZE;
5353<INITIAL>outside return TOK_OUTSIDE;
54<INITIAL>purge return TOK_PURGE;
5455<INITIAL>remainder return TOK_REMAINDER;
5556<INITIAL>remore return TOK_REMOVE;
5657<INITIAL>reset return TOK_RESET;
cameo/lang.y
230230
231231%token TOK_ALIGN TOK_AREA TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY
232232%token TOK_FLIP TOK_KEEP TOK_MILL TOK_OFFSET TOK_OPTIMIZE
233%token TOK_OUTSIDE TOK_REMAINDER
233%token TOK_OUTSIDE TOK_PURGE TOK_REMAINDER
234234%token TOK_REMOVE TOK_RESET
235235%token TOK_REVERSE TOK_ROTATE TOK_STATS TOK_STL TOK_TRANSLATE
236236%token TOK_X TOK_Y TOK_Z
...... 
242242%token <str> STRING
243243
244244%type <str> opt_filename
245%type <num> dimen number x_size y_size
245%type <num> dimen number opt_dimen x_size y_size
246246%type <flag> opt_any
247247%type <oopt> offset_options offset_option
248248%type <axis> axis
...... 
457457            clear_paths();
458458            paths = tmp;
459459        }
460    | TOK_PURGE opt_dimen
461        {
462            struct path *tmp;
463
464            tmp = purge_paths(paths, $2);
465            clear_paths();
466            paths = tmp;
467        }
460468    ;
461469
462470opt_filename:
...... 
488496        }
489497    ;
490498
499opt_dimen:
500        {
501            $$ = 0;
502        }
503    | dimen
504        {
505            $$ = $1;
506        }
507    ;
508
491509x_size:
492510    dimen
493511        {
cameo/ops.c
11/*
22 * ops.c - Higher-level toolpath operations
33 *
4 * Written 2010-2013 by Werner Almesberger
5 * Copyright 2010-2013 Werner Almesberger
4 * Written 2010-2013, 2015 by Werner Almesberger
5 * Copyright 2010-2013, 2105 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1212
1313
1414#include <stddef.h>
15#include <stdbool.h>
1516#include <math.h>
1617
1718#include "path.h"
...... 
193194    }
194195    return res;
195196}
197
198
199static double cross_area(double ax, double ay, double az, double bx, double by,
200    double bz)
201{
202    double x, y, z;
203
204    x = ay * bz - by * az;
205    y = az * bx - ax * bz;
206    z = ax * by - ay * bx;
207    return hypot(hypot(x, y), z);
208}
209
210
211struct path *purge_paths(const struct path *paths, double len)
212{
213    const struct path *path;
214    struct path *p = NULL, **anchor = &p, *new;
215    struct point *a, *b, *c;
216    struct point *end;
217    double area, t;
218    bool closed;
219
220    if (!len)
221        len = EPSILON_PURGE;
222    area = len * len;
223    for (path = paths; path; path = path->next) {
224        if (!path->first)
225            continue;
226        closed = path_is_closed(path);
227        if (closed) {
228            end = path->first;
229            while (end->next != path->last)
230                end = end->next;
231        } else {
232            end = path->last;
233        }
234        a = end;
235        b = path->first;
236        c = b->next;
237        if (!c)
238            continue;
239        new = path_from(path);
240        while (1) {
241            t = cross_area(a->x - b->x, a->y - b->y, a->z - b->z,
242                c->x - b->x, c->y - b->y, c->z - b->z);
243            if (t >= area) {
244                path_add(new, b->x, b->y, b->z);
245                a = b;
246            }
247            b = c;
248            if (closed) {
249                c = c == end ? path->first : c->next;
250            } else {
251                c = c->next;
252            }
253            if (b == path->first || !c)
254                break;
255        }
256        if (new->first) {
257            if (closed)
258                path_add(new, new->first->x, new->first->y,
259                    new->first->z);
260            *anchor = new;
261            anchor = &new->next;
262        } else {
263            path_free(new);
264        }
265    }
266    return p;
267}
cameo/ops.h
11/*
22 * ops.h - Higher-level toolpath operations
33 *
4 * Written 2010-2012 by Werner Almesberger
5 * Copyright 2010-2012 Werner Almesberger
4 * Written 2010-2012, 2015 by Werner Almesberger
5 * Copyright 2010-2012, 2015 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1717#include "path.h"
1818
1919
20#define EPSILON_PURGE 1e-3
21
22
2023struct path *tool_comp_paths(const struct path *paths, int dog_bone,
2124    int all_inside);
2225struct path *try_drill(struct path *path, double d_min, double d_max);
...... 
2528struct path *reverse_paths(const struct path *paths);
2629struct path *select_paths(const struct path *paths, double xa, double ya,
2730    double xb, double yb, int inside);
31struct path *purge_paths(const struct path *paths, double len);
2832
2933#endif /* !OPS_H */

Archive Download the corresponding diff file

Branches:
master



interactive