ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/writeoct.c
(Generate patch)

Comparing ray/src/ot/writeoct.c (file contents):
Revision 1.4 by greg, Wed Dec 12 22:46:35 1990 UTC vs.
Revision 2.6 by greg, Thu Apr 29 14:36:49 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  writeoct.c - routines for writing octree information to stdout.
6   *
# Line 13 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   #include  "standard.h"
11  
12   #include  "octree.h"
16
13   #include  "object.h"
14 + #include  "oconv.h"
15  
16 < #include  "otypes.h"
16 > #ifdef putc_unlocked            /* avoid horrendous overhead of flockfile */
17 > #define putc    putc_unlocked
18 > #endif
19  
20 + 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 < writeoct(store, scene, ofn)             /* write octree structures to stdout */
27 < int  store;
28 < CUBE  *scene;
29 < char  *ofn[];
26 >
27 > void
28 > writeoct(               /* write octree structures to stdout */
29 >        int  store,
30 >        CUBE  *scene,
31 >        char  *ofn[]
32 > )
33   {
34          char  sbuf[64];
35 <        register int  i;
35 >        int  i;
36                                          /* write format number */
37 <        putint((long)OCTMAGIC, 2);
37 >        oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2);
38  
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 <                putstr(sbuf);
44 >                oputstr(sbuf);
45          }
46          sprintf(sbuf, "%.12g", scene->cusize);
47 <        putstr(sbuf);
47 >        oputstr(sbuf);
48                                          /* write object file names */
49          if (store & IO_FILES)
50                  for (i = 0; ofn[i] != NULL; i++)
51 <                        putstr(ofn[i]);
52 <        putstr("");
51 >                        oputstr(ofn[i]);
52 >        oputstr("");
53                                          /* write number of objects */
54 <        putint((long)nobjects, sizeof(OBJECT));
54 >        oputint((long)nobjects, sizeof(OBJECT));
55  
56          if (!(store & IO_TREE))
57                  return;
# Line 54 | Line 61 | char  *ofn[];
61          if (store & IO_FILES || !(store & IO_SCENE))
62                  return;
63                                          /* write the scene */
64 <        for (i = 0; i < NUMOTYPE; i++)
58 <                putstr(ofun[i].funame);
59 <        putstr("");
60 <        for (i = 0; i < nobjects; i++)
61 <                putobj(objptr(i));
62 <        putobj(NULL);
64 >        writescene(0, nobjects, stdout);
65   }
66  
67  
68 < static
69 < putstr(s)                       /* write null-terminated string to stdout */
70 < register char  *s;
68 > static void
69 > oputstr(                        /* write null-terminated string to stdout */
70 >        register char  *s
71 > )
72   {
73 <        do
71 <                putc(*s, stdout);
72 <        while (*s++);
73 >        putstr(s, stdout);
74          if (ferror(stdout))
75                  error(SYSTEM, "write error in putstr");
76   }
77  
78  
79 < static
80 < putfullnode(fn)                 /* write out a full node */
81 < OCTREE  fn;
79 > static void
80 > putfullnode(                    /* write out a full node */
81 >        OCTREE  fn
82 > )
83   {
84          OBJECT  oset[MAXSET+1];
85          register int  i;
86  
87          objset(oset, fn);
88          for (i = 0; i <= oset[0]; i++)
89 <                putint((long)oset[i], sizeof(OBJECT));
89 >                oputint((long)oset[i], sizeof(OBJECT));
90   }
91  
92  
93 < static
94 < putint(i, siz)                  /* write a siz-byte integer to stdout */
95 < register long  i;
96 < register int  siz;
93 > static void
94 > oputint(                        /* write a siz-byte integer to stdout */
95 >        register long  i,
96 >        register int  siz
97 > )
98   {
99 <        while (siz--)
97 <                putc(i>>(siz<<3) & 0xff, stdout);
99 >        putint(i, siz, stdout);
100          if (ferror(stdout))
101                  error(SYSTEM, "write error in putint");
102   }
103  
104  
105 < static
106 < putflt(f)                       /* put out floating point number */
107 < double  f;
105 > static void
106 > oputflt(                        /* put out floating point number */
107 >        double  f
108 > )
109   {
110 <        extern double  frexp();
111 <        int  e;
112 <
110 <        putint((long)(frexp(f,&e)*0x7fffffff), 4);
111 <        putint((long)e, 1);
110 >        putflt(f, stdout);
111 >        if (ferror(stdout))
112 >                error(SYSTEM, "write error in putflt");
113   }
114  
115  
116 < static
117 < puttree(ot)                     /* write octree to stdout in pre-order form */
118 < register OCTREE  ot;
116 > static void
117 > puttree(                        /* write octree to stdout in pre-order form */
118 >        register OCTREE  ot
119 > )
120   {
121          register int  i;
122          
# Line 127 | Line 129 | register OCTREE  ot;
129                  putfullnode(ot);                /* write fullnode */
130          } else
131                  putc(OT_EMPTY, stdout);         /* indicate empty */
130 }
131
132
133 static
134 putobj(o)                       /* write out object */
135 register OBJREC  *o;
136 {
137        register int  i;
138
139        if (o == NULL) {                /* terminator */
140                putint(-1L, 1);
141                return;
142        }
143        putint((long)o->otype, 1);
144        putint((long)o->omod, sizeof(OBJECT));
145        putstr(o->oname);
146        putint((long)o->oargs.nsargs, 2);
147        for (i = 0; i < o->oargs.nsargs; i++)
148                putstr(o->oargs.sarg[i]);
149 #ifdef  IARGS
150        putint((long)o->oargs.niargs, 2);
151        for (i = 0; i < o->oargs.niargs; i++)
152                putint((long)o->oargs.iarg[i], 4);
153 #endif
154        putint((long)o->oargs.nfargs, 2);
155        for (i = 0; i < o->oargs.nfargs; i++)
156                putflt(o->oargs.farg[i]);
132   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines