ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 1.5
Committed: Wed Oct 23 11:32:45 1991 UTC (32 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +1 -1 lines
Log Message:
changed definition of OCTMAGIC

File Contents

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