Compare commits
4 Commits
02bbdc7249
...
c2b9a31c93
Author | SHA1 | Date | |
---|---|---|---|
|
c2b9a31c93 | ||
|
87c2ffd88d | ||
|
a1056ee836 | ||
|
2a02aab5a9 |
@ -3,6 +3,8 @@ 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 \
|
||||
@ -26,3 +28,5 @@ rdwredges.o: rdwredges.c objtrucs.h \
|
||||
|
||||
essai_faces: essai_faces.c Makefile
|
||||
$(CC) $(OPT) $< -o $@
|
||||
|
||||
# have a nice day !
|
||||
|
22
tools/edges2cylinders.awk
Executable file
22
tools/edges2cylinders.awk
Executable file
@ -0,0 +1,22 @@
|
||||
#!/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"
|
||||
}
|
@ -19,33 +19,40 @@ int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* EXPERIMENTAL GRUIK-CODE !!! */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int load_and_printf_evblob(char *filename, int mode)
|
||||
{
|
||||
EdgesAndVertices eav;
|
||||
int foo, idx, a, b;
|
||||
|
||||
fprintf(stderr, "### EdgesAndVertices - %s %s\n", __DATE__, __TIME__);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, filename, mode);
|
||||
#endif
|
||||
|
||||
verbosity = 0;
|
||||
if (mode) {
|
||||
fprintf(stderr, "W: in %s 'mode' must be zero, and was %d\n",
|
||||
__func__, mode);
|
||||
}
|
||||
|
||||
memset(&eav, 0, sizeof(EdgesAndVertices));
|
||||
foo = x_load_vertedges("foo.evblob", &eav);
|
||||
fprintf(stderr, " load vertice & edges blob -> %d\n", foo);
|
||||
foo = x_load_vertedges(filename, &eav);
|
||||
if (foo) {
|
||||
fprintf(stderr, " load vertice & edges blob -> %d\n", foo);
|
||||
return 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++) {
|
||||
|
||||
@ -53,16 +60,62 @@ for (idx=0; idx<eav.Elist->fidx; idx++) {
|
||||
b = eav.Elist->edges[idx].B;
|
||||
// fprintf(stderr, "%7d %7d\n", a, b);
|
||||
|
||||
printf("%.9f %f %f %f %f %f\n",
|
||||
printf("%.9f %.9f %.9f %.9f %.9f %.9f\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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
@ -224,6 +232,10 @@ 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)
|
||||
@ -253,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);
|
||||
@ -289,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);
|
||||
@ -305,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);
|
||||
|
@ -1,9 +1,10 @@
|
||||
/*
|
||||
* EXPERIMENTAL CODE !
|
||||
*
|
||||
* see also 'rdwredges.c
|
||||
* see also 'rdwredges.c' & 'export_evblob.c'
|
||||
*/
|
||||
|
||||
#define EVBLOB_MAGIC (65872139)
|
||||
|
||||
typedef struct {
|
||||
unsigned long magic;
|
||||
@ -12,6 +13,9 @@ typedef struct {
|
||||
int status;
|
||||
} EdgesAndVertices;
|
||||
|
||||
int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges);
|
||||
/* 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);
|
||||
|
@ -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,6 +121,7 @@ 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)) {
|
||||
@ -151,6 +152,7 @@ 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) {
|
||||
|
@ -7,11 +7,9 @@
|
||||
#include <libgen.h> // for basename(3)
|
||||
|
||||
#include "../bubulles.h"
|
||||
#include "../edges.h"
|
||||
|
||||
int try_to_read_an_OBJ_file(char *fname,
|
||||
char *outfname, char *file_edges,
|
||||
int notused);
|
||||
|
||||
#include "./objtrucs.h"
|
||||
|
||||
int verbosity = 0;
|
||||
|
||||
@ -20,19 +18,21 @@ int main(int argc, char *argv[])
|
||||
int foo;
|
||||
char *fname; /* see manpage basename(3) */
|
||||
|
||||
fprintf(stderr, "\n### READ_OBJ %s %s\n\n", __DATE__, __TIME__);
|
||||
fprintf(stderr, "\n### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__);
|
||||
|
||||
if (2 != argc) {
|
||||
bubulles_version(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
verbosity = 1;
|
||||
verbosity = 0;
|
||||
|
||||
/*
|
||||
fname = basename(argv[1]);
|
||||
fprintf (stderr, "input file name is '%s'\n", fname);
|
||||
*/
|
||||
|
||||
foo = try_to_read_an_OBJ_file(argv[1], "bulles.vertices", "bulles.edges", 0);
|
||||
foo = try_to_read_an_OBJ_file(argv[1], 0);
|
||||
fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo);
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user