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.5 by gregl, Fri Nov 21 13:35:57 1997 UTC vs.
Revision 3.9 by gregl, Tue Nov 25 16:52:04 1997 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ SGI";
10  
11   #include "standard.h"
12   #include "rhd_qtree.h"
13 +                                /* quantity of leaves to free at a time */
14 + #ifndef LFREEPCT
15 + #define LFREEPCT        25
16 + #endif
17  
18   RTREE   qtrunk;                 /* our quadtree trunk */
19   double  qtDepthEps = .02;       /* epsilon to compare depths (z fraction) */
# Line 21 | Line 25 | struct rleaves qtL;            /* our pile of leaves */
25   static RTREE    **twigbundle;   /* free twig blocks (NULL term.) */
26   static int      nexttwig;       /* next free twig */
27  
24 #define is_stump(t)     (!((t)->flgs & (BR_ANY|LF_ANY)))
28  
26
29   static RTREE *
30   newtwig()                       /* allocate a twig */
31   {
# Line 58 | Line 60 | int    really;
60   {
61          register int    i;
62  
63 <        qtrunk.flgs = 0;
62 <        nexttwig = 0;
63 >        qtrunk.flgs = CH_ANY;   /* chop down tree */
64          if (twigbundle == NULL)
65                  return;
66 +        i = (TBUNDLESIZ-1+nexttwig)/TBUNDLESIZ;
67 +        nexttwig = 0;
68          if (!really) {          /* just clear allocated blocks */
69 <                for (i = 0; twigbundle[i] != NULL; i++)
69 >                while (i--)
70                          bzero((char *)twigbundle[i], TBUNDLESIZ*sizeof(RTREE));
71                  return;
72          }
# Line 291 | Line 294 | int    li;
294   }
295  
296  
297 < dev_value(c, p)                 /* add a pixel value to our output queue */
297 > dev_value(c, p)                 /* add a pixel value to our quadtree */
298   COLR    c;
299   FVECT   p;
300   {
# Line 323 | Line 326 | qtMapLeaves(redo)              /* map our leaves to RGB */
326   int     redo;
327   {
328          int     aorg, alen, borg, blen;
329 +                                        /* recompute mapping? */
330 +        if (redo)
331 +                qtL.tml = qtL.bl;
332                                          /* already done? */
333          if (qtL.tml == qtL.tl)
334                  return(1);
329        if (redo)
330                qtL.tml = qtL.bl;
335                                          /* compute segments */
336          aorg = qtL.tml;
337          if (qtL.tl >= aorg) {
# Line 355 | Line 359 | int    redo;
359                                  qtL.chr+borg, blen);
360          qtL.tml = qtL.tl;
361          return(1);
358 }
359
360
361 static
362 redraw(ca, tp, x0, y0, x1, y1, l)       /* redraw portion of a tree */
363 BYTE    ca[3];          /* returned average color */
364 register RTREE  *tp;
365 int     x0, y0, x1, y1;
366 int     l[2][2];
367 {
368        int     csm[3], nc;
369        register BYTE   *cp;
370        BYTE    rgb[3];
371        int     quads = CH_ANY;
372        int     mx, my;
373        register int    i;
374                                        /* compute midpoint */
375        mx = (x0 + x1) >> 1;
376        my = (y0 + y1) >> 1;
377                                        /* see what to do */
378        if (l[0][0] >= mx)
379                quads &= ~(CHF(2)|CHF(0));
380        else if (l[0][1] <= mx)
381                quads &= ~(CHF(3)|CHF(1));
382        if (l[1][0] >= my)
383                quads &= ~(CHF(1)|CHF(0));
384        else if (l[1][1] <= my)
385                quads &= ~(CHF(3)|CHF(2));
386        tp->flgs &= ~quads;             /* mark them done */
387        csm[0] = csm[1] = csm[2] = nc = 0;
388                                        /* do leaves first */
389        for (i = 0; i < 4; i++)
390                if (quads & CHF(i) && tp->flgs & LFF(i)) {
391                        dev_paintr(cp=qtL.rgb[tp->k[i].li],
392                                        i&01 ? mx : x0, i&02 ? my : y0,
393                                        i&01 ? x1 : mx, i&02 ? y1 : my);
394                        csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2];
395                        nc++;
396                        quads &= ~CHF(i);
397                }
398                                        /* now do branches */
399        for (i = 0; i < 4; i++)
400                if (quads & CHF(i) && tp->flgs & BRF(i)) {
401                        redraw(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
402                                        i&01 ? x1 : mx, i&02 ? y1 : my, l);
403                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
404                        nc++;
405                        quads &= ~CHF(i);
406                }
407        if (nc > 1) {
408                ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
409        } else {
410                ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
411        }
412        if (!quads) return;
413                                        /* fill in gaps with average */
414        for (i = 0; i < 4; i++)
415                if (quads & CHF(i))
416                        dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
417                                        i&01 ? x1 : mx, i&02 ? y1 : my);
418 }
419
420
421 static
422 update(ca, tp, x0, y0, x1, y1)  /* update tree display as needed */
423 BYTE    ca[3];          /* returned average color */
424 register RTREE  *tp;
425 int     x0, y0, x1, y1;
426 {
427        int     csm[3], nc;
428        register BYTE   *cp;
429        BYTE    rgb[3];
430        int     gaps = 0;
431        int     mx, my;
432        register int    i;
433                                        /* compute midpoint */
434        mx = (x0 + x1) >> 1;
435        my = (y0 + y1) >> 1;
436        csm[0] = csm[1] = csm[2] = nc = 0;
437                                        /* do leaves first */
438        for (i = 0; i < 4; i++) {
439                if (!(tp->flgs & CHF(i)))
440                        continue;
441                if (tp->flgs & LFF(i)) {
442                        dev_paintr(cp=qtL.rgb[tp->k[i].li],
443                                        i&01 ? mx : x0, i&02 ? my : y0,
444                                        i&01 ? x1 : mx, i&02 ? y1 : my);
445                        csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2];
446                        nc++;
447                } else if (!(tp->flgs & BRF(i)))
448                        gaps |= 1<<i;   /* empty stem */
449        }
450                                        /* now do branches */
451        for (i = 0; i < 4; i++)
452                if ((tp->flgs & CHBRF(i)) == CHBRF(i)) {
453                        update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
454                                        i&01 ? x1 : mx, i&02 ? y1 : my);
455                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
456                        nc++;
457                }
458        if (nc > 1) {
459                ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
460        } else {
461                ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
462        }
463                                        /* fill in gaps with average */
464        for (i = 0; gaps && i < 4; gaps >>= 1, i++)
465                if (gaps & 01)
466                        dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
467                                        i&01 ? x1 : mx, i&02 ? y1 : my);
468        tp->flgs &= ~CH_ANY;            /* all done */
469 }
470
471
472 qtRedraw(x0, y0, x1, y1)        /* redraw part or all of our screen */
473 int     x0, y0, x1, y1;
474 {
475        int     lim[2][2];
476        BYTE    ca[3];
477
478        if (is_stump(&qtrunk))
479                return;
480        if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 &
481                (lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1))
482                return;
483        redraw(ca, &qtrunk, 0, 0, odev.hres, odev.vres, lim);
484 }
485
486
487 qtUpdate()                      /* update our tree display */
488 {
489        BYTE    ca[3];
490
491        if (is_stump(&qtrunk))
492                return;
493        if (!qtMapLeaves(0))
494                return;
495        update(ca, &qtrunk, 0, 0, odev.hres, odev.vres);
362   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines