refactoring, first step

This commit is contained in:
tTh 2023-04-20 22:33:46 +02:00
parent a1056ee836
commit 87c2ffd88d
6 changed files with 141 additions and 42 deletions

22
tools/edges2cylinders.awk Executable file
View File

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

View File

@ -19,33 +19,40 @@ int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */ /* EXPERIMENTAL GRUIK-CODE !!! */
int load_and_printf_evblob(char *filename, int mode)
int main(int argc, char *argv[])
{ {
EdgesAndVertices eav; EdgesAndVertices eav;
int foo, idx, a, b; int foo, idx, a, b;
fprintf(stderr, "### EdgesAndVertices - %s %s\n", __DATE__, __TIME__); #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, filename, mode);
#endif
verbosity = 0; if (mode) {
fprintf(stderr, "W: in %s 'mode' must be zero, and was %d\n",
__func__, mode);
}
memset(&eav, 0, sizeof(EdgesAndVertices)); memset(&eav, 0, sizeof(EdgesAndVertices));
foo = x_load_vertedges("foo.evblob", &eav); foo = x_load_vertedges(filename, &eav);
fprintf(stderr, " load vertice & edges blob -> %d\n", foo); if (foo) {
fprintf(stderr, " load vertice & edges blob -> %d\n", foo);
return foo;
}
if (verbosity) { if (verbosity) {
fprintf(stderr, "vertices at %p\n", eav.Blist); fprintf(stderr, "vertices at %p\n", eav.Blist);
fprintf(stderr, "edges at %p\n", eav.Elist); fprintf(stderr, "edges at %p\n", eav.Elist);
fprintf(stderr, "status is %d\n", eav.status); fprintf(stderr, "status is %d\n", eav.status);
fprintf(stderr, "got %d vertices and %d edges\n",
eav.Blist->fidx,
eav.Elist->fidx);
} }
/* /*
* OK we have (maybe) all the data in da place * OK we have (maybe) all the data in da place
* and we can spit all the edges to stdout * and we can spit all the edges to stdout
*/ */
fprintf(stderr, "got %d vertices and %d edges\n",
eav.Blist->fidx,
eav.Elist->fidx);
for (idx=0; idx<eav.Elist->fidx; idx++) { for (idx=0; idx<eav.Elist->fidx; idx++) {
@ -53,16 +60,62 @@ for (idx=0; idx<eav.Elist->fidx; idx++) {
b = eav.Elist->edges[idx].B; b = eav.Elist->edges[idx].B;
// fprintf(stderr, "%7d %7d\n", a, b); // fprintf(stderr, "%7d %7d\n", a, b);
printf("%.9f %f %f %f %f %f\n", printf("%.9f %.9f %.9f %.9f %.9f %.9f\n",
eav.Blist->bbs[a].p.x, eav.Blist->bbs[a].p.x,
eav.Blist->bbs[a].p.y, eav.Blist->bbs[a].p.y,
eav.Blist->bbs[a].p.z, eav.Blist->bbs[a].p.z,
eav.Blist->bbs[b].p.x, eav.Blist->bbs[b].p.x,
eav.Blist->bbs[b].p.y, eav.Blist->bbs[b].p.y,
eav.Blist->bbs[b].p.z ); eav.Blist->bbs[b].p.z );
} }
return 0;
}
/* --------------------------------------------------------------------- */
void help(void)
{
fprintf(stderr, "YOLO!\n");
exit(0);
}
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int main(int argc, char *argv[])
{
int opt, foo;
fprintf(stderr, "### EdgesAndVertices - %s %s\n", __DATE__, __TIME__);
verbosity = 0;
while ((opt = getopt(argc, argv, "hv")) != -1) {
switch(opt) {
case 'h':
help(); break;
case 'v':
verbosity++; break;
default:
fprintf(stderr, "gni(%c)?\n", opt);
break;
}
}
#if DEBUG_LEVEL
fprintf(stderr, "optind=%d argc=%d\n", optind, argc);
#endif
if (optind < argc) {
// fprintf(stderr, "ARG = %s\n", argv[optind]);
foo = load_and_printf_evblob(argv[optind], 0);
if (foo) {
fprintf(stderr, "Error number %d on '%s'\n", foo, argv[optind]);
exit(1);
}
}
else {
fprintf(stderr, "%s need a input filename\n", argv[0]);
exit(1);
}
return 0; return 0;
} }

View File

@ -55,6 +55,8 @@ Tokens TokenList[] = {
{ NULL, 0 } { NULL, 0 }
}; };
/* --------------------------------------------------------------------- */
static int type_of_the_line(char *text) static int type_of_the_line(char *text)
{ {
Tokens *token; Tokens *token;
@ -95,7 +97,6 @@ if (3 == foo) {
return foo; return foo;
} }
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* new Mon 27 Mar 2023 12:08:18 AM CEST /* new Mon 27 Mar 2023 12:08:18 AM CEST
@ -103,13 +104,13 @@ return foo;
* mmmm... complex thing to do... * mmmm... complex thing to do...
* and what is this "phy" parameter ? * and what is this "phy" parameter ?
*/ */
static int parse_face(char *cptr, int phy) static int parse_face(char *cptr)
{ {
int ix, foo, a, b; int ix, foo, a, b;
int pts[3]; int pts[3];
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, phy); fprintf(stderr, ">>> %s ( '%s' )\n", __func__, cptr, phy);
#endif #endif
#if (0) #if (0)
@ -144,7 +145,6 @@ if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) {
* may be we can check the "degenerated cylinder" here ? * may be we can check the "degenerated cylinder" here ?
*/ */
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;
@ -168,48 +168,56 @@ fprintf(stderr, "<<< %s\n", __func__);
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int try_to_read_an_OBJ_file(char *infname, char *file_vert, char *file_edges, /*
int notused) *
*/
int try_to_read_an_OBJ_file(char *infname, int outstyle)
{ {
FILE *fpin; FILE *fpin;
char line[LINE_SZ+1], *cptr, *token; char line[LINE_SZ+1], *cptr, *token;
float x, y, z; float x, y, z;
int foo, nbre, tokenid; int foo, tokenid;
Bubulle bubulle; Bubulle bubulle;
char *outfname;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n\n", __func__, infname, notused); fprintf(stderr, ">>> %s ( '%s' ... %d )\n\n", __func__, infname, notused);
#endif #endif
/* get memory for generated output filename(s) */
if (NULL==(outfname=malloc(strlen(infname)+33)) ) {
fprintf(stderr, "%s : not enough mem, sorry\n", __func__);
return -666;
}
if (NULL==(fpin=fopen(infname, "r"))) { if (NULL==(fpin=fopen(infname, "r"))) {
perror(infname); perror(infname);
exit(1); exit(1);
} }
linenumber = 0; linenumber = 0;
bublist = alloc_bubulles(infname, 400000, 0); bublist = alloc_bubulles(infname, 600000, 0);
if (NULL==bublist) { if (NULL==bublist) {
fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__); fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__);
abort(); abort();
} }
if (verbosity > 1) print_bublist_desc(bublist, 0); if (verbosity > 1) print_bublist_desc(bublist, 0);
edges = alloc_edgelist("krkrkr", 600000, 0); edges = alloc_edgelist("krkrkr", 2200000, 0);
if (NULL==edges) { if (NULL==edges) {
fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__); fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__);
abort(); abort();
} }
if (verbosity > 1) print_edgelist_desc(edges, 0); if (verbosity > 1) print_edgelist_desc(edges, 0);
fprintf(stderr, "\n ***********************************\n"); fprintf(stderr, "\n ***************************************\n");
nbre = 0;
while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
if ('\n' != line[strlen(line)-1]) { if ('\n' != line[strlen(line)-1]) {
fprintf(stderr, "%s: short read on %s...\n", fprintf(stderr, "%s: short read on %s line %d\n",
__func__, infname); __func__, infname, linenumber);
// return -2; // return -2;
break; break;
} }
@ -257,7 +265,7 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
break; break;
case T_face: case T_face:
/* experimental code here */ /* experimental code here */
foo = parse_face(cptr, 0); foo = parse_face(cptr);
if (foo) { if (foo) {
fprintf(stderr, "line %d '%s' parse face -> %d\n", fprintf(stderr, "line %d '%s' parse face -> %d\n",
linenumber, cptr, foo); linenumber, cptr, foo);
@ -293,11 +301,11 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
fprintf(stderr, "token %s -> %d ?\n", token, tokenid); fprintf(stderr, "token %s -> %d ?\n", token, tokenid);
break; break;
} }
nbre++;
} }
fclose(fpin); 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(): %d vertices loaded\n", __func__, bublist->fidx);
@ -309,11 +317,24 @@ if (verbosity > 1) {
print_edgelist_desc(edges, 0); print_edgelist_desc(edges, 0);
} }
bubulles_to_data(file_vert, NULL, bublist, 0); if (outstyle) { /* two ascii files */
strcpy(outfname, infname);
edges_to_data(file_edges, edges, 0); cptr = rindex(outfname, '.');
fprintf(stderr, "rindex -> [%s]\n", cptr);
foo = x_write_vertedges("foo.evblob", bublist, edges); strcpy(cptr, ".vertices");
bubulles_to_data(outfname, NULL, bublist, 0);
// edges_to_data(file_edges, edges, 0);
}
else { /* one 'evblob' file */
strcpy(outfname, infname);
cptr = rindex(outfname, '.');
strcpy(cptr, ".evblob");
fprintf(stderr, "outfname [%s]\n", outfname);
foo = x_write_vertedges(outfname, bublist, edges);
if (foo) {
fprintf(stderr, "Err #%d when writing edges&vertices file\n", foo);
}
}
// Cleanup // Cleanup
free_bubulles(bublist, 0); free_bubulles(bublist, 0);

