| 1 |
gregl |
3.1 |
#ifndef lint |
| 2 |
greg |
3.4 |
static const char RCSid[] = "$Id: rhd_qtree2c.c,v 3.3 2004/01/01 11:21:55 schorsch Exp $"; |
| 3 |
gregl |
3.1 |
#endif |
| 4 |
|
|
/* |
| 5 |
|
|
* Quadtree display support routines for cone output. |
| 6 |
|
|
*/ |
| 7 |
|
|
|
| 8 |
|
|
#include "standard.h" |
| 9 |
|
|
#include "rhd_qtree.h" |
| 10 |
|
|
|
| 11 |
schorsch |
3.3 |
static void redraw(RTREE *tp, int x0, int y0, int x1, int y1, int l[2][2]); |
| 12 |
greg |
3.4 |
static void cpaint(uby8 rgb[3], float *p, int x0, int y0, int x1, int y1); |
| 13 |
|
|
static void update(uby8 ca[3], RTREE *tp, int x0, int y0, int x1, int y1); |
| 14 |
gregl |
3.1 |
|
| 15 |
schorsch |
3.3 |
|
| 16 |
|
|
|
| 17 |
|
|
static void |
| 18 |
|
|
redraw( /* mark portion of a tree for redraw */ |
| 19 |
|
|
register RTREE *tp, |
| 20 |
|
|
int x0, |
| 21 |
|
|
int y0, |
| 22 |
|
|
int x1, |
| 23 |
|
|
int y1, |
| 24 |
|
|
int l[2][2] |
| 25 |
|
|
) |
| 26 |
gregl |
3.1 |
{ |
| 27 |
|
|
int quads = CH_ANY; |
| 28 |
|
|
int mx, my; |
| 29 |
|
|
register int i; |
| 30 |
|
|
/* compute midpoint */ |
| 31 |
|
|
mx = (x0 + x1) >> 1; |
| 32 |
|
|
my = (y0 + y1) >> 1; |
| 33 |
|
|
/* see what to do */ |
| 34 |
|
|
if (l[0][0] > mx) |
| 35 |
|
|
quads &= ~(CHF(UL)|CHF(DL)); |
| 36 |
|
|
else if (l[0][1] < mx) |
| 37 |
|
|
quads &= ~(CHF(UR)|CHF(DR)); |
| 38 |
|
|
if (l[1][0] > my) |
| 39 |
|
|
quads &= ~(CHF(DR)|CHF(DL)); |
| 40 |
|
|
else if (l[1][1] < my) |
| 41 |
|
|
quads &= ~(CHF(UR)|CHF(UL)); |
| 42 |
|
|
tp->flgs |= quads; /* mark quadrants for update */ |
| 43 |
|
|
/* climb the branches */ |
| 44 |
|
|
for (i = 0; i < 4; i++) |
| 45 |
|
|
if (tp->flgs & BRF(i) && quads & CHF(i)) |
| 46 |
|
|
redraw(tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0, |
| 47 |
|
|
i&01 ? x1 : mx, i&02 ? y1 : my, l); |
| 48 |
|
|
} |
| 49 |
|
|
|
| 50 |
|
|
|
| 51 |
schorsch |
3.3 |
static void |
| 52 |
|
|
cpaint( /* paint a cone within a rectangle */ |
| 53 |
greg |
3.4 |
uby8 rgb[3], |
| 54 |
schorsch |
3.3 |
register float *p, |
| 55 |
|
|
int x0, |
| 56 |
|
|
int y0, |
| 57 |
|
|
int x1, |
| 58 |
|
|
int y1 |
| 59 |
|
|
) |
| 60 |
gregl |
3.1 |
{ |
| 61 |
|
|
static FVECT ip, wp; |
| 62 |
|
|
double rad; |
| 63 |
|
|
/* compute base radius */ |
| 64 |
|
|
rad = (double)(y1 - y0 + x1 - x0)/(odev.hres + odev.vres); |
| 65 |
|
|
/* approximate apex pos? */ |
| 66 |
|
|
if (p == NULL || y1-y0 <= qtMinNodesiz || x1-x0 <= qtMinNodesiz) { |
| 67 |
|
|
ip[0] = (double)(x0 + x1)/(odev.hres<<1); |
| 68 |
|
|
ip[1] = (double)(y0 + y1)/(odev.vres<<1); |
| 69 |
|
|
if (p != NULL) { |
| 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 |
|
|
if (odev.v.type == VT_PER) |
| 74 |
|
|
ip[2] = DOT(wp,odev.v.vdir); |
| 75 |
|
|
else |
| 76 |
|
|
ip[2] = VLEN(wp); |
| 77 |
|
|
} else |
| 78 |
|
|
ip[2] = FHUGE; |
| 79 |
|
|
} else if (odev.v.type == VT_PER) { /* special case (faster) */ |
| 80 |
|
|
wp[0] = p[0] - odev.v.vp[0]; |
| 81 |
|
|
wp[1] = p[1] - odev.v.vp[1]; |
| 82 |
|
|
wp[2] = p[2] - odev.v.vp[2]; |
| 83 |
|
|
ip[2] = DOT(wp,odev.v.vdir); |
| 84 |
|
|
ip[0] = DOT(wp,odev.v.hvec)/(ip[2]*odev.v.hn2) + |
| 85 |
|
|
0.5 - odev.v.hoff; |
| 86 |
|
|
ip[1] = DOT(wp,odev.v.vvec)/(ip[2]*odev.v.vn2) + |
| 87 |
|
|
0.5 - odev.v.voff; |
| 88 |
|
|
} else { /* general case */ |
| 89 |
|
|
VCOPY(wp, p); |
| 90 |
|
|
viewloc(ip, &odev.v, wp); |
| 91 |
|
|
} |
| 92 |
|
|
dev_cone(rgb, ip, rad); |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
|
|
|
| 96 |
schorsch |
3.3 |
static void |
| 97 |
|
|
update( /* update tree display as needed */ |
| 98 |
greg |
3.4 |
uby8 ca[3], /* returned average color */ |
| 99 |
schorsch |
3.3 |
register RTREE *tp, |
| 100 |
|
|
int x0, |
| 101 |
|
|
int y0, |
| 102 |
|
|
int x1, |
| 103 |
|
|
int y1 |
| 104 |
|
|
) |
| 105 |
gregl |
3.1 |
{ |
| 106 |
|
|
int csm[3], nc; |
| 107 |
greg |
3.4 |
register uby8 *cp; |
| 108 |
|
|
uby8 rgb[3]; |
| 109 |
gregl |
3.1 |
int gaps = 0; |
| 110 |
|
|
int mx, my; |
| 111 |
|
|
register int i; |
| 112 |
|
|
/* compute midpoint */ |
| 113 |
|
|
mx = (x0 + x1) >> 1; |
| 114 |
|
|
my = (y0 + y1) >> 1; |
| 115 |
|
|
/* draw leaves */ |
| 116 |
|
|
csm[0] = csm[1] = csm[2] = nc = 0; |
| 117 |
|
|
for (i = 0; i < 4; i++) { |
| 118 |
|
|
if (tp->flgs & LFF(i)) { |
| 119 |
|
|
cp = qtL.rgb[tp->k[i].li]; |
| 120 |
|
|
csm[0] += cp[0]; csm[1] += cp[1]; csm[2] += cp[2]; |
| 121 |
|
|
nc++; |
| 122 |
|
|
if (tp->flgs & CHF(i)) |
| 123 |
|
|
cpaint(cp, qtL.wp[tp->k[i].li], |
| 124 |
|
|
i&01 ? mx : x0, i&02 ? my : y0, |
| 125 |
|
|
i&01 ? x1 : mx, i&02 ? y1 : my); |
| 126 |
|
|
} else if ((tp->flgs & CHBRF(i)) == CHF(i)) |
| 127 |
|
|
gaps |= 1<<i; /* empty stem */ |
| 128 |
|
|
} |
| 129 |
|
|
/* do branches */ |
| 130 |
|
|
for (i = 0; i < 4; i++) |
| 131 |
|
|
if ((tp->flgs & CHBRF(i)) == CHBRF(i)) { |
| 132 |
|
|
update(rgb, tp->k[i].b, i&01 ? mx : x0, i&02 ? my : y0, |
| 133 |
|
|
i&01 ? x1 : mx, i&02 ? y1 : my); |
| 134 |
|
|
csm[0] += rgb[0]; csm[1] += rgb[1]; csm[2] += rgb[2]; |
| 135 |
|
|
nc++; |
| 136 |
|
|
} |
| 137 |
|
|
if (nc > 1) { |
| 138 |
|
|
ca[0] = csm[0]/nc; ca[1] = csm[1]/nc; ca[2] = csm[2]/nc; |
| 139 |
|
|
} else { |
| 140 |
|
|
ca[0] = csm[0]; ca[1] = csm[1]; ca[2] = csm[2]; |
| 141 |
|
|
} |
| 142 |
|
|
/* fill in gaps with average */ |
| 143 |
|
|
for (i = 0; gaps && i < 4; gaps >>= 1, i++) |
| 144 |
|
|
if (gaps & 01) |
| 145 |
|
|
cpaint(ca, (float *)NULL, |
| 146 |
|
|
i&01 ? mx : x0, i&02 ? my : y0, |
| 147 |
|
|
i&01 ? x1 : mx, i&02 ? y1 : my); |
| 148 |
|
|
tp->flgs &= ~CH_ANY; /* all done */ |
| 149 |
|
|
} |
| 150 |
|
|
|
| 151 |
|
|
|
| 152 |
schorsch |
3.3 |
extern void |
| 153 |
|
|
qtRedraw( /* redraw part or all of our screen */ |
| 154 |
|
|
int x0, |
| 155 |
|
|
int y0, |
| 156 |
|
|
int x1, |
| 157 |
|
|
int y1 |
| 158 |
|
|
) |
| 159 |
gregl |
3.1 |
{ |
| 160 |
|
|
int lim[2][2]; |
| 161 |
|
|
|
| 162 |
|
|
if (is_stump(&qtrunk)) |
| 163 |
|
|
return; |
| 164 |
schorsch |
3.3 |
if (!(qtMapLeaves((lim[0][0]=x0) <= 0) & ((lim[1][0]=y0) <= 0) & |
| 165 |
|
|
((lim[0][1]=x1) >= odev.hres-1) & ((lim[1][1]=y1) >= odev.vres-1))) |
| 166 |
gregl |
3.1 |
return; |
| 167 |
|
|
redraw(&qtrunk, 0, 0, odev.hres, odev.vres, lim); |
| 168 |
|
|
} |
| 169 |
|
|
|
| 170 |
|
|
|
| 171 |
schorsch |
3.3 |
extern void |
| 172 |
|
|
qtUpdate(void) /* update our tree display */ |
| 173 |
gregl |
3.1 |
{ |
| 174 |
greg |
3.4 |
uby8 ca[3]; |
| 175 |
gregl |
3.1 |
|
| 176 |
|
|
if (is_stump(&qtrunk)) |
| 177 |
|
|
return; |
| 178 |
|
|
if (!qtMapLeaves(0)) |
| 179 |
|
|
return; |
| 180 |
|
|
update(ca, &qtrunk, 0, 0, odev.hres, odev.vres); |
| 181 |
|
|
} |