From f4d5557b4fa5146a98e8853ccd39366000ae013a Mon Sep 17 00:00:00 2001 From: tTh Date: Tue, 21 Mar 2023 20:31:50 +0100 Subject: [PATCH] refactoring --- Makefile | 8 +++---- bubulles.c | 3 --- bubulles.h | 6 ++--- edges.c | 11 +++++++++ edges.h | 5 ++++ tools/Makefile | 7 ++++-- importobj.c => tools/importobj.c | 39 +++++++++++++++++++++++++------- tools/read_obj.c | 4 ++-- 8 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 edges.c create mode 100644 edges.h rename importobj.c => tools/importobj.c (76%) diff --git a/Makefile b/Makefile index 8ad3a05..c7d1c69 100644 --- a/Makefile +++ b/Makefile @@ -12,19 +12,19 @@ CC = gcc OPT = -Wall -g -O3 -DDEBUG_LEVEL=0 -DMUST_ABORT=0 -libbubulles.a: bubulles.o importobj.o +libbubulles.a: bubulles.o edges.o ar r $@ $? bubulles.o: bubulles.c bubulles.h Makefile $(CC) $(OPT) -c $< -importobj.o: importobj.c bubulles.h Makefile +edges.o: edges.c bubulles.h edges.h Makefile $(CC) $(OPT) -c $< # ------------------------------------------------ # --- build some tests and tools -tbb: tbb.c bubulles.h bubulles.o Makefile - $(CC) $(OPT) $< bubulles.o -o tbb +tbb: tbb.c bubulles.h libbubulles.a Makefile + $(CC) $(OPT) $< libbubulles.a -o tbb ############################################# diff --git a/bubulles.c b/bubulles.c index 586a3b8..d74f9c3 100644 --- a/bubulles.c +++ b/bubulles.c @@ -228,10 +228,8 @@ fprintf(stderr, "*** %s : array at %p, sz %d\n", __func__, ar, bbl->size); for (idx=0; idxfidx; idx++) { fprintf(fp, "%12.6f %12.6f %12.6f", ar[idx].p.x, ar[idx].p.y, ar[idx].p.z); - if (opts & 0x01) fprintf(fp, " %12.6f", ar[idx].d); if (opts & 0x02) fprintf(fp, " %6d", ar[idx].gray); - fputs("\n", fp); } fflush(fp); @@ -248,7 +246,6 @@ printf("xyzd %11.6f %11.6f %11.6f %11.6f\n", printf("diam %11.6f gray %5d\n", what->d, what->gray); printf("rgba %11.6f %11.6f %11.6f %11.6f\n", what->col.r, what->col.g, what->col.b, what->col.a); - puts("----------------------------------------------------------"); return 0; diff --git a/bubulles.h b/bubulles.h index 2c95cde..bd1de60 100644 --- a/bubulles.h +++ b/bubulles.h @@ -4,9 +4,9 @@ /* --------------------------------------------------------------------- */ -#define LIBBB_VERSION 57 +#define LIBBB_VERSION 59 -#define SZ_BUBULLE_TEXT 51 /* arbitrary value */ +#define SZ_BUBULLE_TEXT 81 /* arbitrary value */ /* a 3d space coordinate */ typedef struct { @@ -77,7 +77,7 @@ int fprint_bubulles(FILE *fp, char *title, BBList *bbl, int flags); int niceprint_bubulle(Bubulle *what, int unused); /* this is just a wtf function * see tbb.c */ -int bubulles_to_data(char *fname, char *title, BBList *bbl, int k); +int bubulles_to_data(char *fname, char *title, BBList *bbl, int flags); /* --------------------------------------------------------------------- */ /* sometime we want to look at the bounding box */ diff --git a/edges.c b/edges.c new file mode 100644 index 0000000..a1171ac --- /dev/null +++ b/edges.c @@ -0,0 +1,11 @@ +/* + * edges.c + */ + +#include + +#include "edges.h" + +/* --------------------------------------------------------------------- */ + + diff --git a/edges.h b/edges.h new file mode 100644 index 0000000..d6ca827 --- /dev/null +++ b/edges.h @@ -0,0 +1,5 @@ +/* + * edges.h + */ + +/* --------------------------------------------------------------------- */ diff --git a/tools/Makefile b/tools/Makefile index 9c87420..8f90070 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -3,5 +3,8 @@ BBFUNCS = ../libbubulles.a OPT = -Wall -g -DDEBUG_LEVEL=1 -DMUST_ABORT -read_obj: read_obj.c Makefile $(BBFUNCS) - gcc $(OPT) $< $(BBFUNCS) -o $@ +read_obj: read_obj.c Makefile importobj.o $(BBFUNCS) + gcc $(OPT) $< importobj.o $(BBFUNCS) -o $@ + +importobj.o: importobj.c ../bubulles.h Makefile + $(CC) $(OPT) -c $< diff --git a/importobj.c b/tools/importobj.c similarity index 76% rename from importobj.c rename to tools/importobj.c index 159d9df..e8bd662 100644 --- a/importobj.c +++ b/tools/importobj.c @@ -8,7 +8,8 @@ #include #include -#include "bubulles.h" +#include "../bubulles.h" +#include "../edges.h" extern int verbosity; @@ -22,18 +23,19 @@ typedef struct { int id; } Tokens; -enum token_id { T_comment=1, T_vertice }; +enum token_id { T_comment=1, T_vertice, T_group, T_face }; Tokens TokenList[] = { { "#", T_comment }, { "v", T_vertice }, + { "g", T_group }, // to be verified + { "f", T_face }, { NULL, 0 } }; static int type_of_the_line(char *text) { Tokens *token; -int id; #if DEBUG_LEVEL fprintf(stderr, "%s is searching '%s'\n", __func__, text); @@ -74,12 +76,12 @@ 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; +int foo, nbre, tokenid, fa, fb, ix; BBList *bublist; Bubulle bubulle; #if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused); +fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, infname, notused); #endif if (NULL==(fpin=fopen(infname, "r"))) { @@ -87,7 +89,7 @@ if (NULL==(fpin=fopen(infname, "r"))) { exit(1); } -bublist = alloc_bubulles(infname, 1000, 0); +bublist = alloc_bubulles(infname, 150000, 0); if (NULL==bublist) { fprintf(stderr, "err in %s, aborting...\n", __func__); abort(); @@ -110,7 +112,8 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { continue; } tokenid = type_of_the_line(cptr); - if (verbosity) fprintf(stderr, "token '%s' --> %d\n", cptr, tokenid); + if (verbosity > 1) + fprintf(stderr, "token '%s' --> %d\n", cptr, tokenid); memset(&bubulle, 0, sizeof(Bubulle)); @@ -118,6 +121,7 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { case T_comment: /* do nothing */ break; + case T_vertice: x = y = z = 0.0; foo = parse_vertice(cptr, &x, &y, &z); @@ -126,6 +130,24 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { bubulle.p.z = z; if (verbosity > 1) niceprint_bubulle(&bubulle, 0); break; + + case T_group: + cptr = strtok(NULL, " "); + fprintf(stderr, "Group: %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; + } + break; + default: // fprintf(stderr, "token %d ?\n", tokenid); continue; /* wtf ? */ @@ -133,7 +155,8 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { foo = push_bubulle(bublist, &bubulle); if (foo) { - fprintf(stderr, "%s: err %d on push\n", __func__, foo); + fprintf(stderr, "*** %s: error %d on push\n", __func__, foo); + exit(1); break; } nbre++; diff --git a/tools/read_obj.c b/tools/read_obj.c index d78bbc9..a5f9253 100644 --- a/tools/read_obj.c +++ b/tools/read_obj.c @@ -18,10 +18,10 @@ if (2 != argc) { exit(0); } -verbosity = 2; +verbosity = 1; foo = try_to_read_an_OBJ_file(argv[1], "bulles.xyz", 0); -fprintf(stderr, "try to read -> %d\n", foo); +fprintf(stderr, "try to read '%s' --> %d\n", argv[1], foo); return 0; }