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 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

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.5 static const char RCSid[] = "$Id: writeoct.c,v 2.4 2003/03/14 21:27:46 greg Exp $";
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     #include "object.h"
14 schorsch 2.5 #include "oconv.h"
15 greg 1.6
16 greg 1.1
17 schorsch 2.5 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 greg 1.1 {
31     char sbuf[64];
32 greg 2.4 int i;
33 greg 1.1 /* write format number */
34 greg 2.2 oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2);
35 greg 1.1
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 greg 2.2 oputstr(sbuf);
42 greg 1.1 }
43     sprintf(sbuf, "%.12g", scene->cusize);
44 greg 2.2 oputstr(sbuf);
45 greg 1.1 /* write object file names */
46     if (store & IO_FILES)
47     for (i = 0; ofn[i] != NULL; i++)
48 greg 2.2 oputstr(ofn[i]);
49     oputstr("");
50 greg 1.3 /* write number of objects */
51 greg 2.2 oputint((long)nobjects, sizeof(OBJECT));
52 greg 1.1
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 greg 2.4 writescene(0, nobjects, stdout);
62 greg 1.1 }
63    
64    
65 schorsch 2.5 static void
66     oputstr( /* write null-terminated string to stdout */
67     register char *s
68     )
69 greg 1.1 {
70 greg 2.2 putstr(s, stdout);
71 greg 1.1 if (ferror(stdout))
72     error(SYSTEM, "write error in putstr");
73     }
74    
75    
76 schorsch 2.5 static void
77     putfullnode( /* write out a full node */
78     OCTREE fn
79     )
80 greg 1.1 {
81     OBJECT oset[MAXSET+1];
82     register int i;
83    
84     objset(oset, fn);
85     for (i = 0; i <= oset[0]; i++)
86 greg 2.2 oputint((long)oset[i], sizeof(OBJECT));
87 greg 1.1 }
88    
89    
90 schorsch 2.5 static void
91     oputint( /* write a siz-byte integer to stdout */
92     register long i,
93     register int siz
94     )
95 greg 1.1 {
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 schorsch 2.5 static void
103     oputflt( /* put out floating point number */
104     double f
105     )
106 greg 1.1 {
107 greg 2.2 putflt(f, stdout);
108     if (ferror(stdout))
109     error(SYSTEM, "write error in putflt");
110 greg 1.1 }
111    
112    
113 schorsch 2.5 static void
114     puttree( /* write octree to stdout in pre-order form */
115     register OCTREE ot
116     )
117 greg 1.1 {
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     }