Date:2010-09-25 00:53:06 (8 years 10 months ago)
Author:Werner Almesberger
Commit:2cc9a9e5056d4452202900de752d42b8f702557c
Message:Step sizes are now auto-determined, allowing use of files of any resolution.

- solidify/face.h (struct face): record the x, y, and z step sizes
- solidify/face.c (load_file, read_file): moved file I/O from read_file to
load_file
- solidify/face.c (adjust_step, read_file): before populating the array,
determine the x/y and z step sizes
- solidify/solidify.c (main): verify that both faces have the same step
sizes
- solidify/solidify.c (main): don't use hard-coded z step size
- solidify/solidify.c (main): move call to setlocale() next to gtk_init(),
to make it clear whose damage we're trying to control
Files: solidify/face.c (3 diffs)
solidify/face.h (1 diff)
solidify/solidify.c (1 diff)

Change Details

solidify/face.c
2626
2727
2828#define CACHE_DIR ".cache"
29#define DEFAULT_STEP 1 /* 1 mm */
30#define MIN_STEP 0.005 /* 5 um */
2931
3032
31static struct face *read_file(const char *name)
33struct coord {
34    float x, y, z;
35};
36
37
38static struct coord *load_file(const char *name)
3239{
3340    FILE *file;
34    struct face *f;
35    struct histo *h;
36    float x, y, z;
37    int xi, yi, zi;
41    struct coord *v, *n;
42    int s;
3843
3944    if (!strcmp(name, "-")) {
4045        file = stdin;
...... 
5964            }
6065        }
6166    }
67
68    v = n = alloc_type(struct coord);
69    s = 1;
70
71    while (fscanf(file, "%f,%f,%f\r\n", &n->x, &n->y, &n->z) == 3) {
72        n++;
73        if (n-v == s) {
74            struct coord *tmp;
75
76            s += s;
77            tmp = realloc(v, sizeof(struct coord)*s);
78            if (!tmp) {
79                perror("realloc");
80                exit(1);
81            }
82            n = n-v+tmp;
83            v = tmp;
84        }
85    }
86    if (file != stdin)
87        (void) fclose(file);
88
89    n->x = n->y = n->z = 0;
90    return v;
91}
92
93
94static void adjust_step(double *step, double delta)
95{
96    double n = round(delta/MIN_STEP);
97    double s = n*MIN_STEP;
98
99    if (n && s < *step)
100        *step = s;
101}
102
103
104static struct face *read_file(const char *name)
105{
106    struct coord *v, *p;
107    struct face *f;
108    struct histo *h;
109    int xi, yi, zi;
110
111    v = load_file(name);
112
62113    f = alloc_type(struct face);
63114    f->a = new_array();
64115
65    while (fscanf(file, "%f,%f,%f\r\n", &x, &y, &z) == 3) {
66        /* @@@ hack - should auto-scale */
67        xi = round(x*10.0);
68        yi = round(y*10.0);
69        zi = round(z*40.0);
116    /*
117     * Hack: the MDX-15 measures bumps along the x axis with 25 um
118     * resolution, so we just ignore the x resultion we find and use the
119     * y resolution instead.
120     */
121    f->x_step = f->y_step =f->z_step = DEFAULT_STEP;
122    for (p = v; p[1].x || p[1].y || p[1].z; p++) {
123        adjust_step(&f->y_step, fabs(p[0].y-p[1].y));
124        adjust_step(&f->z_step, fabs(p[0].z-p[1].z));
125    }
126    f->x_step = f->y_step;
127
128    for (p = v; p->x || p->y || p->z; p++) {
129        xi = round(p->x/f->x_step);
130        yi = round(p->y/f->y_step);
131        zi = round(p->z/f->z_step);
70132        set(f->a, xi, yi, zi);
71133    }
72    if (file != stdin)
73        (void) fclose(file);
134
135    free(v);
74136
75137    f->sx = f->a->max_x-f->a->min_x+1;
76138    f->sy = f->a->max_y-f->a->min_y+1;
...... 
87149    f->m.a[0][1] = f->m.a[1][0] = 0;
88150    f->m.b[0] = f->m.b[1] = 0;
89151
152    fprintf(stderr, "%g %g %g\n", f->x_step, f->y_step, f->z_step);
90153    fprintf(stderr, "%d-%d / %d-%d / %d-%d\n",
91154        f->a->min_x, f->a->max_x, f->a->min_y, f->a->max_y,
92155        f->a->min_z, f->a->max_z);
solidify/face.h
1919
2020struct face {
2121    struct array *a;
22    double x_step, y_step, z_step;
2223    int sx, sy; /* size */
2324    int cx, cy; /* center */
2425    int z_ref;
solidify/solidify.c
127127int main(int argc, char **argv)
128128{
129129    gtk_init(&argc, &argv);
130    setlocale(LC_ALL, "C"); /* damage control */
131
130132    switch (argc) {
131133    case 4:
132134        break;
133135    default:
134136        usage(*argv);
135137    }
136    setlocale(LC_ALL, "C"); /* damage control */
138
137139    solid.a = read_face(argv[1]);
138140    solid.b = read_face(argv[2]);
139    solid.dist = atof(argv[3])/0.025; /* @@@ hack */
141    if (solid.a->x_step != solid.a->x_step ||
142        solid.a->y_step != solid.a->y_step ||
143        solid.a->z_step != solid.a->z_step) {
144        fprintf(stderr, "both faces must have the same resolution\n");
145        exit(1);
146    }
147    solid.dist = atof(argv[3])/solid.a->z_step;
148
140149    gui();
150
141151    if (!isatty(1))
142152        povray(&solid);
143153

Archive Download the corresponding diff file

Branches:
master



interactive