ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
Revision: 2.7
Committed: Sat Feb 22 02:07:24 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.6: +4 -7 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * Routines to print mkillum objects
6 */
7
8 #include "mkillum.h"
9
10 #define brt(col) (.263*(col)[0]+.655*(col)[1]+.082*(col)[2])
11
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 if (issurface(obj->otype) && !strcmp(mod, VOIDID))
25 return; /* don't print void surfaces */
26 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 float *Ninv;
96 FILE *dfp;
97 int i;
98
99 if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL)
100 error(SYSTEM, "out of memory in flatout");
101 compinv(Ninv, da, m);
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 red green blue");
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+1,
110 0., 2.*PI, m+1);
111 colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
112 colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
113 fputeol(dfp);
114 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 printf("\n5 noneg");
121 dfp = dfopen(il, 0);
122 fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
123 1.+.5/n, .5/n, n+1,
124 0., 2.*PI, m+1);
125 brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
126 brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
127 fputeol(dfp);
128 fclose(dfp);
129 printf(" %s", dfname(il, 0));
130 }
131 printf("\n\t%s il_alth il_azih", FNCFNM);
132 printf("\n0\n9\n");
133 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 free((void *)Ninv);
138 }
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 float *Ninv, *Sinv;
147 FILE *dfp;
148 int i;
149
150 if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL ||
151 (Sinv = (float *)malloc(3*m*sizeof(float))) == NULL)
152 error(SYSTEM, "out of memory in roundout");
153 compinv(Ninv, da, m);
154 compinv(Sinv, da+3*m*(n-1), m);
155 if (il->flags & IL_COLDST) {
156 printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
157 il->matname, DSTSUF);
158 printf("\n9 red green blue");
159 for (i = 0; i < 3; i++) {
160 dfp = dfopen(il, DATORD[i]);
161 fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
162 1.+1./n, -1.-1./n, n+2,
163 0., 2.*PI, m+1);
164 colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
165 colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
166 colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp);
167 fputeol(dfp);
168 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 printf("\n5 noneg");
175 dfp = dfopen(il, 0);
176 fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
177 1.+1./n, -1.-1./n, n+2,
178 0., 2.*PI, m+1);
179 brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
180 brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
181 brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp);
182 fputeol(dfp);
183 fclose(dfp);
184 printf(" %s", dfname(il, 0));
185 }
186 printf("\n\t%s il_alt il_azi", FNCFNM);
187 printf("\n0\n0\n");
188 il->dfnum++;
189 free((void *)Ninv);
190 free((void *)Sinv);
191 }
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 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 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 printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]);
218
219 printobj(il->matname, ob);
220 }
221
222
223 compavg(col, da, n) /* compute average for set of data values */
224 float col[3];
225 register float *da;
226 int n;
227 {
228 register int i;
229
230 col[0] = col[1] = col[2] = 0.;
231 i = n;
232 while (i-- > 0) {
233 col[0] += *da++;
234 col[1] += *da++;
235 col[2] += *da++;
236 }
237 for (i = 0; i < 3; i++)
238 col[i] /= (double)n;
239 }
240
241
242 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 average(il, da, n) /* evaluate average value for distribution */
258 register struct illum_args *il;
259 float *da;
260 int n;
261 {
262 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 /* brighter than minimum? */
269 return(brt(il->col) > il->minbrt+FTINY);
270 }
271
272
273 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 if (colmcnt++ % 5 == 0)
280 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 int p;
295 register float *da;
296 int n, m;
297 double mult;
298 FILE *fp;
299 {
300 register int i, j;
301
302 for (i = 0; i < n; i++) {
303 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 }
309 }
310
311
312 brightout(da, n, m, mult, fp) /* put out brightness distribution data */
313 register float *da;
314 int n, m;
315 double mult;
316 FILE *fp;
317 {
318 register int i, j;
319
320 for (i = 0; i < n; i++) {
321 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 }
327 }