Compare commits
60 Commits
0b5dd38b58
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5eaa64a664 | ||
|
|
d3cca97dbf | ||
|
|
8648d962df | ||
|
|
1fc4d7a05d | ||
|
|
755eb65da3 | ||
|
|
f5de09b23a | ||
|
|
b12bdfe306 | ||
|
|
7cefa36d62 | ||
|
|
992c98cfa8 | ||
|
|
895e61cbb6 | ||
|
|
85f1867424 | ||
|
|
9c336eed8c | ||
|
|
a823bdae0c | ||
|
|
1f52a4c002 | ||
|
|
d65d635577 | ||
|
|
b04bf9e67a | ||
|
|
7dc4fae849 | ||
|
|
e2188897cf | ||
|
|
50d83a6ce2 | ||
|
|
1ff0230d15 | ||
|
|
c0be70d32a | ||
|
|
c2b9a31c93 | ||
|
|
87c2ffd88d | ||
|
|
a1056ee836 | ||
|
|
2a02aab5a9 | ||
|
|
02bbdc7249 | ||
|
|
300bcfa7a0 | ||
|
|
3dbcb198bf | ||
|
|
4bca017774 | ||
|
|
62664c00a6 | ||
|
|
52e5ace4e1 | ||
|
|
c4547fa832 | ||
|
|
6a5d00fa10 | ||
|
|
398a5d3957 | ||
|
|
939b516625 | ||
|
|
b861e8c86b | ||
|
|
9577f1da1f | ||
|
|
9e81fa8319 | ||
|
|
a1e5058d97 | ||
|
|
3d93b66b00 | ||
|
|
26f6421653 | ||
|
|
d1a5a5b5c9 | ||
|
|
329223d195 | ||
|
|
6f254b6ff4 | ||
|
|
83085d1435 | ||
|
|
39b123c641 | ||
|
|
ce2154d9c1 | ||
|
|
f4d5557b4f | ||
|
|
457afac7c0 | ||
|
|
9cbbb35cde | ||
|
|
bcd64245d2 | ||
|
|
02c13e0613 | ||
| 2719a80e1b | |||
| 407818cb34 | |||
| 233c1d5b9e | |||
| ba01f62983 | |||
| 166dc651b4 | |||
| af35f158cd | |||
| b9919b09e5 | |||
| a8e9418d18 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -5,8 +5,5 @@ libbubulles.a
|
||||
tbb
|
||||
gmon.out
|
||||
dummy-file
|
||||
|
||||
tools/covid-19.obj
|
||||
tools/read_obj
|
||||
tools/xyz
|
||||
toto
|
||||
|
||||
|
||||
10
Makefile
10
Makefile
@@ -10,21 +10,21 @@
|
||||
|
||||
CC = gcc
|
||||
|
||||
OPT = -Wall -g -DDEBUG_LEVEL=0 -DMUST_ABORT
|
||||
OPT = -Wall -g -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
|
||||
|
||||
#############################################
|
||||
|
||||
52
bubulles.c
52
bubulles.c
@@ -9,6 +9,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "bubulles.h"
|
||||
#include "edges.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -32,6 +33,8 @@ printf("%-15s %4lu\n", "XYZ", sizeof(XYZ));
|
||||
printf("%-15s %4lu\n", "RGBA", sizeof(RGBA));
|
||||
printf("%-15s %4lu\n", "Bubulle", sizeof(Bubulle));
|
||||
printf("%-15s %4lu\n", "BBList", sizeof(BBList));
|
||||
printf("%-15s %4lu\n", "AnEdge", sizeof(AnEdge));
|
||||
printf("%-15s %4lu\n", "EdgeList", sizeof(EdgeList));
|
||||
puts("");
|
||||
}
|
||||
|
||||
@@ -45,7 +48,7 @@ Bubulle *array;
|
||||
fprintf(stderr, "+++ %s '%s' %d 0x%X\n", __func__, name, sz, unused);
|
||||
#endif
|
||||
|
||||
if (NULL==(bblptr = malloc(sizeof(BBList)))) {
|
||||
if (NULL==(bblptr = calloc(1, sizeof(BBList)))) {
|
||||
fprintf(stderr, "no mem available in %s\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
@@ -75,10 +78,13 @@ return bblptr;
|
||||
/* --------------------------------------------------------------------- */
|
||||
int free_bubulles(BBList *bbl, int k)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, bbl, k);
|
||||
#endif
|
||||
|
||||
if (NULL == bbl->bbs) {
|
||||
fprintf(stderr, "%s : array ptr is null\n", __func__);
|
||||
#ifdef MUST_ABORT
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
#endif
|
||||
return 1;
|
||||
@@ -102,7 +108,7 @@ fprintf(stderr, ">>> %s ( %p %d )\n", __func__, where, idx);
|
||||
if ( (idx < 0) || (idx > where->fidx) ) {
|
||||
fprintf(stderr, "%s : idx %d out of range on %p\n",
|
||||
__func__, idx, where);
|
||||
#ifdef MUST_ABORT
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
#endif
|
||||
return NULL;
|
||||
@@ -115,18 +121,18 @@ return ( &where->bbs[idx] );
|
||||
int print_bublist_desc(BBList *bbl, int opts)
|
||||
{
|
||||
|
||||
printf("------- bblist at %p\n", bbl);
|
||||
printf("\tname \t'%s'\n", bbl->name);
|
||||
fprintf(stderr, "------- bblist at %p\n", bbl);
|
||||
fprintf(stderr, "\tname\t\t'%s'\n", bbl->name);
|
||||
|
||||
printf("\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) {
|
||||
printf("\txyz\t%f %f %f\n",
|
||||
fprintf(stderr, "\txyz\t\t%f %f %f\n",
|
||||
bbl->position.x, bbl->position.y, bbl->position.z);
|
||||
}
|
||||
printf("\tflags\t0x%08lX\n", bbl->flags);
|
||||
printf("\tarray\t%p\n", bbl->bbs);
|
||||
fprintf(stderr, "\tflags\t\t0x%08lX\n", bbl->flags);
|
||||
fprintf(stderr, "\tarray@\t\t%p\n", bbl->bbs);
|
||||
|
||||
puts(""); fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -139,17 +145,12 @@ fprintf(stderr, "%s : %p --> %p\n", __func__, what, where);
|
||||
fprintf(stderr, "XYZ %f %f %f\n", what->p.x, what->p.y, what->p.z);
|
||||
#endif
|
||||
|
||||
if (where->fidx > where->size) {
|
||||
if (where->fidx >= where->size) {
|
||||
/* this is a very bad fatal error */
|
||||
fprintf(stderr, "%s : overflow in BBList at %p\n", __func__, where);
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
}
|
||||
|
||||
if (where->fidx > where->size) {
|
||||
/* array is full */
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : array of %p is full\n", __func__, where);
|
||||
#endif
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -185,7 +186,7 @@ int peek_bubulle(BBList *from, Bubulle *to, int idx)
|
||||
|
||||
if (NULL==from) {
|
||||
fprintf(stderr, "in %s, *from is null\n", __func__);
|
||||
#ifdef MUST_ABORT
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
#endif
|
||||
return -5;
|
||||
@@ -215,7 +216,7 @@ Bubulle *ar;
|
||||
|
||||
if (NULL == bbl) {
|
||||
fprintf(stderr, "in %s, *bbl is NULL\n", __func__);
|
||||
#ifdef MUST_ABORT
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
#endif
|
||||
return -5;
|
||||
@@ -228,12 +229,10 @@ fprintf(stderr, "*** %s : array at %p, sz %d\n", __func__, ar, bbl->size);
|
||||
#endif
|
||||
|
||||
for (idx=0; idx<bbl->fidx; idx++) {
|
||||
fprintf(fp, "%12.6f %12.6f %12.6f",
|
||||
fprintf(fp, "%15.8f %15.8f %15.8f",
|
||||
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);
|
||||
@@ -249,8 +248,7 @@ printf("xyzd %11.6f %11.6f %11.6f %11.6f\n",
|
||||
what->p.x, what->p.y, what->p.z, what->d);
|
||||
printf("diam %11.6f gray %5d\n", what->d, what->gray);
|
||||
printf("rgba %11.6f %11.6f %11.6f %11.6f\n",
|
||||
what->p.x, what->p.y, what->p.z, what->d);
|
||||
|
||||
what->col.r, what->col.g, what->col.b, what->col.a);
|
||||
puts("----------------------------------------------------------");
|
||||
|
||||
return 0;
|
||||
@@ -263,7 +261,7 @@ int idx;
|
||||
|
||||
if (NULL == what) {
|
||||
fprintf(stderr, "SHIT HAPPEN IN %s\n", __func__);
|
||||
#ifdef MUST_ABORT
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
#endif
|
||||
return -5;
|
||||
@@ -339,7 +337,7 @@ int print_bbox(BBox *bbox, int k)
|
||||
|
||||
if (NULL==bbox) {
|
||||
fprintf(stderr, "in %s, *bbox is NULL\n", __func__);
|
||||
#ifdef MUST_ABORT
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
#endif
|
||||
return -5;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
bubulles.h
|
||||
bubulles.h - dirty software from tTh
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
#define LIBBB_VERSION 53
|
||||
#define LIBBB_VERSION 64
|
||||
|
||||
#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 */
|
||||
|
||||
221
edges.c
Normal file
221
edges.c
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* edges.c
|
||||
* a part of libbubulle from tTh
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bubulles.h"
|
||||
#include "edges.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
EdgeList * alloc_edgelist(char *name, int sz, int flags)
|
||||
{
|
||||
EdgeList *elptr;
|
||||
AnEdge *array;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d 0x%X )\n", __func__, name, sz, flags);
|
||||
#endif
|
||||
|
||||
if (NULL==(elptr = calloc(1, sizeof(EdgeList)))) {
|
||||
fprintf(stderr, "no mem available in %s\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
memset(elptr, 0, sizeof(EdgeList));
|
||||
|
||||
if (NULL==(array = calloc(sz, sizeof(Bubulle)))) {
|
||||
fprintf(stderr, "no mem available in %s\n", __func__);
|
||||
free(elptr);
|
||||
return NULL;
|
||||
}
|
||||
elptr->edges = array;
|
||||
|
||||
if ( (NULL != name) && (strlen(name) < SZ_BUBULLE_TEXT) )
|
||||
strcpy(elptr->name, name);
|
||||
else
|
||||
strcpy(elptr->name, "noname");
|
||||
|
||||
elptr->magic = 0x55555555;
|
||||
elptr->size = sz;
|
||||
elptr->flags = flags;
|
||||
|
||||
return elptr;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int free_edgelist(EdgeList *list, int k)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p 0x%X )\n", __func__, list, k);
|
||||
#endif
|
||||
|
||||
if (k) {
|
||||
fprintf(stderr, "%s: k must be 0, was %d\n", __func__, k);
|
||||
return k;
|
||||
}
|
||||
|
||||
free(list->edges);
|
||||
|
||||
memset(list, 0, sizeof(EdgeList));
|
||||
free(list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* with this func, you can search for duplicates, but
|
||||
* it is going to be SLOW with huges object.
|
||||
*/
|
||||
static int is_edge_in_list(EdgeList *list, int p0, int p1)
|
||||
{
|
||||
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++) {
|
||||
if ( (list->edges[idx].A == p0) &&
|
||||
(list->edges[idx].B == p1) ) {
|
||||
retval = 1; place = idx; break; }
|
||||
|
||||
if ( (list->edges[idx].A == p1) &&
|
||||
(list->edges[idx].B == p0) ){
|
||||
retval = 2; place = idx; break; }
|
||||
}
|
||||
|
||||
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
|
||||
* the first one add unconditionnaly the edge to the
|
||||
* (non full) list...
|
||||
*/
|
||||
int push_an_edge(EdgeList *list, int p0, int p1)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1);
|
||||
#endif
|
||||
|
||||
if (list->fidx >= list->size) {
|
||||
fprintf(stderr, "%s: w're doomed and overflowed\n", __func__);
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
list->edges[list->fidx].A = p0;
|
||||
list->edges[list->fidx].B = p1;
|
||||
list->fidx ++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* and the second only insert an edge if it was missing
|
||||
* from the currently know list.
|
||||
*/
|
||||
int push_a_missing_edge(EdgeList *list, int p0, int p1)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, list, p0, p1);
|
||||
#endif
|
||||
|
||||
if (list->fidx >= list->size) {
|
||||
fprintf(stderr, "%s: w're doomed and overflowed\n", __func__);
|
||||
#if MUST_ABORT
|
||||
abort();
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( ! is_edge_in_list(list, p0, p1) ) {
|
||||
list->edges[list->fidx].A = p0;
|
||||
list->edges[list->fidx].B = p1;
|
||||
fprintf(stderr, "edge %d %d poked at %d\n", p0, p1, list->fidx);
|
||||
list->fidx ++;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, " %s: drop edge %d %d\n", __func__, p0, p1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int print_edgelist_desc(EdgeList *list, int k)
|
||||
{
|
||||
|
||||
fprintf(stderr, "------- edgelist '%s' at %p\n", list->name, list);
|
||||
|
||||
if (k) {
|
||||
fprintf(stderr, "%s: k must be 0, was %d\n", __func__, k);
|
||||
return k;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\tarray @ %p\n", list->edges);
|
||||
fprintf(stderr, "\tsize %8d\n", list->size);
|
||||
fprintf(stderr, "\tnext free %8d\n", list->fidx);
|
||||
fprintf(stderr, "\tmagic 0x%08lX\n", list->magic);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* /!\ the output format is subject to changes in
|
||||
* a near futur.
|
||||
*/
|
||||
int edges_to_data(char *fname, EdgeList *list, int k)
|
||||
{
|
||||
FILE *fp;
|
||||
int idx, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %p %d )\n", __func__, fname, list, k);
|
||||
#endif
|
||||
|
||||
if (NULL==(fp=fopen(fname, "w"))) {
|
||||
perror(fname);
|
||||
return -1;
|
||||
}
|
||||
for (idx=0; idx<list->fidx; idx++) {
|
||||
foo = fprintf(fp, "%d %d\n", list->edges[idx].A, list->edges[idx].B);
|
||||
/*
|
||||
* error check
|
||||
*/
|
||||
if (foo < 0) {
|
||||
perror(fname);
|
||||
exit(1); /* be violent ! */
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int print_the_edges(FILE *fp, EdgeList *list, int k)
|
||||
{
|
||||
int idx;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, list, k);
|
||||
#endif
|
||||
|
||||
if (k) {
|
||||
fprintf(stderr, "In %s, k must be 0, was %d\n", __func__, k);
|
||||
return k;
|
||||
}
|
||||
|
||||
fprintf(stderr, " list.fidx = %d\n", list->fidx);
|
||||
|
||||
for (idx=0; idx<list->fidx; idx++) {
|
||||
fprintf(fp, "%6d\t\t%5d %5d\n", idx,
|
||||
list->edges[idx].A, list->edges[idx].B);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
37
edges.h
Normal file
37
edges.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* edges.h
|
||||
* a part of libbubulle from tTh
|
||||
*
|
||||
* https://git.tetalab.org/tTh/libbubulle
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
int A, B;
|
||||
short burz; /* for what usage ??? */
|
||||
} AnEdge;
|
||||
|
||||
typedef struct {
|
||||
unsigned long magic;
|
||||
char name[SZ_BUBULLE_TEXT+1];
|
||||
int size; /* max number of edges */
|
||||
int fidx; /* next free slot */
|
||||
AnEdge *edges;
|
||||
unsigned long flags;
|
||||
} EdgeList;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
EdgeList * alloc_edgelist(char *name, int sz, int flags);
|
||||
int free_edgelist(EdgeList *list, int k);
|
||||
int push_an_edge(EdgeList *list, int p0, int p1);
|
||||
int push_a_missing_edge(EdgeList *list, int p0, int p1);
|
||||
|
||||
// int is_edge_in_list(EdgeList *list, int p0, int p1);
|
||||
|
||||
int print_edgelist_desc(EdgeList *list, int k);
|
||||
int edges_to_data(char *fname, EdgeList *list, int k);
|
||||
int print_the_edges(FILE *file, EdgeList *list, int k);
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
61
importobj.c
61
importobj.c
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
LIBBUBULLES
|
||||
|
||||
some functions for importing bubulles from dot-OBJ files.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bubulles.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
#define LINE_SZ 666
|
||||
|
||||
int try_to_read_an_OBJ_file(char *fname, int notused)
|
||||
{
|
||||
FILE *fpin;
|
||||
char line[LINE_SZ+1], *cptr;
|
||||
float x, y, z;
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
|
||||
#endif
|
||||
|
||||
if (NULL==(fpin=fopen(fname, "r"))) {
|
||||
perror(fname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while(cptr=fgets(line, LINE_SZ, fpin)) {
|
||||
|
||||
if (verbosity>1) fputs(line, stderr);
|
||||
|
||||
cptr = strtok(line, " ");
|
||||
if (strcmp(cptr, "v")) continue;
|
||||
|
||||
cptr = strtok(NULL, " ");
|
||||
foo = sscanf(cptr, "%f", &x);
|
||||
cptr = strtok(NULL, " ");
|
||||
foo = sscanf(cptr, "%f", &y);
|
||||
cptr = strtok(NULL, " ");
|
||||
foo = sscanf(cptr, "%f", &z);
|
||||
|
||||
fprintf(stdout, "%16g %16g %16g\n", x, y, z);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fclose(fpin);
|
||||
|
||||
return -7800;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
95
tbb.c
95
tbb.c
@@ -6,10 +6,87 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include "bubulles.h"
|
||||
#include "edges.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_des_edges_A(int k)
|
||||
{
|
||||
EdgeList * list;
|
||||
int foo, idx;
|
||||
int e0, e1;
|
||||
|
||||
fprintf(stderr, "============== %s %7d ===========\n", __func__, k);
|
||||
|
||||
list = alloc_edgelist("oups?", k, 0);
|
||||
fprintf(stderr, " alloc edge list -> %p\n", list);
|
||||
|
||||
print_edgelist_desc(list, 0);
|
||||
|
||||
foo = push_an_edge(list, 13, 37);
|
||||
fprintf(stderr, " push edge -> %d\n", foo);
|
||||
foo = push_an_edge(list, 24, 36);
|
||||
fprintf(stderr, " push edge -> %d\n", foo);
|
||||
|
||||
foo = print_the_edges(stdout, list, 0);
|
||||
|
||||
for (idx=0; idx<k; idx++) {
|
||||
e0 = idx*7; e1 = 5-idx;
|
||||
foo = push_an_edge(list, e0, e1);
|
||||
if (foo) {
|
||||
fprintf(stderr, "push %d (%d, %d) -> %d\n", idx, e0, e1, foo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foo = print_the_edges(stdout, list, 0); puts("");
|
||||
|
||||
foo = free_edgelist(list, 0);
|
||||
fprintf(stderr, " free list -> %d\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* ici on va faire des essais sur la gestion
|
||||
* de la dé-duplication des aretes.
|
||||
*/
|
||||
int essai_des_edges_B(int k)
|
||||
{
|
||||
EdgeList * list;
|
||||
int foo, idx;
|
||||
int e0, e1;
|
||||
|
||||
fprintf(stderr, "============== %s %7d ===========\n", __func__, k);
|
||||
|
||||
list = alloc_edgelist("gloubigoulba", k, 0);
|
||||
if (NULL == list) {
|
||||
fprintf(stderr, "%s: epic fail\n", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
print_edgelist_desc(list, 0);
|
||||
|
||||
for (idx=0; idx<k; idx++) {
|
||||
e0 = rand() % 666;
|
||||
e1 = rand() % 666;
|
||||
foo = push_a_missing_edge(list, e0, e1);
|
||||
}
|
||||
|
||||
print_edgelist_desc(list, 0);
|
||||
|
||||
foo = print_the_edges(stdout, list, 0); puts("");
|
||||
|
||||
foo = free_edgelist(list, 0);
|
||||
fprintf(stderr, " %s: free list -> %d\n", __func__, foo);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
void test_alloc_free(int nbelm)
|
||||
{
|
||||
BBList *bublist;
|
||||
@@ -109,16 +186,26 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
|
||||
printf("*** Bubulles Testing -- %s %s\n\n", __DATE__, __TIME__);
|
||||
fprintf(stderr, "***\n*** Bubulles Testing %s %s\n***\n",
|
||||
__DATE__, __TIME__);
|
||||
|
||||
bubulles_version(1);
|
||||
bubulles_version(0);
|
||||
|
||||
srand(getpid()); /* INIT RANDOM */
|
||||
|
||||
#if (0)
|
||||
test_alloc_free(5);
|
||||
test_push_pop(20000);
|
||||
test_cleanfill_my_bublist(999);
|
||||
|
||||
foo = test_peek_poke(5000);
|
||||
fprintf(stderr, "test peek/poke -> %d\n", foo);
|
||||
#endif
|
||||
|
||||
|
||||
foo = essai_des_edges_A(25);
|
||||
fprintf(stderr, "test A des edges -> %d\n", foo);
|
||||
foo = essai_des_edges_B(5000);
|
||||
fprintf(stderr, "test B des edges -> %d\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
20
tools/.gitignore
vendored
Normal file
20
tools/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
essai_faces
|
||||
read_obj
|
||||
export_evblob
|
||||
|
||||
*.obj
|
||||
! tools/minimal.obj
|
||||
! tools/cube.obj
|
||||
! overflowed.obj
|
||||
read_obj
|
||||
|
||||
*.xyz
|
||||
*.asc
|
||||
toto
|
||||
core
|
||||
|
||||
*.vertices
|
||||
*.edges
|
||||
*.evblob
|
||||
|
||||
@@ -1,5 +1,32 @@
|
||||
|
||||
BBFUNCS = ../libbubulles.a
|
||||
|
||||
read_obj: read_obj.c Makefile ${BBFUNCS}
|
||||
gcc -Wall -DDEBUG_LEVEL=1 $< ${BBFUNCS} -o $@
|
||||
OPT = -Wall -Wextra -O1 -g -DDEBUG_LEVEL=0 -DMUST_ABORT=0
|
||||
|
||||
all: read_obj export_evblob # essai_faces
|
||||
|
||||
# ---------
|
||||
|
||||
read_obj: read_obj.c Makefile importobj.o rdwredges.o \
|
||||
$(BBFUNCS)
|
||||
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
|
||||
$(CC) $(OPT) -c $<
|
||||
|
||||
rdwredges.o: rdwredges.c objtrucs.h \
|
||||
../bubulles.h ../edges.h Makefile
|
||||
$(CC) $(OPT) -c $<
|
||||
|
||||
# ---------
|
||||
|
||||
essai_faces: essai_faces.c Makefile
|
||||
$(CC) $(OPT) $< -o $@
|
||||
|
||||
# have a nice day !
|
||||
|
||||
67
tools/README.md
Normal file
67
tools/README.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Importer des fichiers .OBJ
|
||||
|
||||
* https://en.wikipedia.org/wiki/Wavefront_.obj_file
|
||||
* http://fegemo.github.io/cefet-cg/attachments/obj-spec.pdf
|
||||
* https://people.sc.fsu.edu/~jburkardt/data/obj/obj.html
|
||||
|
||||
```
|
||||
v -1.177934647 -6.833468914 -73.19773865
|
||||
vn -0.1279897094 -0.4501263499 -0.8837448359
|
||||
v -0.8008174896 -6.425453663 -73.32041931
|
||||
vn -0.05844723806 -0.09480132163 -0.993778944
|
||||
```
|
||||
|
||||
## read_obj
|
||||
|
||||
Première étape : en lisant les vertices, nous saurons positionner
|
||||
nos bubulles. Ensuite, en explorant les faces, nous pouvons
|
||||
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 :
|
||||
c'est-à-dire que la dernière ligne du `.obj` DOIT être terminée
|
||||
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
|
||||
|
||||
* Songer à un système d'auto-scaler et de recentrage
|
||||
* Comment générer un `.obj` à partir d'une image flottante ?
|
||||
* 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
|
||||
|
||||
Quatrième étape : aller vivre à la campagne ?
|
||||
|
||||
|
||||
49
tools/cube.obj
Normal file
49
tools/cube.obj
Normal file
@@ -0,0 +1,49 @@
|
||||
# cube.obj
|
||||
#
|
||||
|
||||
o cube
|
||||
|
||||
v 0.0 0.0 0.0
|
||||
v 0.0 0.0 1.0
|
||||
v 0.0 1.0 0.0
|
||||
v 0.0 1.0 1.0
|
||||
v 1.0 0.0 0.0
|
||||
v 1.0 0.0 1.0
|
||||
v 1.0 1.0 0.0
|
||||
v 1.0 1.0 1.0
|
||||
|
||||
vt 0.25 0.0
|
||||
vt 0.5 0.0
|
||||
vt 0 0.25
|
||||
vt 0.25 0.25
|
||||
vt 0.5 0.25
|
||||
vt 0.75 0.25
|
||||
vt 0.0 0.5
|
||||
vt 0.25 0.5
|
||||
vt 0.5 0.5
|
||||
vt 0.75 0.5
|
||||
vt 0.25 0.75
|
||||
vt 0.5 0.75
|
||||
vt 0.25 1.0
|
||||
vt 0.5 1.0
|
||||
|
||||
vn 0.0 0.0 1.0
|
||||
vn 0.0 0.0 -1.0
|
||||
vn 0.0 1.0 0.0
|
||||
vn 0.0 -1.0 0.0
|
||||
vn 1.0 0.0 0.0
|
||||
vn -1.0 0.0 0.0
|
||||
|
||||
f 1/11/2 7/14/2 5/12/2
|
||||
f 1/11/2 3/13/2 7/14/2
|
||||
f 1/7/6 4/4/6 3/3/6
|
||||
f 1/7/6 2/8/6 4/4/6
|
||||
f 3/1/3 8/5/3 7/2/3
|
||||
f 3/1/3 4/4/3 8/5/3
|
||||
f 5/10/5 7/6/5 8/5/5
|
||||
f 5/10/5 8/5/5 6/9/5
|
||||
f 1/11/4 5/12/4 6/9/4
|
||||
f 1/11/4 6/9/4 2/8/4
|
||||
f 2/8/1 6/9/1 8/5/1
|
||||
f 2/8/1 8/5/1 4/4/1
|
||||
|
||||
24
tools/edges2bubulles.awk
Executable file
24
tools/edges2bubulles.awk
Executable 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
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"
|
||||
}
|
||||
50
tools/essai_faces.c
Normal file
50
tools/essai_faces.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int essai_lecture_face(char *str)
|
||||
{
|
||||
char *buffer, *ptr;
|
||||
int bar;
|
||||
int A, B, C;
|
||||
|
||||
printf("-------- '%s'\n", str);
|
||||
buffer = ptr = strdup(str);
|
||||
for (bar = 0;;) {
|
||||
ptr = strtok(ptr, " \t");
|
||||
if (NULL != ptr) {
|
||||
printf("\t%2d '%s'\n", bar, ptr);
|
||||
ptr = NULL;
|
||||
bar++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
/*
|
||||
* so, here, we know the number of thing to decipher
|
||||
*/
|
||||
|
||||
free(buffer);
|
||||
printf(" -> %d\n", bar);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* GO !
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo, bar;
|
||||
|
||||
foo = essai_lecture_face("3 14 159");
|
||||
foo = essai_lecture_face("2 4 6 8");
|
||||
foo = essai_lecture_face("0/10 1/11 2/12");
|
||||
foo = essai_lecture_face("3.14159");
|
||||
foo = essai_lecture_face("We make porn");
|
||||
|
||||
return 0;
|
||||
}
|
||||
236
tools/export_evblob.c
Normal file
236
tools/export_evblob.c
Normal 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;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
388
tools/importobj.c
Normal file
388
tools/importobj.c
Normal file
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
LIBBUBULLES IMPORT_OBJ
|
||||
some functions for importing bubulles from dot-OBJ files.
|
||||
|
||||
https://git.tetalab.org/tTh/libbubulle/src/branch/master/tools/
|
||||
http://fegemo.github.io/cefet-cg/attachments/obj-spec.pdf
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h> /* for basename(3) */
|
||||
|
||||
#include "../bubulles.h"
|
||||
#include "../edges.h"
|
||||
|
||||
#include "objtrucs.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
#define PSYCHOTIK 1
|
||||
#define LINE_SZ 666
|
||||
|
||||
static BBList *bublist;
|
||||
static EdgeList *edges;
|
||||
static int dropped;
|
||||
static int linenumber;
|
||||
static char obj_filename[LINE_SZ+1];
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
char *token;
|
||||
int id;
|
||||
} Tokens;
|
||||
|
||||
enum token_id { T_comment=1, T_vertice, T_group, T_face, T_vt, T_vn,
|
||||
T_line, T_object, T_smoothing, T_usemtl, T_mtllib };
|
||||
|
||||
Tokens TokenList[] = {
|
||||
{ "#", T_comment },
|
||||
{ "v", T_vertice },
|
||||
{ "g", T_group }, // to be verified !
|
||||
{ "f", T_face },
|
||||
{ "vt", T_vt }, // c'est quoi ce truc ?
|
||||
{ "vn", T_vt }, // c'est quoi ce truc ?
|
||||
{ "l", T_line },
|
||||
{ "o", T_object },
|
||||
{ "s", T_smoothing }, // mmmm....
|
||||
{ "usemtl", T_usemtl },
|
||||
{ "mtllib", T_mtllib },
|
||||
/* and more to come... */
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
static int type_of_the_line(char *text)
|
||||
{
|
||||
Tokens *token;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "%s is searching for '%s'\n", __func__, text);
|
||||
#endif
|
||||
|
||||
for (token=TokenList; token->token; token++) {
|
||||
// fprintf(stderr, " %5s -> %d\n", token->token, token->id);
|
||||
if (!strcmp(token->token, text)) {
|
||||
return token->id;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
static int parse_vertice(char *cptr, float *px, float *py, float *pz)
|
||||
{
|
||||
float x, y, z;
|
||||
int foo;
|
||||
|
||||
/* /!\ this function kill the input buffer */
|
||||
|
||||
foo = 0;
|
||||
cptr = strtok(NULL, " ");
|
||||
foo += sscanf(cptr, "%f", &x);
|
||||
cptr = strtok(NULL, " ");
|
||||
foo += sscanf(cptr, "%f", &y);
|
||||
cptr = strtok(NULL, " ");
|
||||
foo += sscanf(cptr, "%f", &z);
|
||||
|
||||
if (3 == foo) {
|
||||
*px = x; *py = y; *pz = z;
|
||||
}
|
||||
|
||||
return foo;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* new Mon 27 Mar 2023 12:08:18 AM CEST
|
||||
*
|
||||
* mmmm... complex thing to do...
|
||||
*/
|
||||
static int parse_face(char *cptr, int maxvert)
|
||||
{
|
||||
int ix, foo, a, b;
|
||||
int pts[3], valid;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, cptr, maxvert);
|
||||
#endif
|
||||
|
||||
#if (0)
|
||||
fprintf(stderr, "parse_face");
|
||||
for (foo=0; foo<16; foo++) {
|
||||
fprintf(stderr, " %02X", ((unsigned char *)cptr)[foo]);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
|
||||
for (ix=0; ix<3; ix++) {
|
||||
cptr = strtok(NULL, " ");
|
||||
if (NULL == cptr) {
|
||||
fprintf(stderr, "incomplete face in %s\n", __func__);
|
||||
return -4;
|
||||
}
|
||||
if (1 != sscanf(cptr, "%d", &pts[ix])) {
|
||||
fprintf(stderr, "%s: err sscanf\n", __func__);
|
||||
exit(1);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
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] ) {
|
||||
fprintf(stderr, "%s: degenerated face ( %d %d %d )\n", __func__,
|
||||
pts[0], pts[1], pts[2]);
|
||||
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 ?
|
||||
*/
|
||||
if (valid) {
|
||||
for (ix=0; ix<3; ix++) {
|
||||
a = ix % 3;
|
||||
b = (ix+1) % 3;
|
||||
#if PSYCHOTIK
|
||||
foo = push_a_missing_edge(edges, pts[a], pts[b]);
|
||||
#else
|
||||
foo = push_an_edge(edges, pts[a], pts[b]);
|
||||
#endif
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: disaster #%d line %d\n",
|
||||
__func__, foo, linenumber);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dropped) fprintf(stderr, "%s: %d dropped\n", __func__, dropped);
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, "<<< %s\n", __func__);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* The main procedure, who contains a lot of things.
|
||||
*/
|
||||
int try_to_read_an_OBJ_file(char *infname, char *ofname, int outstyle)
|
||||
{
|
||||
FILE *fpin;
|
||||
char line[LINE_SZ+1], *cptr, *token;
|
||||
float x, y, z;
|
||||
int foo, bar, tokenid;
|
||||
Bubulle bubulle;
|
||||
char *outfname, *baseptr;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
|
||||
infname, ofname, outstyle);
|
||||
#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"))) {
|
||||
perror(infname);
|
||||
exit(1);
|
||||
}
|
||||
linenumber = 0;
|
||||
|
||||
bublist = alloc_bubulles(infname, 800000, 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", 3000000, 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");
|
||||
|
||||
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);
|
||||
// return -2;
|
||||
break;
|
||||
}
|
||||
line[strlen(line)-1] = '\0'; /* kill the newline */
|
||||
if (verbosity>1) fprintf(stderr, "line read ==|%s|==\n", line);
|
||||
|
||||
linenumber++;
|
||||
|
||||
cptr = strtok(line, " ");
|
||||
if (NULL == cptr) {
|
||||
/* this is an empty line */
|
||||
// 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)
|
||||
fprintf(stderr, "token '%s' --> %d\n", cptr, tokenid);
|
||||
|
||||
memset(&bubulle, 0, sizeof(Bubulle));
|
||||
|
||||
switch (tokenid) {
|
||||
case T_comment:
|
||||
/* do nothing */
|
||||
break;
|
||||
|
||||
case T_vertice:
|
||||
x = y = z = 0.0;
|
||||
foo = parse_vertice(cptr, &x, &y, &z);
|
||||
if (3 != foo) {
|
||||
fprintf(stderr, "err %d parse vertice %s\n",
|
||||
foo, cptr);
|
||||
abort();
|
||||
}
|
||||
bubulle.p.x = x;
|
||||
bubulle.p.y = y;
|
||||
bubulle.p.z = z;
|
||||
if (verbosity > 2) niceprint_bubulle(&bubulle, 0);
|
||||
foo = push_bubulle(bublist, &bubulle);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d push bubulle\n", foo);
|
||||
abort();
|
||||
}
|
||||
fprintf(stderr, "pushed %f %f %f (%d)\n", x, y, z,
|
||||
bublist->fidx);
|
||||
break;
|
||||
case T_face:
|
||||
/* experimental code here */
|
||||
bar = bublist->fidx - 1;
|
||||
foo = parse_face(cptr, bar);
|
||||
if (foo) {
|
||||
fprintf(stderr, "line %d '%s' parseface -> %d\n",
|
||||
linenumber, cptr, foo);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case T_object:
|
||||
cptr = strtok(NULL, " ");
|
||||
fprintf(stderr, "\tObject: %s\n", cptr);
|
||||
break;
|
||||
case T_group:
|
||||
cptr = strtok(NULL, " ");
|
||||
fprintf(stderr, "\tGroup: %s\n", cptr);
|
||||
break;
|
||||
case T_usemtl:
|
||||
cptr = strtok(NULL, " ");
|
||||
fprintf(stderr, "\tUsemtl: %s\n", cptr);
|
||||
break;
|
||||
case T_mtllib:
|
||||
cptr = strtok(NULL, " ");
|
||||
fprintf(stderr, "\tMtllib: %s\n", cptr);
|
||||
break;
|
||||
|
||||
case T_line:
|
||||
cptr = strtok(NULL, " ");
|
||||
fprintf(stderr, "\tLine: %s\n", cptr);
|
||||
break;
|
||||
case T_smoothing:
|
||||
cptr = strtok(NULL, " ");
|
||||
if (verbosity)
|
||||
fprintf(stderr, "\tSmoothing: %s\n", cptr);
|
||||
break;
|
||||
case T_vt:
|
||||
cptr = strtok(NULL, " ");
|
||||
if (verbosity)
|
||||
fprintf(stderr, "\tvt ??? : %s\n", cptr);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "W: token %s -> %d ?\n", token, tokenid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fpin);
|
||||
|
||||
fprintf(stderr, " +-----------------------------------------\n");
|
||||
|
||||
if(verbosity) {
|
||||
fprintf(stderr, "%s: %d vertices and %d edges loaded.\n", __func__,
|
||||
bublist->fidx, edges->fidx);
|
||||
}
|
||||
|
||||
if (verbosity > 1) {
|
||||
print_bublist_desc(bublist, 0);
|
||||
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 */
|
||||
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);
|
||||
|
||||
if (foo) {
|
||||
fprintf(stderr, "Err #%d when writing edges&vertices file\n", foo);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
free(outfname);
|
||||
free_bubulles(bublist, 0);
|
||||
free_edgelist(edges, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
11
tools/minimal.obj
Normal file
11
tools/minimal.obj
Normal 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 1 2 3
|
||||
f 3 1 0
|
||||
f 0 2 3
|
||||
22
tools/objtrucs.h
Normal file
22
tools/objtrucs.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* EXPERIMENTAL CODE !
|
||||
*
|
||||
* see 'rdwredges.c' for source code
|
||||
* & 'export_evblob.c' for a usecase.
|
||||
*/
|
||||
|
||||
#define EVBLOB_MAGIC (65872139)
|
||||
|
||||
typedef struct {
|
||||
unsigned long magic;
|
||||
BBList *Blist;
|
||||
EdgeList *Elist;
|
||||
int status;
|
||||
} EdgesAndVertices;
|
||||
|
||||
/* 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
11
tools/overflowed.obj
Normal 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
|
||||
188
tools/rdwredges.c
Normal file
188
tools/rdwredges.c
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
LIBBUBULLES IMPORT_OBJ
|
||||
some functions for importing bubulles from dot-OBJ files.
|
||||
|
||||
https://git.tetalab.org/tTh/libbubulle/src/branch/master/tools/
|
||||
http://fegemo.github.io/cefet-cg/attachments/obj-spec.pdf
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../bubulles.h"
|
||||
#include "../edges.h"
|
||||
|
||||
#include "objtrucs.h"
|
||||
|
||||
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 !!! */
|
||||
int x_write_vertedges(char *filename, BBList *bblist, EdgeList *edges)
|
||||
{
|
||||
FILE *fp;
|
||||
int idx, edg[2];
|
||||
double coo[3];
|
||||
int nbre;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__, filename,
|
||||
bblist, edges);
|
||||
#endif
|
||||
|
||||
if (NULL==(fp=fopen(filename, "w"))) {
|
||||
perror(filename);
|
||||
return -4;
|
||||
}
|
||||
|
||||
// print_bublist_desc(bblist, 0);
|
||||
fwrite("VERTICES", 8, 1, fp);
|
||||
nbre = bblist->fidx;
|
||||
fwrite(&nbre, sizeof(int), 1, fp);
|
||||
for (idx=0; idx<bblist->fidx; idx++) {
|
||||
// fprintf(stderr, "vertice %d\n", idx);
|
||||
coo[0] = bblist->bbs[idx].p.x;
|
||||
coo[1] = bblist->bbs[idx].p.y;
|
||||
coo[2] = bblist->bbs[idx].p.z;
|
||||
fwrite(coo, sizeof(coo), 1, fp);
|
||||
}
|
||||
|
||||
// print_edgelist_desc(edges, 0);
|
||||
fwrite("EDGES ", 8, 1, fp);
|
||||
nbre = edges->fidx;
|
||||
fwrite(&nbre, sizeof(int), 1, fp);
|
||||
for (idx=0; idx<edges->fidx; idx++) {
|
||||
edg[0] = edges->edges[idx].A;
|
||||
edg[1] = edges->edges[idx].B;
|
||||
fwrite(edg, sizeof(edg), 1, fp);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
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;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -4,26 +4,70 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../bubulles.h"
|
||||
#include <libgen.h> // for basename(3)
|
||||
#include <unistd.h>
|
||||
|
||||
int try_to_read_an_OBJ_file(char *fname, int notused);
|
||||
int verbosity;
|
||||
#include "../bubulles.h"
|
||||
#include "../edges.h"
|
||||
|
||||
#include "objtrucs.h"
|
||||
|
||||
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 foo;
|
||||
int foo, opt;
|
||||
char *ofname = NULL;
|
||||
|
||||
if (2 != argc) {
|
||||
fprintf(stderr, "### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__);
|
||||
|
||||
if (1 == argc) {
|
||||
bubulles_version(1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
verbosity = 0;
|
||||
|
||||
foo = try_to_read_an_OBJ_file(argv[1], 0);
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
if (verbosity) fprintf(stderr, " arg[%d] = %s\n",
|
||||
optind, argv[optind]);
|
||||
foo = try_to_read_an_OBJ_file(argv[optind], ofname, 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;
|
||||
}
|
||||
|
||||
23
tools/run_read_export.sh
Executable file
23
tools/run_read_export.sh
Executable 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
37
tools/technique.md
Normal 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...
|
||||
|
||||
Reference in New Issue
Block a user