1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.10 |
static const char RCSid[] = "$Id$"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Routines to print mkillum objects |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#include "mkillum.h" |
9 |
|
|
|
10 |
greg |
1.7 |
#define brt(col) (.263*(col)[0]+.655*(col)[1]+.082*(col)[2]) |
11 |
greg |
1.1 |
|
12 |
|
|
char DATORD[] = "RGB"; /* data ordering */ |
13 |
|
|
char DATSUF[] = ".dat"; /* data file suffix */ |
14 |
|
|
char DSTSUF[] = ".dist"; /* distribution suffix */ |
15 |
|
|
char FNCFNM[] = "illum.cal"; /* function file name */ |
16 |
|
|
|
17 |
schorsch |
2.9 |
void compinv(float *rinv, float *rp, int m); |
18 |
|
|
void colorout(int p, float *da, int n, int m, double mult, FILE *fp); |
19 |
|
|
void fputnum(double d, FILE *fp); |
20 |
|
|
void brightout(float *da, int n, int m, double mult, FILE *fp); |
21 |
|
|
void fputeol(FILE *fp); |
22 |
|
|
void compavg(float col[3], float *da, int n); |
23 |
|
|
char * dfname(struct illum_args *il, int c); |
24 |
|
|
FILE * dfopen(struct illum_args *il, int c); |
25 |
greg |
1.1 |
|
26 |
schorsch |
2.9 |
|
27 |
|
|
void |
28 |
|
|
printobj( /* print out an object */ |
29 |
|
|
char *mod, |
30 |
|
|
register OBJREC *obj |
31 |
|
|
) |
32 |
greg |
1.1 |
{ |
33 |
|
|
register int i; |
34 |
|
|
|
35 |
greg |
2.3 |
if (issurface(obj->otype) && !strcmp(mod, VOIDID)) |
36 |
|
|
return; /* don't print void surfaces */ |
37 |
greg |
1.1 |
printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname); |
38 |
|
|
printf("\n%d", obj->oargs.nsargs); |
39 |
|
|
for (i = 0; i < obj->oargs.nsargs; i++) |
40 |
|
|
printf(" %s", obj->oargs.sarg[i]); |
41 |
|
|
#ifdef IARGS |
42 |
|
|
printf("\n%d", obj->oargs.niargs); |
43 |
|
|
for (i = 0; i < obj->oargs.niargs; i++) |
44 |
|
|
printf(" %d", obj->oargs.iarg[i]); |
45 |
|
|
#else |
46 |
|
|
printf("\n0"); |
47 |
|
|
#endif |
48 |
|
|
printf("\n%d", obj->oargs.nfargs); |
49 |
|
|
for (i = 0; i < obj->oargs.nfargs; i++) { |
50 |
|
|
if (i%3 == 0) |
51 |
|
|
putchar('\n'); |
52 |
|
|
printf(" %18.12g", obj->oargs.farg[i]); |
53 |
|
|
} |
54 |
|
|
putchar('\n'); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
|
58 |
|
|
char * |
59 |
schorsch |
2.9 |
dfname( /* return data file name */ |
60 |
|
|
struct illum_args *il, |
61 |
|
|
int c |
62 |
|
|
) |
63 |
greg |
1.1 |
{ |
64 |
|
|
char fname[MAXSTR]; |
65 |
|
|
register char *s; |
66 |
|
|
|
67 |
|
|
s = strcpy(fname, il->datafile); |
68 |
|
|
s += strlen(s); |
69 |
|
|
if (c) *s++ = c; |
70 |
|
|
if (il->dfnum > 0) { |
71 |
|
|
sprintf(s, "%d", il->dfnum); |
72 |
|
|
s += strlen(s); |
73 |
|
|
} |
74 |
|
|
strcpy(s, DATSUF); |
75 |
|
|
return(getpath(fname, NULL, 0)); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
FILE * |
80 |
schorsch |
2.9 |
dfopen( /* open data file */ |
81 |
|
|
register struct illum_args *il, |
82 |
|
|
int c |
83 |
|
|
) |
84 |
greg |
1.1 |
{ |
85 |
|
|
char *fn; |
86 |
|
|
FILE *fp; |
87 |
|
|
/* get a usable file name */ |
88 |
|
|
for (fn = dfname(il, c); |
89 |
|
|
!(il->flags & IL_DATCLB) && access(fn, F_OK) == 0; |
90 |
|
|
fn = dfname(il, c)) |
91 |
|
|
il->dfnum++; |
92 |
|
|
/* open it for writing */ |
93 |
|
|
if ((fp = fopen(fn, "w")) == NULL) { |
94 |
|
|
sprintf(errmsg, "cannot open data file \"%s\"", fn); |
95 |
|
|
error(SYSTEM, errmsg); |
96 |
|
|
} |
97 |
|
|
return(fp); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
|
101 |
schorsch |
2.9 |
extern void |
102 |
|
|
flatout( /* write hemispherical distribution */ |
103 |
|
|
struct illum_args *il, |
104 |
|
|
float *da, |
105 |
|
|
int n, |
106 |
|
|
int m, |
107 |
|
|
FVECT u, |
108 |
|
|
FVECT v, |
109 |
|
|
FVECT w |
110 |
|
|
) |
111 |
greg |
1.1 |
{ |
112 |
greg |
2.5 |
float *Ninv; |
113 |
greg |
1.1 |
FILE *dfp; |
114 |
|
|
int i; |
115 |
|
|
|
116 |
greg |
2.5 |
if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL) |
117 |
|
|
error(SYSTEM, "out of memory in flatout"); |
118 |
|
|
compinv(Ninv, da, m); |
119 |
greg |
1.1 |
if (il->flags & IL_COLDST) { |
120 |
|
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
121 |
|
|
il->matname, DSTSUF); |
122 |
greg |
2.5 |
printf("\n9 red green blue"); |
123 |
greg |
1.1 |
for (i = 0; i < 3; i++) { |
124 |
|
|
dfp = dfopen(il, DATORD[i]); |
125 |
greg |
1.6 |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
126 |
greg |
2.5 |
1.+.5/n, .5/n, n+1, |
127 |
greg |
1.6 |
0., 2.*PI, m+1); |
128 |
greg |
2.5 |
colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp); |
129 |
greg |
1.6 |
colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); |
130 |
greg |
2.5 |
fputeol(dfp); |
131 |
greg |
1.1 |
fclose(dfp); |
132 |
|
|
printf(" %s", dfname(il, DATORD[i])); |
133 |
|
|
} |
134 |
|
|
} else { |
135 |
|
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, |
136 |
|
|
il->matname, DSTSUF); |
137 |
greg |
2.5 |
printf("\n5 noneg"); |
138 |
greg |
1.1 |
dfp = dfopen(il, 0); |
139 |
greg |
2.6 |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
140 |
|
|
1.+.5/n, .5/n, n+1, |
141 |
greg |
1.6 |
0., 2.*PI, m+1); |
142 |
greg |
2.5 |
brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp); |
143 |
greg |
1.6 |
brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); |
144 |
greg |
2.5 |
fputeol(dfp); |
145 |
greg |
1.1 |
fclose(dfp); |
146 |
|
|
printf(" %s", dfname(il, 0)); |
147 |
|
|
} |
148 |
|
|
printf("\n\t%s il_alth il_azih", FNCFNM); |
149 |
greg |
2.5 |
printf("\n0\n9\n"); |
150 |
greg |
1.1 |
printf("\t%f\t%f\t%f\n", u[0], u[1], u[2]); |
151 |
|
|
printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]); |
152 |
|
|
printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]); |
153 |
|
|
il->dfnum++; |
154 |
greg |
2.7 |
free((void *)Ninv); |
155 |
greg |
1.1 |
} |
156 |
|
|
|
157 |
|
|
|
158 |
schorsch |
2.9 |
extern void |
159 |
|
|
roundout( /* write spherical distribution */ |
160 |
|
|
struct illum_args *il, |
161 |
|
|
float *da, |
162 |
|
|
int n, |
163 |
|
|
int m |
164 |
|
|
) |
165 |
greg |
1.1 |
{ |
166 |
greg |
2.5 |
float *Ninv, *Sinv; |
167 |
greg |
1.1 |
FILE *dfp; |
168 |
|
|
int i; |
169 |
|
|
|
170 |
greg |
2.5 |
if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL || |
171 |
|
|
(Sinv = (float *)malloc(3*m*sizeof(float))) == NULL) |
172 |
greg |
2.6 |
error(SYSTEM, "out of memory in roundout"); |
173 |
greg |
2.5 |
compinv(Ninv, da, m); |
174 |
|
|
compinv(Sinv, da+3*m*(n-1), m); |
175 |
greg |
1.1 |
if (il->flags & IL_COLDST) { |
176 |
|
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
177 |
|
|
il->matname, DSTSUF); |
178 |
greg |
2.5 |
printf("\n9 red green blue"); |
179 |
greg |
1.1 |
for (i = 0; i < 3; i++) { |
180 |
|
|
dfp = dfopen(il, DATORD[i]); |
181 |
greg |
1.6 |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
182 |
greg |
2.5 |
1.+1./n, -1.-1./n, n+2, |
183 |
greg |
1.6 |
0., 2.*PI, m+1); |
184 |
greg |
2.5 |
colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp); |
185 |
greg |
1.6 |
colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); |
186 |
greg |
2.5 |
colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp); |
187 |
|
|
fputeol(dfp); |
188 |
greg |
1.1 |
fclose(dfp); |
189 |
|
|
printf(" %s", dfname(il, DATORD[i])); |
190 |
|
|
} |
191 |
|
|
} else { |
192 |
|
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame, |
193 |
|
|
il->matname, DSTSUF); |
194 |
greg |
2.5 |
printf("\n5 noneg"); |
195 |
greg |
1.1 |
dfp = dfopen(il, 0); |
196 |
greg |
2.6 |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
197 |
|
|
1.+1./n, -1.-1./n, n+2, |
198 |
greg |
1.6 |
0., 2.*PI, m+1); |
199 |
greg |
2.5 |
brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp); |
200 |
greg |
1.6 |
brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); |
201 |
greg |
2.5 |
brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp); |
202 |
|
|
fputeol(dfp); |
203 |
greg |
1.1 |
fclose(dfp); |
204 |
|
|
printf(" %s", dfname(il, 0)); |
205 |
|
|
} |
206 |
|
|
printf("\n\t%s il_alt il_azi", FNCFNM); |
207 |
greg |
2.5 |
printf("\n0\n0\n"); |
208 |
greg |
1.1 |
il->dfnum++; |
209 |
greg |
2.7 |
free((void *)Ninv); |
210 |
|
|
free((void *)Sinv); |
211 |
greg |
1.2 |
} |
212 |
|
|
|
213 |
|
|
|
214 |
schorsch |
2.9 |
extern void |
215 |
|
|
illumout( /* print illum object */ |
216 |
|
|
register struct illum_args *il, |
217 |
|
|
OBJREC *ob |
218 |
|
|
) |
219 |
greg |
1.2 |
{ |
220 |
|
|
double cout[3]; |
221 |
|
|
|
222 |
greg |
1.4 |
if (il->sampdens <= 0) |
223 |
|
|
printf("\n%s ", VOIDID); |
224 |
|
|
else |
225 |
|
|
printf("\n%s%s ", il->matname, DSTSUF); |
226 |
|
|
printf("%s %s", ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame, |
227 |
greg |
1.2 |
il->matname); |
228 |
|
|
if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID)) |
229 |
|
|
printf("\n0"); |
230 |
|
|
else |
231 |
|
|
printf("\n1 %s", il->altmat); |
232 |
|
|
if (il->flags & IL_COLAVG) { |
233 |
|
|
cout[0] = il->col[0]; |
234 |
|
|
cout[1] = il->col[1]; |
235 |
|
|
cout[2] = il->col[2]; |
236 |
|
|
} else { |
237 |
|
|
cout[0] = cout[1] = cout[2] = brt(il->col); |
238 |
|
|
} |
239 |
greg |
1.3 |
printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]); |
240 |
greg |
1.2 |
|
241 |
|
|
printobj(il->matname, ob); |
242 |
greg |
1.1 |
} |
243 |
|
|
|
244 |
|
|
|
245 |
schorsch |
2.9 |
void |
246 |
|
|
compavg( /* compute average for set of data values */ |
247 |
|
|
float col[3], |
248 |
|
|
register float *da, |
249 |
|
|
int n |
250 |
|
|
) |
251 |
greg |
1.1 |
{ |
252 |
|
|
register int i; |
253 |
|
|
|
254 |
greg |
2.4 |
col[0] = col[1] = col[2] = 0.; |
255 |
greg |
1.1 |
i = n; |
256 |
|
|
while (i-- > 0) { |
257 |
greg |
2.4 |
col[0] += *da++; |
258 |
|
|
col[1] += *da++; |
259 |
|
|
col[2] += *da++; |
260 |
greg |
1.1 |
} |
261 |
|
|
for (i = 0; i < 3; i++) |
262 |
greg |
2.5 |
col[i] /= (double)n; |
263 |
greg |
2.4 |
} |
264 |
greg |
1.5 |
|
265 |
greg |
2.4 |
|
266 |
schorsch |
2.9 |
void |
267 |
|
|
compinv( /* compute other side of row average */ |
268 |
|
|
register float *rinv, |
269 |
|
|
register float *rp, |
270 |
|
|
int m |
271 |
|
|
) |
272 |
greg |
2.5 |
{ |
273 |
|
|
float avg[3]; |
274 |
|
|
|
275 |
|
|
compavg(avg, rp, m); /* row average */ |
276 |
|
|
while (m-- > 0) { |
277 |
|
|
*rinv++ = 2.*avg[0] - *rp++; |
278 |
|
|
*rinv++ = 2.*avg[1] - *rp++; |
279 |
|
|
*rinv++ = 2.*avg[2] - *rp++; |
280 |
|
|
} |
281 |
|
|
} |
282 |
|
|
|
283 |
|
|
|
284 |
schorsch |
2.9 |
extern int |
285 |
|
|
average( /* evaluate average value for distribution */ |
286 |
|
|
register struct illum_args *il, |
287 |
|
|
float *da, |
288 |
|
|
int n |
289 |
|
|
) |
290 |
greg |
2.4 |
{ |
291 |
greg |
2.5 |
compavg(il->col, da, n); /* average */ |
292 |
|
|
if (il->nsamps > 1) { |
293 |
|
|
il->col[0] /= (double)il->nsamps; |
294 |
|
|
il->col[1] /= (double)il->nsamps; |
295 |
|
|
il->col[2] /= (double)il->nsamps; |
296 |
|
|
} |
297 |
greg |
2.4 |
/* brighter than minimum? */ |
298 |
greg |
1.6 |
return(brt(il->col) > il->minbrt+FTINY); |
299 |
greg |
1.1 |
} |
300 |
|
|
|
301 |
|
|
|
302 |
greg |
1.6 |
static int colmcnt = 0; /* count of columns written */ |
303 |
|
|
|
304 |
schorsch |
2.9 |
void |
305 |
|
|
fputnum( /* put out a number to fp */ |
306 |
|
|
double d, |
307 |
|
|
FILE *fp |
308 |
|
|
) |
309 |
greg |
1.6 |
{ |
310 |
greg |
2.5 |
if (colmcnt++ % 5 == 0) |
311 |
greg |
1.6 |
putc('\n', fp); |
312 |
|
|
fprintf(fp, " %11e", d); |
313 |
|
|
} |
314 |
|
|
|
315 |
|
|
|
316 |
schorsch |
2.9 |
void |
317 |
|
|
fputeol( /* write end of line to fp */ |
318 |
|
|
register FILE *fp |
319 |
|
|
) |
320 |
greg |
1.6 |
{ |
321 |
|
|
putc('\n', fp); |
322 |
|
|
colmcnt = 0; |
323 |
|
|
} |
324 |
|
|
|
325 |
|
|
|
326 |
schorsch |
2.9 |
void |
327 |
|
|
colorout( /* put out color distribution data */ |
328 |
|
|
int p, |
329 |
|
|
register float *da, |
330 |
|
|
int n, |
331 |
|
|
int m, |
332 |
|
|
double mult, |
333 |
|
|
FILE *fp |
334 |
|
|
) |
335 |
greg |
1.1 |
{ |
336 |
greg |
1.6 |
register int i, j; |
337 |
greg |
1.1 |
|
338 |
|
|
for (i = 0; i < n; i++) { |
339 |
greg |
1.6 |
for (j = 0; j < m; j++) { |
340 |
|
|
fputnum(mult*da[p], fp); |
341 |
|
|
da += 3; |
342 |
|
|
} |
343 |
|
|
fputnum(mult*da[p-3*m], fp); /* wrap phi */ |
344 |
greg |
1.1 |
} |
345 |
|
|
} |
346 |
|
|
|
347 |
|
|
|
348 |
schorsch |
2.9 |
void |
349 |
|
|
brightout( /* put out brightness distribution data */ |
350 |
|
|
register float *da, |
351 |
|
|
int n, |
352 |
|
|
int m, |
353 |
|
|
double mult, |
354 |
|
|
FILE *fp |
355 |
|
|
) |
356 |
greg |
1.1 |
{ |
357 |
greg |
1.6 |
register int i, j; |
358 |
greg |
1.1 |
|
359 |
|
|
for (i = 0; i < n; i++) { |
360 |
greg |
1.6 |
for (j = 0; j < m; j++) { |
361 |
|
|
fputnum(mult*brt(da), fp); |
362 |
|
|
da += 3; |
363 |
|
|
} |
364 |
|
|
fputnum(mult*brt(da-3*m), fp); /* wrap phi */ |
365 |
greg |
1.1 |
} |
366 |
|
|
} |