Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions | Variables
rhd_qtree.h File Reference
#include "color.h"
#include "tonemap.h"
#include "rhdriver.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rtree
struct  rleaves
union  rtree.k

Defines

#define DL   0 /* down left */
#define DR   1 /* down right */
#define UL   2 /* up left */
#define UR   3 /* up right */
#define BRF(i)   (0x1<<(i)) /* branch flag bit */
#define LFF(i)   (0x10<<(i)) /* leaf flag bit */
#define CHF(i)   (0x100<<(i)) /* change flag bit */
#define CHBRF(i)   (0x101<<(i)) /* changed branch bit */
#define CHLFF(i)   (0x110<<(i)) /* changed leaf bit */
#define BR_ANY   0xf /* flags for any branches */
#define LF_ANY   0xf0 /* flags for any leaves */
#define CH_ANY   0xf00 /* flags for any change */
#define is_stump(t)   (!((t)->flgs & (BR_ANY|LF_ANY)))

Typedefs

typedef struct rtree RTREE

Functions

int qtAllocLeaves (register int n)
void qtFreeLeaves (void)
int qtCompost (int pct)
void qtReplant (void)
int qtFindLeaf (int x, int y)
int qtMapLeaves (int redo)
void qtRedraw (int x0, int y0, int x1, int y1)
void qtUpdate (void)

Variables

struct rleaves qtL
RTREE qtrunk
double qtDepthEps
int qtMinNodesiz
int rayqleft
TMstructtmGlobal

Class Documentation

struct rtree

Definition at line 30 of file rhd_qtree.h.

Class Members
short flgs
union rtree k
struct rleaves

Definition at line 38 of file rhd_qtree.h.

