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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines