Compare commits

...

4 Commits

Author SHA1 Message Date
tTh f5de09b23a cosmetic 2023-04-30 11:15:59 +02:00
tTh b12bdfe306 add -o option (output filename) 2023-04-30 01:03:49 +02:00
tTh 7cefa36d62 add bouding-box export 2023-04-29 23:44:56 +02:00
tTh 992c98cfa8 must be a cli opt ! 2023-04-28 23:09:56 +02:00
5 changed files with 104 additions and 22 deletions

24
tools/edges2bubulles.awk Executable file
View File

@ -0,0 +1,24 @@
#!/bin/awk -f
#
# this software is NOT ready for prime time !
#
BEGIN {
count = 0
print "/* DO NOT EDIT BY HAND, BASTARD !*/"
print "/* generated ", strftime(), " */"
print
print "#declare OBJ_vertices = object\n{"
print "union {"
}
{
printf "sphere { <%.9f, %.9f, %.9f>, RR }\n", $1, $2, $3
count++;
}
END {
print " }\n}\n"
print "// ", count, "vertices.\n"
}

View File

@ -17,6 +17,43 @@
int verbosity; int verbosity;
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int printf_the_boudingbox(EdgesAndVertices *eav)
{
int idx;
double x, y, z;
double minX, minY, minZ;
double maxX, maxY, maxZ;
minX = minY = minZ = 1e35;
maxX = maxY = maxZ = -1e35;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, eav);
#endif
fprintf(stderr, "====== %s is not fully implemented ======\n", __func__);
for (idx=0; idx<eav->Blist->fidx; idx++) {
x = eav->Blist->bbs[idx].p.x;
y = eav->Blist->bbs[idx].p.y;
z = eav->Blist->bbs[idx].p.z;
if (x < minX) minX = x;
else if (x > maxX) maxX = x;
if (y < minY) minY = y;
else if (y > maxY) maxY = y;
if (z < minZ) minZ = z;
else if (z > maxZ) maxZ = z;
}
printf( "%.9f %.9f %.9f %.9f %.9f %.9f\n",
minX, minY, minZ, maxX, maxY, maxZ);
return -1;
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */ /* EXPERIMENTAL GRUIK-CODE !!! */
int printf_the_vertices(EdgesAndVertices *eav) int printf_the_vertices(EdgesAndVertices *eav)
@ -101,12 +138,16 @@ if (verbosity > 1) {
mode = 666; mode = 666;
if (! strcasecmp("edges", outmode)) { mode = 0; } if (! strcasecmp("edges", outmode)) { mode = 0; }
else if (! strcasecmp("vertices", outmode)) { mode = 1; } else if (! strcasecmp("vertices", outmode)) { mode = 1; }
else if (! strcasecmp("bbox", outmode)) { mode = 2; }
switch (mode) { switch (mode) {
case 0: case 0:
printf_the_edges(&eav); break; printf_the_edges(&eav); break;
case 1: case 1:
printf_the_vertices(&eav); break; printf_the_vertices(&eav); break;
case 2:
printf_the_boudingbox(&eav); break;
default: default:
fprintf(stderr, "no way to do '%s'\n", outmode); fprintf(stderr, "no way to do '%s'\n", outmode);
exit(1); exit(1);
@ -141,10 +182,11 @@ while ((opt = getopt(argc, argv, "ht:v")) != -1) {
case 'v': case 'v':
verbosity++; break; verbosity++; break;
case 't': case 't':
fprintf(stderr, "type -> '%s'\n", optarg); // fprintf(stderr, "type -> '%s'\n", optarg);
outmode = optarg; outmode = optarg;
break; break;
default: default:
fprintf(stderr, "'%c' EBADOPT\n", opt);
exit(1); exit(1);
break; break;
} }

View File

@ -22,6 +22,7 @@ extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define PSYCHOTIK 1
#define LINE_SZ 666 #define LINE_SZ 666
static BBList *bublist; static BBList *bublist;
@ -149,8 +150,11 @@ if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) {
for (ix=0; ix<3; ix++) { for (ix=0; ix<3; ix++) {
a = ix % 3; a = ix % 3;
b = (ix+1) % 3; b = (ix+1) % 3;
// foo = push_a_missing_edge(edges, pts[a], pts[b]); #if PSYCHOTIK
foo = push_a_missing_edge(edges, pts[a], pts[b]);
#else
foo = push_an_edge(edges, pts[a], pts[b]); foo = push_an_edge(edges, pts[a], pts[b]);
#endif
if (foo) { if (foo) {
fprintf(stderr, "%s: disaster #%d line %d\n", fprintf(stderr, "%s: disaster #%d line %d\n",
__func__, foo, linenumber); __func__, foo, linenumber);
@ -171,9 +175,9 @@ return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* /*
* * The main procedure, who contains a lot of things.
*/ */
int try_to_read_an_OBJ_file(char *infname, int outstyle) int try_to_read_an_OBJ_file(char *infname, char *ofname, int outstyle)
{ {
FILE *fpin; FILE *fpin;
char line[LINE_SZ+1], *cptr, *token; char line[LINE_SZ+1], *cptr, *token;
@ -184,7 +188,8 @@ Bubulle bubulle;
char *outfname, *baseptr; char *outfname, *baseptr;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n\n", __func__, infname, outstyle); fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n\n", __func__,
infname, ofname, outstyle);
#endif #endif
/* get memory for generated output filename(s) */ /* get memory for generated output filename(s) */
@ -310,8 +315,8 @@ fclose(fpin);
fprintf(stderr, " ***************************************\n"); fprintf(stderr, " ***************************************\n");
if(verbosity) { if(verbosity) {
fprintf(stderr, "%s(): %d vertices loaded\n", __func__, bublist->fidx); fprintf(stderr, "%s(): %9d vertices loaded\n", __func__, bublist->fidx);
fprintf(stderr, "%s(): %d edges loaded\n", __func__, edges->fidx); fprintf(stderr, "%s(): %9d edges loaded\n", __func__, edges->fidx);
} }
if (verbosity > 1) { if (verbosity > 1) {
@ -319,7 +324,7 @@ if (verbosity > 1) {
print_edgelist_desc(edges, 0); print_edgelist_desc(edges, 0);
} }
if (outstyle) { /* two ascii files */ if (outstyle) { /* two ascii files */
strcpy(outfname, infname); strcpy(outfname, infname);
cptr = rindex(outfname, '.'); cptr = rindex(outfname, '.');
fprintf(stderr, "rindex -> [%s]\n", cptr); fprintf(stderr, "rindex -> [%s]\n", cptr);
@ -327,15 +332,23 @@ if (outstyle) { /* two ascii files */
bubulles_to_data(outfname, NULL, bublist, 0); bubulles_to_data(outfname, NULL, bublist, 0);
// edges_to_data(file_edges, edges, 0); // edges_to_data(file_edges, edges, 0);
} }
else { /* one 'evblob' file */ else { /* one 'evblob' file */
strcpy(outfname, infname); if (NULL == ofname) {
/* see manpage basename(3) */ strcpy(outfname, infname);
baseptr = basename(outfname); /* see manpage basename(3) */
// fprintf(stderr, "baseptr -> [%s]\n", baseptr); baseptr = basename(outfname);
cptr = rindex(baseptr, '.'); // fprintf(stderr, "baseptr -> [%s]\n", baseptr);
strcpy(cptr, ".evblob"); cptr = rindex(baseptr, '.');
// fprintf(stderr, "baseptr-> [%s]\n", baseptr); strcpy(cptr, ".evblob");
foo = x_write_vertedges(baseptr, bublist, edges); fprintf(stderr, "baseptr-> [%s]\n", baseptr);
cptr = baseptr;
}
else {
cptr = ofname;
fprintf(stderr, "writing to %s\n", cptr);
}
foo = x_write_vertedges(cptr, bublist, edges);
if (foo) { if (foo) {
fprintf(stderr, "Err #%d when writing edges&vertices file\n", foo); fprintf(stderr, "Err #%d when writing edges&vertices file\n", foo);
} }

View File

@ -15,7 +15,7 @@ typedef struct {
} EdgesAndVertices; } EdgesAndVertices;
/* in importobj.c */ /* in importobj.c */
int try_to_read_an_OBJ_file(char *fname, int outstyle); int try_to_read_an_OBJ_file(char *fname, char *oname, int outstyle);
/* in rdwredges.c */ /* in rdwredges.c */
int x_write_vertedges (char *filename, BBList *bblist, EdgeList *edges); int x_write_vertedges (char *filename, BBList *bblist, EdgeList *edges);

View File

@ -25,7 +25,7 @@ exit(0);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, opt; int foo, opt;
// char *fname; /* see manpage basename(3) */ char *ofname = NULL;
fprintf(stderr, "\n### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__); fprintf(stderr, "\n### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__);
@ -34,10 +34,13 @@ if (1 == argc) {
exit(0); exit(0);
} }
while ((opt = getopt(argc, argv, "hv")) != -1) { while ((opt = getopt(argc, argv, "ho:v")) != -1) {
switch(opt) { switch(opt) {
case 'h': case 'h':
help(); break; help(); break;
case 'o':
ofname = optarg;
break;
case 'v': case 'v':
verbosity++; break; verbosity++; break;
default: default:
@ -48,8 +51,8 @@ while ((opt = getopt(argc, argv, "hv")) != -1) {
if (optind < argc) { if (optind < argc) {
// fprintf(stderr, "ARG = %s\n", argv[optind]); fprintf(stderr, "arg = %s\n", argv[optind]);
foo = try_to_read_an_OBJ_file(argv[optind], 0); foo = try_to_read_an_OBJ_file(argv[optind], ofname, 0);
if (foo) { if (foo) {
fprintf(stderr, "Error number %d on '%s'\n", foo, argv[optind]); fprintf(stderr, "Error number %d on '%s'\n", foo, argv[optind]);
exit(1); exit(1);