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 | ||
---|---|---|
252 | 252 | Note that this disturbs the order generated by "offset" and should thus |
253 | 253 | not be used on paths that are to be executed in a specific sequence. |
254 | 254 | |
255 | purge [<length>] | |
256 | ||
257 | Remove all corners where the area of the corresponding parallelogram is | |
258 | inferior to the square of the length parameter. This is particularly | |
259 | useful for removing artefacts that cold upset later processing steps. | |
260 | If the length omitted, a default of 1 um is used. | |
261 | ||
255 | 262 | |
256 | 263 | Statistics: |
257 | 264 |
cameo/lang.l | ||
---|---|---|
51 | 51 | <INITIAL>offset return TOK_OFFSET; |
52 | 52 | <INITIAL>optimize return TOK_OPTIMIZE; |
53 | 53 | <INITIAL>outside return TOK_OUTSIDE; |
54 | <INITIAL>purge return TOK_PURGE; | |
54 | 55 | <INITIAL>remainder return TOK_REMAINDER; |
55 | 56 | <INITIAL>remore return TOK_REMOVE; |
56 | 57 | <INITIAL>reset return TOK_RESET; |
cameo/lang.y | ||
---|---|---|
230 | 230 | |
231 | 231 | %token TOK_ALIGN TOK_AREA TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY |
232 | 232 | %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 | |
234 | 234 | %token TOK_REMOVE TOK_RESET |
235 | 235 | %token TOK_REVERSE TOK_ROTATE TOK_STATS TOK_STL TOK_TRANSLATE |
236 | 236 | %token TOK_X TOK_Y TOK_Z |
... | ... | |
242 | 242 | %token <str> STRING |
243 | 243 | |
244 | 244 | %type <str> opt_filename |
245 | %type <num> dimen number x_size y_size | |
245 | %type <num> dimen number opt_dimen x_size y_size | |
246 | 246 | %type <flag> opt_any |
247 | 247 | %type <oopt> offset_options offset_option |
248 | 248 | %type <axis> axis |
... | ... | |
457 | 457 | clear_paths(); |
458 | 458 | paths = tmp; |
459 | 459 | } |
460 | | TOK_PURGE opt_dimen | |
461 | { | |
462 | struct path *tmp; | |
463 | ||
464 | tmp = purge_paths(paths, $2); | |
465 | clear_paths(); | |
466 | paths = tmp; | |
467 | } | |
460 | 468 | ; |
461 | 469 | |
462 | 470 | opt_filename: |
... | ... | |
488 | 496 | } |
489 | 497 | ; |
490 | 498 | |
499 | opt_dimen: | |
500 | { | |
501 | $$ = 0; | |
502 | } | |
503 | | dimen | |
504 | { | |
505 | $$ = $1; | |
506 | } | |
507 | ; | |
508 | ||
491 | 509 | x_size: |
492 | 510 | dimen |
493 | 511 | { |
cameo/ops.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * ops.c - Higher-level toolpath operations |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
12 | 12 | |
13 | 13 | |
14 | 14 | #include <stddef.h> |
15 | #include <stdbool.h> | |
15 | 16 | #include <math.h> |
16 | 17 | |
17 | 18 | #include "path.h" |
... | ... | |
193 | 194 | } |
194 | 195 | return res; |
195 | 196 | } |
197 | ||
198 | ||
199 | static 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 | ||
211 | struct 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 | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * ops.h - Higher-level toolpath operations |
3 | 3 | * |
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 | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
17 | 17 | #include "path.h" |
18 | 18 | |
19 | 19 | |
20 | #define EPSILON_PURGE 1e-3 | |
21 | ||
22 | ||
20 | 23 | struct path *tool_comp_paths(const struct path *paths, int dog_bone, |
21 | 24 | int all_inside); |
22 | 25 | struct path *try_drill(struct path *path, double d_min, double d_max); |
... | ... | |
25 | 28 | struct path *reverse_paths(const struct path *paths); |
26 | 29 | struct path *select_paths(const struct path *paths, double xa, double ya, |
27 | 30 | double xb, double yb, int inside); |
31 | struct path *purge_paths(const struct path *paths, double len); | |
28 | 32 | |
29 | 33 | #endif /* !OPS_H */ |
Branches:
master