commit du bug rebelle

This commit is contained in:
tTh 2023-05-02 10:06:24 +02:00
parent d3cca97dbf
commit 5eaa64a664
12 changed files with 163 additions and 56 deletions

24
edges.c
View File

@ -70,28 +70,36 @@ return 0;
*/ */
static int is_edge_in_list(EdgeList *list, int p0, int p1) 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++) { for (idx=0; idx < list->fidx; idx++) {
if ( (list->edges[idx].A == p0) && 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) && 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 * we have two functions for adding an edge to a list
* the first one add unconditionnaly the edge to the * the first one add unconditionnaly the edge to the
* (non full) list... * (non full) list...
*/ */
int push_an_edge(EdgeList *list, int p0, int p1) int push_an_edge(EdgeList *list, int p0, int p1)
{ {
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1); fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1);
#endif #endif
@ -130,8 +138,12 @@ if (list->fidx >= list->size) {
if ( ! is_edge_in_list(list, p0, p1) ) { if ( ! is_edge_in_list(list, p0, p1) ) {
list->edges[list->fidx].A = p0; list->edges[list->fidx].A = p0;
list->edges[list->fidx].B = p1; list->edges[list->fidx].B = p1;
fprintf(stderr, "edge %d %d poked at %d\n", p0, p1, list->fidx);
list->fidx ++; list->fidx ++;
} }
else {
fprintf(stderr, " %s: drop edge %d %d\n", __func__, p0, p1);
}
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

2
tools/.gitignore vendored
View File

@ -6,7 +6,9 @@ export_evblob
*.obj *.obj
! tools/minimal.obj ! tools/minimal.obj
! tools/cube.obj ! tools/cube.obj
! overflowed.obj
read_obj read_obj
*.xyz *.xyz
*.asc *.asc
toto toto

View File

@ -1,7 +1,7 @@
BBFUNCS = ../libbubulles.a 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 all: read_obj export_evblob # essai_faces

View File

@ -32,6 +32,10 @@ printf(" -> %d\n", bar);
return 0; return 0;
} }
/*
* GO !
*/
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, bar; int foo, bar;

View File

@ -88,7 +88,7 @@ fprintf(stderr, ">>> %s ( %p )\n", __func__, eav);
if (verbosity) fprintf(stderr, " fprinting %d edges\n", eav->Elist->fidx); if (verbosity) fprintf(stderr, " fprinting %d edges\n", eav->Elist->fidx);
vmax = eav->Blist->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 * OK we have (maybe) all the data in da place
@ -102,7 +102,7 @@ for (idx=0; idx<eav->Elist->fidx; idx++) {
/* this is a Molly-Guard */ /* this is a Molly-Guard */
if ( (a<0) || (b<0) || (a>vmax) || (b>vmax) ) { if ( (a<0) || (b<0) || (a>vmax) || (b>vmax) ) {
fprintf(stderr, "ERROR: vmax=%d a=%d b=%d\n", vmax, a, b); fprintf(stderr, "ERROR: vmax=%d a=%d b=%d\n", vmax, a, b);
return -1; continue;
} }
printf("%.9f %.9f %.9f %.9f %.9f %.9f\n", printf("%.9f %.9f %.9f %.9f %.9f %.9f\n",
@ -167,6 +167,10 @@ if (foo) {
exit(1); exit(1);
} }
/* deallocate used memory for keep pinpin happy */
free_bubulles(eav.Blist, 1);
free_edgelist(eav.Elist, 1);
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -104,15 +104,14 @@ return foo;
/* new Mon 27 Mar 2023 12:08:18 AM CEST /* new Mon 27 Mar 2023 12:08:18 AM CEST
* *
* mmmm... complex thing to do... * 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 ix, foo, a, b;
int pts[3]; int pts[3], valid;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, cptr); fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, maxvert);
#endif #endif
#if (0) #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] ) { if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) {
fprintf(stderr, "%s: degenerated face ( %d %d %d )\n", __func__, fprintf(stderr, "%s: degenerated face ( %d %d %d )\n", __func__,
pts[0], pts[1], pts[2]); pts[0], pts[1], pts[2]);
dropped++; 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 ? * may be we can check the "degenerated cylinder" here ?
*/ */
if (valid) {
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;
#if PSYCHOTIK #if PSYCHOTIK
foo = push_a_missing_edge(edges, pts[a], pts[b]); foo = push_a_missing_edge(edges, pts[a], pts[b]);
#else #else
foo = push_an_edge(edges, pts[a], pts[b]); foo = push_an_edge(edges, pts[a], pts[b]);
#endif #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);
return -2; return -2;
}
} }
} }
if (dropped) { if (dropped) fprintf(stderr, "%s: %d dropped\n", __func__, dropped);
fprintf(stderr, "%s: %d dropped...\n", __func__, dropped);
// exit(1);
}
#if DEBUG_LEVEL > 1 #if DEBUG_LEVEL > 1
fprintf(stderr, "<<< %s\n", __func__); fprintf(stderr, "<<< %s\n", __func__);
@ -182,15 +189,17 @@ 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;
float x, y, z; float x, y, z;
int foo, tokenid; int foo, bar, tokenid;
Bubulle bubulle; Bubulle bubulle;
char *outfname, *baseptr; char *outfname, *baseptr;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n\n", __func__, fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
infname, ofname, outstyle); infname, ofname, outstyle);
#endif #endif
#if PSYCHOTIK
fprintf(stderr, " *** PSYCHOTIK MODE ENGAGED ***\n");
#endif
/* get memory for generated output filename(s) */ /* get memory for generated output filename(s) */
if (NULL==(outfname=malloc(strlen(infname)+33)) ) { if (NULL==(outfname=malloc(strlen(infname)+33)) ) {
@ -218,7 +227,7 @@ if (NULL==edges) {
} }
if (verbosity > 1) print_edgelist_desc(edges, 0); if (verbosity > 1) print_edgelist_desc(edges, 0);
fprintf(stderr, "\n ***************************************\n"); fprintf(stderr, " +-----------------------------------------\n");
while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
@ -258,21 +267,27 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
case T_vertice: case T_vertice:
x = y = z = 0.0; x = y = z = 0.0;
foo = parse_vertice(cptr, &x, &y, &z); foo = parse_vertice(cptr, &x, &y, &z);
if (3!=foo) { if (3 != foo) {
fprintf(stderr, "err %d parse vertice %s\n",
foo, cptr);
abort(); abort();
} }
bubulle.p.x = x; bubulle.p.x = x;
bubulle.p.y = y; bubulle.p.y = y;
bubulle.p.z = z; bubulle.p.z = z;
if (verbosity > 1) niceprint_bubulle(&bubulle, 0); if (verbosity > 2) niceprint_bubulle(&bubulle, 0);
foo = push_bubulle(bublist, &bubulle); foo = push_bubulle(bublist, &bubulle);
if (foo) { if (foo) {
fprintf(stderr, "err %d push bubulle\n", foo);
abort(); abort();
} }
fprintf(stderr, "pushed %f %f %f (%d)\n", x, y, z,
bublist->fidx);
break; break;
case T_face: case T_face:
/* experimental code here */ /* experimental code here */
foo = parse_face(cptr); bar = bublist->fidx - 1;
foo = parse_face(cptr, bar);
if (foo) { if (foo) {
fprintf(stderr, "line %d '%s' parseface -> %d\n", fprintf(stderr, "line %d '%s' parseface -> %d\n",
linenumber, cptr, foo); linenumber, cptr, foo);
@ -298,10 +313,18 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
break; break;
case T_line: case T_line:
cptr = strtok(NULL, " ");
fprintf(stderr, "\tLine: %s\n", cptr);
break; break;
case T_smoothing: case T_smoothing:
cptr = strtok(NULL, " ");
if (verbosity)
fprintf(stderr, "\tSmoothing: %s\n", cptr);
break; break;
case T_vt: case T_vt:
cptr = strtok(NULL, " ");
if (verbosity)
fprintf(stderr, "\tvt ??? : %s\n", cptr);
break; break;
default: default:
@ -312,11 +335,11 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
fclose(fpin); fclose(fpin);
fprintf(stderr, " ***************************************\n"); fprintf(stderr, " +-----------------------------------------\n");
if(verbosity) { if(verbosity) {
fprintf(stderr, "%s(): %9d vertices loaded\n", __func__, bublist->fidx); fprintf(stderr, "%s: %d vertices and %d edges loaded.\n", __func__,
fprintf(stderr, "%s(): %9d edges loaded\n", __func__, edges->fidx); bublist->fidx, edges->fidx);
} }
if (verbosity > 1) { if (verbosity > 1) {
@ -355,6 +378,7 @@ else { /* one 'evblob' file */
} }
// Cleanup // Cleanup
free(outfname);
free_bubulles(bublist, 0); free_bubulles(bublist, 0);
free_edgelist(edges, 0); free_edgelist(edges, 0);

View File

@ -1,7 +1,11 @@
o minimal o minimal
v 0 0 0 v 0 0 0
v 1 0 0 v 1 0 0
v 0 1 0 v 0 2 0
v 0 0 1 v 0 0 3
f 1/2 2/3 3/1
f 0/1 0/1 0/2 f 0 1 2
f 1 2 3
f 3 1 0
f 0 2 3

11
tools/overflowed.obj Normal file
View File

@ -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

View File

@ -26,9 +26,13 @@ int idx;
unsigned char *cptr = (unsigned char *)ptr; unsigned char *cptr = (unsigned char *)ptr;
for (idx=0; idx<count; idx++) { for (idx=0; idx<count; idx++) {
fprintf(stderr, "%02x", cptr[idx]); fprintf(stderr, "%02x ", cptr[idx]);
} }
fprintf(stderr, " ?\n"); fprintf(stderr, " ?\n");
for (idx=0; idx<count; idx++) {
fprintf(stderr, " %c ", isprint(cptr[idx]) ? cptr[idx] : 'X' );
}
fprintf(stderr, " ?\n");
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */ /* EXPERIMENTAL GRUIK-CODE !!! */
@ -112,7 +116,7 @@ if (1 != foo) {
fprintf(stderr, " %s of '%s': short read %d\n", __func__, filename, foo); fprintf(stderr, " %s of '%s': short read %d\n", __func__, filename, foo);
return -1; return -1;
} }
fprintf(stderr, " %d vertices to be loaded\n", nbre); if (verbosity) fprintf(stderr, " %d vertices to be loaded\n", nbre);
/* allocate memory */ /* allocate memory */
blst = alloc_bubulles(filename, nbre, 0); blst = alloc_bubulles(filename, nbre, 0);
@ -151,7 +155,7 @@ if (1 != foo) {
fprintf(stderr, " %s of '%s': short read %d\n", __func__, filename, foo); fprintf(stderr, " %s of '%s': short read %d\n", __func__, filename, foo);
return -1; return -1;
} }
fprintf(stderr, " %d edges to be loaded\n", nbre); if (verbosity) 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);

View File

@ -17,11 +17,11 @@ int verbosity = 0;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
void help(void) void help(void)
{ {
printf("### READ_OBJ 0X%X TALKING\n", getpid()); printf("### READ_OBJ 0X%X TALKING\n", getpid());
puts("usage:"); puts("usage:");
puts("\t-h\tthis help (use -v -h for more"); puts("\t-h\t\tthis help (use -v -h for more");
puts("\t-o fname\tfix the output filename"); puts("\t-o fname\tfix the output filename");
puts("\t-v\tincrease verbosity"); puts("\t-v\t\tincrease verbosity");
exit(0); exit(0);
} }
@ -32,7 +32,7 @@ int main(int argc, char *argv[])
int foo, opt; int foo, opt;
char *ofname = NULL; char *ofname = NULL;
fprintf(stderr, "\n### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__); fprintf(stderr, "### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__);
if (1 == argc) { if (1 == argc) {
bubulles_version(1); bubulles_version(1);
@ -55,10 +55,12 @@ while ((opt = getopt(argc, argv, "ho:v")) != -1) {
} }
if (optind < argc) { if (optind < argc) {
if (verbosity) fprintf(stderr, "arg[%d] = %s\n", optind, argv[optind]); if (verbosity) fprintf(stderr, " arg[%d] = %s\n",
optind, argv[optind]);
foo = try_to_read_an_OBJ_file(argv[optind], ofname, 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);
} }
} }

23
tools/run_read_export.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
set -e
make read_obj
make export_evblob
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
figlet 'a real WTF' | sed 's/^/XXX /'
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
./read_obj -v minimal.obj
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
./export_evblob -t edges minimal.evblob |
awk '{ printf "%4d | %.0f %.0f %.0f %.0f %.0f %.0f\n", \
NR, $1, $2, $3, $4, $5, $6 }'
echo
./export_evblob -t vertices minimal.evblob

View File

@ -1,9 +1,19 @@
# Technique # Technique
Les détails **gores**...
# Tests ## Le parser
Pour le moment rien à part ce fichier vérolé : Je pense qu'il y a un bug sournois caché dedans
## L'exporteur
Conversion d'un `.evblob` en données tabulées exploitables par
des scripts `awk`.
## Tests
Pour le moment rien, à part ce fichier .OBJ vérolé :
``` ```
o minimal o minimal
@ -17,4 +27,11 @@ f 0 1 2
f 2 3 4 f 2 3 4
f 4 2 1 f 4 2 1
f 0 3 4 f 0 3 4
``` ```
Ça va, vous avez capté le souci ?
## Conclusion
Rien ,'est simple, tout se complique...