2023-04-15 09:56:48 +11:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2023-04-30 08:44:56 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/* 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;
|
|
|
|
}
|
2023-04-26 17:33:05 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p )\n", __func__, eav);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (verbosity) fprintf(stderr, "fprinting %d edges\n", eav->Elist->fidx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
// fprintf(stderr, "%7d %7d\n", a, b);
|
|
|
|
|
|
|
|
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 ? */
|
|
|
|
}
|
2023-04-15 09:56:48 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/* EXPERIMENTAL GRUIK-CODE !!! */
|
2023-04-28 09:02:04 +11:00
|
|
|
int load_and_printf_evblob(char *filename, char *outmode)
|
2023-04-15 09:56:48 +11:00
|
|
|
{
|
|
|
|
EdgesAndVertices eav;
|
2023-04-28 09:02:04 +11:00
|
|
|
int foo, mode;
|
2023-04-15 09:56:48 +11:00
|
|
|
|
2023-04-21 07:33:46 +11:00
|
|
|
#if DEBUG_LEVEL
|
2023-04-28 09:02:04 +11:00
|
|
|
fprintf(stderr, ">>> %s ( '%s' %s )\n", __func__, filename, outmode);
|
2023-04-21 07:33:46 +11:00
|
|
|
#endif
|
2023-04-15 09:56:48 +11:00
|
|
|
|
|
|
|
memset(&eav, 0, sizeof(EdgesAndVertices));
|
2023-04-21 07:33:46 +11:00
|
|
|
foo = x_load_vertedges(filename, &eav);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, " load vertice & edges blob -> %d\n", foo);
|
|
|
|
return foo;
|
|
|
|
}
|
2023-04-15 09:56:48 +11:00
|
|
|
|
2023-04-26 17:33:05 +11:00
|
|
|
if (verbosity > 1) {
|
2023-04-15 09:56:48 +11:00
|
|
|
fprintf(stderr, "vertices at %p\n", eav.Blist);
|
|
|
|
fprintf(stderr, "edges at %p\n", eav.Elist);
|
|
|
|
fprintf(stderr, "status is %d\n", eav.status);
|
2023-04-21 07:33:46 +11:00
|
|
|
fprintf(stderr, "got %d vertices and %d edges\n",
|
|
|
|
eav.Blist->fidx,
|
|
|
|
eav.Elist->fidx);
|
2023-04-15 09:56:48 +11:00
|
|
|
}
|
|
|
|
|
2023-04-28 09:02:04 +11:00
|
|
|
mode = 666;
|
|
|
|
if (! strcasecmp("edges", outmode)) { mode = 0; }
|
|
|
|
else if (! strcasecmp("vertices", outmode)) { mode = 1; }
|
2023-04-30 08:44:56 +11:00
|
|
|
else if (! strcasecmp("bbox", outmode)) { mode = 2; }
|
2023-04-28 09:02:04 +11:00
|
|
|
|
2023-04-26 17:33:05 +11:00
|
|
|
switch (mode) {
|
|
|
|
case 0:
|
|
|
|
printf_the_edges(&eav); break;
|
|
|
|
case 1:
|
|
|
|
printf_the_vertices(&eav); break;
|
2023-04-30 08:44:56 +11:00
|
|
|
case 2:
|
|
|
|
printf_the_boudingbox(&eav); break;
|
|
|
|
|
2023-04-26 17:33:05 +11:00
|
|
|
default:
|
2023-04-28 09:02:04 +11:00
|
|
|
fprintf(stderr, "no way to do '%s'\n", outmode);
|
2023-04-26 17:33:05 +11:00
|
|
|
exit(1);
|
|
|
|
break;
|
2023-04-21 07:33:46 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
void help(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "YOLO!\n");
|
2023-04-26 17:33:05 +11:00
|
|
|
/* XXX */
|
2023-04-21 07:33:46 +11:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/* EXPERIMENTAL GRUIK-CODE !!! */
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int opt, foo;
|
2023-04-28 09:02:04 +11:00
|
|
|
char *outmode = "vertices";
|
2023-04-21 07:33:46 +11:00
|
|
|
|
2023-04-26 17:33:05 +11:00
|
|
|
fprintf(stderr, "### Export EVblob (%s %s)\n", __DATE__, __TIME__);
|
2023-04-15 09:56:48 +11:00
|
|
|
|
2023-04-21 07:33:46 +11:00
|
|
|
verbosity = 0;
|
|
|
|
|
2023-04-26 17:33:05 +11:00
|
|
|
while ((opt = getopt(argc, argv, "ht:v")) != -1) {
|
2023-04-21 07:33:46 +11:00
|
|
|
switch(opt) {
|
|
|
|
case 'h':
|
|
|
|
help(); break;
|
|
|
|
case 'v':
|
|
|
|
verbosity++; break;
|
2023-04-26 17:33:05 +11:00
|
|
|
case 't':
|
2023-04-30 08:44:56 +11:00
|
|
|
// fprintf(stderr, "type -> '%s'\n", optarg);
|
2023-04-28 09:02:04 +11:00
|
|
|
outmode = optarg;
|
2023-04-26 17:33:05 +11:00
|
|
|
break;
|
2023-04-21 07:33:46 +11:00
|
|
|
default:
|
2023-04-30 08:44:56 +11:00
|
|
|
fprintf(stderr, "'%c' EBADOPT\n", opt);
|
2023-04-26 17:33:05 +11:00
|
|
|
exit(1);
|
2023-04-21 07:33:46 +11:00
|
|
|
break;
|
|
|
|
}
|
2023-04-15 09:56:48 +11:00
|
|
|
}
|
|
|
|
|
2023-04-21 07:33:46 +11:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "optind=%d argc=%d\n", optind, argc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (optind < argc) {
|
|
|
|
// fprintf(stderr, "ARG = %s\n", argv[optind]);
|
2023-04-26 17:33:05 +11:00
|
|
|
foo = load_and_printf_evblob(argv[optind], outmode);
|
2023-04-21 07:33:46 +11:00
|
|
|
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);
|
|
|
|
}
|
2023-04-15 09:56:48 +11:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|