refactoring, first step
This commit is contained in:
@@ -55,6 +55,8 @@ Tokens TokenList[] = {
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
static int type_of_the_line(char *text)
|
||||
{
|
||||
Tokens *token;
|
||||
@@ -95,7 +97,6 @@ if (3 == foo) {
|
||||
|
||||
return foo;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* new Mon 27 Mar 2023 12:08:18 AM CEST
|
||||
@@ -103,13 +104,13 @@ return foo;
|
||||
* mmmm... complex thing to do...
|
||||
* and what is this "phy" parameter ?
|
||||
*/
|
||||
static int parse_face(char *cptr, int phy)
|
||||
static int parse_face(char *cptr)
|
||||
{
|
||||
int ix, foo, a, b;
|
||||
int pts[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, phy);
|
||||
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, cptr, phy);
|
||||
#endif
|
||||
|
||||
#if (0)
|
||||
@@ -144,7 +145,6 @@ if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) {
|
||||
* may be we can check the "degenerated cylinder" here ?
|
||||
*/
|
||||
|
||||
|
||||
for (ix=0; ix<3; ix++) {
|
||||
a = ix % 3;
|
||||
b = (ix+1) % 3;
|
||||
@@ -168,48 +168,56 @@ fprintf(stderr, "<<< %s\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int try_to_read_an_OBJ_file(char *infname, char *file_vert, char *file_edges,
|
||||
int notused)
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int try_to_read_an_OBJ_file(char *infname, int outstyle)
|
||||
{
|
||||
FILE *fpin;
|
||||
char line[LINE_SZ+1], *cptr, *token;
|
||||
float x, y, z;
|
||||
int foo, nbre, tokenid;
|
||||
int foo, tokenid;
|
||||
Bubulle bubulle;
|
||||
|
||||
char *outfname;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n\n", __func__, infname, notused);
|
||||
fprintf(stderr, ">>> %s ( '%s' ... %d )\n\n", __func__, infname, notused);
|
||||
#endif
|
||||
|
||||
/* get memory for generated output filename(s) */
|
||||
if (NULL==(outfname=malloc(strlen(infname)+33)) ) {
|
||||
fprintf(stderr, "%s : not enough mem, sorry\n", __func__);
|
||||
return -666;
|
||||
}
|
||||
|
||||
if (NULL==(fpin=fopen(infname, "r"))) {
|
||||
perror(infname);
|
||||
exit(1);
|
||||
}
|
||||
linenumber = 0;
|
||||
|
||||
bublist = alloc_bubulles(infname, 400000, 0);
|
||||
bublist = alloc_bubulles(infname, 600000, 0);
|
||||
if (NULL==bublist) {
|
||||
fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__);
|
||||
abort();
|
||||
}
|
||||
if (verbosity > 1) print_bublist_desc(bublist, 0);
|
||||
|
||||
edges = alloc_edgelist("krkrkr", 600000, 0);
|
||||
edges = alloc_edgelist("krkrkr", 2200000, 0);
|
||||
if (NULL==edges) {
|
||||
fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__);
|
||||
abort();
|
||||
}
|
||||
if (verbosity > 1) print_edgelist_desc(edges, 0);
|
||||
|
||||
fprintf(stderr, "\n ***********************************\n");
|
||||
fprintf(stderr, "\n ***************************************\n");
|
||||
|
||||
nbre = 0;
|
||||
while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
||||
|
||||
if ('\n' != line[strlen(line)-1]) {
|
||||
fprintf(stderr, "%s: short read on %s...\n",
|
||||
__func__, infname);
|
||||
fprintf(stderr, "%s: short read on %s line %d\n",
|
||||
__func__, infname, linenumber);
|
||||
// return -2;
|
||||
break;
|
||||
}
|
||||
@@ -257,7 +265,7 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
||||
break;
|
||||
case T_face:
|
||||
/* experimental code here */
|
||||
foo = parse_face(cptr, 0);
|
||||
foo = parse_face(cptr);
|
||||
if (foo) {
|
||||
fprintf(stderr, "line %d '%s' parse face -> %d\n",
|
||||
linenumber, cptr, foo);
|
||||
@@ -293,11 +301,11 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
|
||||
fprintf(stderr, "token %s -> %d ?\n", token, tokenid);
|
||||
break;
|
||||
}
|
||||
nbre++;
|
||||
}
|
||||
|
||||
fclose(fpin);
|
||||
|
||||
fprintf(stderr, " ***********************************\n");
|
||||
fprintf(stderr, " ***************************************\n");
|
||||
|
||||
if(verbosity) {
|
||||
fprintf(stderr, "%s(): %d vertices loaded\n", __func__, bublist->fidx);
|
||||
@@ -309,11 +317,24 @@ if (verbosity > 1) {
|
||||
print_edgelist_desc(edges, 0);
|
||||
}
|
||||
|
||||
bubulles_to_data(file_vert, NULL, bublist, 0);
|
||||
|
||||
edges_to_data(file_edges, edges, 0);
|
||||
|
||||
foo = x_write_vertedges("foo.evblob", bublist, edges);
|
||||
if (outstyle) { /* two ascii files */
|
||||
strcpy(outfname, infname);
|
||||
cptr = rindex(outfname, '.');
|
||||
fprintf(stderr, "rindex -> [%s]\n", cptr);
|
||||
strcpy(cptr, ".vertices");
|
||||
bubulles_to_data(outfname, NULL, bublist, 0);
|
||||
// edges_to_data(file_edges, edges, 0);
|
||||
}
|
||||
else { /* one 'evblob' file */
|
||||
strcpy(outfname, infname);
|
||||
cptr = rindex(outfname, '.');
|
||||
strcpy(cptr, ".evblob");
|
||||
fprintf(stderr, "outfname [%s]\n", outfname);
|
||||
foo = x_write_vertedges(outfname, bublist, edges);
|
||||
if (foo) {
|
||||
fprintf(stderr, "Err #%d when writing edges&vertices file\n", foo);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
free_bubulles(bublist, 0);
|
||||
|
||||
Reference in New Issue
Block a user