2010-09-22 23:04:43 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "array.h"
|
2010-09-22 23:40:03 +03:00
|
|
|
#include "histo.h"
|
2010-09-22 23:04:43 +03:00
|
|
|
#include "face.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct face *read_face(const char *name)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
struct face *f;
|
2010-09-22 23:40:03 +03:00
|
|
|
struct histo *h;
|
2010-09-22 23:04:43 +03:00
|
|
|
float x, y, z;
|
|
|
|
int xi, yi, zi;
|
|
|
|
|
2010-09-22 23:40:03 +03:00
|
|
|
if (!strcmp(name, "-")) {
|
|
|
|
file = stdin;
|
|
|
|
} else {
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(name);
|
|
|
|
if (len > 4 && !strcmp(name+len-4, ".bz2")) {
|
|
|
|
char tmp[1000]; /* @@@ enough */
|
|
|
|
|
|
|
|
sprintf(tmp, "bzcat \"%s\"", name);
|
|
|
|
file = popen(tmp, "r");
|
|
|
|
if (!file) {
|
|
|
|
perror(tmp);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
file = fopen(name, "r");
|
|
|
|
if (!file) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2010-09-22 23:04:43 +03:00
|
|
|
}
|
|
|
|
f = alloc_type(struct face);
|
|
|
|
f->a = new_array();
|
|
|
|
|
|
|
|
while (fscanf(file, "%f,%f,%f\r\n", &x, &y, &z) == 3) {
|
|
|
|
/* @@@ hack - should auto-scale */
|
|
|
|
xi = round(x*10.0);
|
|
|
|
yi = round(y*10.0);
|
|
|
|
zi = round(z*40.0);
|
|
|
|
set(f->a, xi, yi, zi);
|
|
|
|
}
|
2010-09-22 23:40:03 +03:00
|
|
|
if (file != stdin)
|
|
|
|
(void) fclose(file);
|
2010-09-22 23:04:43 +03:00
|
|
|
|
|
|
|
f->sx = f->a->max_x-f->a->min_x+1;
|
|
|
|
f->sy = f->a->max_y-f->a->min_y+1;
|
2010-09-22 23:40:03 +03:00
|
|
|
h = make_histo(f->a);
|
|
|
|
f->z_ref = f->a->min_z+median(h);
|
|
|
|
free_histo(h);
|
2010-09-23 01:20:29 +03:00
|
|
|
f->fx = f->fy = 0;
|
|
|
|
|
2010-09-22 23:04:43 +03:00
|
|
|
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_z, f->a->max_z);
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|