1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.4 |
static const char RCSid[] = "$Id$"; |
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 |
|
|
|
14 |
|
|
#include "object.h" |
15 |
|
|
|
16 |
greg |
2.4 |
static int oputint(), oputstr(), puttree(); |
17 |
greg |
1.6 |
|
18 |
greg |
1.1 |
|
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 |
greg |
2.4 |
int i; |
26 |
greg |
1.1 |
/* write format number */ |
27 |
greg |
2.2 |
oputint((long)(OCTMAGIC+sizeof(OBJECT)), 2); |
28 |
greg |
1.1 |
|
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 |
greg |
2.2 |
oputstr(sbuf); |
35 |
greg |
1.1 |
} |
36 |
|
|
sprintf(sbuf, "%.12g", scene->cusize); |
37 |
greg |
2.2 |
oputstr(sbuf); |
38 |
greg |
1.1 |
/* write object file names */ |
39 |
|
|
if (store & IO_FILES) |
40 |
|
|
for (i = 0; ofn[i] != NULL; i++) |
41 |
greg |
2.2 |
oputstr(ofn[i]); |
42 |
|
|
oputstr(""); |
43 |
greg |
1.3 |
/* write number of objects */ |
44 |
greg |
2.2 |
oputint((long)nobjects, sizeof(OBJECT)); |
45 |
greg |
1.1 |
|
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 |
greg |
2.4 |
writescene(0, nobjects, stdout); |
55 |
greg |
1.1 |
} |
56 |
|
|
|
57 |
|
|
|
58 |
|
|
static |
59 |
greg |
2.2 |
oputstr(s) /* write null-terminated string to stdout */ |
60 |
greg |
1.1 |
register char *s; |
61 |
|
|
{ |
62 |
greg |
2.2 |
putstr(s, stdout); |
63 |
greg |
1.1 |
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 |
greg |
2.2 |
oputint((long)oset[i], sizeof(OBJECT)); |
78 |
greg |
1.1 |
} |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
static |
82 |
greg |
2.2 |
oputint(i, siz) /* write a siz-byte integer to stdout */ |
83 |
greg |
1.1 |
register long i; |
84 |
|
|
register int siz; |
85 |
|
|
{ |
86 |
greg |
2.2 |
putint(i, siz, stdout); |
87 |
greg |
1.1 |
if (ferror(stdout)) |
88 |
|
|
error(SYSTEM, "write error in putint"); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
|
92 |
|
|
static |
93 |
greg |
2.2 |
oputflt(f) /* put out floating point number */ |
94 |
greg |
1.1 |
double f; |
95 |
|
|
{ |
96 |
greg |
2.2 |
putflt(f, stdout); |
97 |
|
|
if (ferror(stdout)) |
98 |
|
|
error(SYSTEM, "write error in putflt"); |
99 |
greg |
1.1 |
} |
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 |
|
|
} |