| 1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Quadtree driver support routines. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
#include <string.h> |
| 9 |
+ |
|
| 10 |
|
#include "standard.h" |
| 11 |
|
#include "rhd_qtree.h" |
| 12 |
|
/* quantity of leaves to free at a time */ |
| 30 |
|
|
| 31 |
|
int rayqleft = 0; /* rays left to queue before flush */ |
| 32 |
|
|
| 33 |
< |
static int4 falleaves; /* our list of fallen leaves */ |
| 33 |
> |
static int32 falleaves; /* our list of fallen leaves */ |
| 34 |
|
|
| 35 |
|
#define composted(li) (qtL.bl <= qtL.tl ? \ |
| 36 |
|
((li) < qtL.bl || (li) >= qtL.tl) : \ |
| 41 |
|
static RTREE **twigbundle; /* free twig blocks (NULL term.) */ |
| 42 |
|
static int nexttwig; /* next free twig */ |
| 43 |
|
|
| 44 |
+ |
static RTREE *newtwig(void); |
| 45 |
+ |
static void qtFreeTree(int really); |
| 46 |
+ |
static void shaketree(RTREE *tp); |
| 47 |
+ |
static int putleaf(int li, int drop); |
| 48 |
|
|
| 49 |
+ |
|
| 50 |
|
static RTREE * |
| 51 |
< |
newtwig() /* allocate a twig */ |
| 51 |
> |
newtwig(void) /* allocate a twig */ |
| 52 |
|
{ |
| 53 |
|
register int bi; |
| 54 |
|
|
| 60 |
|
} |
| 61 |
|
bi = nexttwig / TBUNDLESIZ; |
| 62 |
|
if (twigbundle[bi] == NULL) { /* new block */ |
| 63 |
< |
twigbundle = (RTREE **)realloc((char *)twigbundle, |
| 63 |
> |
twigbundle = (RTREE **)realloc((void *)twigbundle, |
| 64 |
|
(bi+2)*sizeof(RTREE *)); |
| 65 |
|
if (twigbundle == NULL) |
| 66 |
|
goto memerr; |
| 73 |
|
return(twigbundle[bi] + (nexttwig++ - bi*TBUNDLESIZ)); |
| 74 |
|
memerr: |
| 75 |
|
error(SYSTEM, "out of memory in newtwig"); |
| 76 |
+ |
return NULL; /* pro forma return */ |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
< |
qtFreeTree(really) /* free allocated twigs */ |
| 81 |
< |
int really; |
| 80 |
> |
static void |
| 81 |
> |
qtFreeTree( /* free allocated twigs */ |
| 82 |
> |
int really |
| 83 |
> |
) |
| 84 |
|
{ |
| 85 |
|
register int i; |
| 86 |
|
|
| 91 |
|
nexttwig = 0; |
| 92 |
|
if (!really) { /* just clear allocated blocks */ |
| 93 |
|
while (i--) |
| 94 |
< |
bzero((char *)twigbundle[i], TBUNDLESIZ*sizeof(RTREE)); |
| 94 |
> |
memset((char *)twigbundle[i], '\0', TBUNDLESIZ*sizeof(RTREE)); |
| 95 |
|
return; |
| 96 |
|
} |
| 97 |
|
/* else "really" means free up memory */ |
| 98 |
|
for (i = 0; twigbundle[i] != NULL; i++) |
| 99 |
< |
free((char *)twigbundle[i]); |
| 100 |
< |
free((char *)twigbundle); |
| 99 |
> |
free((void *)twigbundle[i]); |
| 100 |
> |
free((void *)twigbundle); |
| 101 |
|
twigbundle = NULL; |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
|
| 105 |
< |
#define LEAFSIZ (3*sizeof(float)+sizeof(int4)+\ |
| 105 |
> |
#define LEAFSIZ (3*sizeof(float)+sizeof(int32)+\ |
| 106 |
|
sizeof(TMbright)+6*sizeof(BYTE)) |
| 107 |
|
|
| 108 |
< |
int |
| 109 |
< |
qtAllocLeaves(n) /* allocate space for n leaves */ |
| 110 |
< |
register int n; |
| 108 |
> |
extern int |
| 109 |
> |
qtAllocLeaves( /* allocate space for n leaves */ |
| 110 |
> |
register int n |
| 111 |
> |
) |
| 112 |
|
{ |
| 113 |
|
unsigned nbytes; |
| 114 |
|
register unsigned i; |
| 130 |
|
return(0); |
| 131 |
|
/* assign larger alignment types earlier */ |
| 132 |
|
qtL.wp = (float (*)[3])qtL.base; |
| 133 |
< |
qtL.wd = (int4 *)(qtL.wp + n); |
| 133 |
> |
qtL.wd = (int32 *)(qtL.wp + n); |
| 134 |
|
qtL.brt = (TMbright *)(qtL.wd + n); |
| 135 |
|
qtL.chr = (BYTE (*)[3])(qtL.brt + n); |
| 136 |
|
qtL.rgb = (BYTE (*)[3])(qtL.chr + n); |
| 143 |
|
#undef LEAFSIZ |
| 144 |
|
|
| 145 |
|
|
| 146 |
< |
qtFreeLeaves() /* free our allocated leaves and twigs */ |
| 146 |
> |
extern void |
| 147 |
> |
qtFreeLeaves(void) /* free our allocated leaves and twigs */ |
| 148 |
|
{ |
| 149 |
|
qtFreeTree(1); /* free tree also */ |
| 150 |
|
if (qtL.nl <= 0) |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
< |
static |
| 159 |
< |
shaketree(tp) /* shake dead leaves from tree */ |
| 160 |
< |
register RTREE *tp; |
| 158 |
> |
static void |
| 159 |
> |
shaketree( /* shake dead leaves from tree */ |
| 160 |
> |
register RTREE *tp |
| 161 |
> |
) |
| 162 |
|
{ |
| 163 |
|
register int i, li; |
| 164 |
|
|
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
|
| 178 |
< |
int |
| 179 |
< |
qtCompost(pct) /* free up some leaves */ |
| 180 |
< |
int pct; |
| 178 |
> |
extern int |
| 179 |
> |
qtCompost( /* free up some leaves */ |
| 180 |
> |
int pct |
| 181 |
> |
) |
| 182 |
|
{ |
| 183 |
< |
register int4 *fl; |
| 183 |
> |
register int32 *fl; |
| 184 |
|
int nused, nclear, nmapped; |
| 185 |
|
/* figure out how many leaves to clear */ |
| 186 |
|
nclear = qtL.nl * pct / 100; |
| 210 |
|
} |
| 211 |
|
|
| 212 |
|
|
| 213 |
< |
int |
| 214 |
< |
qtFindLeaf(x, y) /* find closest leaf to (x,y) */ |
| 215 |
< |
int x, y; |
| 213 |
> |
extern int |
| 214 |
> |
qtFindLeaf( /* find closest leaf to (x,y) */ |
| 215 |
> |
int x, |
| 216 |
> |
int y |
| 217 |
> |
) |
| 218 |
|
{ |
| 219 |
|
register RTREE *tp = &qtrunk; |
| 220 |
|
int li = -1; |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
|
| 252 |
< |
static |
| 253 |
< |
putleaf(li, drop) /* put a leaf in our tree */ |
| 254 |
< |
register int li; |
| 255 |
< |
int drop; |
| 252 |
> |
static int |
| 253 |
> |
putleaf( /* put a leaf in our tree */ |
| 254 |
> |
register int li, |
| 255 |
> |
int drop |
| 256 |
> |
) |
| 257 |
|
{ |
| 258 |
|
register RTREE *tp = &qtrunk; |
| 259 |
|
int x0=0, y0=0, x1=odev.hres, y1=odev.vres; |
| 334 |
|
tp->k[q].li = lo; |
| 335 |
|
} |
| 336 |
|
dropit: |
| 337 |
< |
if (drop) |
| 337 |
> |
if (drop) { |
| 338 |
|
if (li+1 == (qtL.tl ? qtL.tl : qtL.nl)) |
| 339 |
|
qtL.tl = li; /* special case */ |
| 340 |
|
else { |
| 342 |
|
qtL.wd[li] = falleaves; |
| 343 |
|
falleaves = li; |
| 344 |
|
} |
| 345 |
+ |
} |
| 346 |
|
return(li == lo); |
| 347 |
|
} |
| 348 |
|
|
| 349 |
|
|
| 350 |
< |
dev_value(c, p, v) /* add a pixel value to our quadtree */ |
| 351 |
< |
COLR c; |
| 352 |
< |
FVECT p, v; |
| 350 |
> |
extern void |
| 351 |
> |
dev_value( /* add a pixel value to our quadtree */ |
| 352 |
> |
COLR c, |
| 353 |
> |
FVECT d, |
| 354 |
> |
FVECT p |
| 355 |
> |
) |
| 356 |
|
{ |
| 357 |
|
register int li; |
| 358 |
|
int mapit; |
| 371 |
|
qtCompost(LFREEPCT); |
| 372 |
|
mapit = 0; /* we'll map it later */ |
| 373 |
|
} |
| 374 |
< |
VCOPY(qtL.wp[li], p); |
| 375 |
< |
qtL.wd[li] = encodedir(v); |
| 376 |
< |
tmCvColrs(&qtL.brt[li], qtL.chr[li], c, 1); |
| 374 |
> |
if (p == NULL) |
| 375 |
> |
VSUM(qtL.wp[li], odev.v.vp, d, FHUGE); |
| 376 |
> |
else |
| 377 |
> |
VCOPY(qtL.wp[li], p); |
| 378 |
> |
qtL.wd[li] = encodedir(d); |
| 379 |
> |
tmCvColrs(&qtL.brt[li], qtL.chr[li], (COLR *)c, 1); |
| 380 |
|
if (putleaf(li, 1)) { |
| 381 |
|
if (mapit) |
| 382 |
< |
tmMapPixels(qtL.rgb+li, qtL.brt+li, qtL.chr+li, 1); |
| 382 |
> |
tmMapPixels((BYTE *)(qtL.rgb+li), qtL.brt+li, |
| 383 |
> |
(BYTE *)(qtL.chr+li), 1); |
| 384 |
|
if (--rayqleft == 0) |
| 385 |
|
dev_flush(); /* flush output */ |
| 386 |
|
} |
| 387 |
|
} |
| 388 |
|
|
| 389 |
|
|
| 390 |
< |
qtReplant() /* replant our tree using new view */ |
| 390 |
> |
extern void |
| 391 |
> |
qtReplant(void) /* replant our tree using new view */ |
| 392 |
|
{ |
| 393 |
|
register int i; |
| 394 |
|
/* anything to replant? */ |
| 403 |
|
} |
| 404 |
|
|
| 405 |
|
|
| 406 |
< |
qtMapLeaves(redo) /* map our leaves to RGB */ |
| 407 |
< |
int redo; |
| 406 |
> |
extern int |
| 407 |
> |
qtMapLeaves( /* map our leaves to RGB */ |
| 408 |
> |
int redo |
| 409 |
> |
) |
| 410 |
|
{ |
| 411 |
|
int aorg, alen, borg, blen; |
| 412 |
|
/* recompute mapping? */ |
| 434 |
|
if (tmComputeMapping(0., 0., 0.) != TM_E_OK) |
| 435 |
|
return(0); |
| 436 |
|
} |
| 437 |
< |
if (tmMapPixels(qtL.rgb+aorg, qtL.brt+aorg, |
| 438 |
< |
qtL.chr+aorg, alen) != TM_E_OK) |
| 437 |
> |
if (tmMapPixels((BYTE *)(qtL.rgb+aorg), qtL.brt+aorg, |
| 438 |
> |
(BYTE *)(qtL.chr+aorg), alen) != TM_E_OK) |
| 439 |
|
return(0); |
| 440 |
|
if (blen > 0) |
| 441 |
< |
tmMapPixels(qtL.rgb+borg, qtL.brt+borg, |
| 442 |
< |
qtL.chr+borg, blen); |
| 441 |
> |
tmMapPixels((BYTE *)(qtL.rgb+borg), qtL.brt+borg, |
| 442 |
> |
(BYTE *)(qtL.chr+borg), blen); |
| 443 |
|
qtL.tml = qtL.tl; |
| 444 |
|
return(1); |
| 445 |
|
} |