Compare commits

...

28 Commits

Author SHA1 Message Date
tTh
5eaa64a664 commit du bug rebelle 2023-05-02 10:06:24 +02:00
tTh
d3cca97dbf add a new page 2023-05-01 22:59:51 +02:00
tTh
8648d962df cosmetic 2023-05-01 13:09:01 +02:00
tTh
1fc4d7a05d add the help 2023-05-01 11:57:07 +02:00
tTh
755eb65da3 add sanity checks 2023-05-01 11:11:20 +02:00
tTh
f5de09b23a cosmetic 2023-04-30 11:15:59 +02:00
tTh
b12bdfe306 add -o option (output filename) 2023-04-30 01:03:49 +02:00
tTh
7cefa36d62 add bouding-box export 2023-04-29 23:44:56 +02:00
tTh
992c98cfa8 must be a cli opt ! 2023-04-28 23:09:56 +02:00
tTh
895e61cbb6 frobnicate parameters handling 2023-04-28 00:02:04 +02:00
tTh
85f1867424 little tweak 2023-04-28 00:00:50 +02:00
tTh
9c336eed8c adding command line options 2023-04-27 23:59:59 +02:00
tTh
a823bdae0c cosmetic 2023-04-27 20:29:39 +02:00
tTh
1f52a4c002 cosmetic 2023-04-27 19:34:58 +02:00
tTh
d65d635577 expliquer... 2023-04-27 05:56:40 +02:00
tTh
b04bf9e67a refactoring of export_evblob in progress 2023-04-26 08:33:05 +02:00
tTh
7dc4fae849 repair debug messages 2023-04-24 14:12:15 +02:00
tTh
e2188897cf minimal explanation 2023-04-22 18:42:25 +02:00
tTh
50d83a6ce2 output file in current directory 2023-04-22 18:41:34 +02:00
tTh
1ff0230d15 cosmetic 2023-04-22 18:40:37 +02:00
tTh
c0be70d32a oups.. 2023-04-22 10:31:50 +02:00
tTh
c2b9a31c93 move a proto declaration to the right place 2023-04-20 22:55:46 +02:00
tTh
87c2ffd88d refactoring, first step 2023-04-20 22:33:46 +02:00
tTh
a1056ee836 add a all: target 2023-04-19 10:41:50 +02:00
tTh
2a02aab5a9 print "#bla..." comments 2023-04-15 17:30:50 +02:00
tTh
02bbdc7249 commit du soir, espoir 2023-04-15 00:56:48 +02:00
tTh
300bcfa7a0 admin stuff 2023-04-14 13:30:43 +02:00
tTh
3dbcb198bf first working version, need more test 2023-04-14 10:10:01 +02:00
20 changed files with 758 additions and 98 deletions

8
.gitignore vendored
View File

@@ -7,11 +7,3 @@ gmon.out
dummy-file dummy-file
toto toto
tools/*.obj
! tools/minimal.obj
! tools/cube.obj
tools/read_obj
tools/*.xyz
tools/*.asc
tools/toto
tools/core

View File

@@ -122,15 +122,15 @@ int print_bublist_desc(BBList *bbl, int opts)
{ {
fprintf(stderr, "------- bblist at %p\n", bbl); fprintf(stderr, "------- bblist at %p\n", bbl);
fprintf(stderr, "\tname \t'%s'\n", bbl->name); fprintf(stderr, "\tname\t\t'%s'\n", bbl->name);
fprintf(stderr, "\tsize\t%6d\n\tfidx\t%6d\n", bbl->size, bbl->fidx); fprintf(stderr, "\tsize/fidx\t%d %d\n", bbl->size, bbl->fidx);
if (opts & 0x01) { if (opts & 0x01) {
fprintf(stderr, "\txyz\t%f %f %f\n", fprintf(stderr, "\txyz\t\t%f %f %f\n",
bbl->position.x, bbl->position.y, bbl->position.z); bbl->position.x, bbl->position.y, bbl->position.z);
} }
fprintf(stderr, "\tflags\t0x%08lX\n", bbl->flags); fprintf(stderr, "\tflags\t\t0x%08lX\n", bbl->flags);
fprintf(stderr, "\tarray\t%p\n", bbl->bbs); fprintf(stderr, "\tarray@\t\t%p\n", bbl->bbs);
fflush(stderr); fflush(stderr);

View File

@@ -4,7 +4,7 @@
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define LIBBB_VERSION 63 #define LIBBB_VERSION 64
#define SZ_BUBULLE_TEXT 81 /* arbitrary value */ #define SZ_BUBULLE_TEXT 81 /* arbitrary value */

24
edges.c
View File

