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