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

slicer/: new option -z to add intermediate layers

This commit is contained in:
Werner Almesberger 2015-01-08 09:53:52 -03:00
parent 9fc0962edc
commit b2d6ef5f3c
3 changed files with 74 additions and 2 deletions

View File

@ -152,6 +152,63 @@ void slice(struct v f[3])
} }
/* ----- Insert intermediate layers ---------------------------------------- */
struct ctx {
float z_step;
bool first;
float z0; /* only defined if !first */
bool more; /* returned due to having made changes */
};
static gboolean check_z(gpointer key, gpointer value, gpointer data)
{
const struct z *z = value;
struct ctx *ctx = data;
float d;
int n, i;
if (!z->present)
return 0;
if (ctx->first) {
ctx->first = 0;
ctx->z0 = z->z;
return 0;
}
d = z->z - ctx->z0;
if (d <= ctx->z_step) {
ctx->z0 = z->z;
return 0;
}
n = (d / ctx->z_step) + 1;
for (i = 1; i < n; i++)
mark_z(ctx->z0 + d / n * i);
ctx->more = 1;
return 1;
}
void slice_intermediate(float z_step)
{
struct ctx ctx = {
.z_step = z_step,
};
do {
ctx.first = 1;
ctx.more = 0;
g_tree_foreach(tree, check_z, &ctx);
}
while (ctx.more);
}
/* ----- Dumping ----------------------------------------------------------- */ /* ----- Dumping ----------------------------------------------------------- */

View File

@ -18,6 +18,7 @@
void slice(struct v f[3]); void slice(struct v f[3]);
void slice_intermediate(float z_step);
void slice_dump(float box); void slice_dump(float box);
void slice_init(void); void slice_init(void);

View File

@ -21,7 +21,13 @@
static void usage(const char *name) static void usage(const char *name)
{ {
fprintf(stderr, "usage: %s [-b distance] [file.stl]\n", name); fprintf(stderr,
"usage: %s [-b distance] [-z distance] [file.stl]\n"
" -b distance draw a box at the specified distance around the object\n"
" (default: do not draw a box)\n"
" -z distance duplicate layers if distance to next lower is larger than\n"
" specified (default: do not insert intermediate layers\n"
, name);
exit(1); exit(1);
} }
@ -29,17 +35,23 @@ static void usage(const char *name)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
float box = 0; float box = 0;
float z_step = 0;
int c; int c;
slice_init(); slice_init();
while ((c = getopt(argc, argv, "b:")) != EOF) while ((c = getopt(argc, argv, "b:z:")) != EOF)
switch (c) { switch (c) {
case 'b': case 'b':
box = atof(optarg); box = atof(optarg);
if (!box) if (!box)
usage(*argv); usage(*argv);
break; break;
case 'z':
z_step = atof(optarg);
if (!z_step)
usage(*argv);
break;
default: default:
usage(*argv); usage(*argv);
} }
@ -55,6 +67,8 @@ int main(int argc, char **argv)
usage(*argv); usage(*argv);
} }
if (z_step)
slice_intermediate(z_step);
slice_dump(box); slice_dump(box);
return 0; return 0;