ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
Revision: 2.1
Committed: Tue Nov 12 17:05:08 1991 UTC (32 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.8: +0 -0 lines
Log Message:
updated revision number for release 2.0

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1991 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Routines to print mkillum objects
9     */
10    
11     #include "mkillum.h"
12    
13 greg 1.7 #define brt(col) (.263*(col)[0]+.655*(col)[1]+.082*(col)[2])
14 greg 1.1
15     char DATORD[] = "RGB"; /* data ordering */
16     char DATSUF[] = ".dat"; /* data file suffix */
17     char DSTSUF[] = ".dist"; /* distribution suffix */
18     char FNCFNM[] = "illum.cal"; /* function file name */
19    
20    
21     printobj(mod, obj) /* print out an object */
22     char *mod;
23     register OBJREC *obj;
24     {
25     register int i;
26    
27     printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname);
28     printf("\n%d", obj->oargs.nsargs);
29     for (i = 0; i < obj->oargs.nsargs; i++)
30     printf(" %s", obj->oargs.sarg[i]);
31     #ifdef IARGS
32     printf("\n%d", obj->oargs.niargs);
33     for (i = 0; i < obj->oargs.niargs; i++)
34     printf(" %d", obj->oargs.iarg[i]);
35     #else
36     printf("\n0");
37     #endif
38     printf("\n%d", obj->oargs.nfargs);
39     for (i = 0; i < obj->oargs.nfargs; i++) {
40     if (i%3 == 0)
41     putchar('\n');
42     printf(" %18.12g", obj->oargs.farg[i]);
43     }
44     putchar('\n');
45     }
46    
47    
48     char *
49     dfname(il, c) /* return data file name */
50     struct illum_args *il;
51     int c;
52     {
53     extern char *getpath(), *strcpy();
54     char fname[MAXSTR];
55     register char *s;
56    
57     s = strcpy(fname, il->datafile);
58     s += strlen(s);
59     if (c) *s++ = c;
60     if (il->dfnum > 0) {
61     sprintf(s, "%d", il->dfnum);
62     s += strlen(s);
63     }
64     strcpy(s, DATSUF);
65     return(getpath(fname, NULL, 0));
66     }
67    
68    
69     FILE *
70     dfopen(il, c) /* open data file */
71     register struct illum_args *il;
72     int c;
73     {
74     char *fn;
75     FILE *fp;
76     /* get a usable file name */
77     for (fn = dfname(il, c);
78     !(il->flags & IL_DATCLB) && access(fn, F_OK) == 0;
79     fn = dfname(il, c))
80     il->dfnum++;
81     /* open it for writing */
82     if ((fp = fopen(fn, "w")) == NULL) {
83     sprintf(errmsg, "cannot open data file \"%s\"", fn);
84     error(SYSTEM, errmsg);
85     }
86     return(fp);
87     }
88    
89    
90     flatout(il, da, n, m, u, v, w) /* write hemispherical distribution */
91     struct illum_args *il;
92     float *da;
93     int n, m;
94     FVECT u, v, w;
95     {
96     FILE *dfp;
97     int i;
98    
99     if (il->flags & IL_COLDST) {
100     printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
101     il->matname, DSTSUF);
102     printf("\n9 red green blue");
103     for (i = 0; i < 3; i++) {
104     dfp = dfopen(il, DATORD[i]);
105 greg 1.6 fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
106     1.-.5/n, .5/n, n,
107     0., 2.*PI, m+1);
108     colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
109 greg 1.1 fclose(dfp);
110     printf(" %s", dfname(il, DATORD[i]));
111     }
112     } else {
113     printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
114     il->matname, DSTSUF);
115 greg 1.8 printf("\n5 noneg");
116 greg 1.1 dfp = dfopen(il, 0);
117 greg 1.6 fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.-.5/n, .5/n, n,
118     0., 2.*PI, m+1);
119     brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
120 greg 1.1 fclose(dfp);
121     printf(" %s", dfname(il, 0));
122     }
123     printf("\n\t%s il_alth il_azih", FNCFNM);
124     printf("\n0\n9\n");
125     printf("\t%f\t%f\t%f\n", u[0], u[1], u[2]);
126     printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]);
127     printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]);
128     il->dfnum++;
129     }
130    
131    
132     roundout(il, da, n, m) /* write spherical distribution */
133     struct illum_args *il;
134     float *da;
135     int n, m;
136     {
137     FILE *dfp;
138     int i;
139    
140     if (il->flags & IL_COLDST) {
141     printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
142     il->matname, DSTSUF);
143     printf("\n9 red green blue");
144     for (i = 0; i < 3; i++) {
145     dfp = dfopen(il, DATORD[i]);
146 greg 1.6 fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
147     1.-1./n, -1.+1./n, n,
148     0., 2.*PI, m+1);
149     colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
150 greg 1.1 fclose(dfp);
151     printf(" %s", dfname(il, DATORD[i]));
152     }
153     } else {
154     printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
155     il->matname, DSTSUF);
156 greg 1.8 printf("\n5 noneg");
157 greg 1.1 dfp = dfopen(il, 0);
158 greg 1.6 fprintf(dfp, "2\n%f %f %d\n%f %f %d\n", 1.-1./n, -1.+1./n, n,
159     0., 2.*PI, m+1);
160     brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
161 greg 1.1 fclose(dfp);
162     printf(" %s", dfname(il, 0));
163     }
164     printf("\n\t%s il_alt il_azi", FNCFNM);
165     printf("\n0\n0\n");
166     il->dfnum++;
167 greg 1.2 }
168    
169    
170     illumout(il, ob) /* print illum object */
171     register struct illum_args *il;
172     OBJREC *ob;
173     {
174     double cout[3];
175    
176 greg 1.4 if (il->sampdens <= 0)
177     printf("\n%s ", VOIDID);
178     else
179     printf("\n%s%s ", il->matname, DSTSUF);
180     printf("%s %s", ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
181 greg 1.2 il->matname);
182     if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID))
183     printf("\n0");
184     else
185     printf("\n1 %s", il->altmat);
186     if (il->flags & IL_COLAVG) {
187     cout[0] = il->col[0];
188     cout[1] = il->col[1];
189     cout[2] = il->col[2];
190     } else {
191     cout[0] = cout[1] = cout[2] = brt(il->col);
192     }
193 greg 1.3 printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]);
194 greg 1.2
195     printobj(il->matname, ob);
196 greg 1.1 }
197    
198    
199     average(il, da, n) /* compute average value for distribution */
200     register struct illum_args *il;
201     register float *da;
202     int n;
203     {
204     register int i;
205    
206     il->col[0] = il->col[1] = il->col[2] = 0.;
207     i = n;
208     while (i-- > 0) {
209     il->col[0] += *da++;
210     il->col[1] += *da++;
211     il->col[2] += *da++;
212     }
213     for (i = 0; i < 3; i++)
214     il->col[i] /= (double)n*il->nsamps;
215 greg 1.5
216 greg 1.6 return(brt(il->col) > il->minbrt+FTINY);
217 greg 1.1 }
218    
219    
220 greg 1.6 static int colmcnt = 0; /* count of columns written */
221    
222     fputnum(d, fp) /* put out a number to fp */
223     double d;
224     FILE *fp;
225     {
226     if (colmcnt++ % 6 == 0)
227     putc('\n', fp);
228     fprintf(fp, " %11e", d);
229     }
230    
231    
232     fputeol(fp) /* write end of line to fp */
233     register FILE *fp;
234     {
235     putc('\n', fp);
236     colmcnt = 0;
237     }
238    
239    
240     colorout(p, da, n, m, mult, fp) /* put out color distribution data */
241 greg 1.1 int p;
242     register float *da;
243 greg 1.6 int n, m;
244 greg 1.1 double mult;
245     FILE *fp;
246     {
247 greg 1.6 register int i, j;
248 greg 1.1
249     for (i = 0; i < n; i++) {
250 greg 1.6 for (j = 0; j < m; j++) {
251     fputnum(mult*da[p], fp);
252     da += 3;
253     }
254     fputnum(mult*da[p-3*m], fp); /* wrap phi */
255 greg 1.1 }
256 greg 1.6 fputeol(fp);
257 greg 1.1 }
258    
259    
260 greg 1.6 brightout(da, n, m, mult, fp) /* put out brightness distribution data */
261 greg 1.1 register float *da;
262 greg 1.6 int n, m;
263 greg 1.1 double mult;
264     FILE *fp;
265     {
266 greg 1.6 register int i, j;
267 greg 1.1
268     for (i = 0; i < n; i++) {
269 greg 1.6 for (j = 0; j < m; j++) {
270     fputnum(mult*brt(da), fp);
271     da += 3;
272     }
273     fputnum(mult*brt(da-3*m), fp); /* wrap phi */
274 greg 1.1 }
275 greg 1.6 fputeol(fp);
276 greg 1.1 }