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.1 by gregl, Wed Nov 19 18:01:03 1997 UTC vs.
Revision 3.3 by gregl, Thu Nov 20 18:03:43 1997 UTC

# Line 11 | Line 11 | static char SCCSid[] = "$SunId$ SGI";
11   #include "standard.h"
12   #include "rhd_qtree.h"
13  
14 static RLEAF    *leafpile;      /* our collection of leaf values */
15 static int      nleaves;        /* count of leaves in our pile */
16 static int      bleaf, tleaf;   /* bottom and top (next) leaf index (ring) */
17
14   RTREE   qtrunk;                 /* our quadtree trunk */
15   double  qtDepthEps = .02;       /* epsilon to compare depths (z fraction) */
16   int     qtMinNodesiz = 2;       /* minimum node dimension (pixels) */
17  
18 + static RLEAF    *leafpile;      /* our collection of leaf values */
19 + static int      nleaves;        /* count of leaves in our pile */
20 + static int      bleaf, tleaf;   /* bottom and top (next) leaf index (ring) */
21 +
22   #define TBUNDLESIZ      409     /* number of twigs in a bundle */
23  
24   static RTREE    **twigbundle;   /* free twig blocks (NULL term.) */
# Line 58 | Line 58 | memerr:
58   }
59  
60  
61 < static
62 < freetwigs(really)               /* free allocated twigs */
61 > qtFreeTree(really)              /* free allocated twigs */
62   int     really;
63   {
64          register int    i;
# Line 101 | Line 100 | int    n;
100          unsigned        nbytes;
101          register unsigned       i;
102  
103 <        freetwigs(0);           /* make sure tree is empty */
103 >        qtFreeTree(0);          /* make sure tree is empty */
104          if (n <= 0)
105                  return(0);
106          if (nleaves >= n)
# Line 124 | Line 123 | int    n;
123  
124   qtFreeLeaves()                  /* free our allocated leaves and twigs */
125   {
126 <        freetwigs(1);           /* free tree also */
126 >        qtFreeTree(1);          /* free tree also */
127          if (nleaves <= 0)
128                  return;
129          free((char *)leafpile);
# Line 140 | Line 139 | register RTREE *tp;
139          register int    i, li;
140  
141          for (i = 0; i < 4; i++)
142 <                if (tp->flgs & BRF(i)) {
143 <                        if (shaketree(tp->k[i].b))
144 <                                tp->flgs |= CHF(i);
146 <                } else if (tp->k[i].l != NULL) {
142 >                if (tp->flgs & BRF(i))
143 >                        shaketree(tp->k[i].b);
144 >                else if (tp->k[i].l != NULL) {
145                          li = tp->k[i].l - leafpile;
146                          if (bleaf < tleaf ? (li < bleaf || li >= tleaf) :
147                                          (li < bleaf && li >= tleaf)) {
148                                  tmAddHisto(&tp->k[i].l->brt, 1, -1);
149                                  tp->k[i].l = NULL;
152                                tp->flgs |= CHF(i);
150                          }
151                  }
155        return(tp->flgs & CH_ANY);
152   }
153  
154  
# Line 167 | Line 163 | int    pct;
163                  return(0);
164          nused = tleaf > bleaf ? tleaf-bleaf : tleaf+nleaves-bleaf;
165          if (nclear >= nused) {  /* clear them all */
166 <                freetwigs(0);
166 >                qtFreeTree(0);
167                  bleaf = tleaf = 0;
168                  return(nused);
169          }
# Line 178 | Line 174 | int    pct;
174   }
175  
176  
177 + RLEAF *
178 + qtFindLeaf(x, y)                /* find closest leaf to (x,y) */
179 + int     x, y;
180 + {
181 +        register RTREE  *tp = &qtrunk;
182 +        RLEAF   *lp = NULL;
183 +        int     x0=0, y0=0, x1=odev.hres, y1=odev.vres;
184 +        int     mx, my;
185 +        register int    q;
186 +                                        /* check limits */
187 +        if (x < 0 || x >= odev.hres || y < 0 || y >= odev.vres)
188 +                return(NULL);
189 +                                        /* find nearby leaf in our tree */
190 +        for ( ; ; ) {
191 +                for (q = 0; q < 4; q++)         /* find any leaf this level */
192 +                        if (!(tp->flgs & BRF(q)) && tp->k[q].l != NULL) {
193 +                                lp = tp->k[q].l;
194 +                                break;
195 +                        }
196 +                q = 0;                          /* which quadrant are we? */
197 +                mx = (x0 + x1) >> 1;
198 +                my = (y0 + y1) >> 1;
199 +                if (x < mx) x1 = mx;
200 +                else {x0 = mx; q |= 01;}
201 +                if (y < my) y1 = my;
202 +                else {y0 = my; q |= 02;}
203 +                if (tp->flgs & BRF(q)) {        /* branch down if not a leaf */
204 +                        tp = tp->k[q].b;
205 +                        continue;
206 +                }
207 +                if (tp->k[q].l != NULL)         /* good shot! */
208 +                        return(tp->k[q].l);
209 +                return(lp);                     /* else return what we have */
210 +        }
211 + }
212 +
213 +
214   static
215   addleaf(lp)                     /* add a leaf to our tree */
216   RLEAF   *lp;
# Line 265 | Line 298 | qtReplant()                    /* replant our tree using new view */
298  
299          if (bleaf == tleaf)             /* anything to replant? */
300                  return;
301 <        freetwigs(0);                   /* blow the tree away */
301 >        qtFreeTree(0);                  /* blow the tree away */
302                                          /* now rebuild it */
303          for (i = bleaf; i != tleaf; ) {
304                  addleaf(leafpile+i);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines