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.41 by greg, Wed May 31 17:25:21 2017 UTC vs.
Revision 2.45 by greg, Wed May 6 01:30:00 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 129 | 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          FILE            *ofp, *uvfp[2];
133          int             assignD = 0;
134          char            cmd[128];
# Line 191 | Line 191 | eval_isotropic(char *funame)
191                  assignD = (fundefined(funame) < 6);
192                                                  /* run through directions */
193          for (ix = 0; ix < sqres/2; ix++) {
194 <                RBFNODE *rbf = NULL;
195 <                iovec[0] = 2.*(ix+.5)/sqres - 1.;
196 <                iovec[1] = .0;
197 <                iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]);
194 >                const int       zipsgn = (ix & 1)*2 - 1;
195 >                RBFNODE         *rbf = NULL;
196 >                iovec[0] = 2.*sqfact*(ix+.5) - 1.;
197 >                iovec[1] = zipsgn*sqfact*.5;
198 >                iovec[2] = input_orient * sqrt(1. - iovec[0]*iovec[0]
199 >                                                - iovec[1]*iovec[1]);
200                  if (funame == NULL)
201                          rbf = advect_rbf(iovec, lobe_lim);
202                  for (ox = 0; ox < sqres; ox++) {
203                      float       last_bsdf = -1;
204                      for (oy = 0; oy < sqres; oy++) {
205 <                        SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
205 >                        SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+.5)*sqfact);
206                          iovec[5] = output_orient *
207                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
208                          if (funame == NULL) {
209                              SDValue     sdv;
210                              eval_rbfcol(&sdv, rbf, iovec+3);
211                              bsdf = sdv.cieY;
212 + #if (NSSAMP > 0)
213 +                            if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
214 +                                int     ssi;
215 +                                double  ssa[2], sum = 0, usum = 0, vsum = 0;
216 +                                                /* super-sample voxel */
217 +                                for (ssi = NSSAMP; ssi--; ) {
218 +                                    SDmultiSamp(ssa, 2, (ssi+frandom()) *
219 +                                                        (1./NSSAMP));
220 +                                    SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
221 +                                                        (oy+ssa[1])*sqfact);
222 +                                    iovec[5] = output_orient *
223 +                                        sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
224 +                                    eval_rbfcol(&sdv, rbf, iovec+3);
225 +                                    sum += sdv.cieY;
226 +                                    if (rbf_colorimetry == RBCtristimulus) {
227 +                                        sdv.cieY /=
228 +                                            -2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.;
229 +                                        usum += 4.*sdv.spec.cx * sdv.cieY;
230 +                                        vsum += 9.*sdv.spec.cy * sdv.cieY;
231 +                                    }
232 +                                }
233 +                                bsdf = sum * (1./NSSAMP);
234 +                                if (rbf_colorimetry == RBCtristimulus) {
235 +                                    uv[0] = usum / (sum+FTINY);
236 +                                    uv[1] = vsum / (sum+FTINY);
237 +                                }
238 +                            } else
239 + #endif
240                              if (rbf_colorimetry == RBCtristimulus) {
241                                  uv[0] = uv[1] = 1. /
242                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
# Line 224 | Line 254 | eval_isotropic(char *funame)
254   #if (NSSAMP > 0)
255                              if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
256                                  int     ssi;
257 <                                double  ssa[3], ssvec[6], sum = 0;
257 >                                double  ssa[4], ssvec[6], sum = 0;
258                                                  /* super-sample voxel */
259                                  for (ssi = NSSAMP; ssi--; ) {
260 <                                    SDmultiSamp(ssa, 3, (ssi+frandom()) *
260 >                                    SDmultiSamp(ssa, 4, (ssi+frandom()) *
261                                                          (1./NSSAMP));
262 <                                    ssvec[0] = 2.*(ix+ssa[0])/sqres - 1.;
263 <                                    ssvec[1] = .0;
264 <                                    ssvec[2] = input_orient *
265 <                                                sqrt(1. - ssvec[0]*ssvec[0]);
266 <                                    SDsquare2disk(ssvec+3, (ox+ssa[1])/sqres,
267 <                                                (oy+ssa[2])/sqres);
262 >                                    ssvec[0] = 2.*sqfact*(ix+ssa[0]) - 1.;
263 >                                    ssvec[1] = zipsgn*sqfact*ssa[1];
264 >                                    ssvec[2] = 1. - ssvec[0]*ssvec[0]
265 >                                                        - ssvec[1]*ssvec[1];
266 >                                    if (ssvec[2] < .0) {
267 >                                        ssvec[1] = 0;
268 >                                        ssvec[2] = 1. - ssvec[0]*ssvec[0];
269 >                                    }
270 >                                    ssvec[2] = input_orient * sqrt(ssvec[2]);
271 >                                    SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact,
272 >                                                (oy+ssa[3])*sqfact);
273                                      ssvec[5] = output_orient *
274                                                  sqrt(1. - ssvec[3]*ssvec[3] -
275                                                          ssvec[4]*ssvec[4]);
# Line 246 | Line 281 | eval_isotropic(char *funame)
281                                      }
282                                      sum += funvalue(funame, 6, ssvec);
283                                  }
284 <                                bsdf = sum/NSSAMP;
284 >                                bsdf = sum * (1./NSSAMP);
285                              }
286   #endif
287                          }
# Line 269 | Line 304 | eval_isotropic(char *funame)
304                  }
305                  if (rbf != NULL)
306                          free(rbf);
307 <                prog_show((ix+1.)*(2./sqres));
307 >                prog_show((ix+1.)*(2.*sqfact));
308          }
309          prog_done();
310          if (pctcull >= 0) {                     /* finish output */
# Line 314 | Line 349 | static void
349   eval_anisotropic(char *funame)
350   {
351          const int       sqres = 1<<samp_order;
352 +        const double    sqfact = 1./(double)sqres;
353          FILE            *ofp, *uvfp[2];
354          int             assignD = 0;
355          char            cmd[128];
# Line 383 | Line 419 | eval_anisotropic(char *funame)
419          for (ix = 0; ix < sqres; ix++)
420              for (iy = 0; iy < sqres; iy++) {
421                  RBFNODE *rbf = NULL;            /* Klems reversal */
422 <                SDsquare2disk(iovec, 1.-(ix+.5)/sqres, 1.-(iy+.5)/sqres);
422 >                SDsquare2disk(iovec, 1.-(ix+.5)*sqfact, 1.-(iy+.5)*sqfact);
423                  iovec[2] = input_orient *
424                                  sqrt(1. - iovec[0]*iovec[0] - iovec[1]*iovec[1]);
425                  if (funame == NULL)
# Line 391 | Line 427 | eval_anisotropic(char *funame)
427                  for (ox = 0; ox < sqres; ox++) {
428                      float       last_bsdf = -1;
429                      for (oy = 0; oy < sqres; oy++) {
430 <                        SDsquare2disk(iovec+3, (ox+.5)/sqres, (oy+.5)/sqres);
430 >                        SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+.5)*sqfact);
431                          iovec[5] = output_orient *
432                                  sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
433                          if (funame == NULL) {
434                              SDValue     sdv;
435                              eval_rbfcol(&sdv, rbf, iovec+3);
436                              bsdf = sdv.cieY;
437 + #if (NSSAMP > 0)
438 +                            if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) {
439 +                                int     ssi;
440 +                                double  ssa[2], sum = 0, usum = 0, vsum = 0;
441 +                                                /* super-sample voxel */
442 +                                for (ssi = NSSAMP; ssi--; ) {
443 +                                    SDmultiSamp(ssa, 2, (ssi+frandom()) *
444 +                                                        (1./NSSAMP));
445 +                                    SDsquare2disk(iovec+3, (ox+ssa[0])*sqfact,
446 +                                                        (oy+ssa[1])*sqfact);
447 +                                    iovec[5] = output_orient *
448 +                                        sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]);
449 +                                    eval_rbfcol(&sdv, rbf, iovec+3);
450 +                                    sum += sdv.cieY;
451 +                                    if (rbf_colorimetry == RBCtristimulus) {
452 +                                        sdv.cieY /=
453 +                                            -2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.;
454 +                                        usum += 4.*sdv.spec.cx * sdv.cieY;
455 +                                        vsum += 9.*sdv.spec.cy * sdv.cieY;
456 +                                    }
457 +                                }
458 +                                bsdf = sum * (1./NSSAMP);
459 +                                if (rbf_colorimetry == RBCtristimulus) {
460 +                                    uv[0] = usum / (sum+FTINY);
461 +                                    uv[1] = vsum / (sum+FTINY);
462 +                                }
463 +                            } else
464 + #endif
465                              if (rbf_colorimetry == RBCtristimulus) {
466                                  uv[0] = uv[1] = 1. /
467                                      (-2.*sdv.spec.cx + 12.*sdv.spec.cy + 3.);
# Line 420 | Line 484 | eval_anisotropic(char *funame)
484                                  for (ssi = NSSAMP; ssi--; ) {
485                                      SDmultiSamp(ssa, 4, (ssi+frandom()) *
486                                                          (1./NSSAMP));
487 <                                    SDsquare2disk(ssvec, 1.-(ix+ssa[0])/sqres,
488 <                                                1.-(iy+ssa[1])/sqres);
487 >                                    SDsquare2disk(ssvec, 1.-(ix+ssa[0])*sqfact,
488 >                                                1.-(iy+ssa[1])*sqfact);
489                                      ssvec[2] = input_orient *
490                                                  sqrt(1. - ssvec[0]*ssvec[0] -
491                                                          ssvec[1]*ssvec[1]);
492 <                                    SDsquare2disk(ssvec+3, (ox+ssa[2])/sqres,
493 <                                                (oy+ssa[3])/sqres);
492 >                                    SDsquare2disk(ssvec+3, (ox+ssa[2])*sqfact,
493 >                                                (oy+ssa[3])*sqfact);
494                                      ssvec[5] = output_orient *
495                                                  sqrt(1. - ssvec[3]*ssvec[3] -
496                                                          ssvec[4]*ssvec[4]);
# Line 438 | Line 502 | eval_anisotropic(char *funame)
502                                      }
503                                      sum += funvalue(funame, 6, ssvec);
504                                  }
505 <                                bsdf = sum/NSSAMP;
505 >                                bsdf = sum * (1./NSSAMP);
506                              }
507   #endif
508                          }
# Line 575 | Line 639 | main(int argc, char *argv[])
639                                  if (strchr(argv[++i], '=') != NULL) {
640                                          add_wbsdf("-f", 1);
641                                          add_wbsdf(argv[i], 1);
642 <                                } else
643 <                                        fcompile(argv[i]);
642 >                                } else {
643 >                                        char    *fpath = getpath(argv[i],
644 >                                                            getrlibpath(), 0);
645 >                                        if (fpath == NULL) {
646 >                                                fprintf(stderr,
647 >                                                "%s: cannot find file '%s'\n",
648 >                                                        argv[0], argv[i]);
649 >                                                return(1);
650 >                                        }
651 >                                        fcompile(fpath);
652 >                                        if (single_plane_incident < 0)
653 >                                                single_plane_incident = 0;
654 >                                }
655                          } else
656                                  dofwd = (argv[i][0] == '+');
657                          break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines