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) (.263*(col)[0]+.655*(col)[1]+.082*(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 |
if (issurface(obj->otype) && !strcmp(mod, VOIDID)) |
28 |
return; /* don't print void surfaces */ |
29 |
printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname); |
30 |
printf("\n%d", obj->oargs.nsargs); |
31 |
for (i = 0; i < obj->oargs.nsargs; i++) |
32 |
printf(" %s", obj->oargs.sarg[i]); |
33 |
#ifdef IARGS |
34 |
printf("\n%d", obj->oargs.niargs); |
35 |
for (i = 0; i < obj->oargs.niargs; i++) |
36 |
printf(" %d", obj->oargs.iarg[i]); |
37 |
#else |
38 |
printf("\n0"); |
39 |
#endif |
40 |
printf("\n%d", obj->oargs.nfargs); |
41 |
for (i = 0; i < obj->oargs.nfargs; i++) { |
42 |
if (i%3 == 0) |
43 |
putchar('\n'); |
44 |
printf(" %18.12g", obj->oargs.farg[i]); |
45 |
} |
46 |
putchar('\n'); |
47 |
} |
48 |
|
49 |
|
50 |
char * |
51 |
dfname(il, c) /* return data file name */ |
52 |
struct illum_args *il; |
53 |
int c; |
54 |
{ |
55 |
extern char *getpath(), *strcpy(); |
56 |
char fname[MAXSTR]; |
57 |
register char *s; |
58 |
|
59 |
s = strcpy(fname, il->datafile); |
60 |
s += strlen(s); |
61 |
if (c) *s++ = c; |
62 |
if (il->dfnum > 0) { |
63 |
sprintf(s, "%d", il->dfnum); |
64 |
s += strlen(s); |
65 |
} |
66 |
strcpy(s, DATSUF); |
67 |
return(getpath(fname, NULL, 0)); |
68 |
} |
69 |
|
70 |
|
71 |
FILE * |
72 |
dfopen(il, c) /* open data file */ |
73 |
register struct illum_args *il; |
74 |
int c; |
75 |
{ |
76 |
char *fn; |
77 |
FILE *fp; |
78 |
/* get a usable file name */ |
79 |
for (fn = dfname(il, c); |
80 |
!(il->flags & IL_DATCLB) && access(fn, F_OK) == 0; |
81 |
fn = dfname(il, c)) |
82 |
il->dfnum++; |
83 |
/* open it for writing */ |
84 |
if ((fp = fopen(fn, "w")) == NULL) { |
85 |
sprintf(errmsg, "cannot open data file \"%s\"", fn); |
86 |
error(SYSTEM, errmsg); |
87 |
} |
88 |
return(fp); |
89 |
} |
90 |
|
91 |
|
92 |
flatout(il, da, n, m, u, v, w) /* write hemispherical distribution */ |
93 |
struct illum_args *il; |
94 |
float *da; |
95 |
int n, m; |
96 |
FVECT u, v, w; |
97 |
{ |
98 |
FILE *dfp; |
99 |
float col[3]; |
100 |
int i; |
101 |
|
102 |
if (il->flags & IL_COLDST) { |
103 |
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
104 |
il->matname, DSTSUF); |
105 |
printf("\n9 h_red h_grn h_blu"); |
106 |
for (i = 0; i < 3; i++) { |
107 |
dfp = dfopen(il, DATORD[i]); |
108 |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
109 |
1.-.5/n, .5/n, n, |
110 |
0., 2.*PI, m+1); |
111 |
colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); |
112 |
fclose(dfp); |
113 |
printf(" %s", dfname(il, DATORD[i])); |
114 |
} |
115 |
} else { |
116 |
printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, |
117 |
il->matname, DSTSUF); |
118 |
printf("\n5 h_gry"); |
119 |
dfp = dfopen(il, 0); |
120 |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.-.5/n, .5/n, n, |
121 |
0., 2.*PI, m+1); |
122 |
brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); |
123 |
fclose(dfp); |
124 |
printf(" %s", dfname(il, 0)); |
125 |
} |
126 |
printf("\n\t%s il_alth il_azih", FNCFNM); |
127 |
printf("\n0\n13\n"); |
128 |
compavg(col, da, m, il->nsamps); |
129 |
printf("\t%f\t%f\t%f\t%f\n", col[0]/il->col[0], |
130 |
col[1]/il->col[1], col[2]/il->col[2], 1.-.5/n); |
131 |
printf("\t%f\t%f\t%f\n", u[0], u[1], u[2]); |
132 |
printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]); |
133 |
printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]); |
134 |
il->dfnum++; |
135 |
} |
136 |
|
137 |
|
138 |
roundout(il, da, n, m) /* write spherical distribution */ |
139 |
struct illum_args *il; |
140 |
float *da; |
141 |
int n, m; |
142 |
{ |
143 |
FILE *dfp; |
144 |
float col[3]; |
145 |
int i; |
146 |
|
147 |
if (il->flags & IL_COLDST) { |
148 |
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
149 |
il->matname, DSTSUF); |
150 |
printf("\n9 s_red s_grn s_blu"); |
151 |
for (i = 0; i < 3; i++) { |
152 |
dfp = dfopen(il, DATORD[i]); |
153 |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
154 |
1.-1./n, -1.+1./n, n, |
155 |
0., 2.*PI, m+1); |
156 |
colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); |
157 |
fclose(dfp); |
158 |
printf(" %s", dfname(il, DATORD[i])); |
159 |
} |
160 |
} else { |
161 |
printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, |
162 |
il->matname, DSTSUF); |
163 |
printf("\n5 s_gry"); |
164 |
dfp = dfopen(il, 0); |
165 |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.-1./n, -1.+1./n, n, |
166 |
0., 2.*PI, m+1); |
167 |
brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); |
168 |
fclose(dfp); |
169 |
printf(" %s", dfname(il, 0)); |
170 |
} |
171 |
printf("\n\t%s il_alt il_azi", FNCFNM); |
172 |
printf("\n0\n7\n"); |
173 |
compavg(col, da, m, il->nsamps); /* north pole */ |
174 |
printf("\t%f\t%f\t%f\n", col[0]/il->col[0], |
175 |
col[1]/il->col[1], col[2]/il->col[2]); |
176 |
compavg(col, da+(n-1)*m*3, m, il->nsamps); /* south pole */ |
177 |
printf("\t%f\t%f\t%f\n", col[0]/il->col[0], |
178 |
col[1]/il->col[1], col[2]/il->col[2]); |
179 |
printf("\t%f\n", 1.-1./n); |
180 |
il->dfnum++; |
181 |
} |
182 |
|
183 |
|
184 |
illumout(il, ob) /* print illum object */ |
185 |
register struct illum_args *il; |
186 |
OBJREC *ob; |
187 |
{ |
188 |
double cout[3]; |
189 |
|
190 |
if (il->sampdens <= 0) |
191 |
printf("\n%s ", VOIDID); |
192 |
else |
193 |
printf("\n%s%s ", il->matname, DSTSUF); |
194 |
printf("%s %s", ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame, |
195 |
il->matname); |
196 |
if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID)) |
197 |
printf("\n0"); |
198 |
else |
199 |
printf("\n1 %s", il->altmat); |
200 |
if (il->flags & IL_COLAVG) { |
201 |
cout[0] = il->col[0]; |
202 |
cout[1] = il->col[1]; |
203 |
cout[2] = il->col[2]; |
204 |
} else { |
205 |
cout[0] = cout[1] = cout[2] = brt(il->col); |
206 |
} |
207 |
printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]); |
208 |
|
209 |
printobj(il->matname, ob); |
210 |
} |
211 |
|
212 |
|
213 |
compavg(col, da, n, ns) /* compute average for set of data values */ |
214 |
float col[3]; |
215 |
register float *da; |
216 |
int n, ns; |
217 |
{ |
218 |
register int i; |
219 |
|
220 |
col[0] = col[1] = col[2] = 0.; |
221 |
i = n; |
222 |
while (i-- > 0) { |
223 |
col[0] += *da++; |
224 |
col[1] += *da++; |
225 |
col[2] += *da++; |
226 |
} |
227 |
for (i = 0; i < 3; i++) |
228 |
col[i] /= (double)(n*ns); |
229 |
} |
230 |
|
231 |
|
232 |
average(il, da, n) /* evaluate average value for distribution */ |
233 |
register struct illum_args *il; |
234 |
float *da; |
235 |
int n; |
236 |
{ |
237 |
compavg(il->col, da, n, il->nsamps); |
238 |
/* brighter than minimum? */ |
239 |
return(brt(il->col) > il->minbrt+FTINY); |
240 |
} |
241 |
|
242 |
|
243 |
static int colmcnt = 0; /* count of columns written */ |
244 |
|
245 |
fputnum(d, fp) /* put out a number to fp */ |
246 |
double d; |
247 |
FILE *fp; |
248 |
{ |
249 |
if (colmcnt++ % 6 == 0) |
250 |
putc('\n', fp); |
251 |
fprintf(fp, " %11e", d); |
252 |
} |
253 |
|
254 |
|
255 |
fputeol(fp) /* write end of line to fp */ |
256 |
register FILE *fp; |
257 |
{ |
258 |
putc('\n', fp); |
259 |
colmcnt = 0; |
260 |
} |
261 |
|
262 |
|
263 |
colorout(p, da, n, m, mult, fp) /* put out color distribution data */ |
264 |
int p; |
265 |
register float *da; |
266 |
int n, m; |
267 |
double mult; |
268 |
FILE *fp; |
269 |
{ |
270 |
register int i, j; |
271 |
|
272 |
for (i = 0; i < n; i++) { |
273 |
for (j = 0; j < m; j++) { |
274 |
fputnum(mult*da[p], fp); |
275 |
da += 3; |
276 |
} |
277 |
fputnum(mult*da[p-3*m], fp); /* wrap phi */ |
278 |
} |
279 |
fputeol(fp); |
280 |
} |
281 |
|
282 |
|
283 |
brightout(da, n, m, mult, fp) /* put out brightness distribution data */ |
284 |
register float *da; |
285 |
int n, m; |
286 |
double mult; |
287 |
FILE *fp; |
288 |
{ |
289 |
register int i, j; |
290 |
|
291 |
for (i = 0; i < n; i++) { |
292 |
for (j = 0; j < m; j++) { |
293 |
fputnum(mult*brt(da), fp); |
294 |
da += 3; |
295 |
} |
296 |
fputnum(mult*brt(da-3*m), fp); /* wrap phi */ |
297 |
} |
298 |
fputeol(fp); |
299 |
} |