maybe we can read eges ?
This commit is contained in:
parent
329223d195
commit
d1a5a5b5c9
2
Makefile
2
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 $@ $?
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
#define LIBBB_VERSION 61
|
||||
#define LIBBB_VERSION 62
|
||||
|
||||
#define SZ_BUBULLE_TEXT 81 /* arbitrary value */
|
||||
|
||||
|
6
edges.c
6
edges.c
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* edges.c
|
||||
* a part of libbubulle from tTh
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -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; foo<list->fidx; foo++) {
|
||||
printf("%d\t\t%5d %5d\n", foo, list->edges[foo].A, list->edges[foo].B);
|
||||
}
|
||||
|
2
edges.h
2
edges.h
@ -1,11 +1,13 @@
|
||||
/*
|
||||
* edges.h
|
||||
* a part of libbubulle from tTh
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
int A, B;
|
||||
short burz;
|
||||
} AnEdge;
|
||||
|
||||
typedef struct {
|
||||
|
@ -16,6 +16,10 @@ extern int verbosity;
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
#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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user