19 |
|
#define MAXANG 20. |
20 |
|
#endif |
21 |
|
|
22 |
< |
#define MAXDIFF2 (long)( MAXANG*MAXANG /90./90.*(1L<<15)*(1L<<15)) |
22 |
> |
#define MAXDIFF2 (PI*PI/180./180.* MAXANG*MAXANG ) |
23 |
|
|
24 |
|
#define abs(i) ((i) < 0 ? -(i) : (i)) |
25 |
|
|
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
< |
#define LEAFSIZ (3*sizeof(float)+2*sizeof(short)+\ |
105 |
> |
#define LEAFSIZ (3*sizeof(float)+sizeof(int4)+\ |
106 |
|
sizeof(TMbright)+6*sizeof(BYTE)) |
107 |
|
|
108 |
|
int |
129 |
|
return(0); |
130 |
|
/* assign larger alignment types earlier */ |
131 |
|
qtL.wp = (float (*)[3])qtL.base; |
132 |
< |
qtL.wd = (short (*)[2])(qtL.wp + n); |
132 |
> |
qtL.wd = (int4 *)(qtL.wp + n); |
133 |
|
qtL.brt = (TMbright *)(qtL.wd + n); |
134 |
|
qtL.chr = (BYTE (*)[3])(qtL.brt + n); |
135 |
|
qtL.rgb = (BYTE (*)[3])(qtL.chr + n); |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
< |
static |
206 |
< |
encodedir(pa, dv) /* encode a normalized direction vector */ |
207 |
< |
short pa[2]; |
205 |
> |
#define DCSCALE 11585.2 /* (1<<13)*sqrt(2) */ |
206 |
> |
#define FXNEG 01 |
207 |
> |
#define FYNEG 02 |
208 |
> |
#define FZNEG 04 |
209 |
> |
#define FXACT 010 |
210 |
> |
#define FZACT 020 |
211 |
> |
#define F1SFT 5 |
212 |
> |
#define F2SFT 18 |
213 |
> |
#define FMASK 0x1fff |
214 |
> |
|
215 |
> |
static int4 |
216 |
> |
encodedir(dv) /* encode a normalized direction vector */ |
217 |
|
FVECT dv; |
218 |
|
{ |
219 |
< |
pa[1] = 0; |
220 |
< |
if (dv[2] >= 1.) |
221 |
< |
pa[0] = (1L<<15)-1; |
222 |
< |
else if (dv[2] <= -1.) |
223 |
< |
pa[0] = -((1L<<15)-1); |
224 |
< |
else { |
225 |
< |
pa[0] = ((1L<<15)-1)/(PI/2.) * asin(dv[2]); |
226 |
< |
pa[1] = ((1L<<15)-1)/PI * atan2(dv[1], dv[0]); |
219 |
> |
register int4 dc = 0; |
220 |
> |
int cd[3], cm; |
221 |
> |
register int i; |
222 |
> |
|
223 |
> |
for (i = 0; i < 3; i++) |
224 |
> |
if (dv[i] < 0.) { |
225 |
> |
cd[i] = dv[i] * -DCSCALE; |
226 |
> |
dc |= 1<<i; |
227 |
> |
} else |
228 |
> |
cd[i] = dv[i] * DCSCALE; |
229 |
> |
if (cd[0] <= cd[1]) { |
230 |
> |
dc |= FXACT | cd[0] << F1SFT; |
231 |
> |
cm = cd[1]; |
232 |
> |
} else { |
233 |
> |
dc |= cd[1] << F1SFT; |
234 |
> |
cm = cd[0]; |
235 |
|
} |
236 |
+ |
if (cd[2] <= cm) |
237 |
+ |
dc |= FZACT | cd[2] << F2SFT; |
238 |
+ |
else |
239 |
+ |
dc |= cm << F2SFT; |
240 |
+ |
return(dc); |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
< |
#define ALTSHFT 5 |
245 |
< |
#define NALT (1<<ALTSHFT) |
246 |
< |
#define azisft(alt) azisftab[abs(alt)>>(15-ALTSHFT)] |
244 |
> |
static |
245 |
> |
decodedir(dv, dc) /* decode a normalized direction vector */ |
246 |
> |
FVECT dv; /* returned */ |
247 |
> |
register int4 dc; |
248 |
> |
{ |
249 |
> |
double d1, d2, der; |
250 |
|
|
251 |
< |
static unsigned short azisftab[NALT]; |
251 |
> |
d1 = ((dc>>F1SFT & FMASK)+.5)/DCSCALE; |
252 |
> |
d2 = ((dc>>F2SFT & FMASK)+.5)/DCSCALE; |
253 |
> |
der = sqrt(1. - d1*d1 - d2*d2); |
254 |
> |
if (dc & FXACT) { |
255 |
> |
dv[0] = d1; |
256 |
> |
if (dc & FZACT) { dv[1] = der; dv[2] = d2; } |
257 |
> |
else { dv[1] = d2; dv[2] = der; } |
258 |
> |
} else { |
259 |
> |
dv[1] = d1; |
260 |
> |
if (dc & FZACT) { dv[0] = der; dv[2] = d2; } |
261 |
> |
else { dv[0] = d2; dv[2] = der; } |
262 |
> |
} |
263 |
> |
if (dc & FXNEG) dv[0] = -dv[0]; |
264 |
> |
if (dc & FYNEG) dv[1] = -dv[1]; |
265 |
> |
if (dc & FZNEG) dv[2] = -dv[2]; |
266 |
> |
} |
267 |
|
|
268 |
< |
static |
269 |
< |
azisftinit(alt) /* initialize azimuth scale factor table */ |
270 |
< |
int alt; |
268 |
> |
|
269 |
> |
static double |
270 |
> |
dir2diff(dc1, dc2) /* relative radians^2 between directions */ |
271 |
> |
int4 dc1, dc2; |
272 |
|
{ |
273 |
< |
register int i; |
273 |
> |
FVECT v1, v2; |
274 |
|
|
275 |
< |
for (i = NALT; i--; ) |
276 |
< |
azisftab[i] = 2.*(1L<<15) * cos(PI/2.*(i+.5)/NALT); |
277 |
< |
return(azisft(alt)); |
275 |
> |
decodedir(v1, dc1); |
276 |
> |
decodedir(v2, dc2); |
277 |
> |
|
278 |
> |
return(2. - 2.*DOT(v1,v2)); |
279 |
|
} |
280 |
|
|
239 |
– |
#define azisf(alt) (azisftab[0] ? azisft(alt) : azisftinit(alt)) >> 15 |
281 |
|
|
282 |
< |
static long |
283 |
< |
dir2diff(pa1, pa2) /* relative distance^2 between directions */ |
284 |
< |
short pa1[2], pa2[2]; |
282 |
> |
static double |
283 |
> |
fdir2diff(dc1, v2) /* relative radians^2 between directions */ |
284 |
> |
int4 dc1; |
285 |
> |
register FVECT v2; |
286 |
|
{ |
287 |
< |
long altd2, azid2; |
246 |
< |
int alt; |
287 |
> |
FVECT v1; |
288 |
|
|
289 |
< |
altd2 = pa1[0] - pa2[0]; /* get altitude difference^2 */ |
290 |
< |
altd2 *= altd2; |
291 |
< |
if (altd2 > MAXDIFF2) |
251 |
< |
return(altd2); /* too large already */ |
252 |
< |
azid2 = pa1[1] - pa2[1]; /* get adjusted azimuth difference^2 */ |
253 |
< |
if (azid2 < 0) azid2 = -azid2; |
254 |
< |
if (azid2 >= 1L<<15) { /* wrap sphere */ |
255 |
< |
azid2 -= 1L<<16; |
256 |
< |
if (azid2 < 0) azid2 = -azid2; |
257 |
< |
} |
258 |
< |
alt = (pa1[0]+pa2[0])/2; |
259 |
< |
azid2 = azid2*azisf(alt); /* evaluation order is important */ |
260 |
< |
azid2 *= azid2; |
261 |
< |
return(altd2 + azid2); |
289 |
> |
decodedir(v1, dc1); |
290 |
> |
|
291 |
> |
return(2. - 2.*DOT(v1,v2)); |
292 |
|
} |
293 |
|
|
294 |
|
|
336 |
|
register RTREE *tp = &qtrunk; |
337 |
|
int x0=0, y0=0, x1=odev.hres, y1=odev.vres; |
338 |
|
int lo = -1; |
339 |
< |
long d2; |
310 |
< |
short dc[2]; |
339 |
> |
double d2; |
340 |
|
int x, y, mx, my; |
341 |
|
double z; |
342 |
< |
FVECT ip, wp; |
342 |
> |
FVECT ip, wp, vd; |
343 |
|
register int q; |
344 |
|
/* compute leaf location in view */ |
345 |
|
VCOPY(wp, qtL.wp[li]); |
352 |
|
error(INTERNAL, "bad view assumption in addleaf"); |
353 |
|
#endif |
354 |
|
for (q = 0; q < 3; q++) |
355 |
< |
wp[q] = (wp[q] - odev.v.vp[q])/ip[2]; |
356 |
< |
encodedir(dc, wp); /* compute pixel direction */ |
328 |
< |
d2 = dir2diff(dc, qtL.wd[li]); |
355 |
> |
vd[q] = (wp[q] - odev.v.vp[q])/ip[2]; |
356 |
> |
d2 = fdir2diff(qtL.wd[li], vd); |
357 |
|
if (d2 > MAXDIFF2) |
358 |
|
return(0); /* leaf dir. too far off */ |
359 |
|
x = ip[0] * odev.hres; |
388 |
|
if (z > (1.+qtDepthEps)*ip[2]) |
389 |
|
return(0); /* old one closer */ |
390 |
|
if (z >= (1.-qtDepthEps)*ip[2] && |
391 |
< |
dir2diff(dc, qtL.wd[lo]) < d2) |
391 |
> |
fdir2diff(qtL.wd[lo], vd) < d2) |
392 |
|
return(0); /* old one better */ |
393 |
|
tp->k[q].li = li; /* else new one is */ |
394 |
|
tp->flgs |= CHF(q); |
402 |
|
my = ip[1] * odev.vres; |
403 |
|
if (mx >= (x0 + x1) >> 1) q |= 01; |
404 |
|
if (my >= (y0 + y1) >> 1) q |= 02; |
405 |
+ |
tp->flgs = CH_ANY|LFF(q); /* all new */ |
406 |
|
tp->k[q].li = lo; |
378 |
– |
tp->flgs |= LFF(q)|CH_ANY; /* all new */ |
407 |
|
} |
408 |
|
return(1); /* done */ |
409 |
|
} |
417 |
|
|
418 |
|
li = newleaf(); |
419 |
|
VCOPY(qtL.wp[li], p); |
420 |
< |
encodedir(qtL.wd[li], v); |
420 |
> |
qtL.wd[li] = encodedir(v); |
421 |
|
tmCvColrs(&qtL.brt[li], qtL.chr[li], c, 1); |
422 |
|
if (!addleaf(li)) |
423 |
|
ungetleaf(li); |