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.52 by greg, Mon May 18 20:08:57 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
30 < #define NSSAMP          100
31 < #endif
30 > static int              nssamp = 256;
31                                  /* limit on number of RBF lobes */
32   static int              lobe_lim = 15000;
33                                  /* progress bar length */
# Line 38 | Line 37 | static int             do_prog = 79;
37   static char             *wrapBSDF[MAXCARG] = {"wrapBSDF", "-U"};
38   static int              wbsdfac = 2;
39  
40 < /* Add argument to wrapBSDF, allocating space if isstatic */
40 > /* Add argument to wrapBSDF, allocating space if !isstatic */
41   static void
42   add_wbsdf(const char *arg, int isstatic)
43   {
# Line 127 | Line 126 | static void
126   eval_isotropic(char *funame)
127   {
128          const int       sqres = 1<<samp_order;
129 +        const double    sqfact = 1./(double)sqres;
130 +        float           *val_last = NULL;
131 +        float           *val_next = NULL;
132 +        SDValue         *sdv_next = NULL;
133          FILE            *ofp, *uvfp[2];
134          int             assignD = 0;
135          char            cmd[128];
# Line 135 | Line 138 | eval_isotropic(char *funame)
138          float           bsdf, uv[2];
139  
140          if (pctcull >= 0) {
141 <                sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
142 <                                pctcull, samp_order, create_component_file(0));
141 >                sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
142 >                                recip, pctcull, samp_order, create_component_file(0));
143                  ofp = popen(cmd, "w");
144                  if (ofp == NULL) {
145                          fprintf(stderr, "%s: cannot create pipe to rttree_reduce\n",
# Line 149 | Line 152 | eval_isotropic(char *funame)
152   #endif
153                  if (rbf_colorimetry == RBCtristimulus) {
154                          double  uvcull = 100. - (100.-pctcull)*.25;
155 <                        sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
156 <                                        uvcull, samp_order, create_component_file(1));
155 >                        sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
156 >                                        recip, uvcull, samp_order, create_component_file(1));
157                          uvfp[0] = popen(cmd, "w");
158 <                        sprintf(cmd, "rttree_reduce -a -h -ff -r 3 -t %f -g %d > %s",
159 <                                        uvcull, samp_order, create_component_file(2));
158 >                        sprintf(cmd, "rttree_reduce%s -h -ff -r 3 -t %f -g %d > %s",
159 >                                        recip, uvcull, samp_order, create_component_file(2));
160                          uvfp[1] = popen(cmd, "w");
161                          if ((uvfp[0] == NULL) | (uvfp[1] == NULL)) {
162                                  fprintf(stderr, "%s: cannot open pipes to uv output\n",
# Line 187 | Line 190 | eval_isotropic(char *funame)
190          }
191          if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
192                  assignD = (fundefined(funame) < 6);
193 +        val_last = (float *)calloc(sqres, sizeof(float));
194 +        if (funame == NULL)
195 +                sdv_next = (SDValue *)malloc(sizeof(SDValue)*sqres);
196 +        else
197 +                val_next = (float *)malloc(sizeof(float)*sqres);
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 +                                                /* presample first row */
209 +                for (oy = 0; oy < sqres; oy++) {
210 +                    SDsquare2disk(iovec+3, .5*sqfact, (oy+.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[oy], rbf, iovec+3);
215 +                    } else {
216 +                        if (assignD) {
217 +                            varset("Dx", '=', -iovec[3]);
218 +                            varset("Dy", '=', -iovec[4]);
219 +                            varset("Dz", '=', -iovec[5]);
220 +                            ++eclock;
221 +                        }
222 +                        val_next[oy] = funvalue(funame, 6, iovec);
223 +                    }
224 +                }
225                  for (ox = 0; ox < sqres; ox++) {
226 <                    float       last_bsdf = -1;
226 >                    /*
227 >                     * Super-sample when we detect a difference from before
228 >                     * or after in this row, above or below.
229 >                     */
230                      for (oy = 0; oy < sqres; oy++) {
231 <                        SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
232 <                        iovec[5] = output_orient *
231 >                        if (ox < sqres-1) {     /* keeping one row ahead... */
232 >                            SDsquare2disk(iovec+3, (ox+1.5)*sqfact, (oy+.5)*sqfact);
233 >                            iovec[5] = output_orient *
234                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
235 +                        }
236                          if (funame == NULL) {
237 <                            SDValue     sdv;
206 <                            eval_rbfcol(&sdv, rbf, iovec+3);
237 >                            SDValue     sdv = sdv_next[oy];
238                              bsdf = sdv.cieY;
239 +                            if (ox < sqres-1)
240 +                                eval_rbfcol(&sdv_next[oy], rbf, iovec+3);
241 +                            if (abs_diff(bsdf, sdv_next[oy].cieY) > ssamp_thresh ||
242 +                                (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
243 +                                (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
244 +                                (oy < sqres-1 &&
245 +                                    abs_diff(bsdf, sdv_next[oy+1].cieY) > ssamp_thresh)) {
246 +                                int     ssi;
247 +                                double  ssa[2], sum = 0, usum = 0, vsum = 0;
248 +                                                /* super-sample voxel */
249 +                                for (ssi = nssamp; ssi--; ) {
250 +                                    SDmultiSamp(ssa, 2, (ssi+frandom()) /
251 +                                                        (double)nssamp);
252 +                                    SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
253 +                                                        (oy+ssa[1])*sqfact);
254 +                                    iovec[5] = output_orient *
255 +                                        sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
256 +                                    eval_rbfcol(&sdv, rbf, iovec+3);
257 +                                    sum += sdv.cieY;
258 +                                    if (rbf_colorimetry == RBCtristimulus) {
259 +                                        sdv.cieY /=
260 +                                            -2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.;
261 +                                        usum += 4.*sdv.spec.cx * sdv.cieY;
262 +                                        vsum += 9.*sdv.spec.cy * sdv.cieY;
263 +                                    }
264 +                                }
265 +                                bsdf = sum / (double)nssamp;
266 +                                if (rbf_colorimetry == RBCtristimulus) {
267 +                                    uv[0] = usum / (sum+FTINY);
268 +                                    uv[1] = vsum / (sum+FTINY);
269 +                                }
270 +                            } else
271                              if (rbf_colorimetry == RBCtristimulus) {
209                                c_ccvt(&sdv.spec, C_CSXY);
272                                  uv[0] = uv[1] = 1. /
273                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
274                                  uv[0] *= 4.*sdv.spec.cx;
275                                  uv[1] *= 9.*sdv.spec.cy;
276                              }
277                          } else {
278 <                            if (assignD) {
279 <                                varset("Dx", '=', -iovec[3]);
280 <                                varset("Dy", '=', -iovec[4]);
281 <                                varset("Dz", '=', -iovec[5]);
282 <                                ++eclock;
278 >                            bsdf = val_next[oy];
279 >                            if (ox < sqres-1) {
280 >                                if (assignD) {
281 >                                    varset("Dx", '=', -iovec[3]);
282 >                                    varset("Dy", '=', -iovec[4]);
283 >                                    varset("Dz", '=', -iovec[5]);
284 >                                    ++eclock;
285 >                                }
286 >                                val_next[oy] = funvalue(funame, 6, iovec);
287                              }
288 <                            bsdf = funvalue(funame, 6, iovec);
289 < #if (NSSAMP > 0)
290 <                            if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
288 >                            if (abs_diff(bsdf, val_next[oy]) > ssamp_thresh ||
289 >                                (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
290 >                                (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
291 >                                (oy < sqres-1 &&
292 >                                    abs_diff(bsdf, val_next[oy+1]) > ssamp_thresh)) {
293                                  int     ssi;
294 <                                double  ssa[3], ssvec[6], sum = 0;
294 >                                double  ssa[4], ssvec[6], sum = 0;
295                                                  /* super-sample voxel */
296 <                                for (ssi = NSSAMP; ssi--; ) {
297 <                                    SDmultiSamp(ssa, 3, (ssi+frandom()) *
298 <                                                        (1./NSSAMP));
299 <                                    ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.;
300 <                                    ssvec[1] = .0;
301 <                                    ssvec[2] = input_orient *
302 <                                                sqrt(1. - ssvec[0]*ssvec[0]);
303 <                                    SDsquare2disk(ssvec+3, (ox+ssa[1])/sqres,
304 <                                                (oy+ssa[2])/sqres);
296 >                                for (ssi = nssamp; ssi--; ) {
297 >                                    SDmultiSamp(ssa, 4, (ssi+frandom()) /
298 >                                                        (double)nssamp);
299 >                                    ssvec[0] = 2.*sqfact*(ix+ssa[0]) - 1.;
300 >                                    ssvec[1] = zipsgn*sqfact*ssa[1];
301 >                                    ssvec[2] = 1. - ssvec[0]*ssvec[0]
302 >                                                        - ssvec[1]*ssvec[1];
303 >                                    if (ssvec[2] < .0) {
304 >                                        ssvec[1] = 0;
305 >                                        ssvec[2] = 1. - ssvec[0]*ssvec[0];
306 >                                    }
307 >                                    ssvec[2] = input_orient * sqrt(ssvec[2]);
308 >                                    SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact,
309 >                                                (oy+ssa[3])*sqfact);
310                                      ssvec[5] = output_orient *
311                                                  sqrt(1. - ssvec[3]*ssvec[3] -
312                                                          ssvec[4]*ssvec[4]);
# Line 245 | Line 318 | eval_isotropic(char *funame)
318                                      }
319                                      sum += funvalue(funame, 6, ssvec);
320                                  }
321 <                                bsdf = sum/NSSAMP;
321 >                                bsdf = sum / (double)nssamp;
322                              }
250 #endif
323                          }
324                          if (pctcull >= 0)
325 <                                fwrite(&bsdf, sizeof(bsdf), 1, ofp);
325 >                                putbinary(&bsdf, sizeof(bsdf), 1, ofp);
326                          else
327                                  fprintf(ofp, "\t%.3e\n", bsdf);
328  
329                          if (rbf_colorimetry == RBCtristimulus) {
330                                  if (pctcull >= 0) {
331 <                                        fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]);
332 <                                        fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]);
331 >                                        putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]);
332 >                                        putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]);
333                                  } else {
334                                          fprintf(uvfp[0], "\t%.3e\n", uv[0]);
335                                          fprintf(uvfp[1], "\t%.3e\n", uv[1]);
336                                  }
337                          }
338 <                        last_bsdf = bsdf;
338 >                        if (val_last != NULL)
339 >                                val_last[oy] = bsdf;
340                      }
341                  }
342                  if (rbf != NULL)
343                          free(rbf);
344 <                prog_show((ix+1.)*(2./sqres));
344 >                prog_show((ix+1.)*(2.*sqfact));
345          }
346          prog_done();
347 +        if (val_last != NULL) {
348 +                free(val_last);
349 +                if (val_next != NULL) free(val_next);
350 +                if (sdv_next != NULL) free(sdv_next);
351 +        }
352          if (pctcull >= 0) {                     /* finish output */
353                  if (pclose(ofp)) {
354                          fprintf(stderr, "%s: error running rttree_reduce on Y\n",
# Line 313 | Line 391 | static void
391   eval_anisotropic(char *funame)
392   {
393          const int       sqres = 1<<samp_order;
394 +        const double    sqfact = 1./(double)sqres;
395 +        float           *val_last = NULL;
396 +        float           *val_next = NULL;
397 +        SDValue         *sdv_next = NULL;
398          FILE            *ofp, *uvfp[2];
399          int             assignD = 0;
400          char            cmd[128];
# Line 322 | Line 404 | eval_anisotropic(char *funame)
404  
405          if (pctcull >= 0) {
406                  const char      *avgopt = (input_orient>0 ^ output_orient>0)
407 <                                                ? "" : " -a";
407 >                                                ? "" : recip;
408                  sprintf(cmd, "rttree_reduce%s -h -ff -r 4 -t %f -g %d > %s",
409                                  avgopt, pctcull, samp_order,
410                                  create_component_file(0));
# Line 378 | Line 460 | eval_anisotropic(char *funame)
460          }
461          if (funame != NULL)                     /* need to assign Dx, Dy, Dz? */
462                  assignD = (fundefined(funame) < 6);
463 +        val_last = (float *)calloc(sqres, sizeof(float));
464 +        if (funame == NULL)
465 +                sdv_next = (SDValue *)malloc(sizeof(SDValue)*sqres);
466 +        else
467 +                val_next = (float *)malloc(sizeof(float)*sqres);
468                                                  /* run through directions */
469          for (ix = 0; ix < sqres; ix++)
470              for (iy = 0; iy < sqres; iy++) {
471                  RBFNODE *rbf = NULL;            /* Klems reversal */
472 <                SDsquare2disk(iovec, 1.-(ix+.5)/sqres, 1.-(iy+.5)/sqres);
472 >                SDsquare2disk(iovec, 1.-(ix+.5)*sqfact, 1.-(iy+.5)*sqfact);
473                  iovec[2] = input_orient *
474                                  sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]);
475                  if (funame == NULL)
476                          rbf = advect_rbf(iovec, lobe_lim);
477 +                                                /* presample first row */
478 +                for (oy = 0; oy < sqres; oy++) {
479 +                    SDsquare2disk(iovec+3, .5*sqfact, (oy+.5)*sqfact);
480 +                    iovec[5] = output_orient *
481 +                                sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
482 +                    if (funame == NULL) {
483 +                        eval_rbfcol(&sdv_next[oy], rbf, iovec+3);
484 +                    } else {
485 +                        if (assignD) {
486 +                            varset("Dx", '=', -iovec[3]);
487 +                            varset("Dy", '=', -iovec[4]);
488 +                            varset("Dz", '=', -iovec[5]);
489 +                            ++eclock;
490 +                        }
491 +                        val_next[oy] = funvalue(funame, 6, iovec);
492 +                    }
493 +                }
494                  for (ox = 0; ox < sqres; ox++) {
495 <                    float       last_bsdf = -1;
495 >                    /*
496 >                     * Super-sample when we detect a difference from before
497 >                     * or after in this row, above or below.
498 >                     */
499                      for (oy = 0; oy < sqres; oy++) {
500 <                        SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
501 <                        iovec[5] = output_orient *
500 >                        if (ox < sqres-1) {     /* keeping one row ahead... */
501 >                            SDsquare2disk(iovec+3, (ox+1.5)*sqfact, (oy+.5)*sqfact);
502 >                            iovec[5] = output_orient *
503                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
504 +                        }
505                          if (funame == NULL) {
506 <                            SDValue     sdv;
398 <                            eval_rbfcol(&sdv, rbf, iovec+3);
506 >                            SDValue     sdv = sdv_next[oy];
507                              bsdf = sdv.cieY;
508 +                            if (ox < sqres-1)
509 +                                eval_rbfcol(&sdv_next[oy], rbf, iovec+3);
510 +                            if (abs_diff(bsdf, sdv_next[oy].cieY) > ssamp_thresh ||
511 +                                (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
512 +                                (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
513 +                                (oy < sqres-1 &&
514 +                                    abs_diff(bsdf, sdv_next[oy+1].cieY) > ssamp_thresh)) {
515 +                                int     ssi;
516 +                                double  ssa[2], sum = 0, usum = 0, vsum = 0;
517 +                                                /* super-sample voxel */
518 +                                for (ssi = nssamp; ssi--; ) {
519 +                                    SDmultiSamp(ssa, 2, (ssi+frandom()) /
520 +                                                        (double)nssamp);
521 +                                    SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
522 +                                                        (oy+ssa[1])*sqfact);
523 +                                    iovec[5] = output_orient *
524 +                                        sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
525 +                                    eval_rbfcol(&sdv, rbf, iovec+3);
526 +                                    sum += sdv.cieY;
527 +                                    if (rbf_colorimetry == RBCtristimulus) {
528 +                                        sdv.cieY /=
529 +                                            -2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.;
530 +                                        usum += 4.*sdv.spec.cx * sdv.cieY;
531 +                                        vsum += 9.*sdv.spec.cy * sdv.cieY;
532 +                                    }
533 +                                }
534 +                                bsdf = sum / (double)nssamp;
535 +                                if (rbf_colorimetry == RBCtristimulus) {
536 +                                    uv[0] = usum / (sum+FTINY);
537 +                                    uv[1] = vsum / (sum+FTINY);
538 +                                }
539 +                            } else
540                              if (rbf_colorimetry == RBCtristimulus) {
401                                c_ccvt(&sdv.spec, C_CSXY);
541                                  uv[0] = uv[1] = 1. /
542                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
543                                  uv[0] *= 4.*sdv.spec.cx;
544                                  uv[1] *= 9.*sdv.spec.cy;
545                              }
546                          } else {
547 <                            if (assignD) {
548 <                                varset("Dx", '=', -iovec[3]);
549 <                                varset("Dy", '=', -iovec[4]);
550 <                                varset("Dz", '=', -iovec[5]);
551 <                                ++eclock;
547 >                            bsdf = val_next[oy];
548 >                            if (ox < sqres-1) {
549 >                                if (assignD) {
550 >                                    varset("Dx", '=', -iovec[3]);
551 >                                    varset("Dy", '=', -iovec[4]);
552 >                                    varset("Dz", '=', -iovec[5]);
553 >                                    ++eclock;
554 >                                }
555 >                                val_next[oy] = funvalue(funame, 6, iovec);
556                              }
557 <                            bsdf = funvalue(funame, 6, iovec);
558 < #if (NSSAMP > 0)
559 <                            if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
557 >                            if (abs_diff(bsdf, val_next[oy]) > ssamp_thresh ||
558 >                                (ox && abs_diff(bsdf, val_last[oy]) > ssamp_thresh) ||
559 >                                (oy && abs_diff(bsdf, val_last[oy-1]) > ssamp_thresh) ||
560 >                                (oy < sqres-1 &&
561 >                                    abs_diff(bsdf, val_next[oy+1]) > ssamp_thresh)) {
562                                  int     ssi;
563                                  double  ssa[4], ssvec[6], sum = 0;
564                                                  /* super-sample voxel */
565 <                                for (ssi = NSSAMP; ssi--; ) {
566 <                                    SDmultiSamp(ssa, 4, (ssi+frandom()) *
567 <                                                        (1./NSSAMP));
568 <                                    SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres,
569 <                                                1.-(iy+ssa[1])/sqres);
565 >                                for (ssi = nssamp; ssi--; ) {
566 >                                    SDmultiSamp(ssa, 4, (ssi+frandom()) /
567 >                                                        (double)nssamp);
568 >                                    SDsquare2disk(ssvec, 1.-(ix+ssa[0])*sqfact,
569 >                                                1.-(iy+ssa[1])*sqfact);
570                                      ssvec[2] = input_orient *
571                                                  sqrt(1. - ssvec[0]*ssvec[0] -
572                                                          ssvec[1]*ssvec[1]);
573 <                                    SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres,
574 <                                                (oy+ssa[3])/sqres);
573 >                                    SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact,
574 >                                                (oy+ssa[3])*sqfact);
575                                      ssvec[5] = output_orient *
576                                                  sqrt(1. - ssvec[3]*ssvec[3] -
577                                                          ssvec[4]*ssvec[4]);
# Line 438 | Line 583 | eval_anisotropic(char *funame)
583                                      }
584                                      sum += funvalue(funame, 6, ssvec);
585                                  }
586 <                                bsdf = sum/NSSAMP;
586 >                                bsdf = sum / (double)nssamp;
587                              }
443 #endif
588                          }
589                          if (pctcull >= 0)
590 <                                fwrite(&bsdf, sizeof(bsdf), 1, ofp);
590 >                                putbinary(&bsdf, sizeof(bsdf), 1, ofp);
591                          else
592                                  fprintf(ofp, "\t%.3e\n", bsdf);
593  
594                          if (rbf_colorimetry == RBCtristimulus) {
595                                  if (pctcull >= 0) {
596 <                                        fwrite(&uv[0], sizeof(*uv), 1, uvfp[0]);
597 <                                        fwrite(&uv[1], sizeof(*uv), 1, uvfp[1]);
596 >                                        putbinary(&uv[0], sizeof(*uv), 1, uvfp[0]);
597 >                                        putbinary(&uv[1], sizeof(*uv), 1, uvfp[1]);
598                                  } else {
599                                          fprintf(uvfp[0], "\t%.3e\n", uv[0]);
600                                          fprintf(uvfp[1], "\t%.3e\n", uv[1]);
601                                  }
602                          }
603 <                        last_bsdf = bsdf;
603 >                        if (val_last != NULL)
604 >                                val_last[oy] = bsdf;
605                      }
606                  }
607                  if (rbf != NULL)
# Line 464 | Line 609 | eval_anisotropic(char *funame)
609                  prog_show((ix*sqres+iy+1.)/(sqres*sqres));
610              }
611          prog_done();
612 +        if (val_last != NULL) {
613 +                free(val_last);
614 +                if (val_next != NULL) free(val_next);
615 +                if (sdv_next != NULL) free(sdv_next);
616 +        }
617          if (pctcull >= 0) {                     /* finish output */
618                  if (pclose(ofp)) {
619                          fprintf(stderr, "%s: error running rttree_reduce on Y\n",
# Line 565 | Line 715 | main(int argc, char *argv[])
715          esupport &= ~(E_INCHAN|E_OUTCHAN);
716          scompile("PI:3.14159265358979323846", NULL, 0);
717          biggerlib();
718 <        for (i = 1; i < argc-1 && (argv[i][0] == '-') | (argv[i][0] == '+'); i++)
718 >        for (i = 1; i < argc && (argv[i][0] == '-') | (argv[i][0] == '+'); i++)
719                  switch (argv[i][1]) {           /* get options */
720                  case 'e':
721                          scompile(argv[++i], NULL, 0);
722 +                        if (single_plane_incident < 0)
723 +                                single_plane_incident = 0;
724                          break;
725                  case 'f':
726                          if (!argv[i][2]) {
727                                  if (strchr(argv[++i], '=') != NULL) {
728                                          add_wbsdf("-f", 1);
729                                          add_wbsdf(argv[i], 1);
730 <                                } else
731 <                                        fcompile(argv[i]);
730 >                                } else {
731 >                                        char    *fpath = getpath(argv[i],
732 >                                                            getrlibpath(), 0);
733 >                                        if (fpath == NULL) {
734 >                                                fprintf(stderr,
735 >                                                "%s: cannot find file '%s'\n",
736 >                                                        argv[0], argv[i]);
737 >                                                return(1);
738 >                                        }
739 >                                        fcompile(fpath);
740 >                                        if (single_plane_incident < 0)
741 >                                                single_plane_incident = 0;
742 >                                }
743                          } else
744                                  dofwd = (argv[i][0] == '+');
745                          break;
746 +                case 'a':
747 +                        recip = (argv[i][0] == '+') ? " -a" : "";
748 +                        break;
749                  case 'b':
750                          dobwd = (argv[i][0] == '+');
751                          break;
752 +                case 'n':
753 +                        nssamp = atoi(argv[++i]);
754 +                        if (nssamp <= 0)
755 +                                goto userr;
756 +                        break;
757 +                case 's':
758 +                        ssamp_thresh = atof(argv[++i]);
759 +                        if (ssamp_thresh <= FTINY)
760 +                                goto userr;
761 +                        break;
762                  case 't':
763                          switch (argv[i][2]) {
764                          case '3':
# Line 695 | Line 871 | main(int argc, char *argv[])
871          return(wrap_up());
872   userr:
873          fprintf(stderr,
874 <        "Usage: %s [-g Nlog2][-t pctcull][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
874 >        "Usage: %s [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][-l maxlobes] [bsdf.sir ..] > bsdf.xml\n",
875                                  progname);
876          fprintf(stderr,
877 <        "   or: %s -t{3|4} [-g Nlog2][-t pctcull][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
877 >        "   or: %s -t{3|4} [{+|-}a][-g Nlog2][-t pctcull][-n nss][-s thresh][{+|-}for[ward]][{+|-}b[ackward]][-e expr][-f file] bsdf_func > bsdf.xml\n",
878                                  progname);
879          return(1);
880   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines