1
0
mirror of git://projects.qi-hardware.com/ben-scans.git synced 2024-11-22 03:43:09 +02:00

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
This commit is contained in:
Werner Almesberger 2010-09-24 19:53:06 -03:00
parent 0c494069c3
commit 2cc9a9e505
3 changed files with 89 additions and 15 deletions

View File

@ -26,15 +26,20 @@
#define CACHE_DIR ".cache" #define CACHE_DIR ".cache"
#define DEFAULT_STEP 1 /* 1 mm */
#define MIN_STEP 0.005 /* 5 um */
static struct face *read_file(const char *name) struct coord {
float x, y, z;
};
static struct coord *load_file(const char *name)
{ {
FILE *file; FILE *file;
struct face *f; struct coord *v, *n;
struct histo *h; int s;
float x, y, z;
int xi, yi, zi;
if (!strcmp(name, "-")) { if (!strcmp(name, "-")) {
file = stdin; file = stdin;
@ -59,19 +64,76 @@ static struct face *read_file(const char *name)
} }
} }
} }
f = alloc_type(struct face);
f->a = new_array();
while (fscanf(file, "%f,%f,%f\r\n", &x, &y, &z) == 3) { v = n = alloc_type(struct coord);
/* @@@ hack - should auto-scale */ s = 1;
xi = round(x*10.0);
yi = round(y*10.0); while (fscanf(file, "%f,%f,%f\r\n", &n->x, &n->y, &n->z) == 3) {
zi = round(z*40.0); n++;
set(f->a, xi, yi, zi); if (n-v == s) {
struct coord *tmp;
s += s;
tmp = realloc(v, sizeof(struct coord)*s);
if (!tmp) {
perror("realloc");
exit(1);
}
n = n-v+tmp;
v = tmp;
}
} }
if (file != stdin) if (file != stdin)
(void) fclose(file); (void) fclose(file);
n->x = n->y = n->z = 0;
return v;
}
static void adjust_step(double *step, double delta)
{
double n = round(delta/MIN_STEP);
double s = n*MIN_STEP;
if (n && s < *step)
*step = s;
}
static struct face *read_file(const char *name)
{
struct coord *v, *p;
struct face *f;
struct histo *h;
int xi, yi, zi;
v = load_file(name);
f = alloc_type(struct face);
f->a = new_array();
/*
* Hack: the MDX-15 measures bumps along the x axis with 25 um
* resolution, so we just ignore the x resultion we find and use the
* y resolution instead.
*/
f->x_step = f->y_step =f->z_step = DEFAULT_STEP;
for (p = v; p[1].x || p[1].y || p[1].z; p++) {
adjust_step(&f->y_step, fabs(p[0].y-p[1].y));
adjust_step(&f->z_step, fabs(p[0].z-p[1].z));
}
f->x_step = f->y_step;
for (p = v; p->x || p->y || p->z; p++) {
xi = round(p->x/f->x_step);
yi = round(p->y/f->y_step);
zi = round(p->z/f->z_step);
set(f->a, xi, yi, zi);
}
free(v);
f->sx = f->a->max_x-f->a->min_x+1; f->sx = f->a->max_x-f->a->min_x+1;
f->sy = f->a->max_y-f->a->min_y+1; f->sy = f->a->max_y-f->a->min_y+1;
@ -87,6 +149,7 @@ static struct face *read_file(const char *name)
f->m.a[0][1] = f->m.a[1][0] = 0; f->m.a[0][1] = f->m.a[1][0] = 0;
f->m.b[0] = f->m.b[1] = 0; f->m.b[0] = f->m.b[1] = 0;
fprintf(stderr, "%g %g %g\n", f->x_step, f->y_step, f->z_step);
fprintf(stderr, "%d-%d / %d-%d / %d-%d\n", fprintf(stderr, "%d-%d / %d-%d / %d-%d\n",
f->a->min_x, f->a->max_x, f->a->min_y, f->a->max_y, f->a->min_x, f->a->max_x, f->a->min_y, f->a->max_y,
f->a->min_z, f->a->max_z); f->a->min_z, f->a->max_z);

View File

@ -19,6 +19,7 @@
struct face { struct face {
struct array *a; struct array *a;
double x_step, y_step, z_step;
int sx, sy; /* size */ int sx, sy; /* size */
int cx, cy; /* center */ int cx, cy; /* center */
int z_ref; int z_ref;

View File

@ -127,17 +127,27 @@ static void usage(const char *name)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
setlocale(LC_ALL, "C"); /* damage control */
switch (argc) { switch (argc) {
case 4: case 4:
break; break;
default: default:
usage(*argv); usage(*argv);
} }
setlocale(LC_ALL, "C"); /* damage control */
solid.a = read_face(argv[1]); solid.a = read_face(argv[1]);
solid.b = read_face(argv[2]); solid.b = read_face(argv[2]);
solid.dist = atof(argv[3])/0.025; /* @@@ hack */ if (solid.a->x_step != solid.a->x_step ||
solid.a->y_step != solid.a->y_step ||
solid.a->z_step != solid.a->z_step) {
fprintf(stderr, "both faces must have the same resolution\n");
exit(1);
}
solid.dist = atof(argv[3])/solid.a->z_step;
gui(); gui();
if (!isatty(1)) if (!isatty(1))
povray(&solid); povray(&solid);