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 |
if (l[0][0] >= mx) |
29 |
quads &= ~(CHF(2)|CHF(0)); |
30 |
else if (l[0][1] < mx) |
31 |
quads &= ~(CHF(3)|CHF(1)); |
32 |
if (l[1][0] >= my) |
33 |
quads &= ~(CHF(1)|CHF(0)); |
34 |
else if (l[1][1] < my) |
35 |
quads &= ~(CHF(3)|CHF(2)); |
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 |
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 |
int gaps = 0; |
55 |
int mx, my; |
56 |
register int i; |
57 |
/* compute midpoint */ |
58 |
mx = (x0 + x1) >> 1; |
59 |
my = (y0 + y1) >> 1; |
60 |
csm[0] = csm[1] = csm[2] = nc = 0; |
61 |
/* do leaves first */ |
62 |
for (i = 0; i < 4; i++) { |
63 |
if (tp->flgs & LFF(i)) { |
64 |
cp = qtL.rgb[tp->k[i].li]; |
65 |
csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2]; |
66 |
nc++; |
67 |
if (tp->flgs & CHF(i)) |
68 |
dev_paintr(cp, i&01 ? mx : x0, i&02 ? my : y0, |
69 |
i&01 ? x1 : mx, i&02 ? y1 : my); |
70 |
} else if ((tp->flgs & CHBRF(i)) == CHF(i)) |
71 |
gaps |= 1<<i; /* empty stem */ |
72 |
} |
73 |
/* now do branches */ |
74 |
for (i = 0; i < 4; i++) |
75 |
if ((tp->flgs & CHBRF(i)) == CHBRF(i)) { |
76 |
update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0, |
77 |
i&01 ? x1 : mx, i&02 ? y1 : my); |
78 |
csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2]; |
79 |
nc++; |
80 |
} |
81 |
if (nc > 1) { |
82 |
ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc; |
83 |
} else { |
84 |
ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2]; |
85 |
} |
86 |
/* fill in gaps with average */ |
87 |
for (i = 0; gaps && i < 4; gaps >>= 1, i++) |
88 |
if (gaps & 01) |
89 |
dev_paintr(ca, i&01 ? mx : x0, i&02 ? my : y0, |
90 |
i&01 ? x1 : mx, i&02 ? y1 : my); |
91 |
tp->flgs &= ~CH_ANY; /* all done */ |
92 |
} |
93 |
|
94 |
|
95 |
qtRedraw(x0, y0, x1, y1) /* redraw part or all of our screen */ |
96 |
int x0, y0, x1, y1; |
97 |
{ |
98 |
int lim[2][2]; |
99 |
|
100 |
if (is_stump(&qtrunk)) |
101 |
return; |
102 |
if (!qtMapLeaves((lim[0][0]=x0) <= 0 & (lim[1][0]=y0) <= 0 & |
103 |
(lim[0][1]=x1) >= odev.hres-1 & (lim[1][1]=y1) >= odev.vres-1)) |
104 |
return; |
105 |
redraw(&qtrunk, 0, 0, odev.hres, odev.vres, lim); |
106 |
} |
107 |
|
108 |
|
109 |
qtUpdate() /* update our tree display */ |
110 |
{ |
111 |
BYTE ca[3]; |
112 |
|
113 |
if (is_stump(&qtrunk)) |
114 |
return; |
115 |
if (!qtMapLeaves(0)) |
116 |
return; |
117 |
update(ca, &qtrunk, 0, 0, odev.hres, odev.vres); |
118 |
} |