Compare commits

..

2 Commits

Author SHA1 Message Date
tTh
ce2154d9c1 krkrkr 2023-03-24 15:32:13 +01:00
tTh
f4d5557b4f refactoring 2023-03-21 20:31:50 +01:00
8 changed files with 92 additions and 19 deletions

View File

@ -12,19 +12,19 @@ CC = gcc
OPT = -Wall -g -O3 -DDEBUG_LEVEL=0 -DMUST_ABORT=0 OPT = -Wall -g -O3 -DDEBUG_LEVEL=0 -DMUST_ABORT=0
libbubulles.a: bubulles.o importobj.o libbubulles.a: bubulles.o edges.o
ar r $@ $? ar r $@ $?
bubulles.o: bubulles.c bubulles.h Makefile bubulles.o: bubulles.c bubulles.h Makefile
$(CC) $(OPT) -c $< $(CC) $(OPT) -c $<
importobj.o: importobj.c bubulles.h Makefile edges.o: edges.c bubulles.h edges.h Makefile
$(CC) $(OPT) -c $< $(CC) $(OPT) -c $<
# ------------------------------------------------ # ------------------------------------------------
# --- build some tests and tools # --- build some tests and tools
tbb: tbb.c bubulles.h bubulles.o Makefile tbb: tbb.c bubulles.h libbubulles.a Makefile
$(CC) $(OPT) $< bubulles.o -o tbb $(CC) $(OPT) $< libbubulles.a -o tbb
############################################# #############################################

View File

