ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 2.4
Committed: Fri Mar 14 21:27:46 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.3: +4 -38 lines
Log Message:
Added -a option to obj2mesh to incorporate materials in mesh

File Contents

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