ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
Revision: 2.12
Committed: Thu Sep 13 17:52:35 2007 UTC (16 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R0, rad3R9
Changes since 2.11: +24 -26 lines
Log Message:
Made use of COLORV in place of float more consistent

File Contents

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