@@ -70,28 +70,36 @@ return 0;
*/ */
static int is_edge_in_list(EdgeList *list, int p0, int p1) static int is_edge_in_list(EdgeList *list, int p0, int p1)
{ {
int idx; int idx, retval, place;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1);
#endif
retval = 0; place = -1;
for (idx=0; idx < list->fidx; idx++) { for (idx=0; idx < list->fidx; idx++) {
if ( (list->edges[idx].A == p0) && if ( (list->edges[idx].A == p0) &&
(list->edges[idx].B == p1) ) return 1; (list->edges[idx].B == p1) ) {
retval = 1; place = idx; break; }
if ( (list->edges[idx].A == p1) && if ( (list->edges[idx].A == p1) &&
(list->edges[idx].B == p0) ) return 2; (list->edges[idx].B == p0) ){
retval = 2; place = idx; break; }
} }
return 0; /* NOT FOUND */ if (retval) fprintf(stderr, " edge %d %d found at %d\n", p0, p1, idx);
return retval;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* /*
*
* we have two functions for adding an edge to a list * we have two functions for adding an edge to a list
* the first one add unconditionnaly the edge to the * the first one add unconditionnaly the edge to the
* (non full) list... * (non full) list...
*/ */
int push_an_edge(EdgeList *list, int p0, int p1) int push_an_edge(EdgeList *list, int p0, int p1)
{ {
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1); fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1);
#endif #endif
@@ -130,8 +138,12 @@ if (list->fidx >= list->size) {
if ( ! is_edge_in_list(list, p0, p1) ) { if ( ! is_edge_in_list(list, p0, p1) ) {
list->edges[list->fidx].A = p0; list->edges[list->fidx].A = p0;
list->edges[list->fidx].B = p1; list->edges[list->fidx].B = p1;
fprintf(stderr, "edge %d %d poked at %d\n", p0, p1, list->fidx);
list->fidx ++; list->fidx ++;
} }
else {
fprintf(stderr, " %s: drop edge %d %d\n", __func__, p0, p1);
}
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

8
tbb.c
View File

@@ -186,7 +186,8 @@ int main(int argc, char *argv[])
{ {
int foo; int foo;
fprintf(stderr, "*** Bubulles Testing %s %s\n\n", __DATE__, __TIME__); fprintf(stderr, "***\n*** Bubulles Testing %s %s\n***\n",
__DATE__, __TIME__);
bubulles_version(0); bubulles_version(0);
@@ -200,8 +201,9 @@ foo = test_peek_poke(5000);
fprintf(stderr, "test peek/poke -> %d\n", foo); fprintf(stderr, "test peek/poke -> %d\n", foo);
#endif #endif
// XXX foo = essai_des_edges_A(25);
// XXX fprintf(stderr, "test A des edges -> %d\n", foo); foo = essai_des_edges_A(25);
fprintf(stderr, "test A des edges -> %d\n", foo);
foo = essai_des_edges_B(5000); foo = essai_des_edges_B(5000);
fprintf(stderr, "test B des edges -> %d\n", foo); fprintf(stderr, "test B des edges -> %d\n", foo);

14
tools/.gitignore vendored
View File

@@ -1,8 +1,20 @@
essai_faces essai_faces
read_obj read_obj
export_evblob
*.obj
! tools/minimal.obj
! tools/cube.obj
! overflowed.obj
read_obj
*.xyz
*.asc
toto
core
*.vertices *.vertices
*.edges *.edges
*.blob *.evblob

View File

@@ -1,12 +1,22 @@
BBFUNCS = ../libbubulles.a BBFUNCS = ../libbubulles.a
OPT = -Wall -Wextra -g -DDEBUG_LEVEL=0 -DMUST_ABORT=0 OPT = -Wall -Wextra -O1 -g -DDEBUG_LEVEL=0 -DMUST_ABORT=0
read_obj: read_obj.c Makefile importobj.o rdwredges.o \ all: read_obj export_evblob # essai_faces
# ---------
read_obj: read_obj.c Makefile importobj.o rdwredges.o \
$(BBFUNCS) $(BBFUNCS)
gcc $(OPT) $< importobj.o rdwredges.o $(BBFUNCS) -o $@ gcc $(OPT) $< importobj.o rdwredges.o $(BBFUNCS) -o $@
export_evblob: export_evblob.c Makefile importobj.o rdwredges.o \
$(BBFUNCS)
gcc $(OPT) $< importobj.o rdwredges.o $(BBFUNCS) -o $@
# ---------
importobj.o: importobj.c ../bubulles.h ../edges.h Makefile importobj.o: importobj.c ../bubulles.h ../edges.h Makefile
$(CC) $(OPT) -c $< $(CC) $(OPT) -c $<
@@ -18,3 +28,5 @@ rdwredges.o: rdwredges.c objtrucs.h \
essai_faces: essai_faces.c Makefile essai_faces: essai_faces.c Makefile
$(CC) $(OPT) $< -o $@ $(CC) $(OPT) $< -o $@
# have a nice day !

View File

@@ -1,4 +1,3 @@
# Importer des fichiers .OBJ # Importer des fichiers .OBJ
* https://en.wikipedia.org/wiki/Wavefront_.obj_file * https://en.wikipedia.org/wiki/Wavefront_.obj_file
@@ -18,16 +17,48 @@ Première étape : en lisant les vertices, nous saurons positionner
nos bubulles. Ensuite, en explorant les faces, nous pouvons nos bubulles. Ensuite, en explorant les faces, nous pouvons
en déduire les arètes (aka: edges). en déduire les arètes (aka: edges).
Et à partir de cette analyse, nous allons générer un fichier
binaire contenant les points xyx, et les arêtes pointA-pointB.
Le format de ce fichier doit être considéré *opaque*.
il sera généré dans le $PWD en utilisant le basename du fichier .OBJ mais
avec l'extension `.evblob`.
Ce n'est qu'une première étape, d'autres formats de sortie
pourront être implémentés.
Attention, mon parser EXIGE des fichiers Unix bien conformés : Attention, mon parser EXIGE des fichiers Unix bien conformés :
c'est-à-dire que la dernière ligne du `.obj` DOIT être terminée c'est-à-dire que la dernière ligne du `.obj` DOIT être terminée
par un newline ! par un newline !
## export_evblob & bla.awk
Deuxième étape : À partir du fichier .evblob généré à l'étape
précédente, nous allons créer (entre autres options ?)
un fichier utilisable par Povray. La première option a été
la génération des arêtes, nous aurons donc sur `stdout`
six nombres réels: xyz(pointA) et xyz(pointB) :
```
25.2275466 19.5029792 -25.1227169 35.6406135 19.5029792 0.0166420
35.6406135 19.5029792 0.0166420 0.0881849 19.5029792 -35.5357818
0.0881849 19.5029792 -35.5357818 25.2275466 19.5029792 -25.1227169
```
Et là, c'est trop facile pour la suite, Unix sait le faire depuis
quarante ans.
Un petit [script Awk](./edges2cylinders.awk) fera l'affaire,
en toute simplicité.
Bien entendu, la même chose pourrait être faire pour les vertices,
ce qui nous remet dans la droite ligne orthodoxe des bubulles.
## TODO LIST ## TODO LIST
* Songer à un système d'auto-scaler et de recentrage * Songer à un système d'auto-scaler et de recentrage
* Import/export en blob du combo "edges & vertices"
* Comment générer un `.obj` à partir d'une image flottante ? * Comment générer un `.obj` à partir d'une image flottante ?
* Gérer les arêtes de longueur nulle (degenerated cylinder) * Gérer les arêtes de longueur nulle (degenerated cylinder)
* Que faire des vertices qui ne sont pas utilisées par des faces ?
* Plonger un peu dans la [technique](./technique.md).
## rendu final ## rendu final

24
tools/edges2bubulles.awk Executable file
View File

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

22
tools/edges2cylinders.awk Executable file
View 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"
}

View File

@@ -32,6 +32,10 @@ printf(" -> %d\n", bar);
return 0; return 0;
} }
/*
* GO !
*/
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, bar; int foo, bar;

236
tools/export_evblob.c Normal file
View File

@@ -0,0 +1,236 @@
/*
* EdgesAndVertices
https://git.tetalab.org/tTh/libbubulle/src/branch/master/tools/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../bubulles.h"
#include "../edges.h"
#include "objtrucs.h"
int verbosity;
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int printf_the_boudingbox(EdgesAndVertices *eav)
{
int idx;
double x, y, z;
double minX, minY, minZ;
double maxX, maxY, maxZ;
minX = minY = minZ = 1e35;
maxX = maxY = maxZ = -1e35;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, eav);
#endif
fprintf(stderr, "====== %s is not fully implemented ======\n", __func__);
for (idx=0; idx<eav->Blist->fidx; idx++) {
x = eav->Blist->bbs[idx].p.x;
y = eav->Blist->bbs[idx].p.y;
z = eav->Blist->bbs[idx].p.z;
if (x < minX) minX = x;
else if (x > maxX) maxX = x;
if (y < minY) minY = y;
else if (y > maxY) maxY = y;
if (z < minZ) minZ = z;
else if (z > maxZ) maxZ = z;
}
printf( "%.9f %.9f %.9f %.9f %.9f %.9f\n",
minX, minY, minZ, maxX, maxY, maxZ);
return -1;
}
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int printf_the_vertices(EdgesAndVertices *eav)
{
int idx;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, eav);
#endif
if (verbosity) fprintf(stderr, "fprinting %d vertices\n", eav->Blist->fidx);
for (idx=0; idx<eav->Blist->fidx; idx++) {
printf("%.9f %.9f %.9f\n",
eav->Blist->bbs[idx].p.x,
eav->Blist->bbs[idx].p.y,
eav->Blist->bbs[idx].p.z );
}
return 0;
}
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int printf_the_edges(EdgesAndVertices *eav)
{
int idx, a, b, vmax;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, eav);
#endif
if (verbosity) fprintf(stderr, " fprinting %d edges\n", eav->Elist->fidx);
vmax = eav->Blist->fidx;
fprintf(stderr, " %s: eav->Blist->fidx = %d\n", __func__, vmax);
/*
* OK we have (maybe) all the data in da place
* and we can spit all the edges to stdout
*/
for (idx=0; idx<eav->Elist->fidx; idx++) {
a = eav->Elist->edges[idx].A;
b = eav->Elist->edges[idx].B;
/* this is a Molly-Guard */
if ( (a<0) || (b<0) || (a>vmax) || (b>vmax) ) {
fprintf(stderr, "ERROR: vmax=%d a=%d b=%d\n", vmax, a, b);
continue;
}
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; /* allway success ? */
}
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int load_and_printf_evblob(char *filename, char *outmode)
{
EdgesAndVertices eav;
int foo, mode;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %s )\n", __func__, filename, outmode);
#endif
memset(&eav, 0, sizeof(EdgesAndVertices));
foo = x_load_vertedges(filename, &eav);
if (foo) {
fprintf(stderr, " load vertice & edges blob -> %d\n", foo);
return foo;
}
if (verbosity > 1) {
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);
}
mode = 666;
if (! strcasecmp("edges", outmode)) { mode = 0; }
else if (! strcasecmp("vertices", outmode)) { mode = 1; }
else if (! strcasecmp("bbox", outmode)) { mode = 2; }
switch (mode) {
case 0:
foo = printf_the_edges(&eav); break;
case 1:
foo = printf_the_vertices(&eav); break;
case 2:
foo = printf_the_boudingbox(&eav); break;
default:
fprintf(stderr, "%s: no way for '%s'\n", __func__, outmode);
exit(1);
break;
}
if (foo) {
fprintf(stderr, "%s: action '%s' -> %d\n", __func__, outmode, foo);
exit(1);
}
/* deallocate used memory for keep pinpin happy */
free_bubulles(eav.Blist, 1);
free_edgelist(eav.Elist, 1);
return 0;
}
/* --------------------------------------------------------------------- */
void help(void)
{
puts("usage:\n $ export_evblob [opts] fichier.evblob");
puts("\t-h\tsome short help...");
puts("\t-t\tone of [edges vertices bbox]");
puts("\t-v\tbe more verbose");
exit(0);
}
/* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int main(int argc, char *argv[])
{
int opt, foo;
char *outmode = "vertices";
fprintf(stderr, "### Export EVblob (%s %s)\n", __DATE__, __TIME__);
verbosity = 0;
while ((opt = getopt(argc, argv, "ht:v")) != -1) {
switch(opt) {
case 'h':
help(); break;
case 'v':
verbosity++; break;
case 't':
// fprintf(stderr, "type -> '%s'\n", optarg);
outmode = optarg;
break;
default:
fprintf(stderr, "'%c' EBADOPT\n", opt);
exit(1);
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], outmode);
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

@@ -11,6 +11,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <libgen.h> /* for basename(3) */
#include "../bubulles.h" #include "../bubulles.h"
#include "../edges.h" #include "../edges.h"
@@ -21,6 +22,7 @@ extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define PSYCHOTIK 1
#define LINE_SZ 666 #define LINE_SZ 666
static BBList *bublist; static BBList *bublist;
@@ -48,13 +50,15 @@ Tokens TokenList[] = {
{ "vn", T_vt }, // c'est quoi ce truc ? { "vn", T_vt }, // c'est quoi ce truc ?
{ "l", T_line }, { "l", T_line },
{ "o", T_object }, { "o", T_object },
{ "s", T_smoothing }, { "s", T_smoothing }, // mmmm....
{ "usemtl", T_usemtl }, { "usemtl", T_usemtl },
{ "mtllib", T_mtllib }, { "mtllib", T_mtllib },
/* and more to come... */ /* and more to come... */
{ NULL, 0 } { NULL, 0 }
}; };
/* --------------------------------------------------------------------- */
static int type_of_the_line(char *text) static int type_of_the_line(char *text)
{ {
Tokens *token; Tokens *token;
@@ -95,21 +99,19 @@ if (3 == foo) {
return foo; return foo;
} }
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* new Mon 27 Mar 2023 12:08:18 AM CEST /* new Mon 27 Mar 2023 12:08:18 AM CEST
* *
* mmmm... complex thing to do... * 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 maxvert)
{ {
int ix, foo, a, b; int ix, foo, a, b;
int pts[3]; int pts[3], valid;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, phy); fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, maxvert);
#endif #endif
#if (0) #if (0)
@@ -133,54 +135,77 @@ for (ix=0; ix<3; ix++) {
} }
} }
/** check the freshly read datas **/ fprintf(stderr, " %s: pts %5d %5d %5d\n", __func__,
pts[0], pts[1], pts[2]);
valid = 1;
/**** check the freshly read datas ****/
if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) { if ( pts[0]==pts[1] || pts[0]==pts[2] || pts[2]==pts[1] ) {
fprintf(stderr, "%s: degenerated face ( %d %d %d )\n", __func__, fprintf(stderr, "%s: degenerated face ( %d %d %d )\n", __func__,
pts[0], pts[1], pts[2]); pts[0], pts[1], pts[2]);
dropped++; dropped++;
valid = 0;
}
if ( (pts[0]>maxvert) || (pts[1]>maxvert) || (pts[2]>maxvert) ) {
fprintf(stderr, "%s: out of bound ( %d %d %d )\n", __func__,
pts[0], pts[1], pts[2]);
valid = 0;
} }
/* /*
* may be we can check the "degenerated cylinder" here ? * may be we can check the "degenerated cylinder" here ?
*/ */
if (valid) {
for (ix=0; ix<3; ix++) {
for (ix=0; ix<3; ix++) { a = ix % 3;
a = ix % 3; b = (ix+1) % 3;
b = (ix+1) % 3; #if PSYCHOTIK
foo = push_a_missing_edge(edges, pts[a], pts[b]); foo = push_a_missing_edge(edges, pts[a], pts[b]);
if (foo) { #else
fprintf(stderr, "%s: disaster #%d line %d\n", foo = push_an_edge(edges, pts[a], pts[b]);
__func__, foo, linenumber); #endif
return -2; if (foo) {
fprintf(stderr, "%s: disaster #%d line %d\n",
__func__, foo, linenumber);
return -2;
}
} }
} }
if (dropped) { if (dropped) fprintf(stderr, "%s: %d dropped\n", __func__, dropped);
fprintf(stderr, "%s: %d dropped...\n", __func__, dropped);
exit(1);
}
#if DEBUG_LEVEL #if DEBUG_LEVEL > 1
fprintf(stderr, "<<< %s\n", __func__); fprintf(stderr, "<<< %s\n", __func__);
#endif #endif
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int try_to_read_an_OBJ_file(char *infname, char *file_vert, char *file_edges, /*
int notused) * The main procedure, who contains a lot of things.
*/
int try_to_read_an_OBJ_file(char *infname, char *ofname, int outstyle)
{ {
FILE *fpin; FILE *fpin;
char line[LINE_SZ+1], *cptr, *token; char line[LINE_SZ+1], *cptr, *token;
float x, y, z; float x, y, z;
int foo, nbre, tokenid; int foo, bar, tokenid;
Bubulle bubulle; Bubulle bubulle;
char *outfname, *baseptr;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n\n", __func__, infname, notused); fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
infname, ofname, outstyle);
#endif #endif
#if PSYCHOTIK
fprintf(stderr, " *** PSYCHOTIK MODE ENGAGED ***\n");
#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"))) { if (NULL==(fpin=fopen(infname, "r"))) {
perror(infname); perror(infname);
@@ -188,28 +213,27 @@ if (NULL==(fpin=fopen(infname, "r"))) {
} }
linenumber = 0; linenumber = 0;
bublist = alloc_bubulles(infname, 400000, 0); bublist = alloc_bubulles(infname, 800000, 0);
if (NULL==bublist) { if (NULL==bublist) {
fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__); fprintf(stderr, "in %s, no mem for bubls, aborting...\n", __func__);
abort(); abort();
} }
if (verbosity > 1) print_bublist_desc(bublist, 0); if (verbosity > 1) print_bublist_desc(bublist, 0);
edges = alloc_edgelist("krkrkr", 600000, 0); edges = alloc_edgelist("krkrkr", 3000000, 0);
if (NULL==edges) { if (NULL==edges) {
fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__); fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__);
abort(); abort();
} }
if (verbosity > 1) print_edgelist_desc(edges, 0); if (verbosity > 1) print_edgelist_desc(edges, 0);
fprintf(stderr, "\n ***********************************\n"); fprintf(stderr, " +-----------------------------------------\n");
nbre = 0;
while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) { while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
if ('\n' != line[strlen(line)-1]) { if ('\n' != line[strlen(line)-1]) {
fprintf(stderr, "%s: short read on %s...\n", fprintf(stderr, "%s: short read on %s line %d\n",
__func__, infname); __func__, infname, linenumber);
// return -2; // return -2;
break; break;
} }
@@ -224,6 +248,10 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
// fprintf(stderr, "no token ?\n"); // fprintf(stderr, "no token ?\n");
continue; continue;
} }
if ('#' == cptr[0]) { // found a comment
fprintf(stderr, " %s\n", cptr);
continue;
}
token = cptr; token = cptr;
tokenid = type_of_the_line(cptr); tokenid = type_of_the_line(cptr);
if (verbosity > 1) if (verbosity > 1)
@@ -239,23 +267,29 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
case T_vertice: case T_vertice:
x = y = z = 0.0; x = y = z = 0.0;
foo = parse_vertice(cptr, &x, &y, &z); foo = parse_vertice(cptr, &x, &y, &z);
if (3!=foo) { if (3 != foo) {
fprintf(stderr, "err %d parse vertice %s\n",
foo, cptr);
abort(); abort();
} }
bubulle.p.x = x; bubulle.p.x = x;
bubulle.p.y = y; bubulle.p.y = y;
bubulle.p.z = z; bubulle.p.z = z;
if (verbosity > 1) niceprint_bubulle(&bubulle, 0); if (verbosity > 2) niceprint_bubulle(&bubulle, 0);
foo = push_bubulle(bublist, &bubulle); foo = push_bubulle(bublist, &bubulle);
if (foo) { if (foo) {
fprintf(stderr, "err %d push bubulle\n", foo);
abort(); abort();
} }
fprintf(stderr, "pushed %f %f %f (%d)\n", x, y, z,
bublist->fidx);
break; break;
case T_face: case T_face:
/* experimental code here */ /* experimental code here */
foo = parse_face(cptr, 0); bar = bublist->fidx - 1;
foo = parse_face(cptr, bar);
if (foo) { if (foo) {
fprintf(stderr, "line %d '%s' parse face -> %d\n", fprintf(stderr, "line %d '%s' parseface -> %d\n",
linenumber, cptr, foo); linenumber, cptr, foo);
exit(1); exit(1);
} }
@@ -279,25 +313,33 @@ while(NULL!=(cptr=fgets(line, LINE_SZ, fpin))) {
break; break;
case T_line: case T_line:
cptr = strtok(NULL, " ");
fprintf(stderr, "\tLine: %s\n", cptr);
break; break;
case T_smoothing: case T_smoothing:
cptr = strtok(NULL, " ");
if (verbosity)
fprintf(stderr, "\tSmoothing: %s\n", cptr);
break; break;
case T_vt: case T_vt:
cptr = strtok(NULL, " ");
if (verbosity)
fprintf(stderr, "\tvt ??? : %s\n", cptr);
break; break;
default: default:
fprintf(stderr, "token %s -> %d ?\n", token, tokenid); fprintf(stderr, "W: token %s -> %d ?\n", token, tokenid);
break; break;
} }
nbre++;
} }
fclose(fpin); fclose(fpin);
fprintf(stderr, " ***********************************\n"); fprintf(stderr, " +-----------------------------------------\n");
if(verbosity) { if(verbosity) {
fprintf(stderr, "%s(): %d vertices loaded\n", __func__, bublist->fidx); fprintf(stderr, "%s: %d vertices and %d edges loaded.\n", __func__,
fprintf(stderr, "%s(): %d edges loaded\n", __func__, edges->fidx); bublist->fidx, edges->fidx);
} }
if (verbosity > 1) { if (verbosity > 1) {
@@ -305,13 +347,38 @@ if (verbosity > 1) {
print_edgelist_desc(edges, 0); print_edgelist_desc(edges, 0);
} }
bubulles_to_data(file_vert, NULL, bublist, 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 */
if (NULL == ofname) {
strcpy(outfname, infname);
/* see manpage basename(3) */
baseptr = basename(outfname);
// fprintf(stderr, "baseptr -> [%s]\n", baseptr);
cptr = rindex(baseptr, '.');
strcpy(cptr, ".evblob");
fprintf(stderr, "baseptr-> [%s]\n", baseptr);
cptr = baseptr;
}
else {
cptr = ofname;
fprintf(stderr, "writing to %s\n", cptr);
}
foo = x_write_vertedges(cptr, bublist, edges);
edges_to_data(file_edges, edges, 0); if (foo) {
fprintf(stderr, "Err #%d when writing edges&vertices file\n", foo);
foo = x_write_vertedges("foo.blob", bublist, edges); }
}
// Cleanup // Cleanup
free(outfname);
free_bubulles(bublist, 0); free_bubulles(bublist, 0);
free_edgelist(edges, 0); free_edgelist(edges, 0);

View File

@@ -1,7 +1,11 @@
o minimal o minimal
v 0 0 0 v 0 0 0
v 1 0 0 v 1 0 0
v 0 1 0 v 0 2 0
v 0 0 1 v 0 0 3
f 1/2 2/3 3/1
f 0/1 0/1 0/2 f 0 1 2
f 1 2 3
f 3 1 0
f 0 2 3

View File

@@ -1,14 +1,22 @@
/* /*
* EXPERIMENTAL CODE ! * EXPERIMENTAL CODE !
*
* see 'rdwredges.c' for source code
* & 'export_evblob.c' for a usecase.
*/ */
#define EVBLOB_MAGIC (65872139)
typedef struct { typedef struct {
unsigned long magic; unsigned long magic;
BBList *Blist; BBList *Blist;
EdgeList *Elist; EdgeList *Elist;
int status; int status;
} EdgeAndVertices; } EdgesAndVertices;
int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges); /* in importobj.c */
int try_to_read_an_OBJ_file(char *fname, char *oname, int outstyle);
/* in rdwredges.c */
int x_write_vertedges (char *filename, BBList *bblist, EdgeList *edges);
int x_load_vertedges (char *filename, EdgesAndVertices *eav);

11
tools/overflowed.obj Normal file
View File

@@ -0,0 +1,11 @@
o minimal
v 0 0 0
v 1 0 0
v 0 2 0
v 0 0 3
f 0 1 2
f 2 3 4
f 4 2 1
f 0 3 4

View File

@@ -19,6 +19,21 @@
extern int verbosity; extern int verbosity;
/* --------------------------------------------------------------------- */
static void dumper(void *ptr, int count)
{
int idx;
unsigned char *cptr = (unsigned char *)ptr;
for (idx=0; idx<count; idx++) {
fprintf(stderr, "%02x ", cptr[idx]);
}
fprintf(stderr, " ?\n");
for (idx=0; idx<count; idx++) {
fprintf(stderr, " %c ", isprint(cptr[idx]) ? cptr[idx] : 'X' );
}
fprintf(stderr, " ?\n");
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */ /* EXPERIMENTAL GRUIK-CODE !!! */
int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges) int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges)
@@ -26,27 +41,34 @@ int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges)
FILE *fp; FILE *fp;
int idx, edg[2]; int idx, edg[2];
double coo[3]; double coo[3];
int nbre;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__, filename, fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__, filename,
bblist, edges); bblist, edges);
#endif
if (NULL==(fp=fopen(filename, "w"))) { if (NULL==(fp=fopen(filename, "w"))) {
perror(filename); perror(filename);
return -4; return -4;
} }
print_bublist_desc(bblist, 0); // print_bublist_desc(bblist, 0);
fwrite("VERTICES", 8, 1, fp); fwrite("VERTICES", 8, 1, fp);
nbre = bblist->fidx;
fwrite(&nbre, sizeof(int), 1, fp);
for (idx=0; idx<bblist->fidx; idx++) { for (idx=0; idx<bblist->fidx; idx++) {
fprintf(stderr, "vertice %d\n", idx); // fprintf(stderr, "vertice %d\n", idx);
coo[0] = bblist->bbs[idx].p.x; coo[0] = bblist->bbs[idx].p.x;
coo[1] = bblist->bbs[idx].p.y; coo[1] = bblist->bbs[idx].p.y;
coo[2] = bblist->bbs[idx].p.z; coo[2] = bblist->bbs[idx].p.z;
fwrite(coo, sizeof(coo), 1, fp); fwrite(coo, sizeof(coo), 1, fp);
} }
print_edgelist_desc(edges, 0); // print_edgelist_desc(edges, 0);
fwrite("EDGES ", 8, 1, fp); fwrite("EDGES ", 8, 1, fp);
nbre = edges->fidx;
fwrite(&nbre, sizeof(int), 1, fp);
for (idx=0; idx<edges->fidx; idx++) { for (idx=0; idx<edges->fidx; idx++) {
edg[0] = edges->edges[idx].A; edg[0] = edges->edges[idx].A;
edg[1] = edges->edges[idx].B; edg[1] = edges->edges[idx].B;
@@ -57,3 +79,110 @@ fclose(fp);
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* EXPERIMENTAL GRUIK-CODE !!! */
int x_load_vertedges(char *filename, EdgesAndVertices *eav)
{
BBList *blst;
EdgeList *elst;
FILE *fp;
char marker[8];
int nbre, foo, idx, edg[2];
double coo[3];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, filename, eav);
#endif
if (NULL==(fp=fopen(filename, "r"))) {
perror(filename);
return -4;
}
/* + + + + + + + + + + + */
foo = fread(marker, 8, 1, fp);
if (1 != foo) {
fprintf(stderr, " %s of '%s': short read %d\n", __func__, filename, foo);
return -1;
}
if (memcmp("VERTICES", marker, 8)) {
fprintf(stderr, " %s is not an evblob file.\n", filename);
dumper(marker, 8);
return -4;
}
/* now, get the numbers of vertices */
foo = fread(&nbre, sizeof(int), 1, fp);
if (1 != foo) {
fprintf(stderr, " %s of '%s': short read %d\n", __func__, filename, foo);
return -1;
}
if (verbosity) fprintf(stderr, " %d vertices to be loaded\n", nbre);
/* allocate memory */
blst = alloc_bubulles(filename, nbre, 0);
if (NULL==blst) {
fprintf(stderr, "in %s, no mem, aborting...\n", __func__);
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)) {
fprintf(stderr, "%s err reading vertice #%d\n", __func__, idx);
exit(1);
}
blst->bbs[idx].p.x = coo[0];
blst->bbs[idx].p.y = coo[1];
blst->bbs[idx].p.z = coo[2];
blst->fidx++;
}
/* + + + + + + + + + + + */
foo = fread(marker, 8, 1, fp);
if (1 != foo) {
fprintf(stderr, " %s of '%s': short read %d\n", __func__, filename, foo);
return -1;
}
if (memcmp("EDGES ", marker, 8)) {
fprintf(stderr, " %s is not an evblob file.\n", filename);
dumper(marker, 8);
return -4;
}
/* now, get the numbers of eges */
foo = fread(&nbre, sizeof(int), 1, fp);
if (1 != foo) {
fprintf(stderr, " %s of '%s': short read %d\n", __func__, filename, foo);
return -1;
}
if (verbosity) fprintf(stderr, " %d edges to be loaded\n", nbre);
/* allocate memory for edges list */
elst = alloc_edgelist("krkrkr", nbre, 0);
if (NULL==elst) {
fprintf(stderr, "no mem for edges in %s, aborting...\n", __func__);
abort(); /* be violent before OOMK */
}
/* read (and check ?) the edges */
for (idx=0; idx<nbre; idx++) {
if (2 != fread(edg, sizeof(int), 2, fp)) {
fprintf(stderr, "%s: err reading edge #%d\n", __func__, idx);
return -6;
}
elst->edges[idx].A = edg[0];
elst->edges[idx].B = edg[1];
elst->fidx++;
}
/* so, now I think we have got all the data */
eav->Blist = blst;
eav->Elist = elst;
eav->status = 0x51;
fclose(fp);
return 0;
}
/* --------------------------------------------------------------------- */

View File

@@ -5,35 +5,69 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <libgen.h> // for basename(3) #include <libgen.h> // for basename(3)
#include <unistd.h>
#include "../bubulles.h" #include "../bubulles.h"
#include "../edges.h"
int try_to_read_an_OBJ_file(char *fname, #include "objtrucs.h"
char *outfname, char *file_edges,
int notused);
int verbosity = 0; int verbosity = 0;
/* --------------------------------------------------------------------- */
void help(void)
{
printf("### READ_OBJ 0X%X TALKING\n", getpid());
puts("usage:");
puts("\t-h\t\tthis help (use -v -h for more");
puts("\t-o fname\tfix the output filename");
puts("\t-v\t\tincrease verbosity");
exit(0);
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo; int foo, opt;
char *fname; /* see manpage basename(3) */ char *ofname = NULL;
fprintf(stderr, "\n### READ_OBJ %s %s\n\n", __DATE__, __TIME__); fprintf(stderr, "### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__);
if (2 != argc) { if (1 == argc) {
bubulles_version(1); bubulles_version(1);
exit(0); exit(0);
} }
verbosity = 1; while ((opt = getopt(argc, argv, "ho:v")) != -1) {
switch(opt) {
case 'h':
help(); break;
case 'o':
ofname = optarg;
break;
case 'v':
verbosity++; break;
default:
exit(1);
break;
}
}
fname = basename(argv[1]); if (optind < argc) {
fprintf (stderr, "input file name is '%s'\n", fname); if (verbosity) fprintf(stderr, " arg[%d] = %s\n",
optind, argv[optind]);
foo = try_to_read_an_OBJ_file(argv[1], "bulles.vertices", "bulles.edges", 0); foo = try_to_read_an_OBJ_file(argv[optind], ofname, 0);
fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo); 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; return 0;
} }

23
tools/run_read_export.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
set -e
make read_obj
make export_evblob
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
figlet 'a real WTF' | sed 's/^/XXX /'
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
./read_obj -v minimal.obj
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
./export_evblob -t edges minimal.evblob |
awk '{ printf "%4d | %.0f %.0f %.0f %.0f %.0f %.0f\n", \
NR, $1, $2, $3, $4, $5, $6 }'
echo
./export_evblob -t vertices minimal.evblob

37
tools/technique.md Normal file
View File

@@ -0,0 +1,37 @@
# Technique
Les détails **gores**...
## Le parser
Je pense qu'il y a un bug sournois caché dedans
## L'exporteur
Conversion d'un `.evblob` en données tabulées exploitables par
des scripts `awk`.
## Tests
Pour le moment rien, à part ce fichier .OBJ vérolé :
```
o minimal
v 0 0 0
v 1 0 0
v 0 2 0
v 0 0 3
f 0 1 2
f 2 3 4
f 4 2 1
f 0 3 4
```
Ça va, vous avez capté le souci ?
## Conclusion
Rien ,'est simple, tout se complique...