@ -9,6 +9,7 @@
#include <string.h> #include <string.h>
#include "bubulles.h" #include "bubulles.h"
#include "edges.h"
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
@ -32,6 +33,8 @@ printf("%-15s %4lu\n", "XYZ", sizeof(XYZ));
printf("%-15s %4lu\n", "RGBA", sizeof(RGBA)); printf("%-15s %4lu\n", "RGBA", sizeof(RGBA));
printf("%-15s %4lu\n", "Bubulle", sizeof(Bubulle)); printf("%-15s %4lu\n", "Bubulle", sizeof(Bubulle));
printf("%-15s %4lu\n", "BBList", sizeof(BBList)); printf("%-15s %4lu\n", "BBList", sizeof(BBList));
printf("%-15s %4lu\n", "AnEdge", sizeof(AnEdge));
printf("%-15s %4lu\n", "EdgeList", sizeof(EdgeList));
puts(""); puts("");
} }
@ -228,10 +231,8 @@ fprintf(stderr, "*** %s : array at %p, sz %d\n", __func__, ar, bbl->size);
for (idx=0; idx<bbl->fidx; idx++) { for (idx=0; idx<bbl->fidx; idx++) {
fprintf(fp, "%12.6f %12.6f %12.6f", fprintf(fp, "%12.6f %12.6f %12.6f",
ar[idx].p.x, ar[idx].p.y, ar[idx].p.z); ar[idx].p.x, ar[idx].p.y, ar[idx].p.z);
if (opts & 0x01) fprintf(fp, " %12.6f", ar[idx].d); if (opts & 0x01) fprintf(fp, " %12.6f", ar[idx].d);
if (opts & 0x02) fprintf(fp, " %6d", ar[idx].gray); if (opts & 0x02) fprintf(fp, " %6d", ar[idx].gray);
fputs("\n", fp); fputs("\n", fp);
} }
fflush(fp); fflush(fp);
@ -248,7 +249,6 @@ printf("xyzd %11.6f %11.6f %11.6f %11.6f\n",
printf("diam %11.6f gray %5d\n", what->d, what->gray); printf("diam %11.6f gray %5d\n", what->d, what->gray);
printf("rgba %11.6f %11.6f %11.6f %11.6f\n", printf("rgba %11.6f %11.6f %11.6f %11.6f\n",
what->col.r, what->col.g, what->col.b, what->col.a); what->col.r, what->col.g, what->col.b, what->col.a);
puts("----------------------------------------------------------"); puts("----------------------------------------------------------");
return 0; return 0;

View File

@ -4,9 +4,9 @@
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define LIBBB_VERSION 57 #define LIBBB_VERSION 60
#define SZ_BUBULLE_TEXT 51 /* arbitrary value */ #define SZ_BUBULLE_TEXT 81 /* arbitrary value */
/* a 3d space coordinate */ /* a 3d space coordinate */
typedef struct { typedef struct {
@ -77,7 +77,7 @@ int fprint_bubulles(FILE *fp, char *title, BBList *bbl, int flags);
int niceprint_bubulle(Bubulle *what, int unused); int niceprint_bubulle(Bubulle *what, int unused);
/* this is just a wtf function * see tbb.c */ /* 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 */ /* sometime we want to look at the bounding box */

23
edges.c Normal file
View File

@ -0,0 +1,23 @@
/*
* edges.c
*/
#include <stdio.h>
#include "bubulles.h"
#include "edges.h"
/* --------------------------------------------------------------------- */
int print_edgelist_desc(EdgeList *list, int k)
{
printf("edgelist addr: %p\n", list);
if (k) {
fprintf(stderr, "%s: k must be 0, was %d\n", __func__, k);
return k;
}
return 0;
}
/* --------------------------------------------------------------------- */

19
edges.h Normal file
View File

@ -0,0 +1,19 @@
/*
* edges.h
*/
/* --------------------------------------------------------------------- */
typedef struct {
int A, B;
} AnEdge;
typedef struct {
char name[SZ_BUBULLE_TEXT+1];
int size; /* max number of edges */
int fidx; /* next free slot */
AnEdge *edges;
unsigned long flags;
} EdgeList;
/* --------------------------------------------------------------------- */

View File

@ -3,5 +3,8 @@ 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 $(BBFUNCS) read_obj: read_obj.c Makefile importobj.o $(BBFUNCS)
gcc $(OPT) $< $(BBFUNCS) -o $@ gcc $(OPT) $< importobj.o $(BBFUNCS) -o $@
importobj.o: importobj.c ../bubulles.h Makefile
$(CC) $(OPT) -c $<

View File

@ -8,7 +8,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "bubulles.h" #include "../bubulles.h"
#include "../edges.h"
extern int verbosity; extern int verbosity;
@ -22,18 +23,19 @@ typedef struct {
int id; int id;
} Tokens; } Tokens;
enum token_id { T_comment=1, T_vertice }; enum token_id { T_comment=1, T_vertice, T_group, T_face };
Tokens TokenList[] = { Tokens TokenList[] = {
{ "#", T_comment }, { "#", T_comment },
{ "v", T_vertice }, { "v", T_vertice },
{ "g", T_group }, // to be verified
{ "f", T_face },
{ NULL, 0 } { NULL, 0 }
}; };
static int type_of_the_line(char *text) static int type_of_the_line(char *text)
{ {
Tokens *token; Tokens *token;
int id;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "%s is searching '%s'\n", __func__, text); 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; FILE *fpin;
char line[LINE_SZ+1], *cptr; char line[LINE_SZ+1], *cptr;
float x, y, z; float x, y, z;
int foo, nbre, tokenid; int foo, nbre, tokenid, fa, fb, ix;
BBList *bublist; BBList *bublist;
Bubulle bubulle; Bubulle bubulle;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused); fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, infname, notused);
#endif #endif
if (NULL==(fpin=fopen(infname, "r"))) { if (NULL==(fpin=fopen(infname, "r"))) {
@ -112,7 +114,8 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
continue; continue;
} }
tokenid = type_of_the_line(cptr); tokenid = type_of_the_line(cptr);
if (verbosity > 1) fprintf(stderr, "token '%s' --> %d\n", cptr, tokenid); if (verbosity > 1)
fprintf(stderr, "token '%s' --> %d\n", cptr, tokenid);
memset(&bubulle, 0, sizeof(Bubulle)); memset(&bubulle, 0, sizeof(Bubulle));
@ -120,6 +123,7 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
case T_comment: case T_comment:
/* do nothing */ /* do nothing */
break; break;
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);
@ -128,6 +132,24 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
bubulle.p.z = z; bubulle.p.z = z;
if (verbosity > 1) niceprint_bubulle(&bubulle, 0); if (verbosity > 1) niceprint_bubulle(&bubulle, 0);
break; 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: default:
// fprintf(stderr, "token %d ?\n", tokenid); // fprintf(stderr, "token %d ?\n", tokenid);
continue; /* wtf ? */ continue; /* wtf ? */
@ -135,7 +157,8 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
foo = push_bubulle(bublist, &bubulle); foo = push_bubulle(bublist, &bubulle);
if (foo) { 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; break;
} }
nbre++; nbre++;

View File

@ -20,8 +20,13 @@ if (2 != argc) {
verbosity = 1; verbosity = 1;
<<<<<<< HEAD
foo = try_to_read_an_OBJ_file(argv[1], "bulles.xyz", 0);
fprintf(stderr, "try to read '%s' --> %d\n", argv[1], foo);
=======
foo = try_to_read_an_OBJ_file(argv[1], "bubulles.asc", 0); foo = try_to_read_an_OBJ_file(argv[1], "bubulles.asc", 0);
fprintf(stderr, "try to read -> %d\n", foo); fprintf(stderr, "try to read -> %d\n", foo);
>>>>>>> 457afac7c0a208413ff6a7f1d0932da76ecf685b
return 0; return 0;
} }