refactoring
This commit is contained in:
parent
9cbbb35cde
commit
f4d5557b4f
8
Makefile
8
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
|
||||
|
||||
#############################################
|
||||
|
@ -228,10 +228,8 @@ fprintf(stderr, "*** %s : array at %p, sz %d\n", __func__, ar, bbl->size);
|
||||
for (idx=0; idx<bbl->fidx; 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;
|
||||
|
@ -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 */
|
||||
|
11
edges.c
Normal file
11
edges.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* edges.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "edges.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
|
5
edges.h
Normal file
5
edges.h
Normal file
@ -0,0 +1,5 @@
|
||||
/*
|
||||
* edges.h
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
@ -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 $<
|
||||
|
@ -8,7 +8,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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++;
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user