ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 1.6
Committed: Mon Oct 28 12:21:52 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.5: +2 -0 lines
Log Message:
added advanced static function declarations for SGI compiler

File Contents

# Content
1 /* Copyright (c) 1986 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * writeoct.c - routines for writing octree information to stdout.
9 *
10 * 7/30/85
11 */
12
13 #include "standard.h"
14
15 #include "octree.h"
16
17 #include "object.h"
18
19 #include "otypes.h"
20
21 static int putint(), putstr(), puttree(), putobj();
22
23
24 writeoct(store, scene, ofn) /* write octree structures to stdout */
25 int store;
26 CUBE *scene;
27 char *ofn[];
28 {
29 char sbuf[64];
30 register int i;
31 /* write format number */
32 putint((long)(OCTMAGIC+sizeof(OBJECT)), 2);
33
34 if (!(store & IO_BOUNDS))
35 return;
36 /* write boundaries */
37 for (i = 0; i < 3; i++) {
38 sprintf(sbuf, "%.12g", scene->cuorg[i]);
39 putstr(sbuf);
40 }
41 sprintf(sbuf, "%.12g", scene->cusize);
42 putstr(sbuf);
43 /* write object file names */
44 if (store & IO_FILES)
45 for (i = 0; ofn[i] != NULL; i++)
46 putstr(ofn[i]);
47 putstr("");
48 /* write number of objects */
49 putint((long)nobjects, sizeof(OBJECT));
50
51 if (!(store & IO_TREE))
52 return;
53 /* write the octree */
54 puttree(scene->cutree);
55
56 if (store & IO_FILES || !(store & IO_SCENE))
57 return;
58 /* write the scene */
59 for (i = 0; i < NUMOTYPE; i++)
60 putstr(ofun[i].funame);
61 putstr("");
62 for (i = 0; i < nobjects; i++)
63 putobj(objptr(i));
64 putobj(NULL);
65 }
66
67
68 static
69 putstr(s) /* write null-terminated string to stdout */
70 register char *s;
71 {
72 do
73 putc(*s, stdout);
74 while (*s++);
75 if (ferror(stdout))
76 error(SYSTEM, "write error in putstr");
77 }
78
79
80 static
81 putfullnode(fn) /* write out a full node */
82 OCTREE fn;
83 {
84 OBJECT oset[MAXSET+1];
85 register int i;
86
87 objset(oset, fn);
88 for (i = 0; i <= oset[0]; i++)
89 putint((long)oset[i], sizeof(OBJECT));
90 }
91
92
93 static
94 putint(i, siz) /* write a siz-byte integer to stdout */
95 register long i;
96 register int siz;
97 {
98 while (siz--)
99 putc(i>>(siz<<3) & 0xff, stdout);
100 if (ferror(stdout))
101 error(SYSTEM, "write error in putint");
102 }
103
104
105 static
106 putflt(f) /* put out floating point number */
107 double f;
108 {
109 extern double frexp();
110 int e;
111
112 putint((long)(frexp(f,&e)*0x7fffffff), 4);
113 putint((long)e, 1);
114 }
115
116
117 static
118 puttree(ot) /* write octree to stdout in pre-order form */
119 register OCTREE ot;
120 {
121 register int i;
122
123 if (istree(ot)) {
124 putc(OT_TREE, stdout); /* indicate tree */
125 for (i = 0; i < 8; i++) /* write tree */
126 puttree(octkid(ot, i));
127 } else if (isfull(ot)) {
128 putc(OT_FULL, stdout); /* indicate fullnode */
129 putfullnode(ot); /* write fullnode */
130 } else
131 putc(OT_EMPTY, stdout); /* indicate empty */
132 }
133
134
135 static
136 putobj(o) /* write out object */
137 register OBJREC *o;
138 {
139 register int i;
140
141 if (o == NULL) { /* terminator */
142 putint(-1L, 1);
143 return;
144 }
145 putint((long)o->otype, 1);
146 putint((long)o->omod, sizeof(OBJECT));
147 putstr(o->oname);
148 putint((long)o->oargs.nsargs, 2);
149 for (i = 0; i < o->oargs.nsargs; i++)
150 putstr(o->oargs.sarg[i]);
151 #ifdef IARGS
152 putint((long)o->oargs.niargs, 2);
153 for (i = 0; i < o->oargs.niargs; i++)
154 putint((long)o->oargs.iarg[i], 4);
155 #endif
156 putint((long)o->oargs.nfargs, 2);
157 for (i = 0; i < o->oargs.nfargs; i++)
158 putflt(o->oargs.farg[i]);
159 }