Root/slicer/slicer.c

1/*
2 * slicer.c - Generate slices
3 *
4 * Written 2015 by Werner Almesberger
5 * Copyright 2015 by Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdlib.h>
15#include <stdio.h>
16#include <unistd.h>
17
18#include "slice.h"
19#include "stl.h"
20
21
22static void usage(const char *name)
23{
24    fprintf(stderr,
25"usage: %s [-b distance] [-z distance] [file.stl]\n"
26" -b distance draw a box at the specified distance around the object\n"
27" (default: do not draw a box)\n"
28" -z distance duplicate layers if distance to next lower is larger than\n"
29" specified (default: do not insert intermediate layers\n"
30    , name);
31    exit(1);
32}
33
34
35int main(int argc, char **argv)
36{
37    float box = 0;
38    float z_step = 0;
39    int c;
40
41    slice_init();
42
43    while ((c = getopt(argc, argv, "b:z:")) != EOF)
44        switch (c) {
45        case 'b':
46            box = atof(optarg);
47            if (!box)
48                usage(*argv);
49            break;
50        case 'z':
51            z_step = atof(optarg);
52            if (!z_step)
53                usage(*argv);
54            break;
55        default:
56            usage(*argv);
57        }
58
59    switch (argc-optind) {
60    case 0:
61        stl_load_file(stdin, slice);
62        break;
63    case 1:
64        stl_load(argv[optind], slice);
65        break;
66    default:
67        usage(*argv);
68    }
69
70    if (z_step)
71        slice_intermediate(z_step);
72    slice_dump(box);
73
74    return 0;
75}
76

Archive Download this file

Branches:
master



interactive