Compare commits

..

No commits in common. "c2b9a31c93b081d4f0d6fb882df572df415783b1" and "02bbdc724941aa97f40777df6cae848e9126440b" have entirely different histories.

7 changed files with 44 additions and 154 deletions

View File

@ -3,8 +3,6 @@ BBFUNCS = ../libbubulles.a
OPT = -Wall -Wextra -g -DDEBUG_LEVEL=0 -DMUST_ABORT=0
all: read_obj export_evblob essai_faces
# ---------
read_obj: read_obj.c Makefile importobj.o rdwredges.o \
@ -28,5 +26,3 @@ rdwredges.o: rdwredges.c objtrucs.h \
essai_faces: essai_faces.c Makefile
$(CC) $(OPT) $< -o $@
# have a nice day !

View File

@ -1,22 +0,0 @@
#!/bin/awk -f
#
# this software is NOT ready for prime time !
#
BEGIN {
print "/* DO NOT EDIT BY HAND, BASTARD !*/"
print "/* generated ", strftime(), "*/"
print
print "#declare OBJ_edges = object\n{"
print "union {"
}
{
printf "cylinder { <%.9f, %.9f, %.9f>, <%.9f, %.9f, %.9f>, RR }\n", \
$1, $2, $3, $4, $5, $6
}
END {
print " }\n}\n"
}

View File

@ -19,40 +19,33 @@ int verbosity;
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int load_and_printf_evblob(char *filename, int mode)
int main(int argc, char *argv[])
{
EdgesAndVertices eav;
int foo, idx, a, b;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, filename, mode);
#endif
fprintf(stderr, "### EdgesAndVertices - %s %s\n", __DATE__, __TIME__);
if (mode) {
fprintf(stderr, "W: in %s 'mode' must be zero, and was %d\n",
__func__, mode);
}
verbosity = 0;
memset(&eav, 0, sizeof(EdgesAndVertices));
foo = x_load_vertedges(filename, &eav);
if (foo) {
fprintf(stderr, " load vertice & edges blob -> %d\n", foo);
return foo;
}
foo = x_load_vertedges("foo.evblob", &eav);
fprintf(stderr, " load vertice & edges blob -> %d\n", foo);
if (verbosity) {
fprintf(stderr, "vertices at %p\n", eav.Blist);
fprintf(stderr, "edges at %p\n", eav.Elist);
fprintf(stderr, "status is %d\n", eav.status);
fprintf(stderr, "got %d vertices and %d edges\n",
eav.Blist->fidx,
eav.Elist->fidx);
}
/*
* OK we have (maybe) all the data in da place
* and we can spit all the edges to stdout
*/
fprintf(stderr, "got %d vertices and %d edges\n",
eav.Blist->fidx,
eav.Elist->fidx);
for (idx=0; idx<eav.Elist->fidx; idx++) {
@ -60,62 +53,16 @@ for (idx=0; idx<eav.Elist->fidx; idx++) {
b = eav.Elist->edges[idx].B;
// fprintf(stderr, "%7d %7d\n", a, b);
printf("%.9f %.9f %.9f %.9f %.9f %.9f\n",
printf("%.9f %f %f %f %f %f\n",
eav.Blist->bbs[a].p.x,
eav.Blist->bbs[a].p.y,
eav.Blist->bbs[a].p.z,
eav.Blist->bbs[b].p.x,
eav.Blist->bbs[b].p.y,
eav.Blist->bbs[b].p.z );
}
return 0;
}
/* --------------------------------------------------------------------- */
void help(void)
{
fprintf(stderr, "YOLO!\n");
exit(0);
}
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int main(int argc, char *argv[])
{
int opt, foo;
fprintf(stderr, "### EdgesAndVertices - %s %s\n", __DATE__, __TIME__);
verbosity = 0;
while ((opt = getopt(argc, argv, "hv")) != -1) {
switch(opt) {
case 'h':
help(); break;
case 'v':
verbosity++; break;
default:
fprintf(stderr, "gni(%c)?\n", opt);
break;
}
}
#if DEBUG_LEVEL
fprintf(stderr, "optind=%d argc=%d\n", optind, argc);
#endif
if (optind < argc) {
// fprintf(stderr, "ARG = %s\n", argv[optind]);
foo = load_and_printf_evblob(argv[optind], 0);
if (foo) {
fprintf(stderr, "Error number %d on '%s'\n", foo, argv[optind]);
exit(1);
}
}
else {
fprintf(stderr, "%s need a input filename\n", argv[0]);
exit(1);
}
return 0;
}

View File

@ -55,8 +55,6 @@ Tokens TokenList[] = {
{ NULL, 0 }
};
/* --------------------------------------------------------------------- */
static int type_of_the_line(char *text)
{
Tokens *token;
@ -97,6 +95,7 @@ if (3 == foo) {
return foo;
}
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/* new Mon 27 Mar 2023 12:08:18 AM CEST
@ -104,13 +103,13 @@ return foo;
* mmmm... complex thing to do...
* and what is this "phy" parameter ?
*/
static int parse_face(char *cptr)
static int parse_face(char *cptr, int phy)
{
int ix, foo, a, b;
int pts[3];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, cptr, phy);
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, phy);
#endif
#if (0)
@ -145,6 +144,7 @@ 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,56 +168,48 @@ fprintf(stderr, "<<< %s\n", __func__);
return 0;
}
/* --------------------------------------------------------------------- */
/*
*
*/
int try_to_read_an_OBJ_file(char *infname, int outstyle)
int try_to_read_an_OBJ_file(char *infname, char *file_vert, char *file_edges,
int notused)
{
FILE *fpin;
char line[LINE_SZ+1], *cptr, *token;
float x, y, z;
int foo, tokenid;
int foo, nbre, 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, 600000, 0);
bublist = alloc_bubulles(infname, 400000, 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", 2200000, 0);
edges = alloc_edgelist("krkrkr", 600000, 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 line %d\n",
__func__, infname, linenumber);
fprintf(stderr, "%s: short read on %s...\n",
__func__, infname);
// return -2;
break;
}
@ -232,10 +224,6 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
// fprintf(stderr, "no token ?\n");
continue;
}
if ('#' == cptr[0]) { // found a comment
fprintf(stderr, " %s\n", cptr);
continue;
}
token = cptr;
tokenid = type_of_the_line(cptr);
if (verbosity > 1)
@ -265,7 +253,7 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
break;
case T_face:
/* experimental code here */
foo = parse_face(cptr);
foo = parse_face(cptr, 0);
if (foo) {
fprintf(stderr, "line %d '%s' parse face -> %d\n",
linenumber, cptr, foo);
@ -301,11 +289,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);
@ -317,24 +305,11 @@ if (verbosity > 1) {
print_edgelist_desc(edges, 0);
}
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);
}
}
bubulles_to_data(file_vert, NULL, bublist, 0);
edges_to_data(file_edges, edges, 0);
foo = x_write_vertedges("foo.evblob", bublist, edges);
// Cleanup
free_bubulles(bublist, 0);

