1 |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* Routines to print mkillum objects |
9 |
*/ |
10 |
|
11 |
#include "mkillum.h" |
12 |
|
13 |
#define brt(col) (.295*(col)[0] + .636*(col)[1] + .070*(col)[2]) |
14 |
|
15 |
char DATORD[] = "RGB"; /* data ordering */ |
16 |
char DATSUF[] = ".dat"; /* data file suffix */ |
17 |
char DSTSUF[] = ".dist"; /* distribution suffix */ |
18 |
char FNCFNM[] = "illum.cal"; /* function file name */ |
19 |
|
20 |
|
21 |
printobj(mod, obj) /* print out an object */ |
22 |
char *mod; |
23 |
register OBJREC *obj; |
24 |
{ |
25 |
register int i; |
26 |
|
27 |
printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname); |
28 |
printf("\n%d", obj->oargs.nsargs); |
29 |
for (i = 0; i < obj->oargs.nsargs; i++) |
30 |
printf(" %s", obj->oargs.sarg[i]); |
31 |
#ifdef IARGS |
32 |
printf("\n%d", obj->oargs.niargs); |
33 |
for (i = 0; i < obj->oargs.niargs; i++) |
34 |
printf(" %d", obj->oargs.iarg[i]); |
35 |
#else |
36 |
printf("\n0"); |
37 |
#endif |
38 |
printf("\n%d", obj->oargs.nfargs); |
39 |
for (i = 0; i < obj->oargs.nfargs; i++) { |
40 |
if (i%3 == 0) |
41 |
putchar('\n'); |
42 |
printf(" %18.12g", obj->oargs.farg[i]); |
43 |
} |
44 |
putchar('\n'); |
45 |
} |
46 |
|
47 |
|
48 |
char * |
49 |
dfname(il, c) /* return data file name */ |
50 |
struct illum_args *il; |
51 |
int c; |
52 |
{ |
53 |
extern char *getpath(), *strcpy(); |
54 |
char fname[MAXSTR]; |
55 |
register char *s; |
56 |
|
57 |
s = strcpy(fname, il->datafile); |
58 |
s += strlen(s); |
59 |
if (c) *s++ = c; |
60 |
if (il->dfnum > 0) { |
61 |
sprintf(s, "%d", il->dfnum); |
62 |
s += strlen(s); |
63 |
} |
64 |
strcpy(s, DATSUF); |
65 |
return(getpath(fname, NULL, 0)); |
66 |
} |
67 |
|
68 |
|
69 |
FILE * |
70 |
dfopen(il, c) /* open data file */ |
71 |
register struct illum_args *il; |
72 |
int c; |
73 |
{ |
74 |
char *fn; |
75 |
FILE *fp; |
76 |
/* get a usable file name */ |
77 |
for (fn = dfname(il, c); |
78 |
!(il->flags & IL_DATCLB) && access(fn, F_OK) == 0; |
79 |
fn = dfname(il, c)) |
80 |
il->dfnum++; |
81 |
/* open it for writing */ |
82 |
if ((fp = fopen(fn, "w")) == NULL) { |
83 |
sprintf(errmsg, "cannot open data file \"%s\"", fn); |
84 |
error(SYSTEM, errmsg); |
85 |
} |
86 |
return(fp); |
87 |
} |
88 |
|
89 |
|
90 |
flatout(il, da, n, m, u, v, w) /* write hemispherical distribution */ |
91 |
struct illum_args *il; |
92 |
float *da; |
93 |
int n, m; |
94 |
FVECT u, v, w; |
95 |
{ |
96 |
FILE *dfp; |
97 |
int i; |
98 |
|
99 |
average(il, da, n*m); |
100 |
if (il->flags & IL_COLDST) { |
101 |
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
102 |
il->matname, DSTSUF); |
103 |
printf("\n9 red green blue"); |
104 |
for (i = 0; i < 3; i++) { |
105 |
dfp = dfopen(il, DATORD[i]); |
106 |
fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m); |
107 |
colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp); |
108 |
fclose(dfp); |
109 |
printf(" %s", dfname(il, DATORD[i])); |
110 |
} |
111 |
} else { |
112 |
printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, |
113 |
il->matname, DSTSUF); |
114 |
printf("\n5 noop"); |
115 |
dfp = dfopen(il, 0); |
116 |
fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m); |
117 |
brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp); |
118 |
fclose(dfp); |
119 |
printf(" %s", dfname(il, 0)); |
120 |
} |
121 |
printf("\n\t%s il_alth il_azih", FNCFNM); |
122 |
printf("\n0\n9\n"); |
123 |
printf("\t%f\t%f\t%f\n", u[0], u[1], u[2]); |
124 |
printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]); |
125 |
printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]); |
126 |
il->dfnum++; |
127 |
} |
128 |
|
129 |
|
130 |
roundout(il, da, n, m) /* write spherical distribution */ |
131 |
struct illum_args *il; |
132 |
float *da; |
133 |
int n, m; |
134 |
{ |
135 |
FILE *dfp; |
136 |
int i; |
137 |
|
138 |
average(il, da, n*m); |
139 |
if (il->flags & IL_COLDST) { |
140 |
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
141 |
il->matname, DSTSUF); |
142 |
printf("\n9 red green blue"); |
143 |
for (i = 0; i < 3; i++) { |
144 |
dfp = dfopen(il, DATORD[i]); |
145 |
fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m); |
146 |
colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp); |
147 |
fclose(dfp); |
148 |
printf(" %s", dfname(il, DATORD[i])); |
149 |
} |
150 |
} else { |
151 |
printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, |
152 |
il->matname, DSTSUF); |
153 |
printf("\n5 noop"); |
154 |
dfp = dfopen(il, 0); |
155 |
fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m); |
156 |
brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp); |
157 |
fclose(dfp); |
158 |
printf(" %s", dfname(il, 0)); |
159 |
} |
160 |
printf("\n\t%s il_alt il_azi", FNCFNM); |
161 |
printf("\n0\n0\n"); |
162 |
il->dfnum++; |
163 |
} |
164 |
|
165 |
|
166 |
illumout(il, ob) /* print illum object */ |
167 |
register struct illum_args *il; |
168 |
OBJREC *ob; |
169 |
{ |
170 |
double cout[3]; |
171 |
|
172 |
printf("\n%s%s %s %s", il->matname, DSTSUF, |
173 |
ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame, |
174 |
il->matname); |
175 |
if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID)) |
176 |
printf("\n0"); |
177 |
else |
178 |
printf("\n1 %s", il->altmat); |
179 |
if (il->flags & IL_COLAVG) { |
180 |
cout[0] = il->col[0]; |
181 |
cout[1] = il->col[1]; |
182 |
cout[2] = il->col[2]; |
183 |
} else { |
184 |
cout[0] = cout[1] = cout[2] = brt(il->col); |
185 |
} |
186 |
printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]); |
187 |
|
188 |
printobj(il->matname, ob); |
189 |
} |
190 |
|
191 |
|
192 |
average(il, da, n) /* compute average value for distribution */ |
193 |
register struct illum_args *il; |
194 |
register float *da; |
195 |
int n; |
196 |
{ |
197 |
register int i; |
198 |
|
199 |
il->col[0] = il->col[1] = il->col[2] = 0.; |
200 |
i = n; |
201 |
while (i-- > 0) { |
202 |
il->col[0] += *da++; |
203 |
il->col[1] += *da++; |
204 |
il->col[2] += *da++; |
205 |
} |
206 |
for (i = 0; i < 3; i++) |
207 |
il->col[i] /= (double)n*il->nsamps; |
208 |
} |
209 |
|
210 |
|
211 |
colorout(p, da, n, mult, fp) /* put out color distribution data */ |
212 |
int p; |
213 |
register float *da; |
214 |
int n; |
215 |
double mult; |
216 |
FILE *fp; |
217 |
{ |
218 |
register int i; |
219 |
|
220 |
for (i = 0; i < n; i++) { |
221 |
if (i%6 == 0) |
222 |
putc('\n', fp); |
223 |
fprintf(fp, " %11e", mult*da[p]); |
224 |
da += 3; |
225 |
} |
226 |
putc('\n', fp); |
227 |
} |
228 |
|
229 |
|
230 |
brightout(da, n, mult, fp) /* put out brightness distribution data */ |
231 |
register float *da; |
232 |
int n; |
233 |
double mult; |
234 |
FILE *fp; |
235 |
{ |
236 |
register int i; |
237 |
|
238 |
for (i = 0; i < n; i++) { |
239 |
if (i%6 == 0) |
240 |
putc('\n', fp); |
241 |
fprintf(fp, " %11e", mult*brt(da)); |
242 |
da += 3; |
243 |
} |
244 |
putc('\n', fp); |
245 |
} |