mirror of
git://projects.qi-hardware.com/ben-scans.git
synced 2024-11-25 13:44:05 +02:00
ecf993e0f2
- solidify/Makefile, solidify/histo.h, solidify/histo.c: generate a Z histogram and find the median height - solidify/face.c (read_face): set z_ref to the median, not the average - solidify/face.c (read_face): uncompress .bz2 files on the fly - solidify/face.c (read_face): don't close standard input (for style)
40 lines
641 B
C
40 lines
641 B
C
#include "util.h"
|
|
#include "array.h"
|
|
#include "histo.h"
|
|
|
|
|
|
struct histo *make_histo(struct array *a)
|
|
{
|
|
int i;
|
|
struct histo *h;
|
|
|
|
h = alloc_type(struct histo);
|
|
h->n = a->max_z-a->min_z+1;
|
|
h->b = alloc_size(h->n*sizeof(int));
|
|
for (i = 0; i != h->n; i++)
|
|
h->b[i] = 0;
|
|
for (i = 0; i != (a->max_x-a->min_x+1)*(a->max_y-a->min_y+1); i++)
|
|
if (a->data[i] != UNDEF)
|
|
h->b[a->data[i]-a->min_z]++;
|
|
return h;
|
|
}
|
|
|
|
|
|
void free_histo(struct histo *h)
|
|
{
|
|
free(h);
|
|
}
|
|
|
|
|
|
int median(const struct histo *h)
|
|
{
|
|
int tot = 0, sum = 0;
|
|
int i;
|
|
|
|
for (i = 0; i != h->n; i++)
|
|
tot += h->b[i];
|
|
for (i = 0; sum < tot/2; i++)
|
|
sum += h->b[i];
|
|
return i-1;
|
|
}
|