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

Comparing ray/src/hd/rhd_qtree.c (file contents):
Revision 3.9 by gregl, Tue Nov 25 16:52:04 1997 UTC vs.
Revision 3.14 by gregl, Mon Dec 29 17:31:45 1997 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ SGI";
14   #ifndef LFREEPCT
15   #define LFREEPCT        25
16   #endif
17 +                                /* maximum allowed angle difference (deg.) */
18 + #ifndef MAXANG
19 + #define MAXANG          20
20 + #endif
21 + #if MAXANG>0
22 + #define MAXDIFF2        ( MAXANG*MAXANG * (PI*PI/180./180.))
23 + #endif
24  
25 + #define abs(i)          ((i) < 0 ? -(i) : (i))
26 +
27   RTREE   qtrunk;                 /* our quadtree trunk */
28 < double  qtDepthEps = .02;       /* epsilon to compare depths (z fraction) */
28 > double  qtDepthEps = .05;       /* epsilon to compare depths (z fraction) */
29   int     qtMinNodesiz = 2;       /* minimum node dimension (pixels) */
30   struct rleaves  qtL;            /* our pile of leaves */
31  
# Line 78 | Line 87 | int    really;
87   }
88  
89  
90 < static int
91 < newleaf()                       /* allocate a leaf from our pile */
83 < {
84 <        int     li;
85 <        
86 <        li = qtL.tl++;
87 <        if (qtL.tl >= qtL.nl)   /* get next leaf in ring */
88 <                qtL.tl = 0;
89 <        if (qtL.tl == qtL.bl)   /* need to shake some free */
90 <                qtCompost(LFREEPCT);
91 <        return(li);
92 < }
90 > #define LEAFSIZ         (3*sizeof(float)+sizeof(int4)+\
91 >                        sizeof(TMbright)+6*sizeof(BYTE))
92  
94
95 #define LEAFSIZ         (3*sizeof(float)+sizeof(TMbright)+6*sizeof(BYTE))
96
93   int
94   qtAllocLeaves(n)                /* allocate space for n leaves */
95   register int    n;
# Line 118 | Line 114 | register int   n;
114                  return(0);
115                                  /* assign larger alignment types earlier */
116          qtL.wp = (float (*)[3])qtL.base;
117 <        qtL.brt = (TMbright *)(qtL.wp + n);
117 >        qtL.wd = (int4 *)(qtL.wp + n);
118 >        qtL.brt = (TMbright *)(qtL.wd + n);
119          qtL.chr = (BYTE (*)[3])(qtL.brt + n);
120          qtL.rgb = (BYTE (*)[3])(qtL.chr + n);
121          qtL.nl = n;
# Line 234 | Line 231 | int    li;
231          register RTREE  *tp = &qtrunk;
232          int     x0=0, y0=0, x1=odev.hres, y1=odev.vres;
233          int     lo = -1;
234 +        double  d2;
235          int     x, y, mx, my;
236          double  z;
237 <        FVECT   ip, wp;
237 >        FVECT   ip, wp, vd;
238          register int    q;
239 <                                        /* compute leaf location */
239 >                                        /* compute leaf location in view */
240          VCOPY(wp, qtL.wp[li]);
241          viewloc(ip, &odev.v, wp);
242          if (ip[2] <= 0. || ip[0] < 0. || ip[0] >= 1.
243                          || ip[1] < 0. || ip[1] >= 1.)
244 <                return;
244 >                return(-1);                     /* behind or outside view */
245 > #ifdef DEBUG
246 >        if (odev.v.type == VT_PAR | odev.v.vfore > FTINY)
247 >                error(INTERNAL, "bad view assumption in addleaf");
248 > #endif
249 >        for (q = 0; q < 3; q++)
250 >                vd[q] = (wp[q] - odev.v.vp[q])/ip[2];
251 >        d2 = fdir2diff(qtL.wd[li], vd);
252 > #ifdef MAXDIFF2
253 >        if (d2 > MAXDIFF2)
254 >                return(0);                      /* leaf dir. too far off */
255 > #endif
256          x = ip[0] * odev.hres;
257          y = ip[1] * odev.vres;
258          z = ip[2];
# Line 266 | Line 275 | int    li;
275                          tp->flgs |= CHLFF(q);
276                          break;
277                  }      
278 <                                                /* check existing leaf */
270 <                if (lo != tp->k[q].li) {
278 >                if (lo != tp->k[q].li) {        /* check old leaf */
279                          lo = tp->k[q].li;
280                          VCOPY(wp, qtL.wp[lo]);
281                          viewloc(ip, &odev.v, wp);
282                  }
283                                                  /* is node minimum size? */
284 <                if (x1-x0 <= qtMinNodesiz || y1-y0 <= qtMinNodesiz) {
285 <                        if (z > (1.-qtDepthEps)*ip[2])  /* who is closer? */
286 <                                return;                 /* old one is */
287 <                        tp->k[q].li = li;               /* new one is */
284 >                if (y1-y0 <= qtMinNodesiz || x1-x0 <= qtMinNodesiz) {
285 >                        if (z > (1.+qtDepthEps)*ip[2])
286 >                                return(0);              /* old one closer */
287 >                        if (z >= (1.-qtDepthEps)*ip[2] &&
288 >                                        fdir2diff(qtL.wd[lo], vd) < d2)
289 >                                return(0);              /* old one better */
290 >                        tp->k[q].li = li;               /* else new one is */
291                          tp->flgs |= CHF(q);
292                          break;
293                  }
# Line 288 | Line 299 | int    li;
299                  my = ip[1] * odev.vres;
300                  if (mx >= (x0 + x1) >> 1) q |= 01;
301                  if (my >= (y0 + y1) >> 1) q |= 02;
302 +                tp->flgs = CH_ANY|LFF(q);       /* all new */
303                  tp->k[q].li = lo;
292                tp->flgs |= LFF(q)|CH_ANY;      /* all new */
304          }
305 +        return(1);              /* done */
306   }
307  
308  
309 < dev_value(c, p)                 /* add a pixel value to our quadtree */
309 > dev_value(c, p, v)              /* add a pixel value to our quadtree */
310   COLR    c;
311 < FVECT   p;
311 > FVECT   p, v;
312   {
313          register int    li;
314  
315 <        li = newleaf();
315 >        li = qtL.tl++;
316 >        if (qtL.tl >= qtL.nl)   /* advance to next leaf in ring */
317 >                qtL.tl = 0;
318 >        if (qtL.tl == qtL.bl)   /* need to shake some free */
319 >                qtCompost(LFREEPCT);
320          VCOPY(qtL.wp[li], p);
321 +        qtL.wd[li] = encodedir(v);
322          tmCvColrs(&qtL.brt[li], qtL.chr[li], c, 1);
323 <        addleaf(li);
323 >        if (!addleaf(li))
324 >                qtL.tl = li;    /* unget this leaf */
325   }
326  
327  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines