ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
Revision: 2.8
Committed: Mon Mar 10 17:26:26 2003 UTC (21 years ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.7: +1 -2 lines
Log Message:
Compile fixes for Linux

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