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

Comparing ray/src/common/bsdf_t.c (file contents):
Revision 3.15 by greg, Fri Jun 3 18:12:58 2011 UTC vs.
Revision 3.23 by greg, Mon Aug 22 18:21:05 2011 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   *
11   */
12  
13 + #define _USE_MATH_DEFINES
14   #include "rtio.h"
15   #include <stdlib.h>
16   #include <math.h>
# Line 25 | Line 26 | typedef int    SDtreCallback(float val, const double *cmi
26  
27                                          /* reference width maximum (1.0) */
28   static const unsigned   iwbits = sizeof(unsigned)*4;
29 < static const unsigned   iwmax = (1<<(sizeof(unsigned)*4))-1;
29 > static const unsigned   iwmax = 1<<(sizeof(unsigned)*4);
30                                          /* maximum cumulative value */
31   static const unsigned   cumlmax = ~0;
32                                          /* constant z-vector */
33   static const FVECT      zvec = {.0, .0, 1.};
34 +                                        /* quantization value */
35 + static double           quantum = 1./256.;
36  
37   /* Struct used for our distribution-building callback */
38   typedef struct {
# Line 299 | Line 302 | SDdotravTre(const SDNode *st, const double *pos, int c
302                                          bmin[i] = cmin[i] + csiz;
303                                  else
304                                          bmin[i] = cmin[i];
302                        for (i = SD_MAXDIM; i-- > st->ndim; )
303                                bmin[i] = .0;
305  
306                          rval += rv = SDdotravTre(st->u.t[n], pos, cmask,
307                                                          cf, cptr, bmin, csiz);
# Line 326 | Line 327 | SDdotravTre(const SDNode *st, const double *pos, int c
327                                  clim[i][0] = 0;
328                                  clim[i][1] = 1 << st->log2GR;
329                          }
329                                        /* fill in unused dimensions */
330                for (i = SD_MAXDIM; i-- > st->ndim; ) {
331                        clim[i][0] = 0; clim[i][1] = 1;
332                }
330   #if (SD_MAXDIM == 4)
331                  bmin[0] = cmin[0] + csiz*clim[0][0];
332                  for (cpos[0] = clim[0][0]; cpos[0] < clim[0][1]; cpos[0]++) {
333                      bmin[1] = cmin[1] + csiz*clim[1][0];
334                      for (cpos[1] = clim[1][0]; cpos[1] < clim[1][1]; cpos[1]++) {
335                          bmin[2] = cmin[2] + csiz*clim[2][0];
336 <                        for (cpos[2] = clim[2][0]; cpos[2] < clim[2][1]; cpos[2]++) {
337 <                            bmin[3] = cmin[3] + csiz*(cpos[3] = clim[3][0]);
336 >                        if (st->ndim == 3) {
337 >                            cpos[2] = clim[2][0];
338                              n = cpos[0];
339 <                            for (i = 1; i < st->ndim; i++)
339 >                            for (i = 1; i < 3; i++)
340                                  n = (n << st->log2GR) + cpos[i];
341 <                            for ( ; cpos[3] < clim[3][1]; cpos[3]++) {
341 >                            for ( ; cpos[2] < clim[2][1]; cpos[2]++) {
342                                  rval += rv = (*cf)(st->u.v[n++], bmin, csiz, cptr);
343                                  if (rv < 0)
344                                      return rv;
345 <                                bmin[3] += csiz;
345 >                                bmin[2] += csiz;
346                              }
347 <                            bmin[2] += csiz;
347 >                        } else {
348 >                            for (cpos[2] = clim[2][0]; cpos[2] < clim[2][1]; cpos[2]++) {
349 >                                bmin[3] = cmin[3] + csiz*(cpos[3] = clim[3][0]);
350 >                                n = cpos[0];
351 >                                for (i = 1; i < 4; i++)
352 >                                    n = (n << st->log2GR) + cpos[i];
353 >                                for ( ; cpos[3] < clim[3][1]; cpos[3]++) {
354 >                                    rval += rv = (*cf)(st->u.v[n++], bmin, csiz, cptr);
355 >                                    if (rv < 0)
356 >                                        return rv;
357 >                                    bmin[3] += csiz;
358 >                                }
359 >                                bmin[2] += csiz;
360 >                            }
361                          }
362                          bmin[1] += csiz;
363                      }
# Line 600 | Line 610 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
610   {
611          const SDTre     *sdt;
612          double          inCoord[2];
603        int             vflags;
613          int             i;
614          SDTreCDst       *cd, *cdlast;
615                                          /* check arguments */
616          if ((inVec == NULL) | (sdc == NULL) ||
617                          (sdt = (SDTre *)sdc->dist) == NULL)
618                  return NULL;
619 <        if (sdt->st->ndim == 3)         /* isotropic BSDF? */
619 >        if (sdt->st->ndim == 3) {       /* isotropic BSDF? */
620                  inCoord[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]);
621 <        else if (sdt->st->ndim == 4)
621 >        } else if (sdt->st->ndim == 4) {
622                  SDdisk2square(inCoord, -inVec[0], -inVec[1]);
623 <        else
623 >        } else
624                  return NULL;            /* should be internal error */
625 +                                        /* quantize to avoid f.p. errors */
626 +        for (i = sdt->st->ndim - 2; i--; )
627 +                inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum;
628          cdlast = NULL;                  /* check for direction in cache list */
629          for (cd = (SDTreCDst *)sdc->cdList; cd != NULL;
630 <                                cdlast = cd, cd = (SDTreCDst *)cd->next) {
630 >                                        cdlast = cd, cd = cd->next) {
631                  for (i = sdt->st->ndim - 2; i--; )
632                          if ((cd->clim[i][0] > inCoord[i]) |
633                                          (inCoord[i] >= cd->clim[i][1]))
# Line 627 | Line 639 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
639                  cdlast = cd = make_cdist(sdt, inCoord);
640          if (cdlast != NULL) {           /* move entry to head of cache list */
641                  cdlast->next = cd->next;
642 <                cd->next = sdc->cdList;
642 >                cd->next = (SDTreCDst *)sdc->cdList;
643                  sdc->cdList = (SDCDst *)cd;
644          }
645          return (SDCDst *)cd;            /* ready to go */
# Line 703 | Line 715 | SDsampTreCDist(FVECT ioVec, double randX, const SDCDst
715                                          /* binary search to find position */
716          ilower = 0; iupper = cd->calen;
717          while ((i = (iupper + ilower) >> 1) != ilower)
718 <                if ((long)target >= (long)cd->carr[i].cuml)
718 >                if (target >= cd->carr[i].cuml)
719                          ilower = i;
720                  else
721                          iupper = i;
# Line 834 | Line 846 | get_extrema(SDSpectralDF *df)
846          double  stepWidth, dhemi, bmin[4], bmax[4];
847  
848          stepWidth = SDsmallestLeaf(st);
849 +        if (quantum > stepWidth)        /* adjust quantization factor */
850 +                quantum = stepWidth;
851          df->minProjSA = M_PI*stepWidth*stepWidth;
852          if (stepWidth < .03125)
853                  stepWidth = .03125;     /* 1/32 resolution good enough */
# Line 873 | Line 887 | load_bsdf_data(SDData *sd, ezxml_t wdb, int ndim)
887          SDSpectralDF    *df;
888          SDTre           *sdt;
889          char            *sdata;
876        int             i;
890                                          /* allocate BSDF component */
891          sdata = ezxml_txt(ezxml_child(wdb, "WavelengthDataDirection"));
892          if (!sdata)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines