1
0
mirror of git://projects.qi-hardware.com/ben-scans.git synced 2024-11-22 08:00:19 +02:00
ben-scans/solidify/histo.c
Werner Almesberger ecf993e0f2 solidify: set the initial height to the median; uncompress .bz2 on the fly.
- 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)
2010-09-22 17:40:03 -03:00

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;
}