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

Comparing ray/src/util/glaresrc.c (file contents):
Revision 1.7 by greg, Wed Mar 20 12:18:14 1991 UTC vs.
Revision 1.13 by greg, Fri Apr 19 17:41:03 1991 UTC

# Line 49 | Line 49 | analyze()                      /* analyze our scene */
49                  memerr("view span brightness buffer");
50          for (v = vsize; v >= -vsize; v--) {
51                  close_sources(v);
52 + #ifndef DEBUG
53 +                if (verbose)
54 +                        fprintf(stderr, "%s: analyzing... %3ld%%\r",
55 +                                progname, 100L*(vsize-v)/(2*vsize));
56 + #endif
57                  getviewspan(v, spanbr);
58                  left = hsize + 1;
59                  for (h = -hsize; h <= hsize; h++) {
# Line 67 | Line 72 | analyze()                      /* analyze our scene */
72                                          addsrcspan(newspan(left,h,v,spanbr));
73                                          left = hsize + 1;
74                                  }
75 <                                addindirect(h, spanbr[h+hsize]);
75 >                                addindirect(h, v, spanbr[h+hsize]);
76                          }
77                  }
78                  if (left < h)
# Line 75 | Line 80 | analyze()                      /* analyze our scene */
80          }
81          free((char *)spanbr);
82          close_allsrcs();
78        absorb_specks();
83   }
84  
85  
86 < addindirect(h, br)              /* add brightness to indirect illuminances */
87 < int     h;
86 > addindirect(h, v, br)           /* add brightness to indirect illuminances */
87 > int     h, v;
88   double  br;
89   {
90          double  tanb, d;
91 +        int     hl;
92          register int    i;
93  
94 <        if (h <= -hlim) {                       /* left region */
95 <                d = (double)(h+hlim)/sampdens;
96 <                if (d <= -1.0+FTINY)
94 >        hl = hlim(v);
95 >        if (h <= -hl) {                 /* left region */
96 >                d = (double)(-h-hl)/sampdens;
97 >                if (d >= 1.0-FTINY)
98                          return;
99                  tanb = d/sqrt(1.0-d*d);
100                  for (i = 0; i < nglardirs; i++) {
101                          d = indirect[i].lcos - tanb*indirect[i].lsin;
102                          if (d > 0.0) {
103                                  indirect[i].sum += d * br;
104 <                                indirect[i].n++;
104 >                                indirect[i].n += d;
105                          }
106                  }
107                  return;
108          }
109 <        if (h >= hlim) {                        /* right region */
110 <                d = (double)(h-hlim)/sampdens;
111 <                if (d >= 1.0-FTINY)
109 >        if (h >= hl) {                  /* right region */
110 >                d = (double)(-h+hl)/sampdens;
111 >                if (d <= -1.0+FTINY)
112                          return;
113                  tanb = d/sqrt(1.0-d*d);
114                  for (i = 0; i < nglardirs; i++) {
115                          d = indirect[i].rcos - tanb*indirect[i].rsin;
116                          if (d > 0.0) {
117                                  indirect[i].sum += d * br;
118 <                                indirect[i].n++;
118 >                                indirect[i].n += d;
119                          }
120                  }
121                  return;
122          }
123                                          /* central region */
124          for (i = 0; i < nglardirs; i++) {
125 <                d = cos(h_theta(h) - indirect[i].theta);
125 >                d = cos(h_theta(h,v) - indirect[i].theta);
126                  if (d > 0.0) {
127                          indirect[i].sum += d * br;
128 <                        indirect[i].n++;
128 >                        indirect[i].n += d;
129                  }
130          }
131   }
# Line 136 | Line 142 | comp_thresh()                  /* compute glare threshold */
142                                  progname);
143          brsum = 0.0;
144          nsamps = 0;
145 <        for (v = vsize; v >= -vsize; v -= TSAMPSTEP)
145 >        for (v = vsize; v >= -vsize; v -= TSAMPSTEP) {
146                  for (h = -hsize; h <= hsize; h += TSAMPSTEP) {
147                          if ((br = getviewpix(h, v)) < 0.0)
148                                  continue;
149                          brsum += br;
150                          nsamps++;
151                  }
152 +        }
153          if (nsamps == 0) {
154                  fprintf(stderr, "%s: no viewable scene!\n", progname);
155                  exit(1);
# Line 153 | Line 160 | comp_thresh()                  /* compute glare threshold */
160                  exit(1);
161          }
162          if (verbose) {
163 + #ifdef DEBUG
164                  pict_stats();
165 + #endif
166                  fprintf(stderr,
167                          "%s: threshold set to %f cd/m2 from %d samples\n",
168                                  progname, threshold, nsamps);
# Line 272 | Line 281 | register struct source *sp;
281          FVECT   dthis, dright;
282          register struct srcspan *ss;
283          int     h, n;
284 <        double  d;
284 >        double  hsum, vsum, d;
285  
286          sp->dom = 0.0;
287 <        sp->dir[0] = sp->dir[1] = sp->dir[2] = 0.0;
287 >        hsum = vsum = 0.0;
288          sp->brt = 0.0;
289          n = 0;
290          for (ss = sp->first; ss != NULL; ss = ss->next) {
291                  sp->brt += ss->brsum;
292                  n += ss->r - ss->l;
293 <                if (compdir(dright, ss->r, ss->v) < 0)
294 <                        compdir(dright, ss->r-2, ss->v);
295 <                for (h = ss->r-1; h >= ss->l; h--)
296 <                        if (compdir(dthis, h, ss->v) == 0) {
297 <                                d = dist2(dthis, dright);
298 <                                fvsum(sp->dir, sp->dir, dthis, d);
290 <                                sp->dom += d;
291 <                                VCOPY(dright, dthis);
292 <                        }
293 >                for (h = ss->r-1; h >= ss->l; h--) {
294 >                        d = pixsize(h, ss->v);
295 >                        hsum += d*h;
296 >                        vsum += d*ss->v;
297 >                        sp->dom += d;
298 >                }
299                  free((char *)ss);
300          }
301          sp->first = NULL;
302          sp->brt /= (double)n;
303 <        normalize(sp->dir);
303 >        compdir(sp->dir, (int)(hsum/sp->dom), (int)(vsum/sp->dom));
304          sp->next = donelist;
305          donelist = sp;
306          if (verbose)
307                  fprintf(stderr,
308 <        "%s: found source at (%.3f,%.3f,%.3f), dw %.5f, br %.1f (%d samps)\n",
308 >        "%s: source at [%.3f,%.3f,%.3f], dw %.5f, br %.1f (%d samps)\n",
309                          progname, sp->dir[0], sp->dir[1], sp->dir[2],
310                          sp->dom, sp->brt, n);
311   }
# Line 333 | Line 339 | absorb_specks()                        /* eliminate too-small sources */
339                  fprintf(stderr, "%s: absorbing small sources...\n", progname);
340          head.next = donelist;
341          last = &head;
342 <        for (this = donelist; this != NULL; this = this->next)
342 >        for (this = head.next; this != NULL; this = this->next)
343                  if (TOOSMALL(this)) {
344                          last->next = this->next;
345 <                        buddy = findbuddy(this, donelist);
345 >                        buddy = findbuddy(this, head.next);
346                          if (buddy != NULL)
347                                  mergesource(buddy, this);
348                          else
# Line 352 | Line 358 | absorb(s)                      /* absorb a source into indirect */
358   register struct source  *s;
359   {
360          FVECT   dir;
361 <        register int    i, n;
361 >        double  d;
362 >        register int    i;
363  
364          for (i = 0; i < nglardirs; i++) {
365                  spinvector(dir, ourview.vdir, ourview.vup, indirect[i].theta);
366 <                n = DOT(dir,s->dir)*s->dom*(sampdens*sampdens) + 0.5;
367 <                if (n == 0)
366 >                d = DOT(dir,s->dir)*s->dom*(sampdens*sampdens);
367 >                if (d <= 0.0)
368                          continue;
369 <                indirect[i].sum += n * s->brt;
370 <                indirect[i].n += n;
369 >                indirect[i].sum += d * s->brt;
370 >                indirect[i].n += d;
371          }
372          for ( ; s->first != NULL; s->first = s->first->next)
373                  free((char *)s->first);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines