ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
Revision: 2.6
Committed: Thu Apr 29 14:36:49 2004 UTC (20 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6, rad3R6P1
Changes since 2.5: +4 -1 lines
Log Message:
Added macros to avoid flockfile(3) overhead

File Contents

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