| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
schorsch |
2.6 |
static const char RCSid[] = "$Id: getbbox.c,v 2.5 2003/02/22 02:07:26 greg Exp $"; |
| 3 |
greg |
1.1 |
#endif |
| 4 |
|
|
/* |
| 5 |
|
|
* getbbox.c - compute bounding box for scene files |
| 6 |
|
|
* |
| 7 |
|
|
* Adapted from oconv.c 29 May 1991 |
| 8 |
|
|
*/ |
| 9 |
|
|
|
| 10 |
|
|
#include "standard.h" |
| 11 |
|
|
#include "octree.h" |
| 12 |
|
|
#include "object.h" |
| 13 |
schorsch |
2.6 |
#include "oconv.h" |
| 14 |
greg |
1.1 |
|
| 15 |
|
|
char *progname; /* argv[0] */ |
| 16 |
|
|
|
| 17 |
|
|
int nowarn = 0; /* supress warnings? */ |
| 18 |
|
|
|
| 19 |
greg |
2.5 |
void (*addobjnotify[])() = {NULL}; /* new object notifier functions */ |
| 20 |
greg |
1.1 |
|
| 21 |
|
|
FVECT bbmin, bbmax; /* bounding box */ |
| 22 |
|
|
|
| 23 |
schorsch |
2.6 |
static void addobject(OBJREC *o); |
| 24 |
|
|
|
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
|
|
static void |
| 28 |
|
|
addobject( /* add object to bounding box */ |
| 29 |
|
|
OBJREC *o |
| 30 |
|
|
) |
| 31 |
greg |
1.1 |
{ |
| 32 |
|
|
add2bbox(o, bbmin, bbmax); |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
|
|
| 36 |
schorsch |
2.6 |
int |
| 37 |
|
|
main( /* read object files and compute bounds */ |
| 38 |
|
|
int argc, |
| 39 |
|
|
char **argv |
| 40 |
|
|
) |
| 41 |
greg |
1.1 |
{ |
| 42 |
greg |
2.2 |
extern char *getenv(); |
| 43 |
greg |
1.3 |
int nohead = 0; |
| 44 |
greg |
1.1 |
int i; |
| 45 |
|
|
|
| 46 |
|
|
progname = argv[0]; |
| 47 |
|
|
|
| 48 |
greg |
1.3 |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
| 49 |
|
|
switch (argv[i][1]) { |
| 50 |
|
|
case 'w': |
| 51 |
|
|
nowarn = 1; |
| 52 |
|
|
continue; |
| 53 |
|
|
case 'h': |
| 54 |
|
|
nohead = 1; |
| 55 |
|
|
continue; |
| 56 |
|
|
} |
| 57 |
|
|
break; |
| 58 |
|
|
} |
| 59 |
greg |
1.1 |
/* find bounding box */ |
| 60 |
|
|
bbmin[0] = bbmin[1] = bbmin[2] = FHUGE; |
| 61 |
|
|
bbmax[0] = bbmax[1] = bbmax[2] = -FHUGE; |
| 62 |
|
|
/* read input */ |
| 63 |
greg |
1.2 |
if (i >= argc) |
| 64 |
greg |
2.5 |
readobj2(NULL, addobject); |
| 65 |
greg |
1.2 |
else |
| 66 |
|
|
for ( ; i < argc; i++) |
| 67 |
|
|
if (!strcmp(argv[i], "-")) /* from stdin */ |
| 68 |
greg |
2.5 |
readobj2(NULL, addobject); |
| 69 |
greg |
1.2 |
else /* from file */ |
| 70 |
greg |
2.5 |
readobj2(argv[i], addobject); |
| 71 |
greg |
1.2 |
/* print bounding box */ |
| 72 |
greg |
1.3 |
if (!nohead) |
| 73 |
|
|
printf( |
| 74 |
greg |
2.3 |
" xmin xmax ymin ymax zmin zmax\n"); |
| 75 |
greg |
1.3 |
|
| 76 |
greg |
1.1 |
printf("%9g %9g %9g %9g %9g %9g\n", bbmin[0], bbmax[0], |
| 77 |
|
|
bbmin[1], bbmax[1], bbmin[2], bbmax[2]); |
| 78 |
|
|
quit(0); |
| 79 |
schorsch |
2.6 |
return 0; /* pro forma return */ |
| 80 |
greg |
1.1 |
} |
| 81 |
|
|
|
| 82 |
|
|
|
| 83 |
greg |
2.5 |
void |
| 84 |
schorsch |
2.6 |
quit( /* exit program */ |
| 85 |
|
|
int code |
| 86 |
|
|
) |
| 87 |
greg |
1.1 |
{ |
| 88 |
|
|
exit(code); |
| 89 |
|
|
} |
| 90 |
|
|
|
| 91 |
|
|
|
| 92 |
greg |
2.5 |
void |
| 93 |
schorsch |
2.6 |
cputs(void) /* interactive error */ |
| 94 |
greg |
1.1 |
{ |
| 95 |
|
|
/* referenced, but not used */ |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
|
| 99 |
greg |
2.5 |
void |
| 100 |
schorsch |
2.6 |
wputs( /* warning message */ |
| 101 |
|
|
char *s |
| 102 |
|
|
) |
| 103 |
greg |
1.1 |
{ |
| 104 |
|
|
if (!nowarn) |
| 105 |
|
|
eputs(s); |
| 106 |
|
|
} |
| 107 |
|
|
|
| 108 |
|
|
|
| 109 |
greg |
2.5 |
void |
| 110 |
schorsch |
2.6 |
eputs( /* put string to stderr */ |
| 111 |
|
|
register char *s |
| 112 |
|
|
) |
| 113 |
greg |
1.1 |
{ |
| 114 |
|
|
static int inln = 0; |
| 115 |
|
|
|
| 116 |
|
|
if (!inln++) { |
| 117 |
|
|
fputs(progname, stderr); |
| 118 |
|
|
fputs(": ", stderr); |
| 119 |
|
|
} |
| 120 |
|
|
fputs(s, stderr); |
| 121 |
|
|
if (*s && s[strlen(s)-1] == '\n') |
| 122 |
|
|
inln = 0; |
| 123 |
|
|
} |