ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhd_qtree2c.c
Revision: 3.1
Committed: Fri Jan 9 13:57:07 1998 UTC (26 years, 3 months ago) by gregl
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# Content
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ SGI";
5 #endif
6
7 /*
8 * Quadtree display support routines for cone 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 if (l[0][0] > mx)
29 quads &= ~(CHF(UL)|CHF(DL));
30 else if (l[0][1] < mx)
31 quads &= ~(CHF(UR)|CHF(DR));
32 if (l[1][0] > my)
33 quads &= ~(CHF(DR)|CHF(DL));
34 else if (l[1][1] < my)
35 quads &= ~(CHF(UR)|CHF(UL));
36 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 cpaint(rgb, p, x0, y0, x1, y1) /* paint a cone within a rectangle */
47 BYTE rgb[3];
48 register float *p;
49 int x0, y0, x1, y1;
50 {
51 static FVECT ip, wp;
52 double rad;
53 /* compute base radius */
54 rad = (double)(y1 - y0 + x1 - x0)/(odev.hres + odev.vres);
55 /* approximate apex pos? */
56 if (p == NULL || y1-y0 <= qtMinNodesiz || x1-x0 <= qtMinNodesiz) {
57 ip[0] = (double)(x0 + x1)/(odev.hres<<1);
58 ip[1] = (double)(y0 + y1)/(odev.vres<<1);
59 if (p != NULL) {
60 wp[0] = p[0] - odev.v.vp[0];
61 wp[1] = p[1] - odev.v.vp[1];
62 wp[2] = p[2] - odev.v.vp[2];
63 if (odev.v.type == VT_PER)
64 ip[2] = DOT(wp,odev.v.vdir);
65 else
66 ip[2] = VLEN(wp);
67 } else
68 ip[2] = FHUGE;
69 } else if (odev.v.type == VT_PER) { /* special case (faster) */
70 wp[0] = p[0] - odev.v.vp[0];
71 wp[1] = p[1] - odev.v.vp[1];
72 wp[2] = p[2] - odev.v.vp[2];
73 ip[2] = DOT(wp,odev.v.vdir);
74 ip[0] = DOT(wp,odev.v.hvec)/(ip[2]*odev.v.hn2) +
75 0.5 - odev.v.hoff;
76 ip[1] = DOT(wp,odev.v.vvec)/(ip[2]*odev.v.vn2) +
77 0.5 - odev.v.voff;
78 } else { /* general case */
79 VCOPY(wp, p);
80 viewloc(ip, &odev.v, wp);
81 }
82 dev_cone(rgb, ip, rad);
83 }
84
85
86 static
87 update(ca, tp, x0, y0, x1, y1) /* update tree display as needed */
88 BYTE ca[3]; /* returned average color */
89 register RTREE *tp;
90 int x0, y0, x1, y1;
91 {
92 int csm[3], nc;
93 register BYTE *cp;
94 BYTE rgb[3];
95 int gaps = 0;
96 int mx, my;
97 register int i;
98 /* compute midpoint */
99 mx = (x0 + x1) >> 1;
100 my = (y0 + y1) >> 1;
101 /* draw leaves */
102 csm[0] = csm[1] = csm[2] = nc = 0;
103 for (i = 0; i < 4; i++) {
104 if (tp->flgs & LFF(i)) {
105 cp = qtL.rgb[tp->k[i].li];
106 csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2];
107 nc++;
108 if (tp->flgs & CHF(i))
109 cpaint(cp, qtL.wp[tp->k[i].li],
110 i&01 ? mx : x0, i&02 ? my : y0,
111 i&01 ? x1 : mx, i&02 ? y1 : my);
112 } else if ((tp->flgs & CHBRF(i)) == CHF(i))
113 gaps |= 1<<i; /* empty stem */
114 }
115 /* do branches */
116 for (i = 0; i < 4; i++)
117 if ((tp->flgs & CHBRF(i)) == CHBRF(i)) {
118 update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0,
119 i&01 ? x1 : mx, i&02 ? y1 : my);
120 csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2];
121 nc++;
122 }
123 if (nc > 1) {
124 ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc;
125 } else {
126 ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2];
127 }
128 /* fill in gaps with average */
129 for (i = 0; gaps && i < 4; gaps >>= 1, i++)
130 if (gaps & 01)
131 cpaint(ca, (float *)NULL,
132 i&01 ? mx : x0, i&02 ? my : y0,
133 i&01 ? x1 : mx, i&02 ? y1 : my);
134 tp->flgs &= ~CH_ANY; /* all done */
135 }
136
137
138 qtRedraw(x0, y0, x1, y1) /* redraw part or all of our screen */
139 int x0, y0, x1, y1;
140 {
141 int lim[2][2];
142
143 if (is_stump(&qtrunk))
144 return;
145 if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 &
146 (lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1))
147 return;
148 redraw(&qtrunk, 0, 0, odev.hres, odev.vres, lim);
149 }
150
151
152 qtUpdate() /* update our tree display */
153 {
154 BYTE ca[3];
155
156 if (is_stump(&qtrunk))
157 return;
158 if (!qtMapLeaves(0))
159 return;
160 update(ca, &qtrunk, 0, 0, odev.hres, odev.vres);
161 }