--- ray/src/hd/rhd_qtree.c 1997/12/30 17:08:37 3.15 +++ ray/src/hd/rhd_qtree.c 2003/02/22 02:07:24 3.19 @@ -1,9 +1,6 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhd_qtree.c,v 3.19 2003/02/22 02:07:24 greg Exp $"; #endif - /* * Quadtree driver support routines. */ @@ -29,6 +26,8 @@ double qtDepthEps = .05; /* epsilon to compare depths int qtMinNodesiz = 2; /* minimum node dimension (pixels) */ struct rleaves qtL; /* our pile of leaves */ +int rayqleft = 0; /* rays left to queue before flush */ + static int4 falleaves; /* our list of fallen leaves */ #define composted(li) (qtL.bl <= qtL.tl ? \ @@ -87,8 +86,8 @@ int really; } /* else "really" means free up memory */ for (i = 0; twigbundle[i] != NULL; i++) - free((char *)twigbundle[i]); - free((char *)twigbundle); + free((void *)twigbundle[i]); + free((void *)twigbundle); twigbundle = NULL; } @@ -318,41 +317,51 @@ int drop; tp->k[q].li = lo; } dropit: - if (drop) { - qtL.chr[li][0] = qtL.chr[li][1] = qtL.chr[li][2] = 0; - qtL.wd[li] = falleaves; - falleaves = li; - } + if (drop) + if (li+1 == (qtL.tl ? qtL.tl : qtL.nl)) + qtL.tl = li; /* special case */ + else { + qtL.chr[li][0] = qtL.chr[li][1] = qtL.chr[li][2] = 0; + qtL.wd[li] = falleaves; + falleaves = li; + } return(li == lo); } -dev_value(c, p, v) /* add a pixel value to our quadtree */ +dev_value(c, d, p) /* add a pixel value to our quadtree */ COLR c; -FVECT p, v; +FVECT d, p; { register int li; int mapit; /* grab a leaf */ - if (falleaves >= 0) { /* check for fallen leaves */ + if (!imm_mode && falleaves >= 0) { /* check for fallen leaves */ li = falleaves; falleaves = qtL.wd[li]; mapit = qtL.tml <= qtL.tl ? (li < qtL.tml || li >= qtL.tl) : (li < qtL.tml && li >= qtL.tl) ; - } else { /* else allocate new one */ + } else { /* else allocate new one */ li = qtL.tl++; - if (qtL.tl >= qtL.nl) /* advance to next leaf in ring */ + if (qtL.tl >= qtL.nl) /* next leaf in ring */ qtL.tl = 0; - if (qtL.tl == qtL.bl) /* need to shake some free */ + if (qtL.tl == qtL.bl) /* need to shake some free */ qtCompost(LFREEPCT); - mapit = 0; /* we'll map it later */ + mapit = 0; /* we'll map it later */ } - VCOPY(qtL.wp[li], p); - qtL.wd[li] = encodedir(v); + if (p == NULL) + VSUM(qtL.wp[li], odev.v.vp, d, FHUGE); + else + VCOPY(qtL.wp[li], p); + qtL.wd[li] = encodedir(d); tmCvColrs(&qtL.brt[li], qtL.chr[li], c, 1); - if (putleaf(li, 1) && mapit) - tmMapPixels(qtL.rgb+li, qtL.brt+li, qtL.chr+li, 1); + if (putleaf(li, 1)) { + if (mapit) + tmMapPixels(qtL.rgb+li, qtL.brt+li, qtL.chr+li, 1); + if (--rayqleft == 0) + dev_flush(); /* flush output */ + } }