ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 2.3
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +1 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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