Class Members
char * base
int bl
TMbright * brt
BYTE(* chr
int nl
BYTE(* rgb
int tl
int tml
int32 * wd
float(* wp
union rtree.k

Definition at line 32 of file rhd_qtree.h.

Class Members
struct rtree * b
int li

Define Documentation

#define BR_ANY   0xf /* flags for any branches */

Definition at line 26 of file rhd_qtree.h.

#define BRF (   i)    (0x1<<(i)) /* branch flag bit */

Definition at line 21 of file rhd_qtree.h.

#define CH_ANY   0xf00 /* flags for any change */

Definition at line 28 of file rhd_qtree.h.

#define CHBRF (   i)    (0x101<<(i)) /* changed branch bit */

Definition at line 24 of file rhd_qtree.h.

#define CHF (   i)    (0x100<<(i)) /* change flag bit */

Definition at line 23 of file rhd_qtree.h.

#define CHLFF (   i)    (0x110<<(i)) /* changed leaf bit */

Definition at line 25 of file rhd_qtree.h.

#define DL   0 /* down left */

Definition at line 16 of file rhd_qtree.h.

#define DR   1 /* down right */

Definition at line 17 of file rhd_qtree.h.

#define is_stump (   t)    (!((t)->flgs & (BR_ANY|LF_ANY)))

Definition at line 50 of file rhd_qtree.h.

#define LF_ANY   0xf0 /* flags for any leaves */

Definition at line 27 of file rhd_qtree.h.

#define LFF (   i)    (0x10<<(i)) /* leaf flag bit */

Definition at line 22 of file rhd_qtree.h.

#define UL   2 /* up left */

Definition at line 18 of file rhd_qtree.h.

#define UR   3 /* up right */

Definition at line 19 of file rhd_qtree.h.


Typedef Documentation

typedef struct rtree RTREE

Function Documentation

int qtAllocLeaves ( register int  n)

Definition at line 109 of file rhd_qtree.c.

{
       unsigned      nbytes;
       register unsigned    i;

       qtFreeTree(0);              /* make sure tree is empty */
       if (n <= 0)
              return(0);
       if (qtL.nl >= n)
              return(qtL.nl);
       else if (qtL.nl > 0)
              free(qtL.base);
                            /* round space up to nearest power of 2 */
       nbytes = n*LEAFSIZ + 8;
       for (i = 1024; nbytes > i; i <<= 1)
              ;
       n = (i - 8) / LEAFSIZ;      /* should we make sure n is even? */
       qtL.base = (char *)malloc(n*LEAFSIZ);
       if (qtL.base == NULL)
              return(0);
                            /* assign larger alignment types earlier */
       qtL.wp = (float (*)[3])qtL.base;
       qtL.wd = (int32 *)(qtL.wp + n);
       qtL.brt = (TMbright *)(qtL.wd + n);
       qtL.chr = (BYTE (*)[3])(qtL.brt + n);
       qtL.rgb = (BYTE (*)[3])(qtL.chr + n);
       qtL.nl = n;
       qtL.tml = qtL.bl = qtL.tl = 0;
       falleaves = -1;
       return(n);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int qtCompost ( int  pct)

Definition at line 179 of file rhd_qtree.c.

{
       register int32       *fl;
       int    nused, nclear, nmapped;
                            /* figure out how many leaves to clear */
       nclear = qtL.nl * pct / 100;
       nused = qtL.tl - qtL.bl;
       if (nused <= 0) nused += qtL.nl;
       nclear -= qtL.nl - nused;
       if (nclear <= 0)
              return(0);
       if (nclear >= nused) {      /* clear them all */
              qtFreeTree(0);
              qtL.tml = qtL.bl = qtL.tl = 0;
              falleaves = -1;
              return(nused);
       }
                            /* else clear leaves from bottom */
       nmapped = qtL.tml - qtL.bl;
       if (nmapped < 0) nmapped += qtL.nl;
       qtL.bl += nclear;
       if (qtL.bl >= qtL.nl) qtL.bl -= qtL.nl;
       if (nmapped <= nclear) qtL.tml = qtL.bl;
       shaketree(&qtrunk);  /* dereference composted leaves */
       for (fl = &falleaves; *fl >= 0; fl = qtL.wd + *fl)
              while (composted(*fl))
                     if ((*fl = qtL.wd[*fl]) < 0)
                            return(nclear);
       return(nclear);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int qtFindLeaf ( int  x,
int  y 
)

Definition at line 214 of file rhd_qtree.c.

{
       register RTREE       *tp = &qtrunk;
       int    li = -1;
       int    x0=0, y0=0, x1=odev.hres, y1=odev.vres;
       int    mx, my;
       register int  q;
                                   /* check limits */
       if (x < 0 || x >= odev.hres || y < 0 || y >= odev.vres)
              return(-1);
                                   /* find nearby leaf in our tree */
       for ( ; ; ) {
              for (q = 0; q < 4; q++)            /* find any leaf this level */
                     if (tp->flgs & LFF(q)) {
                            li = tp->k[q].li;
                            break;
                     }
              q = 0;                      /* which quadrant are we? */
              mx = (x0 + x1) >> 1;
              my = (y0 + y1) >> 1;
              if (x < mx) x1 = mx;
              else {x0 = mx; q |= 01;}
              if (y < my) y1 = my;
              else {y0 = my; q |= 02;}
              if (tp->flgs & BRF(q)) {    /* branch down if not a leaf */
                     tp = tp->k[q].b;
                     continue;
              }
              if (tp->flgs & LFF(q))             /* good shot! */
                     return(tp->k[q].li);
              return(li);                 /* else return what we have */
       }
}

Here is the caller graph for this function:

void qtFreeLeaves ( void  )

Definition at line 147 of file rhd_qtree.c.

{
       qtFreeTree(1);              /* free tree also */
       if (qtL.nl <= 0)
              return;
       free(qtL.base);
       qtL.base = NULL;
       qtL.nl = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int qtMapLeaves ( int  redo)

Definition at line 407 of file rhd_qtree.c.

{
       int    aorg, alen, borg, blen;
                                   /* recompute mapping? */
       if (redo)
              qtL.tml = qtL.bl;
                                   /* already done? */
       if (qtL.tml == qtL.tl)
              return(1);
                                   /* compute segments */
       aorg = qtL.tml;
       if (qtL.tl >= aorg) {
              alen = qtL.tl - aorg;
              blen = 0;
       } else {
              alen = qtL.nl - aorg;
              borg = 0;
              blen = qtL.tl;
       }
                                   /* (re)compute tone mapping? */
       if (qtL.tml == qtL.bl) {
              tmClearHisto(tmGlobal);
              tmAddHisto(tmGlobal, qtL.brt+aorg, alen, 1);
              if (blen > 0)
                     tmAddHisto(tmGlobal, qtL.brt+borg, blen, 1);
              if (tmComputeMapping(tmGlobal, 0., 0., 0.) != TM_E_OK)
                     return(0);
       }
       if (tmMapPixels(tmGlobal, (BYTE *)(qtL.rgb+aorg), qtL.brt+aorg,
                     (BYTE *)(qtL.chr+aorg), alen) != TM_E_OK)
              return(0);
       if (blen > 0)
              tmMapPixels(tmGlobal, (BYTE *)(qtL.rgb+borg), qtL.brt+borg,
                            (BYTE *)(qtL.chr+borg), blen);
       qtL.tml = qtL.tl;
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qtRedraw ( int  x0,
int  y0,
int  x1,
int  y1 
)

Definition at line 153 of file rhd_qtree2c.c.

{
       int    lim[2][2];

       if (is_stump(&qtrunk))
              return;
       if (!(qtMapLeaves((lim[0][0]=x0) <= 0) & ((lim[1][0]=y0) <= 0) &
              ((lim[0][1]=x1) >= odev.hres-1) & ((lim[1][1]=y1) >= odev.vres-1)))
              return;
       redraw(&qtrunk, 0, 0, odev.hres, odev.vres, lim);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qtReplant ( void  )

Definition at line 391 of file rhd_qtree.c.

{
       register int  i;
                                   /* anything to replant? */
       if (qtL.bl == qtL.tl)
              return;
       qtFreeTree(0);                     /* blow the old tree away */
                                   /* regrow it in new place */
       for (i = qtL.bl; i != qtL.tl; ) {
              putleaf(i, 0);
              if (++i >= qtL.nl) i = 0;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qtUpdate ( void  )

Definition at line 172 of file rhd_qtree2c.c.

{
       BYTE   ca[3];

       if (is_stump(&qtrunk))
              return;
       if (!qtMapLeaves(0))
              return;
       update(ca, &qtrunk, 0, 0, odev.hres, odev.vres);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

double qtDepthEps

Definition at line 27 of file rhd_qtree.c.

struct rleaves qtL

Definition at line 28 of file rhd_qtree.c.

Definition at line 26 of file rhd_qtree.c.

int rayqleft

Definition at line 31 of file rhd_qtree.c.

Definition at line 64 of file rhd_glx1.c.