ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum3.c
(Generate patch)

Comparing ray/src/gen/mkillum3.c (file contents):
Revision 1.1 by greg, Wed Jul 24 16:48:45 1991 UTC vs.
Revision 2.11 by greg, Thu Sep 13 06:31:21 2007 UTC

# Line 1 | Line 1
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  
11 < #define  brt(col)       (.295*(col)[0] + .636*(col)[1] + .070*(col)[2])
11 > #define  brt(col)       (.263*(col)[0]+.655*(col)[1]+.082*(col)[2])
12  
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 + void compinv(float *rinv, float *rp, int m);
19 + void colorout(int p, float *da, int n, int m, double mult, FILE *fp);
20 + void fputnum(double d, FILE *fp);
21 + void brightout(float *da, int n, int m, double mult, FILE *fp);
22 + void fputeol(FILE *fp);
23 + void compavg(float col[3], float *da, int n);
24 + char * dfname(struct illum_args *il, int c);
25 + FILE * dfopen(struct illum_args *il, int c);
26  
27 < printobj(mod, obj)              /* print out an object */
28 < char  *mod;
29 < register OBJREC  *obj;
27 >
28 > void
29 > printobj(               /* print out an object */
30 >        char  *mod,
31 >        register OBJREC  *obj
32 > )
33   {
34          register int  i;
35  
36 +        if (issurface(obj->otype) && !strcmp(mod, VOIDID))
37 +                return;         /* don't print void surfaces */
38          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++)
# Line 46 | Line 57 | register OBJREC  *obj;
57  
58  
59   char *
60 < dfname(il, c)                   /* return data file name */
61 < struct illum_args  *il;
62 < int  c;
60 > dfname(                 /* return data file name */
61 >        struct illum_args  *il,
62 >        int  c
63 > )
64   {
53        extern char  *getpath(), *strcpy();
65          char  fname[MAXSTR];
66          register char  *s;
67  
# Line 67 | Line 78 | int  c;
78  
79  
80   FILE *
81 < dfopen(il, c)                   /* open data file */
82 < register struct illum_args  *il;
83 < int  c;
81 > dfopen(                 /* open data file */
82 >        register struct illum_args  *il,
83 >        int  c
84 > )
85   {
86          char  *fn;
87          FILE  *fp;
# Line 87 | Line 99 | int  c;
99   }
100  
101  
102 < illumout(il, ob)                /* print illum object */
103 < register struct illum_args  *il;
104 < OBJREC  *ob;
102 > extern void
103 > flatout(                /* write hemispherical distribution */
104 >        struct illum_args  *il,
105 >        float  *da,
106 >        int  n,
107 >        int  m,
108 >        FVECT  u,
109 >        FVECT  v,
110 >        FVECT  w
111 > )
112   {
113 <        double  cout[3];
95 <
96 <        printf("\n%s%s %s %s", il->matname, DSTSUF,
97 <                        ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
98 <                        il->matname);
99 <        if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID))
100 <                printf("\n0");
101 <        else
102 <                printf("\n1 %s", il->altmat);
103 <        if (il->flags & IL_COLAVG) {
104 <                cout[0] = il->col[0];
105 <                cout[1] = il->col[1];
106 <                cout[2] = il->col[2];
107 <        } else {
108 <                cout[0] = cout[1] = cout[2] = brt(il->col);
109 <        }
110 <        if (il->flags & IL_LIGHT)
111 <                printf("\n3 %f %f %f\n", cout[0], cout[1], cout[2]);
112 <        else
113 <                printf("\n4 %f %f %f 0\n", cout[0], cout[1], cout[2]);
114 <
115 <        printobj(il->matname, ob);
116 < }
117 <
118 <
119 < flatout(il, da, n, m, u, v, w)          /* write hemispherical distribution */
120 < struct illum_args  *il;
121 < float  *da;
122 < int  n, m;
123 < FVECT  u, v, w;
124 < {
113 >        float  *Ninv;
114          FILE  *dfp;
115          int  i;
116  
117 <        average(il, da, n*m);
117 >        if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL)
118 >                error(SYSTEM, "out of memory in flatout");
119 >        compinv(Ninv, da, m);
120          if (il->flags & IL_COLDST) {
121                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
122                                  il->matname, DSTSUF);
123                  printf("\n9 red green blue");
124                  for (i = 0; i < 3; i++) {
125                          dfp = dfopen(il, DATORD[i]);
126 <                        fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
127 <                        colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
126 >                        fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
127 >                                        1.+.5/n, .5/n, n+1,
128 >                                        0., 2.*PI, m+1);
129 >                        colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
130 >                        colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
131 >                        fputeol(dfp);
132                          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 <                printf("\n5 noop");
138 >                printf("\n5 noneg");
139                  dfp = dfopen(il, 0);
140 <                fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
141 <                brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
140 >                fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
141 >                                1.+.5/n, .5/n, n+1,
142 >                                0., 2.*PI, m+1);
143 >                brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
144 >                brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
145 >                fputeol(dfp);
146                  fclose(dfp);
147                  printf(" %s", dfname(il, 0));
148          }
# Line 153 | Line 152 | FVECT  u, v, w;
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 +        free((void *)Ninv);
156   }
157  
158  
159 < roundout(il, da, n, m)                  /* write spherical distribution */
160 < struct illum_args  *il;
161 < float  *da;
162 < int  n, m;
159 > extern void
160 > roundout(                       /* write spherical distribution */
161 >        struct illum_args  *il,
162 >        float  *da,
163 >        int  n,
164 >        int  m
165 > )
166   {
167 +        float  *Ninv, *Sinv;
168          FILE  *dfp;
169          int  i;
170  
171 <        average(il, da, n*m);
171 >        if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL ||
172 >                        (Sinv = (float *)malloc(3*m*sizeof(float))) == NULL)
173 >                error(SYSTEM, "out of memory in roundout");
174 >        compinv(Ninv, da, m);
175 >        compinv(Sinv, da+3*m*(n-1), m);
176          if (il->flags & IL_COLDST) {
177                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
178                                  il->matname, DSTSUF);
179                  printf("\n9 red green blue");
180                  for (i = 0; i < 3; i++) {
181                          dfp = dfopen(il, DATORD[i]);
182 <                        fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
183 <                        colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
182 >                        fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
183 >                                        1.+1./n, -1.-1./n, n+2,
184 >                                        0., 2.*PI, m+1);
185 >                        colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
186 >                        colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
187 >                        colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp);
188 >                        fputeol(dfp);
189                          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 <                printf("\n5 noop");
195 >                printf("\n5 noneg");
196                  dfp = dfopen(il, 0);
197 <                fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
198 <                brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
197 >                fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
198 >                                1.+1./n, -1.-1./n, n+2,
199 >                                0., 2.*PI, m+1);
200 >                brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
201 >                brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
202 >                brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp);
203 >                fputeol(dfp);
204                  fclose(dfp);
205                  printf(" %s", dfname(il, 0));
206          }
207          printf("\n\t%s il_alt il_azi", FNCFNM);
208          printf("\n0\n0\n");
209          il->dfnum++;
210 +        free((void *)Ninv);
211 +        free((void *)Sinv);
212   }
213  
214  
215 < average(il, da, n)              /* compute average value for distribution */
216 < register struct illum_args  *il;
217 < register float  *da;
218 < int  n;
215 > extern void
216 > illumout(               /* print illum object */
217 >        register struct illum_args  *il,
218 >        OBJREC  *ob
219 > )
220   {
221 +        double  cout[3];
222 +
223 +        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 +                        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 +        printf("\n0\n3 %f %f %f\n", cout[0], cout[1], cout[2]);
241 +
242 +        printobj(il->matname, ob);
243 + }
244 +
245 +
246 + void
247 + compavg(                /* compute average for set of data values */
248 +        float  col[3],
249 +        register float  *da,
250 +        int  n
251 + )
252 + {
253          register int  i;
254  
255 <        il->col[0] = il->col[1] = il->col[2] = 0.;
255 >        col[0] = col[1] = col[2] = 0.;
256          i = n;
257          while (i-- > 0) {
258 <                il->col[0] += *da++;
259 <                il->col[1] += *da++;
260 <                il->col[2] += *da++;
258 >                col[0] += *da++;
259 >                col[1] += *da++;
260 >                col[2] += *da++;
261          }
262          for (i = 0; i < 3; i++)
263 <                il->col[i] /= (double)n*il->nsamps;
263 >                col[i] /= (double)n;
264   }
265  
266  
267 < colorout(p, da, n, mult, fp)    /* put out color distribution data */
268 < int  p;
269 < register float  *da;
270 < int  n;
271 < double  mult;
272 < FILE  *fp;
267 > void
268 > compinv(                /* compute other side of row average */
269 >        register float  *rinv,
270 >        register float  *rp,
271 >        int  m
272 > )
273   {
274 <        register int  i;
274 >        float  avg[3];
275  
276 <        for (i = 0; i < n; i++) {
277 <                if (i%6 == 0)
278 <                        putc('\n', fp);
279 <                fprintf(fp, " %11e", mult*da[p]);
280 <                da += 3;
276 >        compavg(avg, rp, m);            /* row average */
277 >        while (m-- > 0) {
278 >                *rinv++ = 2.*avg[0] - *rp++;
279 >                *rinv++ = 2.*avg[1] - *rp++;
280 >                *rinv++ = 2.*avg[2] - *rp++;
281          }
282 + }
283 +
284 +
285 + extern int
286 + average(                /* evaluate average value for distribution */
287 +        register struct illum_args  *il,
288 +        float  *da,
289 +        int  n
290 + )
291 + {
292 +        compavg(il->col, da, n);        /* average */
293 +        if (il->nsamps > 1) {
294 +                il->col[0] /= (double)il->nsamps;
295 +                il->col[1] /= (double)il->nsamps;
296 +                il->col[2] /= (double)il->nsamps;
297 +        }
298 +                                        /* brighter than minimum? */
299 +        return(brt(il->col) > il->minbrt+FTINY);
300 + }
301 +
302 +
303 + static int      colmcnt = 0;    /* count of columns written */
304 +
305 + void
306 + fputnum(                        /* put out a number to fp */
307 +        double  d,
308 +        FILE  *fp
309 + )
310 + {
311 +        if (colmcnt++ % 5 == 0)
312 +                putc('\n', fp);
313 +        fprintf(fp, " %11e", d);
314 + }
315 +
316 +
317 + void
318 + fputeol(                        /* write end of line to fp */
319 +        register FILE  *fp
320 + )
321 + {
322          putc('\n', fp);
323 +        colmcnt = 0;
324   }
325  
326  
327 < brightout(da, n, mult, fp)      /* put out brightness distribution data */
328 < register float  *da;
329 < int  n;
330 < double  mult;
331 < FILE  *fp;
327 > void
328 > colorout(       /* put out color distribution data */
329 >        int  p,
330 >        register float  *da,
331 >        int  n,
332 >        int  m,
333 >        double  mult,
334 >        FILE  *fp
335 > )
336   {
337 <        register int  i;
337 >        register int  i, j;
338  
339          for (i = 0; i < n; i++) {
340 <                if (i%6 == 0)
341 <                        putc('\n', fp);
342 <                fprintf(fp, " %11e", mult*brt(da));
343 <                da += 3;
340 >                for (j = 0; j < m; j++) {
341 >                        fputnum(mult*da[p], fp);
342 >                        da += 3;
343 >                }
344 >                fputnum(mult*da[p-3*m], fp);    /* wrap phi */
345          }
346 <        putc('\n', fp);
346 > }
347 >
348 >
349 > void
350 > brightout(      /* put out brightness distribution data */
351 >        register float  *da,
352 >        int  n,
353 >        int  m,
354 >        double  mult,
355 >        FILE  *fp
356 > )
357 > {
358 >        register int  i, j;
359 >
360 >        for (i = 0; i < n; i++) {
361 >                for (j = 0; j < m; j++) {
362 >                        fputnum(mult*brt(da), fp);
363 >                        da += 3;
364 >                }
365 >                fputnum(mult*brt(da-3*m), fp);  /* wrap phi */
366 >        }
367   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines