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