1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.8 |
static const char RCSid[] = "$Id: writeoct.c,v 2.7 2004/11/09 16:09:20 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 |
2.6 |
#ifdef putc_unlocked /* avoid horrendous overhead of flockfile */ |
17 |
greg |
2.7 |
#undef putc |
18 |
greg |
2.6 |
#define putc putc_unlocked |
19 |
|
|
#endif |
20 |
greg |
1.1 |
|
21 |
schorsch |
2.5 |
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 |
greg |
1.1 |
{ |
35 |
|
|
char sbuf[64]; |
36 |
greg |
2.4 |
int i; |
37 |
greg |
1.1 |
/* write format number */ |
38 |
greg |
2.2 |
oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2); |
39 |
greg |
1.1 |
|
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 |
greg |
2.2 |
oputstr(sbuf); |
46 |
greg |
1.1 |
} |
47 |
|
|
sprintf(sbuf, "%.12g", scene->cusize); |
48 |
greg |
2.2 |
oputstr(sbuf); |
49 |
greg |
1.1 |
/* write object file names */ |
50 |
|
|
if (store & IO_FILES) |
51 |
|
|
for (i = 0; ofn[i] != NULL; i++) |
52 |
greg |
2.2 |
oputstr(ofn[i]); |
53 |
|
|
oputstr(""); |
54 |
greg |
1.3 |
/* write number of objects */ |
55 |
greg |
2.2 |
oputint((long)nobjects, sizeof(OBJECT)); |
56 |
greg |
1.1 |
|
57 |
|
|
if (!(store & IO_TREE)) |
58 |
|
|
return; |
59 |
|
|
/* write the octree */ |
60 |
|
|
puttree(scene->cutree); |
61 |
|
|
|
62 |
greg |
2.8 |
if (fflush(stdout) == EOF) |
63 |
|
|
error(SYSTEM, "output error in writeoct"); |
64 |
|
|
|
65 |
greg |
1.1 |
if (store & IO_FILES || !(store & IO_SCENE)) |
66 |
|
|
return; |
67 |
|
|
/* write the scene */ |
68 |
greg |
2.4 |
writescene(0, nobjects, stdout); |
69 |
greg |
1.1 |
} |
70 |
|
|
|
71 |
|
|
|
72 |
schorsch |
2.5 |
static void |
73 |
|
|
oputstr( /* write null-terminated string to stdout */ |
74 |
greg |
2.8 |
char *s |
75 |
schorsch |
2.5 |
) |
76 |
greg |
1.1 |
{ |
77 |
greg |
2.8 |
if (putstr(s, stdout) == EOF) |
78 |
|
|
error(SYSTEM, "write error in oputstr"); |
79 |
greg |
1.1 |
} |
80 |
|
|
|
81 |
|
|
|
82 |
schorsch |
2.5 |
static void |
83 |
|
|
putfullnode( /* write out a full node */ |
84 |
|
|
OCTREE fn |
85 |
|
|
) |
86 |
greg |
1.1 |
{ |
87 |
|
|
OBJECT oset[MAXSET+1]; |
88 |
greg |
2.8 |
int i; |
89 |
greg |
1.1 |
|
90 |
|
|
objset(oset, fn); |
91 |
|
|
for (i = 0; i <= oset[0]; i++) |
92 |
greg |
2.2 |
oputint((long)oset[i], sizeof(OBJECT)); |
93 |
greg |
1.1 |
} |
94 |
|
|
|
95 |
|
|
|
96 |
schorsch |
2.5 |
static void |
97 |
|
|
oputint( /* write a siz-byte integer to stdout */ |
98 |
greg |
2.8 |
long i, |
99 |
|
|
int siz |
100 |
schorsch |
2.5 |
) |
101 |
greg |
1.1 |
{ |
102 |
greg |
2.8 |
if (putint(i, siz, stdout) == EOF) |
103 |
|
|
error(SYSTEM, "write error in oputint"); |
104 |
greg |
1.1 |
} |
105 |
|
|
|
106 |
|
|
|
107 |
schorsch |
2.5 |
static void |
108 |
|
|
oputflt( /* put out floating point number */ |
109 |
|
|
double f |
110 |
|
|
) |
111 |
greg |
1.1 |
{ |
112 |
greg |
2.8 |
if (putflt(f, stdout) == EOF) |
113 |
|
|
error(SYSTEM, "write error in oputflt"); |
114 |
greg |
1.1 |
} |
115 |
|
|
|
116 |
|
|
|
117 |
schorsch |
2.5 |
static void |
118 |
|
|
puttree( /* write octree to stdout in pre-order form */ |
119 |
greg |
2.8 |
OCTREE ot |
120 |
schorsch |
2.5 |
) |
121 |
greg |
1.1 |
{ |
122 |
greg |
2.8 |
int i; |
123 |
greg |
1.1 |
|
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 |
|
|
} |