View File

@ -1,9 +1,10 @@
/* /*
* EXPERIMENTAL CODE ! * EXPERIMENTAL CODE !
* *
* see also 'rdwredges.c * see also 'rdwredges.c' & 'export_evblob.c'
*/ */
#define EVBLOB_MAGIC (65872139)
typedef struct { typedef struct {
unsigned long magic; unsigned long magic;

View File

@ -49,7 +49,7 @@ if (NULL==(fp=fopen(filename, "w"))) {
return -4; return -4;
} }
print_bublist_desc(bblist, 0); // print_bublist_desc(bblist, 0);
fwrite("VERTICES", 8, 1, fp); fwrite("VERTICES", 8, 1, fp);
nbre = bblist->fidx; nbre = bblist->fidx;
fwrite(&nbre, sizeof(int), 1, fp); fwrite(&nbre, sizeof(int), 1, fp);
@ -61,7 +61,7 @@ for (idx=0; idx<bblist->fidx; idx++) {
fwrite(coo, sizeof(coo), 1, fp); fwrite(coo, sizeof(coo), 1, fp);
} }
print_edgelist_desc(edges, 0); // print_edgelist_desc(edges, 0);
fwrite("EDGES ", 8, 1, fp); fwrite("EDGES ", 8, 1, fp);
nbre = edges->fidx; nbre = edges->fidx;
fwrite(&nbre, sizeof(int), 1, fp); fwrite(&nbre, sizeof(int), 1, fp);
@ -121,6 +121,7 @@ if (NULL==blst) {
abort(); abort();
} }
if (verbosity > 1) print_bublist_desc(blst, 0); if (verbosity > 1) print_bublist_desc(blst, 0);
/* load all that XYZ points */ /* load all that XYZ points */
for (idx=0; idx<nbre; idx++) { for (idx=0; idx<nbre; idx++) {
if (3 != fread(coo, sizeof(double), 3, fp)) { if (3 != fread(coo, sizeof(double), 3, fp)) {
@ -151,6 +152,7 @@ if (1 != foo) {
return -1; return -1;
} }
fprintf(stderr, " %d edges to be loaded\n", nbre); fprintf(stderr, " %d edges to be loaded\n", nbre);
/* allocate memory for edges list */ /* allocate memory for edges list */
elst = alloc_edgelist("krkrkr", nbre, 0); elst = alloc_edgelist("krkrkr", nbre, 0);
if (NULL==elst) { if (NULL==elst) {

View File

@ -8,9 +8,7 @@
#include "../bubulles.h" #include "../bubulles.h"
int try_to_read_an_OBJ_file(char *fname, int try_to_read_an_OBJ_file(char *fname, int outstyle);
char *outfname, char *file_edges,
int notused);
int verbosity = 0; int verbosity = 0;
@ -20,19 +18,21 @@ int main(int argc, char *argv[])
int foo; int foo;
char *fname; /* see manpage basename(3) */ char *fname; /* see manpage basename(3) */
fprintf(stderr, "\n### READ_OBJ %s %s\n\n", __DATE__, __TIME__); fprintf(stderr, "\n### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__);
if (2 != argc) { if (2 != argc) {
bubulles_version(1); bubulles_version(1);
exit(0); exit(0);
} }
verbosity = 1; verbosity = 0;
/*
fname = basename(argv[1]); fname = basename(argv[1]);
fprintf (stderr, "input file name is '%s'\n", fname); fprintf (stderr, "input file name is '%s'\n", fname);
*/
foo = try_to_read_an_OBJ_file(argv[1], "bulles.vertices", "bulles.edges", 0); foo = try_to_read_an_OBJ_file(argv[1], 0);
fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo); fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo);
return 0; return 0;