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.3 by greg, Thu Jul 25 12:52:21 1991 UTC vs.
Revision 2.6 by greg, Wed Aug 12 14:24:08 1992 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include  "mkillum.h"
12  
13 < #define  brt(col)       (.295*(col)[0] + .636*(col)[1] + .070*(col)[2])
13 > #define  brt(col)       (.263*(col)[0]+.655*(col)[1]+.082*(col)[2])
14  
15   char    DATORD[] = "RGB";               /* data ordering */
16   char    DATSUF[] = ".dat";              /* data file suffix */
# Line 24 | Line 24 | register OBJREC  *obj;
24   {
25          register int  i;
26  
27 +        if (issurface(obj->otype) && !strcmp(mod, VOIDID))
28 +                return;         /* don't print void surfaces */
29          printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname);
30          printf("\n%d", obj->oargs.nsargs);
31          for (i = 0; i < obj->oargs.nsargs; i++)
# Line 93 | Line 95 | float  *da;
95   int  n, m;
96   FVECT  u, v, w;
97   {
98 +        float  *Ninv;
99          FILE  *dfp;
100          int  i;
101  
102 <        average(il, da, n*m);
102 >        if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL)
103 >                error(SYSTEM, "out of memory in flatout");
104 >        compinv(Ninv, da, m);
105          if (il->flags & IL_COLDST) {
106                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
107                                  il->matname, DSTSUF);
108                  printf("\n9 red green blue");
109                  for (i = 0; i < 3; i++) {
110                          dfp = dfopen(il, DATORD[i]);
111 <                        fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
112 <                        colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
111 >                        fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
112 >                                        1.+.5/n, .5/n, n+1,
113 >                                        0., 2.*PI, m+1);
114 >                        colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
115 >                        colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
116 >                        fputeol(dfp);
117                          fclose(dfp);
118                          printf(" %s", dfname(il, DATORD[i]));
119                  }
120          } else {
121                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
122                                  il->matname, DSTSUF);
123 <                printf("\n5 noop");
123 >                printf("\n5 noneg");
124                  dfp = dfopen(il, 0);
125 <                fprintf(dfp, "2\n1 0 %d\n0 %f %d\n", n, 2.*PI, m);
126 <                brightout(da, n*m, 1./il->nsamps/brt(il->col), 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 >                brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
129 >                brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
130 >                fputeol(dfp);
131                  fclose(dfp);
132                  printf(" %s", dfname(il, 0));
133          }
# Line 124 | Line 137 | FVECT  u, v, w;
137          printf("\t%f\t%f\t%f\n", v[0], v[1], v[2]);
138          printf("\t%f\t%f\t%f\n", w[0], w[1], w[2]);
139          il->dfnum++;
140 +        free((char *)Ninv);
141   }
142  
143  
# Line 132 | Line 146 | struct illum_args  *il;
146   float  *da;
147   int  n, m;
148   {
149 +        float  *Ninv, *Sinv;
150          FILE  *dfp;
151          int  i;
152  
153 <        average(il, da, n*m);
153 >        if ((Ninv = (float *)malloc(3*m*sizeof(float))) == NULL ||
154 >                        (Sinv = (float *)malloc(3*m*sizeof(float))) == NULL)
155 >                error(SYSTEM, "out of memory in roundout");
156 >        compinv(Ninv, da, m);
157 >        compinv(Sinv, da+3*m*(n-1), m);
158          if (il->flags & IL_COLDST) {
159                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_CDATA].funame,
160                                  il->matname, DSTSUF);
161                  printf("\n9 red green blue");
162                  for (i = 0; i < 3; i++) {
163                          dfp = dfopen(il, DATORD[i]);
164 <                        fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
165 <                        colorout(i, da, n*m, 1./il->nsamps/il->col[i], dfp);
164 >                        fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
165 >                                        1.+1./n, -1.-1./n, n+2,
166 >                                        0., 2.*PI, m+1);
167 >                        colorout(i, Ninv, 1, m, 1./il->nsamps/il->col[i], dfp);
168 >                        colorout(i, da, n, m, 1./il->nsamps/il->col[i], dfp);
169 >                        colorout(i, Sinv, 1, m, 1./il->nsamps/il->col[i], dfp);
170 >                        fputeol(dfp);
171                          fclose(dfp);
172                          printf(" %s", dfname(il, DATORD[i]));
173                  }
174          } else {
175                  printf("\n%s %s %s%s", VOIDID, ofun[PAT_BDATA].funame,
176                                  il->matname, DSTSUF);
177 <                printf("\n5 noop");
177 >                printf("\n5 noneg");
178                  dfp = dfopen(il, 0);
179 <                fprintf(dfp, "2\n1 -1 %d\n0 %f %d\n", n, 2.*PI, m);
180 <                brightout(da, n*m, 1./il->nsamps/brt(il->col), dfp);
179 >                fprintf(dfp, "2\n%f %f %d\n%f %f %d\n",
180 >                                1.+1./n, -1.-1./n, n+2,
181 >                                0., 2.*PI, m+1);
182 >                brightout(Ninv, 1, m, 1./il->nsamps/brt(il->col), dfp);
183 >                brightout(da, n, m, 1./il->nsamps/brt(il->col), dfp);
184 >                brightout(Sinv, 1, m, 1./il->nsamps/brt(il->col), dfp);
185 >                fputeol(dfp);
186                  fclose(dfp);
187                  printf(" %s", dfname(il, 0));
188          }
189          printf("\n\t%s il_alt il_azi", FNCFNM);
190          printf("\n0\n0\n");
191          il->dfnum++;
192 +        free((char *)Ninv);
193 +        free((char *)Sinv);
194   }
195  
196  
# Line 169 | Line 200 | OBJREC  *ob;
200   {
201          double  cout[3];
202  
203 <        printf("\n%s%s %s %s", il->matname, DSTSUF,
204 <                        ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
203 >        if (il->sampdens <= 0)
204 >                printf("\n%s ", VOIDID);
205 >        else
206 >                printf("\n%s%s ", il->matname, DSTSUF);
207 >        printf("%s %s", ofun[il->flags&IL_LIGHT?MAT_LIGHT:MAT_ILLUM].funame,
208                          il->matname);
209          if (il->flags & IL_LIGHT || !strcmp(il->altmat,VOIDID))
210                  printf("\n0");
# Line 189 | Line 223 | OBJREC  *ob;
223   }
224  
225  
226 < average(il, da, n)              /* compute average value for distribution */
227 < register struct illum_args  *il;
226 > compavg(col, da, n)             /* compute average for set of data values */
227 > float  col[3];
228   register float  *da;
229   int  n;
230   {
231          register int  i;
232  
233 <        il->col[0] = il->col[1] = il->col[2] = 0.;
233 >        col[0] = col[1] = col[2] = 0.;
234          i = n;
235          while (i-- > 0) {
236 <                il->col[0] += *da++;
237 <                il->col[1] += *da++;
238 <                il->col[2] += *da++;
236 >                col[0] += *da++;
237 >                col[1] += *da++;
238 >                col[2] += *da++;
239          }
240          for (i = 0; i < 3; i++)
241 <                il->col[i] /= (double)n*il->nsamps;
241 >                col[i] /= (double)n;
242   }
243  
244  
245 < colorout(p, da, n, mult, fp)    /* put out color distribution data */
245 > compinv(rinv, rp, m)            /* compute other side of row average */
246 > register float  *rinv, *rp;
247 > int  m;
248 > {
249 >        float  avg[3];
250 >
251 >        compavg(avg, rp, m);            /* row average */
252 >        while (m-- > 0) {
253 >                *rinv++ = 2.*avg[0] - *rp++;
254 >                *rinv++ = 2.*avg[1] - *rp++;
255 >                *rinv++ = 2.*avg[2] - *rp++;
256 >        }
257 > }
258 >
259 >
260 > average(il, da, n)              /* evaluate average value for distribution */
261 > register struct illum_args  *il;
262 > float  *da;
263 > int  n;
264 > {
265 >        compavg(il->col, da, n);        /* average */
266 >        if (il->nsamps > 1) {
267 >                il->col[0] /= (double)il->nsamps;
268 >                il->col[1] /= (double)il->nsamps;
269 >                il->col[2] /= (double)il->nsamps;
270 >        }
271 >                                        /* brighter than minimum? */
272 >        return(brt(il->col) > il->minbrt+FTINY);
273 > }
274 >
275 >
276 > static int      colmcnt = 0;    /* count of columns written */
277 >
278 > fputnum(d, fp)                  /* put out a number to fp */
279 > double  d;
280 > FILE  *fp;
281 > {
282 >        if (colmcnt++ % 5 == 0)
283 >                putc('\n', fp);
284 >        fprintf(fp, " %11e", d);
285 > }
286 >
287 >
288 > fputeol(fp)                     /* write end of line to fp */
289 > register FILE  *fp;
290 > {
291 >        putc('\n', fp);
292 >        colmcnt = 0;
293 > }
294 >
295 >
296 > colorout(p, da, n, m, mult, fp) /* put out color distribution data */
297   int  p;
298   register float  *da;
299 < int  n;
299 > int  n, m;
300   double  mult;
301   FILE  *fp;
302   {
303 <        register int  i;
303 >        register int  i, j;
304  
305          for (i = 0; i < n; i++) {
306 <                if (i%6 == 0)
307 <                        putc('\n', fp);
308 <                fprintf(fp, " %11e", mult*da[p]);
309 <                da += 3;
306 >                for (j = 0; j < m; j++) {
307 >                        fputnum(mult*da[p], fp);
308 >                        da += 3;
309 >                }
310 >                fputnum(mult*da[p-3*m], fp);    /* wrap phi */
311          }
226        putc('\n', fp);
312   }
313  
314  
315 < brightout(da, n, mult, fp)      /* put out brightness distribution data */
315 > brightout(da, n, m, mult, fp)   /* put out brightness distribution data */
316   register float  *da;
317 < int  n;
317 > int  n, m;
318   double  mult;
319   FILE  *fp;
320   {
321 <        register int  i;
321 >        register int  i, j;
322  
323          for (i = 0; i < n; i++) {
324 <                if (i%6 == 0)
325 <                        putc('\n', fp);
326 <                fprintf(fp, " %11e", mult*brt(da));
327 <                da += 3;
324 >                for (j = 0; j < m; j++) {
325 >                        fputnum(mult*brt(da), fp);
326 >                        da += 3;
327 >                }
328 >                fputnum(mult*brt(da-3*m), fp);  /* wrap phi */
329          }
244        putc('\n', fp);
330   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines