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

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.3 static const char RCSid[] = "$Id$";
3 greg 1.1 #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 greg 2.2 static int oputint(), oputstr(), puttree(), putobj();
19 greg 1.6
20 greg 1.1
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 greg 2.2 oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2);
30 greg 1.1
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 greg 2.2 oputstr(sbuf);
37 greg 1.1 }
38     sprintf(sbuf, "%.12g", scene->cusize);
39 greg 2.2 oputstr(sbuf);
40 greg 1.1 /* write object file names */
41     if (store & IO_FILES)
42     for (i = 0; ofn[i] != NULL; i++)
43 greg 2.2 oputstr(ofn[i]);
44     oputstr("");
45 greg 1.3 /* write number of objects */
46 greg 2.2 oputint((long)nobjects, sizeof(OBJECT));
47 greg 1.1
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 greg 2.2 oputstr(ofun[i].funame);
58     oputstr("");
59 greg 1.1 for (i = 0; i < nobjects; i++)
60     putobj(objptr(i));
61     putobj(NULL);
62     }
63    
64    
65     static
66 greg 2.2 oputstr(s) /* write null-terminated string to stdout */
67 greg 1.1 register char *s;
68     {
69 greg 2.2 putstr(s, stdout);
70 greg 1.1 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 greg 2.2 oputint((long)oset[i], sizeof(OBJECT));
85 greg 1.1 }
86    
87    
88     static
89 greg 2.2 oputint(i, siz) /* write a siz-byte integer to stdout */
90 greg 1.1 register long i;
91     register int siz;
92     {
93 greg 2.2 putint(i, siz, stdout);
94 greg 1.1 if (ferror(stdout))
95     error(SYSTEM, "write error in putint");
96     }
97    
98    
99     static
100 greg 2.2 oputflt(f) /* put out floating point number */
101 greg 1.1 double f;
102     {
103 greg 2.2 putflt(f, stdout);
104     if (ferror(stdout))
105     error(SYSTEM, "write error in putflt");
106 greg 1.1 }
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 greg 2.2 oputint(-1L, 1);
135 greg 1.1 return;
136     }
137 greg 2.2 oputint((long)o->otype, 1);
138     oputint((long)o->omod, sizeof(OBJECT));
139     oputstr(o->oname);
140     oputint((long)o->oargs.nsargs, 2);
141 greg 1.1 for (i = 0; i < o->oargs.nsargs; i++)
142 greg 2.2 oputstr(o->oargs.sarg[i]);
143 greg 1.1 #ifdef IARGS
144 greg 2.2 oputint((long)o->oargs.niargs, 2);
145 greg 1.1 for (i = 0; i < o->oargs.niargs; i++)
146 greg 2.2 oputint((long)o->oargs.iarg[i], 4);
147 greg 1.1 #endif
148 greg 2.2 oputint((long)o->oargs.nfargs, 2);
149 greg 1.1 for (i = 0; i < o->oargs.nfargs; i++)
150 greg 2.2 oputflt(o->oargs.farg[i]);
151 greg 1.1 }