1
0
mirror of git://projects.qi-hardware.com/ben-scans.git synced 2024-06-07 08:34:12 +03:00

Use the project name to disambiguate names in POV-Ray output.

- solidify/main.pov: change name from "Part" to "Part_batcvr"
- solidify/solid.h (povray), solidify/solid.c (sanitize, povray): use the
  project name as prefix for PGM files and a suffix for the object name
- solidify/solidify.c (main): pass the project's basename to povray()
This commit is contained in:
Werner Almesberger 2010-09-24 21:28:42 -03:00
parent f6ed3bf762
commit 01d8e411f3
4 changed files with 39 additions and 11 deletions

View File

@ -14,7 +14,7 @@ light_source {
}
union {
Part
Part_batcvr
pigment { rgb <0.9, 0.9, 0.9> }
finish {
brilliance 2

View File

@ -47,25 +47,45 @@ static void height_field(const char *name, const struct face *f,
}
void povray(const struct solid *s)
static void sanitize(const char *s, char *res)
{
while (*s) {
if ((*s >= 'A' && *s <= 'Z') ||
(*s >= 'a' && *s <= 'z') ||
(*s >= '0' && *s <= '9') || *s == '_')
*res = *s;
else
*res = '_';
res++;
s++;
}
*res = 0;
}
void povray(const char *name, const struct solid *s)
{
struct matrix m;
char tmp[1000]; /* @@@ enough */
m.a[0][0] = m.a[1][1] = 1;
m.a[0][1] = m.a[1][0] = 0;
m.b[0] = m.b[1] = 0;
height_field("top.pgm", s->a, &m);
height_field("bot.pgm", s->b, &m);
sprintf(tmp, "%s-top.pgm", name);
height_field(tmp, s->a, &m);
sprintf(tmp, "%s-bot.pgm", name);
height_field(tmp, s->b, &m);
/*
* 1/65535 = 0.000015..., so we set the water level a bit lower, e.g.,
* to 0.0001
*/
sanitize(name, tmp);
printf(
"#declare Part =\n"
"#declare Part_%s =\n"
" intersection {\n"
" height_field { pgm \"top.pgm\" water_level 0.00001 smooth }\n"
" height_field { pgm \"bot.pgm\" water_level 0.00001 smooth }\n"
" }\n");
" height_field { pgm \"%s-top.pgm\" water_level 0.00001 smooth }\n"
" height_field { pgm \"%s-bot.pgm\" water_level 0.00001 smooth }\n"
" }\n", tmp, name, name);
}

View File

@ -19,6 +19,6 @@ struct solid {
};
void povray(const struct solid *s);
void povray(const char *name, const struct solid *s);
#endif /* !SOLID_H */

View File

@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <locale.h>
#include <gtk/gtk.h>
@ -148,8 +149,15 @@ int main(int argc, char **argv)
save_project(prj);
if (!isatty(1))
povray(&prj->s);
if (!isatty(1)) {
const char *slash = strrchr(prj->name, '/');
char tmp[1000]; /* @@@ enough */
strcpy(tmp, slash ? slash+1 : prj->name);
if (strchr(tmp, '.'))
*strchr(tmp, '.') = 0;
povray(tmp, &prj->s);
}
return 0;
}