ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_qtree2r.c
Revision: 3.4
Committed: Sat Feb 22 02:07:24 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 3.3: +1 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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