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