ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_qtree2r.c
Revision: 3.3
Committed: Wed Nov 26 20:13:10 1997 UTC (26 years, 4 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.2: +4 -4 lines
Log Message:
changed to using macros in redraw()

File Contents

# User Rev Content
1 gregl 3.1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Quadtree display support routines for rectangle output.
9     */
10    
11     #include "standard.h"
12     #include "rhd_qtree.h"
13    
14    
15     static
16     redraw(tp, x0, y0, x1, y1, l) /* mark portion of a tree for redraw */
17     register RTREE *tp;
18     int x0, y0, x1, y1;
19     int l[2][2];
20     {
21     int quads = CH_ANY;
22     int mx, my;
23     register int i;
24     /* compute midpoint */
25     mx = (x0 + x1) >> 1;
26     my = (y0 + y1) >> 1;
27     /* see what to do */
28 gregl 3.2 if (l[0][0] > mx)
29 gregl 3.3 quads &= ~(CHF(UL)|CHF(DL));
30 gregl 3.1 else if (l[0][1] < mx)
31 gregl 3.3 quads &= ~(CHF(UR)|CHF(DR));
32 gregl 3.2 if (l[1][0] > my)
33 gregl 3.3 quads &= ~(CHF(DR)|CHF(DL));
34 gregl 3.1 else if (l[1][1] < my)
35 gregl 3.3 quads &= ~(CHF(UR)|CHF(UL));
36 gregl 3.1 tp->flgs |= quads; /* mark quadrants for update */
37     /* climb the branches */
38     for (i = 0; i < 4; i++)
39     if (tp->flgs & BRF(i) && quads & CHF(i))
40     redraw(tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
41     i&01 ? x1 : mx, i&02 ? y1 : my, l);
42     }
43    
44    
45     static
46     update(ca, tp, x0, y0, x1, y1) /* update tree display as needed */
47     BYTE ca[3]; /* returned average color */
48     register RTREE *tp;
49     int x0, y0, x1, y1;
50     {
51     int csm[3], nc;
52     register BYTE *cp;
53     BYTE rgb[3];
54 gregl 3.2 double dpth2[4], d2;
55 gregl 3.1 int gaps = 0;
56     int mx, my;
57     register int i;
58 gregl 3.2 /* compute leaf depths */
59     d2 = FHUGE*FHUGE;
60     for (i = 0; i < 4; i++)
61     if (tp->flgs & LFF(i)) {
62     FVECT dv;
63     register float *wp = qtL.wp[tp->k[i].li];
64    
65     dv[0] = wp[0] - odev.v.vp[0];
66     dv[1] = wp[1] - odev.v.vp[1];
67     dv[2] = wp[2] - odev.v.vp[2];
68     dpth2[i] = DOT(dv,dv);
69     if (dpth2[i] < d2)
70     d2 = dpth2[i];
71     }
72     d2 *= (1.+qtDepthEps)*(1.+qtDepthEps);
73 gregl 3.1 /* compute midpoint */
74     mx = (x0 + x1) >> 1;
75     my = (y0 + y1) >> 1;
76 gregl 3.2 /* draw leaves */
77 gregl 3.1 csm[0] = csm[1] = csm[2] = nc = 0;
78     for (i = 0; i < 4; i++) {
79 gregl 3.2 if (tp->flgs & LFF(i) && dpth2[i] <= d2) {
80 gregl 3.1 cp = qtL.rgb[tp->k[i].li];
81     csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2];
82     nc++;
83     if (tp->flgs & CHF(i))
84     dev_paintr(cp, i&01 ? mx : x0, i&02 ? my : y0,
85     i&01 ? x1 : mx, i&02 ? y1 : my);
86     } else if ((tp->flgs & CHBRF(i)) == CHF(i))
87     gaps |= 1<<i; /* empty stem */
88     }
89 gregl 3.2 /* do branches */
90 gregl 3.1 for (i = 0; i < 4; i++)
91     if ((tp->flgs & CHBRF(i)) == CHBRF(i)) {
92     update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
93     i&01 ? x1 : mx, i&02 ? y1 : my);
94     csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
95     nc++;
96     }
97     if (nc > 1) {
98     ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
99     } else {
100     ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
101     }
102     /* fill in gaps with average */
103     for (i = 0; gaps && i < 4; gaps >>= 1, i++)
104     if (gaps & 01)
105     dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0,
106     i&01 ? x1 : mx, i&02 ? y1 : my);
107     tp->flgs &= ~CH_ANY; /* all done */
108     }
109    
110    
111     qtRedraw(x0, y0, x1, y1) /* redraw part or all of our screen */
112     int x0, y0, x1, y1;
113     {
114     int lim[2][2];
115    
116     if (is_stump(&qtrunk))
117     return;
118     if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 &
119     (lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1))
120     return;
121     redraw(&qtrunk, 0, 0, odev.hres, odev.vres, lim);
122     }
123    
124    
125     qtUpdate() /* update our tree display */
126     {
127     BYTE ca[3];
128    
129     if (is_stump(&qtrunk))
130     return;
131     if (!qtMapLeaves(0))
132     return;
133     update(ca, &qtrunk, 0, 0, odev.hres, odev.vres);
134     }