Ben NanoNote 3D scans
Sign in or create your account | Project List | Help
Ben NanoNote 3D scans Commit Details
Date: | 2010-09-25 00:53:06 (13 years 6 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 | ||
---|---|---|
26 | 26 | |
27 | 27 | |
28 | 28 | #define CACHE_DIR ".cache" |
29 | #define DEFAULT_STEP 1 /* 1 mm */ | |
30 | #define MIN_STEP 0.005 /* 5 um */ | |
29 | 31 | |
30 | 32 | |
31 | static struct face *read_file(const char *name) | |
33 | struct coord { | |
34 | float x, y, z; | |
35 | }; | |
36 | ||
37 | ||
38 | static struct coord *load_file(const char *name) | |
32 | 39 | { |
33 | 40 | 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; | |
38 | 43 | |
39 | 44 | if (!strcmp(name, "-")) { |
40 | 45 | file = stdin; |
... | ... | |
59 | 64 | } |
60 | 65 | } |
61 | 66 | } |
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 | ||
94 | static 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 | ||
104 | static 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 | ||
62 | 113 | f = alloc_type(struct face); |
63 | 114 | f->a = new_array(); |
64 | 115 | |
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); | |
70 | 132 | set(f->a, xi, yi, zi); |
71 | 133 | } |
72 | if (file != stdin) | |
73 | (void) fclose(file); | |
134 | ||
135 | free(v); | |
74 | 136 | |
75 | 137 | f->sx = f->a->max_x-f->a->min_x+1; |
76 | 138 | f->sy = f->a->max_y-f->a->min_y+1; |
... | ... | |
87 | 149 | f->m.a[0][1] = f->m.a[1][0] = 0; |
88 | 150 | f->m.b[0] = f->m.b[1] = 0; |
89 | 151 | |
152 | fprintf(stderr, "%g %g %g\n", f->x_step, f->y_step, f->z_step); | |
90 | 153 | fprintf(stderr, "%d-%d / %d-%d / %d-%d\n", |
91 | 154 | f->a->min_x, f->a->max_x, f->a->min_y, f->a->max_y, |
92 | 155 | f->a->min_z, f->a->max_z); |
solidify/face.h | ||
---|---|---|
19 | 19 | |
20 | 20 | struct face { |
21 | 21 | struct array *a; |
22 | double x_step, y_step, z_step; | |
22 | 23 | int sx, sy; /* size */ |
23 | 24 | int cx, cy; /* center */ |
24 | 25 | int z_ref; |
solidify/solidify.c | ||
---|---|---|
127 | 127 | int main(int argc, char **argv) |
128 | 128 | { |
129 | 129 | gtk_init(&argc, &argv); |
130 | setlocale(LC_ALL, "C"); /* damage control */ | |
131 | ||
130 | 132 | switch (argc) { |
131 | 133 | case 4: |
132 | 134 | break; |
133 | 135 | default: |
134 | 136 | usage(*argv); |
135 | 137 | } |
136 | setlocale(LC_ALL, "C"); /* damage control */ | |
138 | ||
137 | 139 | solid.a = read_face(argv[1]); |
138 | 140 | 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 | ||
140 | 149 | gui(); |
150 | ||
141 | 151 | if (!isatty(1)) |
142 | 152 | povray(&solid); |
143 | 153 |
Branches:
master