Date: | 2013-11-07 07:25:45 (10 years 4 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | d64a34045f779e25c5e77a4e125b1e0c17568e81 |
Message: | gp2rml/gp2rml.c: new option -s to set Z scale factor Sounds weird, but the mill seems to be off by some 10%. |
Files: |
gp2rml/gp2rml.c (7 diffs) |
Change Details
gp2rml/gp2rml.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * gp2rml.c - Convert from gnuplot to RML |
3 | 3 | * |
4 | * Written 2010-2012 by Werner Almesberger | |
5 | * Copyright 2010-2012 Werner Almesberger | |
4 | * Written 2010-2013 by Werner Almesberger | |
5 | * Copyright 2010-2013 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 |
... | ... | |
56 | 56 | static struct path *paths = NULL, *curr_path; |
57 | 57 | static struct segment **next_seg; |
58 | 58 | static double z_max = -1e6; /* -1 km :) */ |
59 | static double z_scale = 1; /* < 1: compress; > 1: stretch */ | |
59 | 60 | |
60 | 61 | |
61 | 62 | #define units(mm) ((int) round((mm)*40.0)) |
... | ... | |
155 | 156 | seg = seg->next; |
156 | 157 | while (seg) { |
157 | 158 | printf("!ZZ%d,%d,%d\n", units(seg->x), units(seg->y), |
158 | units(seg->z-z_max)); | |
159 | units((seg->z-z_max)*z_scale)); | |
159 | 160 | d = hypot(x-seg->x, y-seg->y); |
160 | 161 | txy = d/xy_speed; |
161 | 162 | tz = fabs(z-seg->z)/z_speed; |
... | ... | |
185 | 186 | static void usage(const char *name) |
186 | 187 | { |
187 | 188 | fprintf(stderr, |
188 | "usage: %s z_clear[mm] xy_speed z_speed [file]\n\n" | |
189 | " z_clear clearance above the highest peak, in mm (must be > 0)\n" | |
190 | " Unit (\"mm\") can optionally be specified\n" | |
191 | " xy_speed cutting speed, in mm/s\n" | |
192 | " z_speed vertical speed when lowering the pen, in mm/s\n" | |
189 | "usage: %s [-s z_scale] z_clear[mm] xy_speed z_speed [file]\n\n" | |
190 | " -s z_scale scale Z axis by z_scale (default: 1.0)\n" | |
191 | " z_clear clearance above the highest peak, in mm (must be > 0)\n" | |
192 | " Unit (\"mm\") can optionally be specified\n" | |
193 | " xy_speed cutting speed, in mm/s\n" | |
194 | " z_speed vertical speed when lowering the pen, in mm/s\n" | |
193 | 195 | , name); |
194 | 196 | exit(1); |
195 | 197 | } |
... | ... | |
197 | 199 | |
198 | 200 | int main(int argc, const char **argv) |
199 | 201 | { |
202 | const char *name; | |
200 | 203 | FILE *file; |
201 | 204 | char *end; |
202 | 205 | int i; |
203 | 206 | double p[3]; |
204 | 207 | |
208 | name = *argv; | |
209 | ||
210 | if (argc > 2 && !strcmp(argv[1], "-s")) { | |
211 | if (argc < 3) | |
212 | usage(name); | |
213 | z_scale = strtod(argv[2], &end); | |
214 | if (*end) | |
215 | usage(name); | |
216 | argc -= 2; | |
217 | argv += 2; | |
218 | } | |
219 | ||
205 | 220 | switch (argc) { |
206 | 221 | case 4: |
207 | 222 | file = stdin; |
... | ... | |
214 | 229 | } |
215 | 230 | break; |
216 | 231 | default: |
217 | usage(*argv); | |
232 | usage(name); | |
218 | 233 | } |
219 | 234 | for (i = 0; i != 3; i++) { |
220 | 235 | p[i] = strtod(argv[i+1], &end); |
... | ... | |
225 | 240 | if (!i && *end && !strcmp(end, "mm")) |
226 | 241 | continue; |
227 | 242 | if (*end || p[i] <= 0) |
228 | usage(*argv); | |
243 | usage(name); | |
229 | 244 | } |
230 | 245 | |
231 | 246 | process_file(file); |
Branches:
master