maybe we can read eges ?

This commit is contained in:
tTh 2023-03-28 14:50:40 +02:00
parent 329223d195
commit d1a5a5b5c9
7 changed files with 100 additions and 41 deletions

View File

@ -10,7 +10,7 @@
CC = gcc 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 libbubulles.a: bubulles.o edges.o
ar r $@ $? ar r $@ $?

View File

@ -4,7 +4,7 @@
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define LIBBB_VERSION 61 #define LIBBB_VERSION 62
#define SZ_BUBULLE_TEXT 81 /* arbitrary value */ #define SZ_BUBULLE_TEXT 81 /* arbitrary value */

View File

@ -1,5 +1,6 @@
/* /*
* edges.c * edges.c
* a part of libbubulle from tTh
*/ */
#include <stdio.h> #include <stdio.h>
@ -150,10 +151,15 @@ int print_the_edges(EdgeList *list, int k)
{ {
int foo; int foo;
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, list, k);
if (k) { if (k) {
fprintf(stderr, "In %s, k must be 0, was %d\n", __func__, k); fprintf(stderr, "In %s, k must be 0, was %d\n", __func__, k);
return k; return k;
} }
fprintf(stderr, " list.fidx = %d\n", list->fidx);
for (foo=0; foo<list->fidx; foo++) { for (foo=0; foo<list->fidx; foo++) {
printf("%d\t\t%5d %5d\n", foo, list->edges[foo].A, list->edges[foo].B); printf("%d\t\t%5d %5d\n", foo, list->edges[foo].A, list->edges[foo].B);
} }

View File

@ -1,11 +1,13 @@
/* /*
* edges.h * edges.h
* a part of libbubulle from tTh
*/ */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
typedef struct { typedef struct {
int A, B; int A, B;
short burz;
} AnEdge; } AnEdge;
typedef struct { typedef struct {

View File

@ -16,6 +16,10 @@ extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define LINE_SZ 666 #define LINE_SZ 666
static BBList *bublist;
static EdgeList *edges;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
typedef struct { typedef struct {
@ -23,13 +27,14 @@ typedef struct {
int id; int id;
} Tokens; } 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[] = { Tokens TokenList[] = {
{ "#", T_comment }, { "#", T_comment },
{ "v", T_vertice }, { "v", T_vertice },
{ "g", T_group }, // to be verified { "g", T_group }, // to be verified !
{ "f", T_face }, { "f", T_face },
{ "vt", T_vt }, // c'est quoi ce truc ?
{ NULL, 0 } { NULL, 0 }
}; };
@ -37,8 +42,8 @@ static int type_of_the_line(char *text)
{ {
Tokens *token; Tokens *token;
#if DEBUG_LEVEL #if DEBUG_LEVEL > 1
fprintf(stderr, "%s is searching '%s'\n", __func__, text); fprintf(stderr, "%s is searching for '%s'\n", __func__, text);
#endif #endif
for (token=TokenList; token->token; token++) { for (token=TokenList; token->token; token++) {
@ -51,7 +56,7 @@ for (token=TokenList; token->token; token++) {
return -1; 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; float x, y, z;
int foo; int foo;
@ -71,17 +76,52 @@ if (3 == foo) {
return 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) 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, fa, fb, ix; int foo, nbre, tokenid;
BBList *bublist;
Bubulle bubulle; Bubulle bubulle;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, infname, notused); fprintf(stderr, ">>> %s ( '%s' %d )\n\n", __func__, infname, notused);
#endif #endif
if (NULL==(fpin=fopen(infname, "r"))) { if (NULL==(fpin=fopen(infname, "r"))) {
@ -91,11 +131,20 @@ if (NULL==(fpin=fopen(infname, "r"))) {
bublist = alloc_bubulles(infname, 800000, 0); bublist = alloc_bubulles(infname, 800000, 0);
if (NULL==bublist) { if (NULL==bublist) {
fprintf(stderr, "err in %s, aborting...\n", __func__); fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__);
abort(); abort();
} }
print_bublist_desc(bublist, 0); 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; nbre = 0;
while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
@ -106,7 +155,7 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
break; break;
} }
line[strlen(line)-1] = '\0'; /* kill the newline */ 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, " "); cptr = strtok(line, " ");
if (NULL == cptr) { if (NULL == cptr) {
@ -127,49 +176,51 @@ 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) {
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 > 1) niceprint_bubulle(&bubulle, 0);
foo = push_bubulle(bublist, &bubulle);
if (foo) {
abort();
}
break; break;
case T_group: case T_group:
cptr = strtok(NULL, " "); cptr = strtok(NULL, " ");
fprintf(stderr, "Group: %s\n", cptr); fprintf(stderr, "\tGroup: %s\n", cptr);
break; break;
case T_face: case T_face:
fprintf(stderr, "Face A: %s\n", cptr); foo = parse_face(cptr, 0);
for (ix=0; ix<3; ix++) { fprintf(stderr, " parse face -> %d\n", foo);
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; break;
default: default:
// fprintf(stderr, "token %d ?\n", tokenid); fprintf(stderr, "\ttoken %d ?\n", tokenid);
continue; /* wtf ? */ continue; /* wtf ? */
} }
foo = push_bubulle(bublist, &bubulle);
if (foo) {
fprintf(stderr, "*** %s: error %d on push\n", __func__, foo);
exit(1);
break;
}
nbre++; nbre++;
} }
fclose(fpin); fclose(fpin);
fprintf(stderr, "\n\t************************\n");
if(verbosity) { 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); 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; return 0;
} }

View File

@ -18,7 +18,7 @@ if (2 != argc) {
exit(0); exit(0);
} }
verbosity = 1; verbosity = 2;
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 '%s' -> %d\n", argv [1], foo); fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo);