ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_qtree2r.c
Revision: 3.6
Committed: Thu Jan 1 11:21:55 2004 UTC (20 years, 3 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9
Changes since 3.5: +32 -14 lines
Log Message:
Ansification and prototypes.

File Contents

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