1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Routines to print mkillum objects |
6 |
|
*/ |
7 |
|
|
8 |
|
#include "mkillum.h" |
9 |
+ |
#include "paths.h" |
10 |
|
|
13 |
– |
#define brt(col) (.263*(col)[0]+.655*(col)[1]+.082*(col)[2]) |
14 |
– |
|
11 |
|
char DATORD[] = "RGB"; /* data ordering */ |
12 |
|
char DATSUF[] = ".dat"; /* data file suffix */ |
13 |
|
char DSTSUF[] = ".dist"; /* distribution suffix */ |
14 |
|
char FNCFNM[] = "illum.cal"; /* function file name */ |
15 |
|
|
16 |
+ |
static void compinv(COLORV *rinv, COLORV *rp, int m); |
17 |
+ |
static void colorout(int p, COLORV *da, int n, int m, double mult, FILE *fp); |
18 |
+ |
static void fputnum(double d, FILE *fp); |
19 |
+ |
static void brightout(COLORV *da, int n, int m, double mult, FILE *fp); |
20 |
+ |
static void fputeol(FILE *fp); |
21 |
+ |
static void compavg(COLOR col, COLORV *da, int n); |
22 |
+ |
static char * dfname(struct illum_args *il, int c); |
23 |
+ |
static FILE * dfopen(struct illum_args *il, int c); |
24 |
|
|
25 |
< |
printobj(mod, obj) /* print out an object */ |
26 |
< |
char *mod; |
27 |
< |
register OBJREC *obj; |
25 |
> |
|
26 |
> |
void |
27 |
> |
printobj( /* print out an object */ |
28 |
> |
char *mod, |
29 |
> |
OBJREC *obj |
30 |
> |
) |
31 |
|
{ |
32 |
< |
register int i; |
32 |
> |
int i; |
33 |
|
|
34 |
+ |
if (issurface(obj->otype) && !strcmp(mod, VOIDID)) |
35 |
+ |
return; /* don't print void surfaces */ |
36 |
|
printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname); |
37 |
|
printf("\n%d", obj->oargs.nsargs); |
38 |
|
for (i = 0; i < obj->oargs.nsargs; i++) |
55 |
|
|
56 |
|
|
57 |
|
char * |
58 |
< |
dfname(il, c) /* return data file name */ |
59 |
< |
struct illum_args *il; |
60 |
< |
int c; |
58 |
> |
dfname( /* return data file name */ |
59 |
> |
struct illum_args *il, |
60 |
> |
int c |
61 |
> |
) |
62 |
|
{ |
53 |
– |
extern char *getpath(), *strcpy(); |
63 |
|
char fname[MAXSTR]; |
64 |
< |
register char *s; |
64 |
> |
char *s; |
65 |
|
|
66 |
|
s = strcpy(fname, il->datafile); |
67 |
|
s += strlen(s); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
< |
FILE * |
79 |
< |
dfopen(il, c) /* open data file */ |
80 |
< |
register struct illum_args *il; |
81 |
< |
int c; |
78 |
> |
static FILE * |
79 |
> |
dfopen( /* open data file */ |
80 |
> |
struct illum_args *il, |
81 |
> |
int c |
82 |
> |
) |
83 |
|
{ |
84 |
|
char *fn; |
85 |
|
FILE *fp; |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
< |
flatout(il, da, n, m, u, v, w) /* write hemispherical distribution */ |
101 |
< |
struct illum_args *il; |
102 |
< |
float *da; |
103 |
< |
int n, m; |
104 |
< |
FVECT u, v, w; |
100 |
> |
void |
101 |
> |
flatout( /* write hemispherical distribution */ |
102 |
> |
struct illum_args *il, |
103 |
> |
COLORV *da, |
104 |
> |
int n, |
105 |
> |
int m, |
106 |
> |
FVECT u, |
107 |
> |
FVECT v, |
108 |
> |
FVECT w |
109 |
> |
) |
110 |
|
{ |
111 |
+ |
COLORV *Ninv; |
112 |
|
FILE *dfp; |
113 |
|
int i; |
114 |
|
|
115 |
+ |
if ((Ninv = (COLORV *)malloc(3*m*sizeof(COLORV))) == NULL) |
116 |
+ |
error(SYSTEM, "out of memory in flatout"); |
117 |
+ |
compinv(Ninv, da, m); |
118 |
|
if (il->flags & IL_COLDST) { |
119 |
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
120 |
|
il->matname, DSTSUF); |
122 |
|
for (i = 0; i < 3; i++) { |
123 |
|
dfp = dfopen(il, DATORD[i]); |
124 |
|
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
125 |
< |
1.-.5/n, .5/n, n, |
125 |
> |
1.+.5/n, .5/n, n+1, |
126 |
|
0., 2.*PI, m+1); |
127 |
+ |
colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp); |
128 |
|
colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); |
129 |
+ |
fputeol(dfp); |
130 |
|
fclose(dfp); |
131 |
|
printf(" %s", dfname(il, DATORD[i])); |
132 |
|
} |
135 |
|
il->matname, DSTSUF); |
136 |
|
printf("\n5 noneg"); |
137 |
|
dfp = dfopen(il, 0); |
138 |
< |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.-.5/n, .5/n, n, |
138 |
> |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
139 |
> |
1.+.5/n, .5/n, n+1, |
140 |
|
0., 2.*PI, m+1); |
141 |
< |
brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); |
141 |
> |
brightout(Ninv, 1, m, 1./il->nsamps/bright(il->col), dfp); |
142 |
> |
brightout(da, n, m, 1./il->nsamps/bright(il->col), dfp); |
143 |
> |
fputeol(dfp); |
144 |
|
fclose(dfp); |
145 |
|
printf(" %s", dfname(il, 0)); |
146 |
|
} |
150 |
|
printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]); |
151 |
|
printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]); |
152 |
|
il->dfnum++; |
153 |
+ |
free(Ninv); |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
< |
roundout(il, da, n, m) /* write spherical distribution */ |
158 |
< |
struct illum_args *il; |
159 |
< |
float *da; |
160 |
< |
int n, m; |
157 |
> |
void |
158 |
> |
roundout( /* write spherical distribution */ |
159 |
> |
struct illum_args *il, |
160 |
> |
COLORV *da, |
161 |
> |
int n, |
162 |
> |
int m |
163 |
> |
) |
164 |
|
{ |
165 |
+ |
COLORV *Ninv, *Sinv; |
166 |
|
FILE *dfp; |
167 |
|
int i; |
168 |
|
|
169 |
+ |
if ((Ninv = (COLORV *)malloc(3*m*sizeof(COLORV))) == NULL || |
170 |
+ |
(Sinv = (COLORV *)malloc(3*m*sizeof(COLORV))) == NULL) |
171 |
+ |
error(SYSTEM, "out of memory in roundout"); |
172 |
+ |
compinv(Ninv, da, m); |
173 |
+ |
compinv(Sinv, da+3*m*(n-1), m); |
174 |
|
if (il->flags & IL_COLDST) { |
175 |
|
printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame, |
176 |
|
il->matname, DSTSUF); |
178 |
|
for (i = 0; i < 3; i++) { |
179 |
|
dfp = dfopen(il, DATORD[i]); |
180 |
|
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
181 |
< |
1.-1./n, -1.+1./n, n, |
181 |
> |
1.+1./n, -1.-1./n, n+2, |
182 |
|
0., 2.*PI, m+1); |
183 |
+ |
colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp); |
184 |
|
colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp); |
185 |
+ |
colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp); |
186 |
+ |
fputeol(dfp); |
187 |
|
fclose(dfp); |
188 |
|
printf(" %s", dfname(il, DATORD[i])); |
189 |
|
} |
192 |
|
il->matname, DSTSUF); |
193 |
|
printf("\n5 noneg"); |
194 |
|
dfp = dfopen(il, 0); |
195 |
< |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.-1./n, -1.+1./n, n, |
195 |
> |
fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", |
196 |
> |
1.+1./n, -1.-1./n, n+2, |
197 |
|
0., 2.*PI, m+1); |
198 |
< |
brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp); |
198 |
> |
brightout(Ninv, 1, m, 1./il->nsamps/bright(il->col), dfp); |
199 |
> |
brightout(da, n, m, 1./il->nsamps/bright(il->col), dfp); |
200 |
> |
brightout(Sinv, 1, m, 1./il->nsamps/bright(il->col), dfp); |
201 |
> |
fputeol(dfp); |
202 |
|
fclose(dfp); |
203 |
|
printf(" %s", dfname(il, 0)); |
204 |
|
} |
205 |
|
printf("\n\t%s il_alt il_azi", FNCFNM); |
206 |
|
printf("\n0\n0\n"); |
207 |
|
il->dfnum++; |
208 |
+ |
free(Ninv); |
209 |
+ |
free(Sinv); |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
< |
illumout(il, ob) /* print illum object */ |
214 |
< |
register struct illum_args *il; |
215 |
< |
OBJREC *ob; |
213 |
> |
void |
214 |
> |
illumout( /* print illum object */ |
215 |
> |
struct illum_args *il, |
216 |
> |
OBJREC *ob |
217 |
> |
) |
218 |
|
{ |
219 |
|
double cout[3]; |
220 |
|
|
233 |
|
cout[1] = il->col[1]; |
234 |
|
cout[2] = il->col[2]; |
235 |
|
} else { |
236 |
< |
cout[0] = cout[1] = cout[2] = brt(il->col); |
236 |
> |
cout[0] = cout[1] = cout[2] = bright(il->col); |
237 |
|
} |
238 |
|
printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]); |
239 |
|
|
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
< |
average(il, da, n) /* compute average value for distribution */ |
245 |
< |
register struct illum_args *il; |
246 |
< |
register float *da; |
247 |
< |
int n; |
244 |
> |
static void |
245 |
> |
compavg( /* compute average for set of data values */ |
246 |
> |
COLOR col, |
247 |
> |
COLORV *da, |
248 |
> |
int n |
249 |
> |
) |
250 |
|
{ |
251 |
< |
register int i; |
251 |
> |
int i; |
252 |
|
|
253 |
< |
il->col[0] = il->col[1] = il->col[2] = 0.; |
253 |
> |
setcolor(col, 0.0, 0.0, 0.0); |
254 |
|
i = n; |
255 |
|
while (i-- > 0) { |
256 |
< |
il->col[0] += *da++; |
257 |
< |
il->col[1] += *da++; |
211 |
< |
il->col[2] += *da++; |
256 |
> |
addcolor(col, da); |
257 |
> |
da += 3; |
258 |
|
} |
259 |
< |
for (i = 0; i < 3; i++) |
260 |
< |
il->col[i] /= (double)n*il->nsamps; |
259 |
> |
scalecolor(col, 1./(double)n); |
260 |
> |
} |
261 |
|
|
262 |
< |
return(brt(il->col) > il->minbrt+FTINY); |
262 |
> |
|
263 |
> |
static void |
264 |
> |
compinv( /* compute other side of row average */ |
265 |
> |
COLORV *rinv, |
266 |
> |
COLORV *rp, |
267 |
> |
int m |
268 |
> |
) |
269 |
> |
{ |
270 |
> |
COLOR avg; |
271 |
> |
|
272 |
> |
compavg(avg, rp, m); /* row average */ |
273 |
> |
while (m-- > 0) { |
274 |
> |
*rinv++ = 2.*avg[0] - *rp++; |
275 |
> |
*rinv++ = 2.*avg[1] - *rp++; |
276 |
> |
*rinv++ = 2.*avg[2] - *rp++; |
277 |
> |
} |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
+ |
int |
282 |
+ |
average( /* evaluate average value for distribution */ |
283 |
+ |
struct illum_args *il, |
284 |
+ |
COLORV *da, |
285 |
+ |
int n |
286 |
+ |
) |
287 |
+ |
{ |
288 |
+ |
compavg(il->col, da, n); /* average */ |
289 |
+ |
if (il->nsamps > 1) { |
290 |
+ |
il->col[0] /= (double)il->nsamps; |
291 |
+ |
il->col[1] /= (double)il->nsamps; |
292 |
+ |
il->col[2] /= (double)il->nsamps; |
293 |
+ |
} |
294 |
+ |
/* brighter than minimum? */ |
295 |
+ |
return(bright(il->col) > il->minbrt+FTINY); |
296 |
+ |
} |
297 |
+ |
|
298 |
+ |
|
299 |
|
static int colmcnt = 0; /* count of columns written */ |
300 |
|
|
301 |
< |
fputnum(d, fp) /* put out a number to fp */ |
302 |
< |
double d; |
303 |
< |
FILE *fp; |
301 |
> |
static void |
302 |
> |
fputnum( /* put out a number to fp */ |
303 |
> |
double d, |
304 |
> |
FILE *fp |
305 |
> |
) |
306 |
|
{ |
307 |
< |
if (colmcnt++ % 6 == 0) |
307 |
> |
if (colmcnt++ % 5 == 0) |
308 |
|
putc('\n', fp); |
309 |
|
fprintf(fp, " %11e", d); |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
< |
fputeol(fp) /* write end of line to fp */ |
314 |
< |
register FILE *fp; |
313 |
> |
static void |
314 |
> |
fputeol( /* write end of line to fp */ |
315 |
> |
FILE *fp |
316 |
> |
) |
317 |
|
{ |
318 |
|
putc('\n', fp); |
319 |
|
colmcnt = 0; |
320 |
|
} |
321 |
|
|
322 |
|
|
323 |
< |
colorout(p, da, n, m, mult, fp) /* put out color distribution data */ |
324 |
< |
int p; |
325 |
< |
register float *da; |
326 |
< |
int n, m; |
327 |
< |
double mult; |
328 |
< |
FILE *fp; |
323 |
> |
static void |
324 |
> |
colorout( /* put out color distribution data */ |
325 |
> |
int p, |
326 |
> |
COLORV *da, |
327 |
> |
int n, |
328 |
> |
int m, |
329 |
> |
double mult, |
330 |
> |
FILE *fp |
331 |
> |
) |
332 |
|
{ |
333 |
< |
register int i, j; |
333 |
> |
int i, j; |
334 |
|
|
335 |
|
for (i = 0; i < n; i++) { |
336 |
|
for (j = 0; j < m; j++) { |
339 |
|
} |
340 |
|
fputnum(mult*da[p-3*m], fp); /* wrap phi */ |
341 |
|
} |
256 |
– |
fputeol(fp); |
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
< |
brightout(da, n, m, mult, fp) /* put out brightness distribution data */ |
346 |
< |
register float *da; |
347 |
< |
int n, m; |
348 |
< |
double mult; |
349 |
< |
FILE *fp; |
345 |
> |
static void |
346 |
> |
brightout( /* put out brightness distribution data */ |
347 |
> |
COLORV *da, |
348 |
> |
int n, |
349 |
> |
int m, |
350 |
> |
double mult, |
351 |
> |
FILE *fp |
352 |
> |
) |
353 |
|
{ |
354 |
< |
register int i, j; |
354 |
> |
int i, j; |
355 |
|
|
356 |
|
for (i = 0; i < n; i++) { |
357 |
|
for (j = 0; j < m; j++) { |
358 |
< |
fputnum(mult*brt(da), fp); |
358 |
> |
fputnum(mult*bright(da), fp); |
359 |
|
da += 3; |
360 |
|
} |
361 |
< |
fputnum(mult*brt(da-3*m), fp); /* wrap phi */ |
361 |
> |
fputnum(mult*bright(da-3*m), fp); /* wrap phi */ |
362 |
|
} |
275 |
– |
fputeol(fp); |
363 |
|
} |