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

Comparing ray/src/cv/bsdf2ttree.c (file contents):
Revision 2.36 by schorsch, Sun Mar 6 01:13:17 2016 UTC vs.
Revision 2.49 by greg, Fri May 8 22:34:21 2020 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8   */
9  
10   #define _USE_MATH_DEFINES
11 #include <stdio.h>
11   #include <stdlib.h>
12   #include <math.h>
13   #include "random.h"
# Line 19 | Line 18 | static const char RCSid[] = "$Id$";
18   #include "bsdfrep.h"
19                                  /* global argv[0] */
20   char                    *progname;
21 +                                /* reciprocity averaging option */
22 + static const char       *recip = " -a";
23                                  /* percentage to cull (<0 to turn off) */
24   static double           pctcull = 90.;
25                                  /* sampling order */
26   static int              samp_order = 6;
27                                  /* super-sampling threshold */
28 < const double            ssamp_thresh = 0.35;
28 > static double           ssamp_thresh = 0.35;
29                                  /* number of super-samples */
30   #ifndef NSSAMP
31 < #define NSSAMP          100
31 > #define NSSAMP          256
32   #endif
33                                  /* limit on number of RBF lobes */
34   static int              lobe_lim = 15000;
# Line 38 | Line 39 | static int             do_prog = 79;
39   static char             *wrapBSDF[MAXCARG] = {"wrapBSDF", "-U"};
40   static int              wbsdfac = 2;
41  
42 < /* Add argument to wrapBSDF, allocating space if isstatic */
42 > /* Add argument to wrapBSDF, allocating space if !isstatic */
43   static void
44   add_wbsdf(const char *arg, int isstatic)
45   {
# Line 127 | Line 128 | static void
128   eval_isotropic(char *funame)
129   {
130          const int       sqres = 1<<samp_order;
131 +        const double    sqfact = 1./(double)sqres;
132 +        float           *ryval = NULL;
133 +        char            *rtrip = NULL;
134          FILE            *ofp, *uvfp[2];
135          int             assignD = 0;
136          char            cmd[128];
# Line 135 | Line 139 | eval_isotropic(char *funame)
139          float           bsdf, uv[2];
140  
141          if (pctcull >= 0) {
142 <                sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
143 <                                pctcull, samp_order, create_component_file(0));
142 >                sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
143 >                                recip, pctcull, samp_order, create_component_file(0));
144                  ofp = popen(cmd, "w");
145                  if (ofp == NULL) {
146                          fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n",
# Line 149 | Line 153 | eval_isotropic(char *funame)
153   #endif
154                  if (rbf_colorimetry == RBCtristimulus) {
155                          double  uvcull = 100. - (100.-pctcull)*.25;
156 <                        sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
157 <                                        uvcull, samp_order, create_component_file(1));
156 >                        sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
157 >                                        recip, uvcull, samp_order, create_component_file(1));
158                          uvfp[0] = popen(cmd, "w");
159 <                        sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
160 <                                        uvcull, samp_order, create_component_file(2));
159 >                        sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
160 >                                        recip, uvcull, samp_order, create_component_file(2));
161                          uvfp[1] = popen(cmd, "w");
162                          if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) {
163                                  fprintf(stderr, "%s: cannot open pipes to uv output\n",
# Line 187 | Line 191 | eval_isotropic(char *funame)
191          }
192          if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
193                  assignD = (fundefined(funame) < 6);
194 + #if (NSSAMP > 0)
195 +        rtrip = (char *)malloc(sqres);          /* track sample triggerings */
196 +        ryval = (float *)calloc(sqres, sizeof(float));
197 + #endif
198                                                  /* run through directions */
199          for (ix = 0; ix < sqres/2; ix++) {
200 <                RBFNODE *rbf = NULL;
201 <                iovec[0] = 2.*(ix+.5)/sqres - 1.;
202 <                iovec[1] = .0;
203 <                iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]);
200 >                const int       zipsgn = (ix & 1)*2 - 1;
201 >                RBFNODE         *rbf = NULL;
202 >                iovec[0] = 2.*sqfact*(ix+.5) - 1.;
203 >                iovec[1] = zipsgn*sqfact*.5;
204 >                iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]
205 >                                                - iovec[1]*iovec[1]);
206                  if (funame == NULL)
207                          rbf = advect_rbf(iovec, lobe_lim);
208                  for (ox = 0; ox < sqres; ox++) {
209 <                    float       last_bsdf = -1;
209 >                    SDValue     sdv_next;
210 >                    SDsquare2disk(iovec+3, (ox+.5)*sqfact, .5*sqfact);
211 >                    iovec[5] = output_orient *
212 >                                sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
213 >                    if (funame == NULL) {
214 >                        eval_rbfcol(&sdv_next, rbf, iovec+3);
215 >                    } else {
216 >                        sdv_next.spec = c_dfcolor;
217 >                        if (assignD) {
218 >                            varset("Dx", '=', -iovec[3]);
219 >                            varset("Dy", '=', -iovec[4]);
220 >                            varset("Dz", '=', -iovec[5]);
221 >                            ++eclock;
222 >                        }
223 >                        sdv_next.cieY = funvalue(funame, 6, iovec);
224 >                    }
225 >                    /*
226 >                     * Super-sample when we detect a difference from before
227 >                     * or after in this row, or the previous row in this column.
228 >                     * Also super-sample if the previous neighbors performed
229 >                     * super-sampling, regardless of any differences.
230 >                     */
231 >                    memset(rtrip, 0, sqres);
232                      for (oy = 0; oy < sqres; oy++) {
233 <                        SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
234 <                        iovec[5] = output_orient *
233 >                        int     trip;
234 >                        bsdf = sdv_next.cieY;   /* keeping one step ahead... */
235 >                        if (oy < sqres-1) {
236 >                            SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+1.5)*sqfact);
237 >                            iovec[5] = output_orient *
238                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
239 +                        }
240                          if (funame == NULL) {
241 <                            SDValue     sdv;
242 <                            eval_rbfcol(&sdv, rbf, iovec+3);
243 <                            bsdf = sdv.cieY;
241 >                            SDValue     sdv = sdv_next;
242 >                            if (oy < sqres-1)
243 >                                eval_rbfcol(&sdv_next, rbf, iovec+3);
244 > #if (NSSAMP > 0)
245 >                            trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh ||
246 >                                (ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) ||
247 >                                (oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh));
248 >                            if (trip | rtrip[oy] || (oy && rtrip[oy-1])) {
249 >                                int     ssi;
250 >                                double  ssa[2], sum = 0, usum = 0, vsum = 0;
251 >                                                /* super-sample voxel */
252 >                                for (ssi = NSSAMP; ssi--; ) {
253 >                                    SDmultiSamp(ssa, 2, (ssi+frandom()) *
254 >                                                        (1./NSSAMP));
255 >                                    SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
256 >                                                        (oy+ssa[1])*sqfact);
257 >                                    iovec[5] = output_orient *
258 >                                        sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
259 >                                    eval_rbfcol(&sdv, rbf, iovec+3);
260 >                                    sum += sdv.cieY;
261 >                                    if (rbf_colorimetry == RBCtristimulus) {
262 >                                        sdv.cieY /=
263 >                                            -2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.;
264 >                                        usum += 4.*sdv.spec.cx * sdv.cieY;
265 >                                        vsum += 9.*sdv.spec.cy * sdv.cieY;
266 >                                    }
267 >                                }
268 >                                bsdf = sum * (1./NSSAMP);
269 >                                if (rbf_colorimetry == RBCtristimulus) {
270 >                                    uv[0] = usum / (sum+FTINY);
271 >                                    uv[1] = vsum / (sum+FTINY);
272 >                                }
273 >                            } else
274 > #endif
275                              if (rbf_colorimetry == RBCtristimulus) {
209                                c_ccvt(&sdv.spec, C_CSXY);
276                                  uv[0] = uv[1] = 1. /
277                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
278                                  uv[0] *= 4.*sdv.spec.cx;
279                                  uv[1] *= 9.*sdv.spec.cy;
280                              }
281                          } else {
282 <                            if (assignD) {
283 <                                varset("Dx", '=', -iovec[3]);
284 <                                varset("Dy", '=', -iovec[4]);
285 <                                varset("Dz", '=', -iovec[5]);
286 <                                ++eclock;
282 >                            if (oy < sqres-1) {
283 >                                if (assignD) {
284 >                                    varset("Dx", '=', -iovec[3]);
285 >                                    varset("Dy", '=', -iovec[4]);
286 >                                    varset("Dz", '=', -iovec[5]);
287 >                                    ++eclock;
288 >                                }
289 >                                sdv_next.cieY = funvalue(funame, 6, iovec);
290                              }
222                            bsdf = funvalue(funame, 6, iovec);
291   #if (NSSAMP > 0)
292 <                            if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
292 >                            trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh ||
293 >                                (ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) ||
294 >                                (oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh));
295 >                            if (trip | rtrip[oy] || (oy && rtrip[oy-1])) {
296                                  int     ssi;
297 <                                double  ssa[3], ssvec[6], sum = 0;
297 >                                double  ssa[4], ssvec[6], sum = 0;
298                                                  /* super-sample voxel */
299                                  for (ssi = NSSAMP; ssi--; ) {
300 <                                    SDmultiSamp(ssa, 3, (ssi+frandom()) *
300 >                                    SDmultiSamp(ssa, 4, (ssi+frandom()) *
301                                                          (1./NSSAMP));
302 <                                    ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.;
303 <                                    ssvec[1] = .0;
304 <                                    ssvec[2] = input_orient *
305 <                                                sqrt(1. - ssvec[0]*ssvec[0]);
306 <                                    SDsquare2disk(ssvec+3, (ox+ssa[1])/sqres,
307 <                                                (oy+ssa[2])/sqres);
302 >                                    ssvec[0] = 2.*sqfact*(ix+ssa[0]) - 1.;
303 >                                    ssvec[1] = zipsgn*sqfact*ssa[1];
304 >                                    ssvec[2] = 1. - ssvec[0]*ssvec[0]
305 >                                                        - ssvec[1]*ssvec[1];
306 >                                    if (ssvec[2] < .0) {
307 >                                        ssvec[1] = 0;
308 >                                        ssvec[2] = 1. - ssvec[0]*ssvec[0];
309 >                                    }
310 >                                    ssvec[2] = input_orient * sqrt(ssvec[2]);
311 >                                    SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact,
312 >                                                (oy+ssa[3])*sqfact);
313                                      ssvec[5] = output_orient *
314                                                  sqrt(1. - ssvec[3]*ssvec[3] -
315                                                          ssvec[4]*ssvec[4]);
# Line 245 | Line 321 | eval_isotropic(char *funame)
321                                      }
322                                      sum += funvalue(funame, 6, ssvec);
323                                  }
324 <                                bsdf = sum/NSSAMP;
324 >                                bsdf = sum * (1./NSSAMP);
325                              }
326   #endif
327                          }
328                          if (pctcull >= 0)
329 <                                fwrite(&bsdf, sizeof(bsdf), 1, ofp);
329 >                                putbinary(&bsdf, sizeof(bsdf), 1, ofp);
330                          else
331                                  fprintf(ofp, "\t%.3e\n", bsdf);
332  
333                          if (rbf_colorimetry == RBCtristimulus) {
334                                  if (pctcull >= 0) {
335 <                                        fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]);
336 <                                        fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]);
335 >                                        putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]);
336 >                                        putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]);
337                                  } else {
338                                          fprintf(uvfp[0], "\t%.3e\n", uv[0]);
339                                          fprintf(uvfp[1], "\t%.3e\n", uv[1]);
340                                  }
341                          }
342 <                        last_bsdf = bsdf;
342 >                        if (ryval != NULL) {
343 >                                rtrip[oy] = trip;
344 >                                ryval[oy] = bsdf;
345 >                        }
346                      }
347                  }
348                  if (rbf != NULL)
349                          free(rbf);
350 <                prog_show((ix+1.)*(2./sqres));
350 >                prog_show((ix+1.)*(2.*sqfact));
351          }
352          prog_done();
353 +        if (ryval != NULL) {
354 +                free(rtrip);
355 +                free(ryval);
356 +        }
357          if (pctcull >= 0) {                     /* finish output */
358                  if (pclose(ofp)) {
359                          fprintf(stderr, "%s: error running rttree_reduce on Y\n",
# Line 313 | Line 396 | static void
396   eval_anisotropic(char *funame)
397   {
398          const int       sqres = 1<<samp_order;
399 +        const double    sqfact = 1./(double)sqres;
400 +        float           *ryval = NULL;
401 +        char            *rtrip = NULL;
402          FILE            *ofp, *uvfp[2];
403          int             assignD = 0;
404          char            cmd[128];
# Line 322 | Line 408 | eval_anisotropic(char *funame)
408  
409          if (pctcull >= 0) {
410                  const char      *avgopt = (input_orient>0 ^ output_orient>0)
411 <                                                ? "" : " -a";
411 >                                                ? "" : recip;
412                  sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s",
413                                  avgopt, pctcull, samp_order,
414                                  create_component_file(0));
# Line 378 | Line 464 | eval_anisotropic(char *funame)
464          }
465          if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
466                  assignD = (fundefined(funame) < 6);
467 + #if (NSSAMP > 0)
468 +        rtrip = (char *)malloc(sqres);          /* track sample triggerings */
469 +        ryval = (float *)calloc(sqres, sizeof(float));
470 + #endif
471                                                  /* run through directions */
472          for (ix = 0; ix < sqres; ix++)
473              for (iy = 0; iy < sqres; iy++) {
474                  RBFNODE *rbf = NULL;            /* Klems reversal */
475 <                SDsquare2disk(iovec, 1.-(ix+.5)/sqres, 1.-(iy+.5)/sqres);
475 >                SDsquare2disk(iovec, 1.-(ix+.5)*sqfact, 1.-(iy+.5)*sqfact);
476                  iovec[2] = input_orient *
477                                  sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]);
478                  if (funame == NULL)
479                          rbf = advect_rbf(iovec, lobe_lim);
480                  for (ox = 0; ox < sqres; ox++) {
481 <                    float       last_bsdf = -1;
481 >                    SDValue     sdv_next;
482 >                    SDsquare2disk(iovec+3, (ox+.5)*sqfact, .5*sqfact);
483 >                    iovec[5] = output_orient *
484 >                                sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
485 >                    if (funame == NULL) {
486 >                        eval_rbfcol(&sdv_next, rbf, iovec+3);
487 >                    } else {
488 >                        sdv_next.spec = c_dfcolor;
489 >                        if (assignD) {
490 >                            varset("Dx", '=', -iovec[3]);
491 >                            varset("Dy", '=', -iovec[4]);
492 >                            varset("Dz", '=', -iovec[5]);
493 >                            ++eclock;
494 >                        }
495 >                        sdv_next.cieY = funvalue(funame, 6, iovec);
496 >                    }
497 >                    /*
498 >                     * Super-sample when we detect a difference from before
499 >                     * or after in this row, or the previous row in this column.
500 >                     * Also super-sample if the previous neighbors performed
501 >                     * super-sampling, regardless of any differences.
502 >                     */
503 >                    memset(rtrip, 0, sqres);
504                      for (oy = 0; oy < sqres; oy++) {
505 <                        SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
506 <                        iovec[5] = output_orient *
505 >                        int     trip;
506 >                        bsdf = sdv_next.cieY;   /* keeping one step ahead... */
507 >                        if (oy < sqres-1) {
508 >                            SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+1.5)*sqfact);
509 >                            iovec[5] = output_orient *
510                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
511 +                        }
512                          if (funame == NULL) {
513 <                            SDValue     sdv;
514 <                            eval_rbfcol(&sdv, rbf, iovec+3);
515 <                            bsdf = sdv.cieY;
513 >                            SDValue     sdv = sdv_next;
514 >                            if (oy < sqres-1)
515 >                                eval_rbfcol(&sdv_next, rbf, iovec+3);
516 > #if (NSSAMP > 0)
517 >                            trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh ||
518 >                                (ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) ||
519 >                                (oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh));
520 >                            if (trip | rtrip[oy] || (oy && rtrip[oy-1])) {
521 >                                int     ssi;
522 >                                double  ssa[2], sum = 0, usum = 0, vsum = 0;
523 >                                                /* super-sample voxel */
524 >                                for (ssi = NSSAMP; ssi--; ) {
525 >                                    SDmultiSamp(ssa, 2, (ssi+frandom()) *
526 >                                                        (1./NSSAMP));
527 >                                    SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
528 >                                                        (oy+ssa[1])*sqfact);
529 >                                    iovec[5] = output_orient *
530 >                                        sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
531 >                                    eval_rbfcol(&sdv, rbf, iovec+3);
532 >                                    sum += sdv.cieY;
533 >                                    if (rbf_colorimetry == RBCtristimulus) {
534 >                                        sdv.cieY /=
535 >                                            -2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.;
536 >                                        usum += 4.*sdv.spec.cx * sdv.cieY;
537 >                                        vsum += 9.*sdv.spec.cy * sdv.cieY;
538 >                                    }
539 >                                }
540 >                                bsdf = sum * (1./NSSAMP);
541 >                                if (rbf_colorimetry == RBCtristimulus) {
542 >                                    uv[0] = usum / (sum+FTINY);
543 >                                    uv[1] = vsum / (sum+FTINY);
544 >                                }
545 >                            } else
546 > #endif
547                              if (rbf_colorimetry == RBCtristimulus) {
401                                c_ccvt(&sdv.spec, C_CSXY);
548                                  uv[0] = uv[1] = 1. /
549                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
550                                  uv[0] *= 4.*sdv.spec.cx;
551                                  uv[1] *= 9.*sdv.spec.cy;
552                              }
553                          } else {
554 <                            if (assignD) {
555 <                                varset("Dx", '=', -iovec[3]);
556 <                                varset("Dy", '=', -iovec[4]);
557 <                                varset("Dz", '=', -iovec[5]);
558 <                                ++eclock;
554 >                            if (oy < sqres-1) {
555 >                                if (assignD) {
556 >                                    varset("Dx", '=', -iovec[3]);
557 >                                    varset("Dy", '=', -iovec[4]);
558 >                                    varset("Dz", '=', -iovec[5]);
559 >                                    ++eclock;
560 >                                }
561 >                                sdv_next.cieY = funvalue(funame, 6, iovec);
562                              }
414                            bsdf = funvalue(funame, 6, iovec);
563   #if (NSSAMP > 0)
564 <                            if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
564 >                            trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh ||
565 >                                (ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) ||
566 >                                (oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh));
567 >                            if (trip | rtrip[oy] || (oy && rtrip[oy-1])) {
568                                  int     ssi;
569                                  double  ssa[4], ssvec[6], sum = 0;
570                                                  /* super-sample voxel */
571                                  for (ssi = NSSAMP; ssi--; ) {
572                                      SDmultiSamp(ssa, 4, (ssi+frandom()) *
573                                                          (1./NSSAMP));
574 <                                    SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres,
575 <                                                1.-(iy+ssa[1])/sqres);
574 >                                    SDsquare2disk(ssvec, 1.-(ix+ssa[0])*sqfact,
575 >                                                1.-(iy+ssa[1])*sqfact);
576                                      ssvec[2] = input_orient *
577                                                  sqrt(1. - ssvec[0]*ssvec[0] -
578                                                          ssvec[1]*ssvec[1]);
579 <                                    SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres,
580 <                                                (oy+ssa[3])/sqres);
579 >                                    SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact,
580 >                                                (oy+ssa[3])*sqfact);
581                                      ssvec[5] = output_orient *
582                                                  sqrt(1. - ssvec[3]*ssvec[3] -
583                                                          ssvec[4]*ssvec[4]);
# Line 438 | Line 589 | eval_anisotropic(char *funame)
589                                      }
590                                      sum += funvalue(funame, 6, ssvec);
591                                  }
592 <                                bsdf = sum/NSSAMP;
592 >                                bsdf = sum * (1./NSSAMP);
593                              }
594   #endif
595                          }
596                          if (pctcull >= 0)
597 <                                fwrite(&bsdf, sizeof(bsdf), 1, ofp);
597 >                                putbinary(&bsdf, sizeof(bsdf), 1, ofp);
598                          else
599                                  fprintf(ofp, "\t%.3e\n", bsdf);
600  
601                          if (rbf_colorimetry == RBCtristimulus) {
602                                  if (pctcull >= 0) {
603 <                                        fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]);
604 <                                        fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]);
603 >                                        putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]);
604 >                                        putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]);
605                                  } else {
606                                          fprintf(uvfp[0], "\t%.3e\n", uv[0]);
607                                          fprintf(uvfp[1], "\t%.3e\n", uv[1]);
608                                  }
609                          }
610 <                        last_bsdf = bsdf;
610 >                        if (ryval != NULL) {
611 >                                rtrip[oy] = trip;
612 >                                ryval[oy] = bsdf;
613 >                        }
614                      }
461                }
615                  if (rbf != NULL)
616                          free(rbf);
617                  prog_show((ix*sqres+iy+1.)/(sqres*sqres));
618              }
619 +        }
620          prog_done();
621 +        if (ryval != NULL) {
622 +                free(rtrip);
623 +                free(ryval);
624 +        }
625          if (pctcull >= 0) {                     /* finish output */
626                  if (pclose(ofp)) {
627                          fprintf(stderr, "%s: error running rttree_reduce on Y\n",
# Line 565 | Line 723 | main(int argc, char *argv[])
723          esupport &= ~(E_INCHAN|E_OUTCHAN);
724          scompile("PI:3.14159265358979323846", NULL, 0);
725          biggerlib();
726 <        for (i = 1; i < argc-1 && (argv[i][0] == '-') | (argv[i][0] == '+'); i++)
726 >        for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++)
727                  switch (argv[i][1]) {           /* get options */
728                  case 'e':
729                          scompile(argv[++i], NULL, 0);
730 +                        if (single_plane_incident < 0)
731 +                                single_plane_incident = 0;
732                          break;
733                  case 'f':
734                          if (!argv[i][2]) {
735                                  if (strchr(argv[++i], '=') != NULL) {
736                                          add_wbsdf("-f", 1);
737                                          add_wbsdf(argv[i], 1);
738 <                                } else
739 <                                        fcompile(argv[i]);
738 >                                } else {
739 >                                        char    *fpath = getpath(argv[i],
740 >                                                            getrlibpath(), 0);
741 >                                        if (fpath == NULL) {
742 >                                                fprintf(stderr,
743 >                                                "%s: cannot find file '%s'\n",
744 >                                                        argv[0], argv[i]);
745 >                                                return(1);
746 >                                        }
747 >                                        fcompile(fpath);
748 >                                        if (single_plane_incident < 0)
749 >                                                single_plane_incident = 0;
750 >                                }
751                          } else
752                                  dofwd = (argv[i][0] == '+');
753                          break;
754 +                case 'a':
755 +                        recip = (argv[i][0] == '+') ? " -a" : "";
756 +                        break;
757                  case 'b':
758                          dobwd = (argv[i][0] == '+');
759                          break;
# Line 633 | Line 807 | main(int argc, char *argv[])
807                          goto userr;
808                  }
809                  ++eclock;
810 +                ssamp_thresh *= 0.5;            /* lower sampling threshold */
811                  add_wbsdf("-a", 1);
812                  add_wbsdf(tfmt[single_plane_incident], 1);
813                  if (dofwd) {
# Line 695 | Line 870 | main(int argc, char *argv[])
870          return(wrap_up());
871   userr:
872          fprintf(stderr,
873 <        "Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
873 >        "Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
874                                  progname);
875          fprintf(stderr,
876 <        "   or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
876 >        "   or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
877                                  progname);
878          return(1);
879   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines