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

Comparing ray/src/rt/source.c (file contents):
Revision 1.11 by greg, Tue Jun 13 08:20:22 1989 UTC vs.
Revision 1.12 by greg, Tue Jun 13 10:57:52 1989 UTC

# Line 27 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27  
28   extern double  dstrsrc;                 /* source distribution amount */
29   extern double  shadthresh;              /* relative shadow threshold */
30 + extern double  shadcert;                /* shadow testing certainty */
31  
32   SRCREC  *source = NULL;                 /* our list of sources */
33   int  nsources = 0;                      /* the number of sources */
# Line 301 | Line 302 | RAY  *r;                       /* ray that hit surface */
302   int  (*f)();                    /* direct component coefficient function */
303   char  *p;                       /* data for f */
304   {
305 +        extern double  pow();
306          register int  sn;
307          register CONTRIB  *srccnt;
308          register CNTPTR  *cntord;
309 +        int  nshadcheck, ncnts;
310          double  prob, ourthresh, hwt, test2, hit2;
311          RAY  sr;
312  
# Line 311 | Line 314 | char  *p;                      /* data for f */
314          cntord = (CNTPTR *)malloc(nsources*sizeof(CNTPTR));
315          if (srccnt == NULL || cntord == NULL)
316                  error(SYSTEM, "out of memory in direct");
317 +                                                /* compute number to check */
318 +        nshadcheck = pow((double)nsources, shadcert) + .5;
319                                                  /* modify threshold */
320          ourthresh = shadthresh / r->rweight;
321                                                  /* potential contributions */
# Line 339 | Line 344 | char  *p;                      /* data for f */
344          }
345                                                  /* sort contributions */
346          qsort(cntord, nsources, sizeof(CNTPTR), cntcmp);
347 <        hit2 = 0.5; test2 = 1.0;                /* start with prob=.5 */
347 >                                                /* find last */
348 >        sn = 0; ncnts = nsources;
349 >        while (sn < ncnts-1) {
350 >                register int  m;
351 >                m = (sn + ncnts) >> 1;
352 >                if (cntord[m].brt > 0.0)
353 >                        sn = m;
354 >                else
355 >                        ncnts = m;
356 >        }
357 >                                                /* accumulate tail */
358 >        for (sn = ncnts-1; sn > 0; sn--)
359 >                cntord[sn-1].brt += cntord[sn].brt;
360 >                                                /* start with prob=.5 */
361 >        hit2 = 0.5; test2 = 1.0;
362                                                  /* test for shadows */
363 <        for (sn = 0; sn < nsources; sn++) {
363 >        for (sn = 0; sn < ncnts; sn++) {
364                                                  /* check threshold */
365 <                if (cntord[sn].brt <= ourthresh*bright(r->rcol))
365 >                if ((sn+nshadcheck>=ncnts ? cntord[sn].brt :
366 >                                cntord[sn].brt-cntord[sn+nshadcheck].brt) <
367 >                                ourthresh*bright(r->rcol))
368                          break;
369                                                  /* get statistics */
370                  hwt = (double)source[cntord[sn].sno].nhits /
# Line 375 | Line 396 | char  *p;                      /* data for f */
396                                          /* weighted hit rate */
397          hwt = hit2 / test2;
398   #ifdef DEBUG
399 <        {
400 <                int  ntested = sn;
399 >        sprintf(errmsg, "%d tested, %d untested, %f hit rate\n",
400 >                        sn, ncnts-sn, hwt);
401 >        eputs(errmsg);
402   #endif
403                                          /* add in untested sources */
404 <        for ( ; sn < nsources; sn++) {
383 <                if (cntord[sn].brt <= 0.0)
384 <                        break;
404 >        for ( ; sn < ncnts; sn++) {
405                  prob = hwt * (double)source[cntord[sn].sno].nhits /
406                                  (double)source[cntord[sn].sno].ntests;
407                  scalecolor(srccnt[cntord[sn].sno].val, prob);
408                  addcolor(r->rcol, srccnt[cntord[sn].sno].val);
409          }
390 #ifdef DEBUG
391        fprintf(stderr, "%d tested, %d untested, %f hit rate\n",
392                        ntested, sn-ntested, hwt);
393        }
394 #endif
410                  
411          free(srccnt);
412          free(cntord);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines