1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 23:04:16 +02:00

slicer/slice.c, slice.h: optionally draw a box around the object

This commit is contained in:
Werner Almesberger 2015-01-08 09:12:05 -03:00
parent 65fa69cd0c
commit 6b7cecaf5f
2 changed files with 55 additions and 3 deletions

View File

@ -38,6 +38,35 @@ struct z {
static GTree *tree;
/* ----- Bounding box ------------------------------------------------------ */
static bool first = 1;
static float min_x, max_x, min_y, max_y;
static void bbox(float x, float y)
{
if (first) {
min_x = max_x = x;
min_y = max_y = y;
first = 0;
} else {
if (x < min_x)
min_x = x;
if (y < min_y)
min_y = y;
if (x > max_x)
max_x = x;
if (y > max_y)
max_y = y;
}
}
/* ----- Data collection --------------------------------------------------- */
static inline bool eq(float a, float b)
{
return fabsf(a - b) < 1e-6;
@ -91,6 +120,9 @@ fprintf(stderr, "zero point\n");
exit(1);
}
bbox(a->x, a->y);
bbox(b->x, b->y);
z = get_z(a->z);
line = alloc_type(struct line);
line->ax = a->x;
@ -152,9 +184,30 @@ static gboolean dump_range(gpointer key, gpointer value, gpointer data)
}
void slice_dump(void)
static gboolean dump_box(gpointer key, gpointer value, gpointer data)
{
const struct z *z = value;
float box = *(float *) data;
if (!z->present)
return 0;
printf("%f %f %f\n%f %f %f\n%f %f %f\n%f %f %f\n%f %f %f\n\n\n",
min_x - box, min_y - box, z->z,
max_x + box, min_y - box, z->z,
max_x + box, max_y + box, z->z,
min_x - box, max_y + box, z->z,
min_x - box, min_y - box, z->z);
return 0;
}
void slice_dump(float box)
{
g_tree_foreach(tree, dump_range, NULL);
if (box && !first)
g_tree_foreach(tree, dump_box, &box);
}
@ -167,7 +220,6 @@ static gint comp(gconstpointer a, gconstpointer b)
const float *zb = b;
return eq(*za, *zb) ? 0 : *za < *zb ? -1 : 1;
}

View File

@ -18,7 +18,7 @@
void slice(struct v f[3]);
void slice_dump(void);
void slice_dump(float box);
void slice_init(void);
#endif /* !SLICE_H */