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.2 by gregl, Thu Nov 20 11:38:26 1997 UTC vs.
Revision 3.3 by gregl, Thu Nov 20 18:03:43 1997 UTC

# Line 58 | Line 58 | memerr:
58   }
59  
60  
61 < static
62 < freetree(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 <        freetree(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 <        freetree(1);            /* free tree also */
126 >        qtFreeTree(1);          /* free tree also */
127          if (nleaves <= 0)
128                  return;
129          free((char *)leafpile);
# Line 164 | Line 163 | int    pct;
163                  return(0);
164          nused = tleaf > bleaf ? tleaf-bleaf : tleaf+nleaves-bleaf;
165          if (nclear >= nused) {  /* clear them all */
166 <                freetree(0);
166 >                qtFreeTree(0);
167                  bleaf = tleaf = 0;
168                  return(nused);
169          }
# Line 175 | 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 262 | Line 298 | qtReplant()                    /* replant our tree using new view */
298  
299          if (bleaf == tleaf)             /* anything to replant? */
300                  return;
301 <        freetree(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