From d1a5a5b5c9c371d2daa60ec6227eba0439fd3d07 Mon Sep 17 00:00:00 2001 From: tTh Date: Tue, 28 Mar 2023 14:50:40 +0200 Subject: [PATCH] maybe we can read eges ? --- Makefile | 2 +- bubulles.h | 2 +- edges.c | 6 +++ edges.h | 18 ++++---- tools/Makefile | 2 +- tools/importobj.c | 109 ++++++++++++++++++++++++++++++++++------------ tools/read_obj.c | 2 +- 7 files changed, 100 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 7f1a4b1..45c6f6c 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ CC = gcc -OPT = -Wall -g -pg -O3 -DDEBUG_LEVEL=0 -DMUST_ABORT=0 +OPT = -Wall -g -O3 -DDEBUG_LEVEL=0 -DMUST_ABORT=0 libbubulles.a: bubulles.o edges.o ar r $@ $? diff --git a/bubulles.h b/bubulles.h index 93f5ebb..361585a 100644 --- a/bubulles.h +++ b/bubulles.h @@ -4,7 +4,7 @@ /* --------------------------------------------------------------------- */ -#define LIBBB_VERSION 61 +#define LIBBB_VERSION 62 #define SZ_BUBULLE_TEXT 81 /* arbitrary value */ diff --git a/edges.c b/edges.c index dc1d63f..aa0e66d 100644 --- a/edges.c +++ b/edges.c @@ -1,5 +1,6 @@ /* * edges.c + * a part of libbubulle from tTh */ #include @@ -150,10 +151,15 @@ int print_the_edges(EdgeList *list, int k) { int foo; +fprintf(stderr, ">>> %s ( %p %d )\n", __func__, list, k); + if (k) { fprintf(stderr, "In %s, k must be 0, was %d\n", __func__, k); return k; } + +fprintf(stderr, " list.fidx = %d\n", list->fidx); + for (foo=0; foofidx; foo++) { printf("%d\t\t%5d %5d\n", foo, list->edges[foo].A, list->edges[foo].B); } diff --git a/edges.h b/edges.h index 54de80d..c967d05 100644 --- a/edges.h +++ b/edges.h @@ -1,11 +1,13 @@ /* * edges.h + * a part of libbubulle from tTh */ /* --------------------------------------------------------------------- */ typedef struct { - int A, B; + int A, B; + short burz; } AnEdge; typedef struct { @@ -19,14 +21,14 @@ typedef struct { /* --------------------------------------------------------------------- */ -EdgeList * alloc_edgelist(char *name, int sz, int flags); -int free_edgelist(EdgeList *list, int k); -int push_an_edge(EdgeList *list, int p0, int p1); -int push_a_missing_edge(EdgeList *list, int p0, int p1); +EdgeList * alloc_edgelist(char *name, int sz, int flags); +int free_edgelist(EdgeList *list, int k); +int push_an_edge(EdgeList *list, int p0, int p1); +int push_a_missing_edge(EdgeList *list, int p0, int p1); -int is_edge_in_list(EdgeList *list, int p0, int p1); +int is_edge_in_list(EdgeList *list, int p0, int p1); -int print_edgelist_desc(EdgeList *list, int k); -int print_the_edges(EdgeList *list, int k); +int print_edgelist_desc(EdgeList *list, int k); +int print_the_edges(EdgeList *list, int k); /* --------------------------------------------------------------------- */ diff --git a/tools/Makefile b/tools/Makefile index 8f90070..7734a48 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,7 +1,7 @@ BBFUNCS = ../libbubulles.a -OPT = -Wall -g -DDEBUG_LEVEL=1 -DMUST_ABORT +OPT = -Wall -g -DDEBUG_LEVEL=1 -DMUST_ABORT read_obj: read_obj.c Makefile importobj.o $(BBFUNCS) gcc $(OPT) $< importobj.o $(BBFUNCS) -o $@ diff --git a/tools/importobj.c b/tools/importobj.c index f191007..ee34fab 100644 --- a/tools/importobj.c +++ b/tools/importobj.c @@ -15,7 +15,11 @@ extern int verbosity; /* --------------------------------------------------------------------- */ -#define LINE_SZ 666 +#define LINE_SZ 666 + +static BBList *bublist; +static EdgeList *edges; + /* --------------------------------------------------------------------- */ typedef struct { @@ -23,13 +27,14 @@ typedef struct { int id; } Tokens; -enum token_id { T_comment=1, T_vertice, T_group, T_face }; +enum token_id { T_comment=1, T_vertice, T_group, T_face, T_vt }; Tokens TokenList[] = { { "#", T_comment }, { "v", T_vertice }, - { "g", T_group }, // to be verified + { "g", T_group }, // to be verified ! { "f", T_face }, + { "vt", T_vt }, // c'est quoi ce truc ? { NULL, 0 } }; @@ -37,8 +42,8 @@ static int type_of_the_line(char *text) { Tokens *token; -#if DEBUG_LEVEL -fprintf(stderr, "%s is searching '%s'\n", __func__, text); +#if DEBUG_LEVEL > 1 +fprintf(stderr, "%s is searching for '%s'\n", __func__, text); #endif for (token=TokenList; token->token; token++) { @@ -51,7 +56,7 @@ for (token=TokenList; token->token; token++) { return -1; } /* --------------------------------------------------------------------- */ -static int parse_vertice(char *cptr, float *px, float *py, float *pz) +int parse_vertice(char *cptr, float *px, float *py, float *pz) { float x, y, z; int foo; @@ -71,17 +76,52 @@ if (3 == foo) { return foo; } /* --------------------------------------------------------------------- */ +/* new Mon 27 Mar 2023 12:08:18 AM CEST */ +int parse_face(char *cptr, int phy) +{ +int ix, foo; +int fa, fb; + +fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, phy); + +for (ix=0; ix<3; ix++) { + cptr = strtok(NULL, " "); + if (2 != sscanf(cptr, "%d/%d", &fa, &fb)) { + fprintf(stderr, "%s: err sscanf\n", __func__); + exit(1); + return -3; + } + fprintf(stderr, " %d got %d %d\n", ix, fa, fb); + + /* + * yes, i've found 0-lenght edges, wtf ? + */ + if (fa == fb) continue; + + foo = push_a_missing_edge(edges, fa, fb); + if (foo) { + fprintf(stderr, "%s: disaster #%d\n", __func__, foo); +#if MUST_ABORT + abort(); +#endif + return -2; + } + } + +return 0; +} +/* --------------------------------------------------------------------- */ int try_to_read_an_OBJ_file(char *infname, char *outfname, int notused) { FILE *fpin; char line[LINE_SZ+1], *cptr; float x, y, z; -int foo, nbre, tokenid, fa, fb, ix; -BBList *bublist; +int foo, nbre, tokenid; Bubulle bubulle; + #if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, infname, notused); +fprintf(stderr, ">>> %s ( '%s' %d )\n\n", __func__, infname, notused); #endif if (NULL==(fpin=fopen(infname, "r"))) { @@ -91,11 +131,20 @@ if (NULL==(fpin=fopen(infname, "r"))) { bublist = alloc_bubulles(infname, 800000, 0); if (NULL==bublist) { - fprintf(stderr, "err in %s, aborting...\n", __func__); + fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__); abort(); } print_bublist_desc(bublist, 0); +edges = alloc_edgelist("krkrkr", 100000, 0); +if (NULL==edges) { + fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__); + abort(); + } +print_edgelist_desc(edges, 0); + +fprintf(stderr, "\n\t************************\n"); + nbre = 0; while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { @@ -106,7 +155,7 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { break; } line[strlen(line)-1] = '\0'; /* kill the newline */ - if (verbosity>1) fprintf(stderr, "line read ===%s===\n", line); + if (verbosity>1) fprintf(stderr, "line read ==|%s|==\n", line); cptr = strtok(line, " "); if (NULL == cptr) { @@ -127,49 +176,51 @@ 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) { + abort(); + } bubulle.p.x = x; bubulle.p.y = y; bubulle.p.z = z; if (verbosity > 1) niceprint_bubulle(&bubulle, 0); + foo = push_bubulle(bublist, &bubulle); + if (foo) { + abort(); + } break; case T_group: cptr = strtok(NULL, " "); - fprintf(stderr, "Group: %s\n", cptr); + fprintf(stderr, "\tGroup: %s\n", cptr); break; case T_face: - fprintf(stderr, "Face A: %s\n", cptr); - for (ix=0; ix<3; ix++) { - cptr = strtok(NULL, " "); - fprintf(stderr, "Piste %d: %s\n", ix, cptr); - if (2==sscanf(cptr, "%d/%d", &fa, &fb)) - fprintf(stderr, " %d %d %d\n", foo, fa, fb); - else - return -3; - } + foo = parse_face(cptr, 0); + fprintf(stderr, " parse face -> %d\n", foo); break; default: - // fprintf(stderr, "token %d ?\n", tokenid); + fprintf(stderr, "\ttoken %d ?\n", tokenid); continue; /* wtf ? */ } - foo = push_bubulle(bublist, &bubulle); - if (foo) { - fprintf(stderr, "*** %s: error %d on push\n", __func__, foo); - exit(1); - break; - } nbre++; } fclose(fpin); +fprintf(stderr, "\n\t************************\n"); + if(verbosity) { - fprintf(stderr, "%s : %d vertices loaded\n", __func__, nbre); + fprintf(stderr, "in %s, %d vertices loaded\n", __func__, bublist->fidx); } +print_bublist_desc(bublist, 0); bubulles_to_data(outfname, NULL, bublist, 0); +free_bubulles(bublist, 0); + +print_edgelist_desc(edges, 0); +print_the_edges(edges, 0); +free_edgelist(edges, 0); return 0; } diff --git a/tools/read_obj.c b/tools/read_obj.c index 9f1735d..d3527f5 100644 --- a/tools/read_obj.c +++ b/tools/read_obj.c @@ -18,7 +18,7 @@ if (2 != argc) { exit(0); } -verbosity = 1; +verbosity = 2; foo = try_to_read_an_OBJ_file(argv[1], "bubulles.asc", 0); fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo);