ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 2.2
Committed: Mon Jul 13 15:43:33 1992 UTC (32 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +29 -34 lines
Log Message:
moved portable i/o routines to rt library

File Contents

# User Rev Content
1 greg 2.2 /* Copyright (c) 1992 Regents of the University of California */
2 greg 1.1
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 greg 2.2 static int oputint(), oputstr(), puttree(), putobj();
22 greg 1.6
23 greg 1.1
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 greg 2.2 oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2);
33 greg 1.1
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 greg 2.2 oputstr(sbuf);
40 greg 1.1 }
41     sprintf(sbuf, "%.12g", scene->cusize);
42 greg 2.2 oputstr(sbuf);
43 greg 1.1 /* write object file names */
44     if (store & IO_FILES)
45     for (i = 0; ofn[i] != NULL; i++)
46 greg 2.2 oputstr(ofn[i]);
47     oputstr("");
48 greg 1.3 /* write number of objects */
49 greg 2.2 oputint((long)nobjects, sizeof(OBJECT));
50 greg 1.1
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 greg 2.2 oputstr(ofun[i].funame);
61     oputstr("");
62 greg 1.1 for (i = 0; i < nobjects; i++)
63     putobj(objptr(i));
64     putobj(NULL);
65     }
66    
67    
68     static
69 greg 2.2 oputstr(s) /* write null-terminated string to stdout */
70 greg 1.1 register char *s;
71     {
72 greg 2.2 putstr(s, stdout);
73 greg 1.1 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 greg 2.2 oputint((long)oset[i], sizeof(OBJECT));
88 greg 1.1 }
89    
90    
91     static
92 greg 2.2 oputint(i, siz) /* write a siz-byte integer to stdout */
93 greg 1.1 register long i;
94     register int siz;
95     {
96 greg 2.2 putint(i, siz, stdout);
97 greg 1.1 if (ferror(stdout))
98     error(SYSTEM, "write error in putint");
99     }
100    
101    
102     static
103 greg 2.2 oputflt(f) /* put out floating point number */
104 greg 1.1 double f;
105     {
106 greg 2.2 putflt(f, stdout);
107     if (ferror(stdout))
108     error(SYSTEM, "write error in putflt");
109 greg 1.1 }
110    
111    
112     static
113     puttree(ot) /* write octree to stdout in pre-order form */
114     register OCTREE ot;
115     {
116     register int i;
117    
118     if (istree(ot)) {
119     putc(OT_TREE, stdout); /* indicate tree */
120     for (i = 0; i < 8; i++) /* write tree */
121     puttree(octkid(ot, i));
122     } else if (isfull(ot)) {
123     putc(OT_FULL, stdout); /* indicate fullnode */
124     putfullnode(ot); /* write fullnode */
125     } else
126     putc(OT_EMPTY, stdout); /* indicate empty */
127     }
128    
129    
130     static
131     putobj(o) /* write out object */
132     register OBJREC *o;
133     {
134     register int i;
135    
136     if (o == NULL) { /* terminator */
137 greg 2.2 oputint(-1L, 1);
138 greg 1.1 return;
139     }
140 greg 2.2 oputint((long)o->otype, 1);
141     oputint((long)o->omod, sizeof(OBJECT));
142     oputstr(o->oname);
143     oputint((long)o->oargs.nsargs, 2);
144 greg 1.1 for (i = 0; i < o->oargs.nsargs; i++)
145 greg 2.2 oputstr(o->oargs.sarg[i]);
146 greg 1.1 #ifdef IARGS
147 greg 2.2 oputint((long)o->oargs.niargs, 2);
148 greg 1.1 for (i = 0; i < o->oargs.niargs; i++)
149 greg 2.2 oputint((long)o->oargs.iarg[i], 4);
150 greg 1.1 #endif
151 greg 2.2 oputint((long)o->oargs.nfargs, 2);
152 greg 1.1 for (i = 0; i < o->oargs.nfargs; i++)
153 greg 2.2 oputflt(o->oargs.farg[i]);
154 greg 1.1 }