ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 2.7
Committed: Tue Nov 9 16:09:20 2004 UTC (20 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R8, rad3R9, rad4R2P1, rad5R3
Changes since 2.6: +2 -1 lines
Log Message:
Undefined putc macro before redefining it

File Contents

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