diff --git a/edges.c b/edges.c index 7e0ba49..9cbc5da 100644 --- a/edges.c +++ b/edges.c @@ -70,28 +70,36 @@ return 0; */ static int is_edge_in_list(EdgeList *list, int p0, int p1) { -int idx; +int idx, retval, place; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1); +#endif + +retval = 0; place = -1; for (idx=0; idx < list->fidx; idx++) { if ( (list->edges[idx].A == p0) && - (list->edges[idx].B == p1) ) return 1; + (list->edges[idx].B == p1) ) { + retval = 1; place = idx; break; } if ( (list->edges[idx].A == p1) && - (list->edges[idx].B == p0) ) return 2; + (list->edges[idx].B == p0) ){ + retval = 2; place = idx; break; } } -return 0; /* NOT FOUND */ +if (retval) fprintf(stderr, " edge %d %d found at %d\n", p0, p1, idx); + +return retval; } /* --------------------------------------------------------------------- */ /* - * * we have two functions for adding an edge to a list * the first one add unconditionnaly the edge to the * (non full) list... */ int push_an_edge(EdgeList *list, int p0, int p1) { - #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1); #endif @@ -130,8 +138,12 @@ if (list->fidx >= list->size) { if ( ! is_edge_in_list(list, p0, p1) ) { list->edges[list->fidx].A = p0; list->edges[list->fidx].B = p1; + fprintf(stderr, "edge %d %d poked at %d\n", p0, p1, list->fidx); list->fidx ++; } +else { + fprintf(stderr, " %s: drop edge %d %d\n", __func__, p0, p1); + } return 0; } /* --------------------------------------------------------------------- */ diff --git a/tools/.gitignore b/tools/.gitignore index 0b7464b..f54b14c 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -6,7 +6,9 @@ export_evblob *.obj ! tools/minimal.obj ! tools/cube.obj +! overflowed.obj read_obj + *.xyz *.asc toto diff --git a/tools/Makefile b/tools/Makefile index 0d926db..12c3655 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,7 +1,7 @@ BBFUNCS = ../libbubulles.a -OPT = -Wall -Wextra -g -DDEBUG_LEVEL=0 -DMUST_ABORT=0 +OPT = -Wall -Wextra -O1 -g -DDEBUG_LEVEL=0 -DMUST_ABORT=0 all: read_obj export_evblob # essai_faces diff --git a/tools/essai_faces.c b/tools/essai_faces.c index 96322f9..f356ee6 100644 --- a/tools/essai_faces.c +++ b/tools/essai_faces.c @@ -32,6 +32,10 @@ printf(" -> %d\n", bar); return 0; } +/* + * GO ! + */ + int main(int argc, char *argv[]) { int foo, bar; diff --git a/tools/export_evblob.c b/tools/export_evblob.c index 7124e1d..18aacc6 100644 --- a/tools/export_evblob.c +++ b/tools/export_evblob.c @@ -88,7 +88,7 @@ fprintf(stderr, ">>> %s ( %p )\n", __func__, eav); if (verbosity) fprintf(stderr, " fprinting %d edges\n", eav->Elist->fidx); vmax = eav->Blist->fidx; -fprintf(stderr, " in %s, vmax was %d\n", __func__, vmax); +fprintf(stderr, " %s: eav->Blist->fidx = %d\n", __func__, vmax); /* * OK we have (maybe) all the data in da place @@ -102,7 +102,7 @@ for (idx=0; idxElist->fidx; idx++) { /* this is a Molly-Guard */ if ( (a<0) || (b<0) || (a>vmax) || (b>vmax) ) { fprintf(stderr, "ERROR: vmax=%d a=%d b=%d\n", vmax, a, b); - return -1; + continue; } printf("%.9f %.9f %.9f %.9f %.9f %.9f\n", @@ -167,6 +167,10 @@ if (foo) { exit(1); } +/* deallocate used memory for keep pinpin happy */ +free_bubulles(eav.Blist, 1); +free_edgelist(eav.Elist, 1); + return 0; } /* --------------------------------------------------------------------- */ diff --git a/tools/importobj.c b/tools/importobj.c index 2c1a952..f0e5ec3 100644 --- a/tools/importobj.c +++ b/tools/importobj.c @@ -104,15 +104,14 @@ return foo; /* new Mon 27 Mar 2023 12:08:18 AM CEST * * mmmm... complex thing to do... - * and what is this "phy" parameter ? */ -static int parse_face(char *cptr) +static int parse_face(char *cptr, int maxvert) { int ix, foo, a, b; -int pts[3]; +int pts[3], valid; #if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( '%s' )\n", __func__, cptr); +fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, maxvert); #endif #if (0) @@ -136,36 +135,44 @@ for (ix=0; ix<3; ix++) { } } -/** check the freshly read datas **/ +fprintf(stderr, " %s: pts %5d %5d %5d\n", __func__, + pts[0], pts[1], pts[2]); + +valid = 1; + +/**** check the freshly read datas ****/ if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) { fprintf(stderr, "%s: degenerated face ( %d %d %d )\n", __func__, pts[0], pts[1], pts[2]); dropped++; + valid = 0; + } +if ( (pts[0]>maxvert) || (pts[1]>maxvert) || (pts[2]>maxvert) ) { + fprintf(stderr, "%s: out of bound ( %d %d %d )\n", __func__, + pts[0], pts[1], pts[2]); + valid = 0; } - /* * may be we can check the "degenerated cylinder" here ? */ - -for (ix=0; ix<3; ix++) { - a = ix % 3; - b = (ix+1) % 3; +if (valid) { + for (ix=0; ix<3; ix++) { + a = ix % 3; + b = (ix+1) % 3; #if PSYCHOTIK - foo = push_a_missing_edge(edges, pts[a], pts[b]); + 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) { - fprintf(stderr, "%s: disaster #%d line %d\n", - __func__, foo, linenumber); - return -2; + if (foo) { + fprintf(stderr, "%s: disaster #%d line %d\n", + __func__, foo, linenumber); + return -2; + } } } -if (dropped) { - fprintf(stderr, "%s: %d dropped...\n", __func__, dropped); - // exit(1); - } +if (dropped) fprintf(stderr, "%s: %d dropped\n", __func__, dropped); #if DEBUG_LEVEL > 1 fprintf(stderr, "<<< %s\n", __func__); @@ -182,15 +189,17 @@ int try_to_read_an_OBJ_file(char *infname, char *ofname, int outstyle) FILE *fpin; char line[LINE_SZ+1], *cptr, *token; float x, y, z; -int foo, tokenid; +int foo, bar, tokenid; Bubulle bubulle; - char *outfname, *baseptr; #if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n\n", __func__, +fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__, infname, ofname, outstyle); #endif +#if PSYCHOTIK +fprintf(stderr, " *** PSYCHOTIK MODE ENGAGED ***\n"); +#endif /* get memory for generated output filename(s) */ if (NULL==(outfname=malloc(strlen(infname)+33)) ) { @@ -218,7 +227,7 @@ if (NULL==edges) { } if (verbosity > 1) print_edgelist_desc(edges, 0); -fprintf(stderr, "\n ***************************************\n"); +fprintf(stderr, " +-----------------------------------------\n"); while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { @@ -258,21 +267,27 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { case T_vertice: x = y = z = 0.0; foo = parse_vertice(cptr, &x, &y, &z); - if (3!=foo) { + if (3 != foo) { + fprintf(stderr, "err %d parse vertice %s\n", + foo, cptr); abort(); } bubulle.p.x = x; bubulle.p.y = y; bubulle.p.z = z; - if (verbosity > 1) niceprint_bubulle(&bubulle, 0); + if (verbosity > 2) niceprint_bubulle(&bubulle, 0); foo = push_bubulle(bublist, &bubulle); if (foo) { + fprintf(stderr, "err %d push bubulle\n", foo); abort(); } + fprintf(stderr, "pushed %f %f %f (%d)\n", x, y, z, + bublist->fidx); break; case T_face: /* experimental code here */ - foo = parse_face(cptr); + bar = bublist->fidx - 1; + foo = parse_face(cptr, bar); if (foo) { fprintf(stderr, "line %d '%s' parseface -> %d\n", linenumber, cptr, foo); @@ -298,10 +313,18 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { break; case T_line: + cptr = strtok(NULL, " "); + fprintf(stderr, "\tLine: %s\n", cptr); break; case T_smoothing: + cptr = strtok(NULL, " "); + if (verbosity) + fprintf(stderr, "\tSmoothing: %s\n", cptr); break; case T_vt: + cptr = strtok(NULL, " "); + if (verbosity) + fprintf(stderr, "\tvt ??? : %s\n", cptr); break; default: @@ -312,11 +335,11 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { fclose(fpin); -fprintf(stderr, " ***************************************\n"); +fprintf(stderr, " +-----------------------------------------\n"); if(verbosity) { - fprintf(stderr, "%s(): %9d vertices loaded\n", __func__, bublist->fidx); - fprintf(stderr, "%s(): %9d edges loaded\n", __func__, edges->fidx); + fprintf(stderr, "%s: %d vertices and %d edges loaded.\n", __func__, + bublist->fidx, edges->fidx); } if (verbosity > 1) { @@ -355,6 +378,7 @@ else { /* one 'evblob' file */ } // Cleanup +free(outfname); free_bubulles(bublist, 0); free_edgelist(edges, 0); diff --git a/tools/minimal.obj b/tools/minimal.obj index 29c3e9e..a3b6f29 100644 --- a/tools/minimal.obj +++ b/tools/minimal.obj @@ -1,7 +1,11 @@ o minimal + v 0 0 0 v 1 0 0 -v 0 1 0 -v 0 0 1 -f 1/2 2/3 3/1 -f 0/1 0/1 0/2 +v 0 2 0 +v 0 0 3 + +f 0 1 2 +f 1 2 3 +f 3 1 0 +f 0 2 3 diff --git a/tools/overflowed.obj b/tools/overflowed.obj new file mode 100644 index 0000000..8ba547f --- /dev/null +++ b/tools/overflowed.obj @@ -0,0 +1,11 @@ +o minimal + +v 0 0 0 +v 1 0 0 +v 0 2 0 +v 0 0 3 + +f 0 1 2 +f 2 3 4 +f 4 2 1 +f 0 3 4 diff --git a/tools/rdwredges.c b/tools/rdwredges.c index e4c4bb0..8c2e078 100644 --- a/tools/rdwredges.c +++ b/tools/rdwredges.c @@ -26,9 +26,13 @@ int idx; unsigned char *cptr = (unsigned char *)ptr; for (idx=0; idx