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.6 by gregl, Mon Nov 24 15:16:10 1997 UTC vs.
Revision 3.9 by gregl, Tue Nov 25 16:52:04 1997 UTC

# Line 25 | 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  
28 #define is_stump(t)     (!((t)->flgs & (BR_ANY|LF_ANY)))
28  
30
29   static RTREE *
30   newtwig()                       /* allocate a twig */
31   {
# Line 62 | Line 60 | int    really;
60   {
61          register int    i;
62  
63 <        qtrunk.flgs = CH_ANY;
66 <        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 295 | 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 360 | Line 359 | int    redo;
359                                  qtL.chr+borg, blen);
360          qtL.tml = qtL.tl;
361          return(1);
363 }
364
365
366 static
367 redraw(ca, tp, x0, y0, x1, y1, l)       /* redraw portion of a tree */
368 BYTE    ca[3];          /* returned average color */
369 register RTREE  *tp;
370 int     x0, y0, x1, y1;
371 int     l[2][2];
372 {
373        int     csm[3], nc;
374        register BYTE   *cp;
375        BYTE    rgb[3];
376        int     quads = CH_ANY;
377        int     mx, my;
378        register int    i;
379                                        /* compute midpoint */
380        mx = (x0 + x1) >> 1;
381        my = (y0 + y1) >> 1;
382                                        /* see what to do */
383        if (l[0][0] >= mx)
384                quads &= ~(CHF(2)|CHF(0));
385        else if (l[0][1] <= mx)
386                quads &= ~(CHF(3)|CHF(1));
387        if (l[1][0] >= my)
388                quads &= ~(CHF(1)|CHF(0));
389        else if (l[1][1] <= my)
390                quads &= ~(CHF(3)|CHF(2));
391        tp->flgs &= ~quads;             /* mark them done */
392        csm[0] = csm[1] = csm[2] = nc = 0;
393                                        /* do leaves first */
394        for (i = 0; i < 4; i++)
395                if (quads & CHF(i) && tp->flgs & LFF(i)) {
396                        dev_paintr(cp=qtL.rgb[tp->k[i].li],
397                                        i&01 ? mx : x0, i&02 ? my : y0,
398                                        i&01 ? x1 : mx, i&02 ? y1 : my);
399                        csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2];
400                        nc++;
401                        quads &= ~CHF(i);
402                }
403                                        /* now do branches */
404        for (i = 0; i < 4; i++)
405                if (quads & CHF(i) && tp->flgs & BRF(i)) {
406                        redraw(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
407                                        i&01 ? x1 : mx, i&02 ? y1 : my, l);
408                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
409                        nc++;
410                        quads &= ~CHF(i);
411                }
412        if (nc > 1) {
413                ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
414        } else {
415                ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
416        }
417        if (!quads) return;
418                                        /* fill in gaps with average */
419        for (i = 0; i < 4; i++)
420                if (quads & CHF(i))
421                        dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
422                                        i&01 ? x1 : mx, i&02 ? y1 : my);
423 }
424
425
426 static
427 update(ca, tp, x0, y0, x1, y1)  /* update tree display as needed */
428 BYTE    ca[3];          /* returned average color */
429 register RTREE  *tp;
430 int     x0, y0, x1, y1;
431 {
432        int     csm[3], nc;
433        register BYTE   *cp;
434        BYTE    rgb[3];
435        int     gaps = 0;
436        int     mx, my;
437        register int    i;
438                                        /* compute midpoint */
439        mx = (x0 + x1) >> 1;
440        my = (y0 + y1) >> 1;
441        csm[0] = csm[1] = csm[2] = nc = 0;
442                                        /* do leaves first */
443        for (i = 0; i < 4; i++) {
444                if (!(tp->flgs & CHF(i)))
445                        continue;
446                if (tp->flgs & LFF(i)) {
447                        dev_paintr(cp=qtL.rgb[tp->k[i].li],
448                                        i&01 ? mx : x0, i&02 ? my : y0,
449                                        i&01 ? x1 : mx, i&02 ? y1 : my);
450                        csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2];
451                        nc++;
452                } else if (!(tp->flgs & BRF(i)))
453                        gaps |= 1<<i;   /* empty stem */
454        }
455                                        /* now do branches */
456        for (i = 0; i < 4; i++)
457                if ((tp->flgs & CHBRF(i)) == CHBRF(i)) {
458                        update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
459                                        i&01 ? x1 : mx, i&02 ? y1 : my);
460                        csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
461                        nc++;
462                }
463        if (nc > 1) {
464                ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
465        } else {
466                ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
467        }
468                                        /* fill in gaps with average */
469        for (i = 0; gaps && i < 4; gaps >>= 1, i++)
470                if (gaps & 01)
471                        dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
472                                        i&01 ? x1 : mx, i&02 ? y1 : my);
473        tp->flgs &= ~CH_ANY;            /* all done */
474 }
475
476
477 qtRedraw(x0, y0, x1, y1)        /* redraw part or all of our screen */
478 int     x0, y0, x1, y1;
479 {
480        int     lim[2][2];
481        BYTE    ca[3];
482
483        if (is_stump(&qtrunk))
484                return;
485        if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 &
486                (lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1))
487                return;
488        redraw(ca, &qtrunk, 0, 0, odev.hres, odev.vres, lim);
489 }
490
491
492 qtUpdate()                      /* update our tree display */
493 {
494        BYTE    ca[3];
495
496        if (is_stump(&qtrunk))
497                return;
498        if (!qtMapLeaves(0))
499                return;
500        update(ca, &qtrunk, 0, 0, odev.hres, odev.vres);
362   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines