ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 2.5
Committed: Sat Mar 27 12:41:45 2004 UTC (20 years, 6 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.4: +36 -24 lines
Log Message:
Continued ANSIfication. Renamed local initotypes() to ot_initotypes().

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: writeoct.c,v 2.4 2003/03/14 21:27:46 greg Exp $";
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 #include "object.h"
14 #include "oconv.h"
15
16
17 static void oputstr(char *s);
18 static void putfullnode(OCTREE fn);
19 static void oputint(long i, int siz);
20 static void oputflt(double f);
21 static void puttree(OCTREE ot);
22
23
24 void
25 writeoct( /* write octree structures to stdout */
26 int store,
27 CUBE *scene,
28 char *ofn[]
29 )
30 {
31 char sbuf[64];
32 int i;
33 /* write format number */
34 oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2);
35
36 if (!(store & IO_BOUNDS))
37 return;
38 /* write boundaries */
39 for (i = 0; i < 3; i++) {
40 sprintf(sbuf, "%.12g", scene->cuorg[i]);
41 oputstr(sbuf);
42 }
43 sprintf(sbuf, "%.12g", scene->cusize);
44 oputstr(sbuf);
45 /* write object file names */
46 if (store & IO_FILES)
47 for (i = 0; ofn[i] != NULL; i++)
48 oputstr(ofn[i]);
49 oputstr("");
50 /* write number of objects */
51 oputint((long)nobjects, sizeof(OBJECT));
52
53 if (!(store & IO_TREE))
54 return;
55 /* write the octree */
56 puttree(scene->cutree);
57
58 if (store & IO_FILES || !(store & IO_SCENE))
59 return;
60 /* write the scene */
61 writescene(0, nobjects, stdout);
62 }
63
64
65 static void
66 oputstr( /* write null-terminated string to stdout */
67 register char *s
68 )
69 {
70 putstr(s, stdout);
71 if (ferror(stdout))
72 error(SYSTEM, "write error in putstr");
73 }
74
75
76 static void
77 putfullnode( /* write out a full node */
78 OCTREE fn
79 )
80 {
81 OBJECT oset[MAXSET+1];
82 register int i;
83
84 objset(oset, fn);
85 for (i = 0; i <= oset[0]; i++)
86 oputint((long)oset[i], sizeof(OBJECT));
87 }
88
89
90 static void
91 oputint( /* write a siz-byte integer to stdout */
92 register long i,
93 register int siz
94 )
95 {
96 putint(i, siz, stdout);
97 if (ferror(stdout))
98 error(SYSTEM, "write error in putint");
99 }
100
101
102 static void
103 oputflt( /* put out floating point number */
104 double f
105 )
106 {
107 putflt(f, stdout);
108 if (ferror(stdout))
109 error(SYSTEM, "write error in putflt");
110 }
111
112
113 static void
114 puttree( /* write octree to stdout in pre-order form */
115 register OCTREE ot
116 )
117 {
118 register int i;
119
120 if (istree(ot)) {
121 putc(OT_TREE, stdout); /* indicate tree */
122 for (i = 0; i < 8; i++) /* write tree */
123 puttree(octkid(ot, i));
124 } else if (isfull(ot)) {
125 putc(OT_FULL, stdout); /* indicate fullnode */
126 putfullnode(ot); /* write fullnode */
127 } else
128 putc(OT_EMPTY, stdout); /* indicate empty */
129 }