View File

@ -1,10 +1,9 @@
/*
* EXPERIMENTAL CODE !
*
* see also 'rdwredges.c' & 'export_evblob.c'
* see also 'rdwredges.c
*/
#define EVBLOB_MAGIC (65872139)
typedef struct {
unsigned long magic;
@ -13,9 +12,6 @@ typedef struct {
int status;
} EdgesAndVertices;
/* in importobj.c */
int try_to_read_an_OBJ_file(char *fname, int outstyle);
/* in rdwredges.c */
int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges);
int x_load_vertedges(char *filename, EdgesAndVertices *eav);

View File

@ -49,7 +49,7 @@ if (NULL==(fp=fopen(filename, "w"))) {
return -4;
}
// print_bublist_desc(bblist, 0);
print_bublist_desc(bblist, 0);
fwrite("VERTICES", 8, 1, fp);
nbre = bblist->fidx;
fwrite(&nbre, sizeof(int), 1, fp);
@ -61,7 +61,7 @@ for (idx=0; idx<bblist->fidx; idx++) {
fwrite(coo, sizeof(coo), 1, fp);
}
// print_edgelist_desc(edges, 0);
print_edgelist_desc(edges, 0);
fwrite("EDGES ", 8, 1, fp);
nbre = edges->fidx;
fwrite(&nbre, sizeof(int), 1, fp);
@ -121,7 +121,6 @@ if (NULL==blst) {
abort();
}
if (verbosity > 1) print_bublist_desc(blst, 0);
/* load all that XYZ points */
for (idx=0; idx<nbre; idx++) {
if (3 != fread(coo, sizeof(double), 3, fp)) {
@ -152,7 +151,6 @@ if (1 != foo) {
return -1;
}
fprintf(stderr, " %d edges to be loaded\n", nbre);
/* allocate memory for edges list */
elst = alloc_edgelist("krkrkr", nbre, 0);
if (NULL==elst) {

View File

@ -7,9 +7,11 @@
#include <libgen.h> // for basename(3)
#include "../bubulles.h"
#include "../edges.h"
#include "./objtrucs.h"
int try_to_read_an_OBJ_file(char *fname,
char *outfname, char *file_edges,
int notused);
int verbosity = 0;
@ -18,21 +20,19 @@ int main(int argc, char *argv[])
int foo;
char *fname; /* see manpage basename(3) */
fprintf(stderr, "\n### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__);
fprintf(stderr, "\n### READ_OBJ %s %s\n\n", __DATE__, __TIME__);
if (2 != argc) {
bubulles_version(1);
exit(0);
}
verbosity = 0;
verbosity = 1;
/*
fname = basename(argv[1]);
fprintf (stderr, "input file name is '%s'\n", fname);
*/
foo = try_to_read_an_OBJ_file(argv[1], 0);
foo = try_to_read_an_OBJ_file(argv[1], "bulles.vertices", "bulles.edges", 0);
fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo);
return 0;