56 |
|
#define MAX_SORT_INTVL (SORT_INTVL<<6) |
57 |
|
#endif |
58 |
|
|
59 |
< |
static COLOR avsum = BLKCOLOR; /* computed ambient value sum */ |
59 |
> |
static double avsum = 0.; /* computed ambient value sum (log) */ |
60 |
> |
static unsigned int navsum = 0; /* number of values in avsum */ |
61 |
|
static unsigned int nambvals = 0; /* total number of indirect values */ |
62 |
|
static unsigned int nambshare = 0; /* number of values from file */ |
63 |
|
static unsigned long ambclock = 0; /* ambient access clock */ |
70 |
|
* through memory on a multiprocessor, when we want to avoid |
71 |
|
* claiming our own memory (copy on write). Go ahead anyway |
72 |
|
* if more than two thirds of our values are unshared. |
73 |
+ |
* Compile with -Dtracktime=0 to turn this code off. |
74 |
|
*/ |
75 |
+ |
#ifndef tracktime |
76 |
|
#define tracktime (shm_boundary == NULL || nambvals > 3*nambshare) |
77 |
+ |
#endif |
78 |
|
|
79 |
|
#define AMBFLUSH (BUFSIZ/AMBVALSIZ) |
80 |
|
|
148 |
|
pos += (long)nambvals*AMBVALSIZ; |
149 |
|
flen = lseek(fileno(ambfp), 0L, 2); |
150 |
|
if (flen != pos) { |
151 |
< |
error(WARNING, |
151 |
> |
sprintf(errmsg, |
152 |
|
"ignoring last %ld values in ambient file (corrupted)", |
153 |
|
(flen - pos)/AMBVALSIZ); |
154 |
+ |
error(WARNING, errmsg); |
155 |
|
fseek(ambfp, pos, 0); |
156 |
|
ftruncate(fileno(ambfp), pos); |
157 |
|
} |
195 |
|
FVECT nrm; |
196 |
|
{ |
197 |
|
static int rdepth = 0; /* ambient recursion */ |
198 |
< |
double d; |
198 |
> |
double d, l; |
199 |
|
|
200 |
|
if (ambdiv <= 0) /* no ambient calculation */ |
201 |
|
goto dumbamb; |
233 |
|
return; |
234 |
|
dumbamb: /* return global value */ |
235 |
|
copycolor(acol, ambval); |
236 |
< |
if (ambvwt <= 0 | nambvals == 0) |
236 |
> |
if (ambvwt <= 0 | navsum == 0) |
237 |
|
return; |
238 |
< |
scalecolor(acol, (double)ambvwt); |
239 |
< |
addcolor(acol, avsum); /* average in computations */ |
240 |
< |
d = 1.0/(ambvwt+nambvals); |
241 |
< |
scalecolor(acol, d); |
238 |
> |
l = bright(ambval); /* average in computations */ |
239 |
> |
if (l > FTINY) { |
240 |
> |
d = (log(l)*(double)ambvwt + avsum) / |
241 |
> |
(double)(ambvwt + navsum); |
242 |
> |
d = exp(d) / l; |
243 |
> |
scalecolor(acol, d); /* apply color of ambval */ |
244 |
> |
} else { |
245 |
> |
d = exp( avsum / (double)navsum ); |
246 |
> |
setcolor(acol, d, d, d); /* neutral color */ |
247 |
> |
} |
248 |
|
} |
249 |
|
|
250 |
|
|
453 |
|
register AMBVAL *aval; |
454 |
|
{ |
455 |
|
register AMBVAL *av; |
456 |
+ |
double d; |
457 |
|
|
458 |
|
if ((av = newambval()) == NULL) |
459 |
|
error(SYSTEM, "out of memory in avstore"); |
460 |
|
copystruct(av, aval); |
461 |
|
av->latick = ambclock; |
462 |
|
av->next = NULL; |
451 |
– |
addcolor(avsum, av->val); /* add to sum for averaging */ |
463 |
|
nambvals++; |
464 |
+ |
d = bright(av->val); |
465 |
+ |
if (d > FTINY) { /* add to log sum for averaging */ |
466 |
+ |
avsum += log(d); |
467 |
+ |
navsum++; |
468 |
+ |
} |
469 |
|
return(av); |
470 |
|
} |
471 |
|
|