1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Routines to compute "ambient" values using Monte Carlo |
6 |
+ |
* |
7 |
+ |
* Declarations of external symbols in ambient.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
+ |
#include "ray.h" |
13 |
|
#include "ambient.h" |
14 |
– |
|
14 |
|
#include "random.h" |
15 |
|
|
16 |
< |
typedef struct { |
18 |
< |
short t, p; /* theta, phi indices */ |
19 |
< |
COLOR v; /* value sum */ |
20 |
< |
float r; /* 1/distance sum */ |
21 |
< |
float k; /* variance for this division */ |
22 |
< |
int n; /* number of subsamples */ |
23 |
< |
} AMBSAMP; /* ambient sample division */ |
16 |
> |
#ifdef NEWAMB |
17 |
|
|
18 |
< |
typedef struct { |
26 |
< |
FVECT ux, uy, uz; /* x, y and z axis directions */ |
27 |
< |
short nt, np; /* number of theta and phi directions */ |
28 |
< |
} AMBHEMI; /* ambient sample hemisphere */ |
18 |
> |
#else /* ! NEWAMB */ |
19 |
|
|
30 |
– |
extern double sin(), cos(), sqrt(); |
20 |
|
|
21 |
< |
|
22 |
< |
static int |
23 |
< |
ambcmp(d1, d2) /* decreasing order */ |
24 |
< |
AMBSAMP *d1, *d2; |
21 |
> |
void |
22 |
> |
inithemi( /* initialize sampling hemisphere */ |
23 |
> |
AMBHEMI *hp, |
24 |
> |
COLOR ac, |
25 |
> |
RAY *r, |
26 |
> |
double wt |
27 |
> |
) |
28 |
|
{ |
29 |
< |
if (d1->k < d2->k) |
30 |
< |
return(1); |
31 |
< |
if (d1->k > d2->k) |
32 |
< |
return(-1); |
33 |
< |
return(0); |
29 |
> |
double d; |
30 |
> |
int i; |
31 |
> |
/* set number of divisions */ |
32 |
> |
if (ambacc <= FTINY && |
33 |
> |
wt > (d = 0.8*intens(ac)*r->rweight/(ambdiv*minweight))) |
34 |
> |
wt = d; /* avoid ray termination */ |
35 |
> |
hp->nt = sqrt(ambdiv * wt / PI) + 0.5; |
36 |
> |
i = ambacc > FTINY ? 3 : 1; /* minimum number of samples */ |
37 |
> |
if (hp->nt < i) |
38 |
> |
hp->nt = i; |
39 |
> |
hp->np = PI * hp->nt + 0.5; |
40 |
> |
/* set number of super-samples */ |
41 |
> |
hp->ns = ambssamp * wt + 0.5; |
42 |
> |
/* assign coefficient */ |
43 |
> |
copycolor(hp->acoef, ac); |
44 |
> |
d = 1.0/(hp->nt*hp->np); |
45 |
> |
scalecolor(hp->acoef, d); |
46 |
> |
/* make axes */ |
47 |
> |
VCOPY(hp->uz, r->ron); |
48 |
> |
hp->uy[0] = hp->uy[1] = hp->uy[2] = 0.0; |
49 |
> |
for (i = 0; i < 3; i++) |
50 |
> |
if (hp->uz[i] < 0.6 && hp->uz[i] > -0.6) |
51 |
> |
break; |
52 |
> |
if (i >= 3) |
53 |
> |
error(CONSISTENCY, "bad ray direction in inithemi"); |
54 |
> |
hp->uy[i] = 1.0; |
55 |
> |
fcross(hp->ux, hp->uy, hp->uz); |
56 |
> |
normalize(hp->ux); |
57 |
> |
fcross(hp->uy, hp->uz, hp->ux); |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
< |
static int |
62 |
< |
ambnorm(d1, d2) /* standard order */ |
63 |
< |
AMBSAMP *d1, *d2; |
61 |
> |
int |
62 |
> |
divsample( /* sample a division */ |
63 |
> |
AMBSAMP *dp, |
64 |
> |
AMBHEMI *h, |
65 |
> |
RAY *r |
66 |
> |
) |
67 |
|
{ |
49 |
– |
register int c; |
50 |
– |
|
51 |
– |
if (c = d1->t - d2->t) |
52 |
– |
return(c); |
53 |
– |
return(d1->p - d2->p); |
54 |
– |
} |
55 |
– |
|
56 |
– |
|
57 |
– |
divsample(dp, h, r) /* sample a division */ |
58 |
– |
register AMBSAMP *dp; |
59 |
– |
AMBHEMI *h; |
60 |
– |
RAY *r; |
61 |
– |
{ |
68 |
|
RAY ar; |
69 |
< |
int hlist[4]; |
69 |
> |
int hlist[3]; |
70 |
> |
double spt[2]; |
71 |
|
double xd, yd, zd; |
72 |
|
double b2; |
73 |
|
double phi; |
74 |
< |
register int i; |
75 |
< |
|
76 |
< |
if (rayorigin(&ar, r, AMBIENT, 0.5) < 0) |
74 |
> |
int i; |
75 |
> |
/* ambient coefficient for weight */ |
76 |
> |
if (ambacc > FTINY) |
77 |
> |
setcolor(ar.rcoef, AVGREFL, AVGREFL, AVGREFL); |
78 |
> |
else |
79 |
> |
copycolor(ar.rcoef, h->acoef); |
80 |
> |
if (rayorigin(&ar, AMBIENT, r, ar.rcoef) < 0) |
81 |
|
return(-1); |
82 |
+ |
if (ambacc > FTINY) { |
83 |
+ |
multcolor(ar.rcoef, h->acoef); |
84 |
+ |
scalecolor(ar.rcoef, 1./AVGREFL); |
85 |
+ |
} |
86 |
|
hlist[0] = r->rno; |
87 |
|
hlist[1] = dp->t; |
88 |
|
hlist[2] = dp->p; |
89 |
< |
hlist[3] = 0; |
90 |
< |
zd = sqrt((dp->t+urand(ilhash(hlist,4)+dp->n))/h->nt); |
91 |
< |
hlist[3] = 1; |
92 |
< |
phi = 2.0*PI * (dp->p+urand(ilhash(hlist,4)+dp->n))/h->np; |
93 |
< |
xd = cos(phi) * zd; |
79 |
< |
yd = sin(phi) * zd; |
89 |
> |
multisamp(spt, 2, urand(ilhash(hlist,3)+dp->n)); |
90 |
> |
zd = sqrt((dp->t + spt[0])/h->nt); |
91 |
> |
phi = 2.0*PI * (dp->p + spt[1])/h->np; |
92 |
> |
xd = tcos(phi) * zd; |
93 |
> |
yd = tsin(phi) * zd; |
94 |
|
zd = sqrt(1.0 - zd*zd); |
95 |
|
for (i = 0; i < 3; i++) |
96 |
|
ar.rdir[i] = xd*h->ux[i] + |
97 |
|
yd*h->uy[i] + |
98 |
|
zd*h->uz[i]; |
99 |
+ |
checknorm(ar.rdir); |
100 |
|
dimlist[ndims++] = dp->t*h->np + dp->p + 90171; |
101 |
|
rayvalue(&ar); |
102 |
|
ndims--; |
103 |
+ |
multcolor(ar.rcol, ar.rcoef); /* apply coefficient */ |
104 |
|
addcolor(dp->v, ar.rcol); |
105 |
< |
if (ar.rt < FHUGE) |
105 |
> |
/* use rt to improve gradient calc */ |
106 |
> |
if (ar.rt > FTINY && ar.rt < FHUGE) |
107 |
|
dp->r += 1.0/ar.rt; |
108 |
|
/* (re)initialize error */ |
109 |
|
if (dp->n++) { |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
+ |
static int |
120 |
+ |
ambcmp( /* decreasing order */ |
121 |
+ |
const void *p1, |
122 |
+ |
const void *p2 |
123 |
+ |
) |
124 |
+ |
{ |
125 |
+ |
const AMBSAMP *d1 = (const AMBSAMP *)p1; |
126 |
+ |
const AMBSAMP *d2 = (const AMBSAMP *)p2; |
127 |
+ |
|
128 |
+ |
if (d1->k < d2->k) |
129 |
+ |
return(1); |
130 |
+ |
if (d1->k > d2->k) |
131 |
+ |
return(-1); |
132 |
+ |
return(0); |
133 |
+ |
} |
134 |
+ |
|
135 |
+ |
|
136 |
+ |
static int |
137 |
+ |
ambnorm( /* standard order */ |
138 |
+ |
const void *p1, |
139 |
+ |
const void *p2 |
140 |
+ |
) |
141 |
+ |
{ |
142 |
+ |
const AMBSAMP *d1 = (const AMBSAMP *)p1; |
143 |
+ |
const AMBSAMP *d2 = (const AMBSAMP *)p2; |
144 |
+ |
int c; |
145 |
+ |
|
146 |
+ |
if ( (c = d1->t - d2->t) ) |
147 |
+ |
return(c); |
148 |
+ |
return(d1->p - d2->p); |
149 |
+ |
} |
150 |
+ |
|
151 |
+ |
|
152 |
|
double |
153 |
< |
doambient(acol, r, pg, dg) /* compute ambient component */ |
154 |
< |
COLOR acol; |
155 |
< |
RAY *r; |
156 |
< |
FVECT pg, dg; |
153 |
> |
doambient( /* compute ambient component */ |
154 |
> |
COLOR rcol, |
155 |
> |
RAY *r, |
156 |
> |
double wt, |
157 |
> |
FVECT pg, |
158 |
> |
FVECT dg |
159 |
> |
) |
160 |
|
{ |
161 |
< |
double b, d; |
161 |
> |
double b, d=0; |
162 |
|
AMBHEMI hemi; |
163 |
|
AMBSAMP *div; |
164 |
|
AMBSAMP dnew; |
165 |
< |
register AMBSAMP *dp; |
165 |
> |
double acol[3]; |
166 |
> |
AMBSAMP *dp; |
167 |
|
double arad; |
168 |
< |
int ndivs, ns; |
169 |
< |
register int i, j; |
116 |
< |
/* initialize color */ |
117 |
< |
setcolor(acol, 0.0, 0.0, 0.0); |
168 |
> |
int divcnt; |
169 |
> |
int i, j; |
170 |
|
/* initialize hemisphere */ |
171 |
< |
inithemi(&hemi, r); |
172 |
< |
ndivs = hemi.nt * hemi.np; |
173 |
< |
if (ndivs == 0) |
171 |
> |
inithemi(&hemi, rcol, r, wt); |
172 |
> |
divcnt = hemi.nt * hemi.np; |
173 |
> |
/* initialize */ |
174 |
> |
if (pg != NULL) |
175 |
> |
pg[0] = pg[1] = pg[2] = 0.0; |
176 |
> |
if (dg != NULL) |
177 |
> |
dg[0] = dg[1] = dg[2] = 0.0; |
178 |
> |
setcolor(rcol, 0.0, 0.0, 0.0); |
179 |
> |
if (divcnt == 0) |
180 |
|
return(0.0); |
181 |
< |
/* set number of super-samples */ |
182 |
< |
ns = ambssamp * r->rweight + 0.5; |
183 |
< |
if (ns > 0 || pg != NULL || dg != NULL) { |
126 |
< |
div = (AMBSAMP *)malloc(ndivs*sizeof(AMBSAMP)); |
181 |
> |
/* allocate super-samples */ |
182 |
> |
if (hemi.ns > 0 || pg != NULL || dg != NULL) { |
183 |
> |
div = (AMBSAMP *)malloc(divcnt*sizeof(AMBSAMP)); |
184 |
|
if (div == NULL) |
185 |
|
error(SYSTEM, "out of memory in doambient"); |
186 |
|
} else |
187 |
|
div = NULL; |
188 |
|
/* sample the divisions */ |
189 |
|
arad = 0.0; |
190 |
+ |
acol[0] = acol[1] = acol[2] = 0.0; |
191 |
|
if ((dp = div) == NULL) |
192 |
|
dp = &dnew; |
193 |
+ |
divcnt = 0; |
194 |
|
for (i = 0; i < hemi.nt; i++) |
195 |
|
for (j = 0; j < hemi.np; j++) { |
196 |
|
dp->t = i; dp->p = j; |
197 |
|
setcolor(dp->v, 0.0, 0.0, 0.0); |
198 |
|
dp->r = 0.0; |
199 |
|
dp->n = 0; |
200 |
< |
if (divsample(dp, &hemi, r) < 0) |
201 |
< |
goto oopsy; |
200 |
> |
if (divsample(dp, &hemi, r) < 0) { |
201 |
> |
if (div != NULL) |
202 |
> |
dp++; |
203 |
> |
continue; |
204 |
> |
} |
205 |
> |
arad += dp->r; |
206 |
> |
divcnt++; |
207 |
|
if (div != NULL) |
208 |
|
dp++; |
209 |
< |
else { |
209 |
> |
else |
210 |
|
addcolor(acol, dp->v); |
147 |
– |
arad += dp->r; |
148 |
– |
} |
211 |
|
} |
212 |
< |
if (ns > 0) { /* perform super-sampling */ |
212 |
> |
if (!divcnt) { |
213 |
> |
if (div != NULL) |
214 |
> |
free((void *)div); |
215 |
> |
return(0.0); /* no samples taken */ |
216 |
> |
} |
217 |
> |
if (divcnt < hemi.nt*hemi.np) { |
218 |
> |
pg = dg = NULL; /* incomplete sampling */ |
219 |
> |
hemi.ns = 0; |
220 |
> |
} else if (arad > FTINY && divcnt/arad < minarad) { |
221 |
> |
hemi.ns = 0; /* close enough */ |
222 |
> |
} else if (hemi.ns > 0) { /* else perform super-sampling? */ |
223 |
|
comperrs(div, &hemi); /* compute errors */ |
224 |
< |
qsort(div, ndivs, sizeof(AMBSAMP), ambcmp); /* sort divs */ |
224 |
> |
qsort(div, divcnt, sizeof(AMBSAMP), ambcmp); /* sort divs */ |
225 |
|
/* super-sample */ |
226 |
< |
for (i = ns; i > 0; i--) { |
227 |
< |
copystruct(&dnew, div); |
228 |
< |
if (divsample(&dnew, &hemi, r) < 0) |
229 |
< |
goto oopsy; |
230 |
< |
/* reinsert */ |
231 |
< |
dp = div; |
232 |
< |
j = ndivs < i ? ndivs : i; |
226 |
> |
for (i = hemi.ns; i > 0; i--) { |
227 |
> |
dnew = *div; |
228 |
> |
if (divsample(&dnew, &hemi, r) < 0) { |
229 |
> |
dp++; |
230 |
> |
continue; |
231 |
> |
} |
232 |
> |
dp = div; /* reinsert */ |
233 |
> |
j = divcnt < i ? divcnt : i; |
234 |
|
while (--j > 0 && dnew.k < dp[1].k) { |
235 |
< |
copystruct(dp, dp+1); |
235 |
> |
*dp = *(dp+1); |
236 |
|
dp++; |
237 |
|
} |
238 |
< |
copystruct(dp, &dnew); |
238 |
> |
*dp = dnew; |
239 |
|
} |
240 |
|
if (pg != NULL || dg != NULL) /* restore order */ |
241 |
< |
qsort(div, ndivs, sizeof(AMBSAMP), ambnorm); |
241 |
> |
qsort(div, divcnt, sizeof(AMBSAMP), ambnorm); |
242 |
|
} |
243 |
|
/* compute returned values */ |
244 |
|
if (div != NULL) { |
245 |
< |
for (i = ndivs, dp = div; i-- > 0; dp++) { |
245 |
> |
arad = 0.0; /* note: divcnt may be < nt*np */ |
246 |
> |
for (i = hemi.nt*hemi.np, dp = div; i-- > 0; dp++) { |
247 |
|
arad += dp->r; |
248 |
|
if (dp->n > 1) { |
249 |
|
b = 1.0/dp->n; |
255 |
|
} |
256 |
|
b = bright(acol); |
257 |
|
if (b > FTINY) { |
258 |
< |
b = ndivs/b; |
258 |
> |
b = 1.0/b; /* compute & normalize gradient(s) */ |
259 |
|
if (pg != NULL) { |
260 |
|
posgradient(pg, div, &hemi); |
261 |
|
for (i = 0; i < 3; i++) |
266 |
|
for (i = 0; i < 3; i++) |
267 |
|
dg[i] *= b; |
268 |
|
} |
195 |
– |
} else { |
196 |
– |
if (pg != NULL) |
197 |
– |
for (i = 0; i < 3; i++) |
198 |
– |
pg[i] = 0.0; |
199 |
– |
if (dg != NULL) |
200 |
– |
for (i = 0; i < 3; i++) |
201 |
– |
dg[i] = 0.0; |
269 |
|
} |
270 |
< |
free((char *)div); |
270 |
> |
free((void *)div); |
271 |
|
} |
272 |
< |
b = 1.0/ndivs; |
206 |
< |
scalecolor(acol, b); |
272 |
> |
copycolor(rcol, acol); |
273 |
|
if (arad <= FTINY) |
208 |
– |
arad = FHUGE; |
209 |
– |
else |
210 |
– |
arad = (ndivs+ns)/arad; |
211 |
– |
if (arad > maxarad) |
274 |
|
arad = maxarad; |
275 |
< |
else if (arad < minarad) |
275 |
> |
else |
276 |
> |
arad = (divcnt+hemi.ns)/arad; |
277 |
> |
if (pg != NULL) { /* reduce radius if gradient large */ |
278 |
> |
d = DOT(pg,pg); |
279 |
> |
if (d*arad*arad > 1.0) |
280 |
> |
arad = 1.0/sqrt(d); |
281 |
> |
} |
282 |
> |
if (arad < minarad) { |
283 |
|
arad = minarad; |
284 |
< |
arad /= sqrt(r->rweight); |
284 |
> |
if (pg != NULL && d*arad*arad > 1.0) { /* cap gradient */ |
285 |
> |
d = 1.0/arad/sqrt(d); |
286 |
> |
for (i = 0; i < 3; i++) |
287 |
> |
pg[i] *= d; |
288 |
> |
} |
289 |
> |
} |
290 |
> |
if ((arad /= sqrt(wt)) > maxarad) |
291 |
> |
arad = maxarad; |
292 |
|
return(arad); |
217 |
– |
oopsy: |
218 |
– |
if (div != NULL) |
219 |
– |
free((char *)div); |
220 |
– |
return(0.0); |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
< |
inithemi(hp, r) /* initialize sampling hemisphere */ |
297 |
< |
register AMBHEMI *hp; |
298 |
< |
RAY *r; |
296 |
> |
void |
297 |
> |
comperrs( /* compute initial error estimates */ |
298 |
> |
AMBSAMP *da, /* assumes standard ordering */ |
299 |
> |
AMBHEMI *hp |
300 |
> |
) |
301 |
|
{ |
228 |
– |
register int i; |
229 |
– |
/* set number of divisions */ |
230 |
– |
hp->nt = sqrt(ambdiv * r->rweight * 0.5) + 0.5; |
231 |
– |
hp->np = 2 * hp->nt; |
232 |
– |
/* make axes */ |
233 |
– |
VCOPY(hp->uz, r->ron); |
234 |
– |
hp->uy[0] = hp->uy[1] = hp->uy[2] = 0.0; |
235 |
– |
for (i = 0; i < 3; i++) |
236 |
– |
if (hp->uz[i] < 0.6 && hp->uz[i] > -0.6) |
237 |
– |
break; |
238 |
– |
if (i >= 3) |
239 |
– |
error(CONSISTENCY, "bad ray direction in inithemi"); |
240 |
– |
hp->uy[i] = 1.0; |
241 |
– |
fcross(hp->ux, hp->uy, hp->uz); |
242 |
– |
normalize(hp->ux); |
243 |
– |
fcross(hp->uy, hp->uz, hp->ux); |
244 |
– |
} |
245 |
– |
|
246 |
– |
|
247 |
– |
comperrs(da, hp) /* compute initial error estimates */ |
248 |
– |
AMBSAMP *da; /* assumes standard ordering */ |
249 |
– |
register AMBHEMI *hp; |
250 |
– |
{ |
302 |
|
double b, b2; |
303 |
|
int i, j; |
304 |
< |
register AMBSAMP *dp; |
304 |
> |
AMBSAMP *dp; |
305 |
|
/* sum differences from neighbors */ |
306 |
|
dp = da; |
307 |
|
for (i = 0; i < hp->nt; i++) |
345 |
|
} |
346 |
|
|
347 |
|
|
348 |
< |
posgradient(gv, da, hp) /* compute position gradient */ |
349 |
< |
FVECT gv; |
350 |
< |
AMBSAMP *da; /* assumes standard ordering */ |
351 |
< |
AMBHEMI *hp; |
348 |
> |
void |
349 |
> |
posgradient( /* compute position gradient */ |
350 |
> |
FVECT gv, |
351 |
> |
AMBSAMP *da, /* assumes standard ordering */ |
352 |
> |
AMBHEMI *hp |
353 |
> |
) |
354 |
|
{ |
355 |
< |
register int i, j; |
356 |
< |
double b, d; |
355 |
> |
int i, j; |
356 |
> |
double nextsine, lastsine, b, d; |
357 |
|
double mag0, mag1; |
358 |
|
double phi, cosp, sinp, xd, yd; |
359 |
< |
register AMBSAMP *dp; |
359 |
> |
AMBSAMP *dp; |
360 |
|
|
361 |
|
xd = yd = 0.0; |
362 |
|
for (j = 0; j < hp->np; j++) { |
363 |
|
dp = da + j; |
364 |
|
mag0 = mag1 = 0.0; |
365 |
+ |
lastsine = 0.0; |
366 |
|
for (i = 0; i < hp->nt; i++) { |
367 |
|
#ifdef DEBUG |
368 |
|
if (dp->t != i || dp->p != j) |
373 |
|
if (i > 0) { |
374 |
|
d = dp[-hp->np].r; |
375 |
|
if (dp[0].r > d) d = dp[0].r; |
376 |
< |
d *= 1.0 - sqrt((double)i/hp->nt); |
376 |
> |
/* sin(t)*cos(t)^2 */ |
377 |
> |
d *= lastsine * (1.0 - (double)i/hp->nt); |
378 |
|
mag0 += d*(b - bright(dp[-hp->np].v)); |
379 |
|
} |
380 |
+ |
nextsine = sqrt((double)(i+1)/hp->nt); |
381 |
|
if (j > 0) { |
382 |
|
d = dp[-1].r; |
383 |
|
if (dp[0].r > d) d = dp[0].r; |
384 |
< |
mag1 += d*(b - bright(dp[-1].v)); |
384 |
> |
mag1 += d * (nextsine - lastsine) * |
385 |
> |
(b - bright(dp[-1].v)); |
386 |
|
} else { |
387 |
|
d = dp[hp->np-1].r; |
388 |
|
if (dp[0].r > d) d = dp[0].r; |
389 |
< |
mag1 += d*(b - bright(dp[hp->np-1].v)); |
389 |
> |
mag1 += d * (nextsine - lastsine) * |
390 |
> |
(b - bright(dp[hp->np-1].v)); |
391 |
|
} |
392 |
|
dp += hp->np; |
393 |
+ |
lastsine = nextsine; |
394 |
|
} |
395 |
< |
if (hp->nt > 1) { |
337 |
< |
mag0 /= (double)hp->np; |
338 |
< |
mag1 /= (double)hp->nt; |
339 |
< |
} |
395 |
> |
mag0 *= 2.0*PI / hp->np; |
396 |
|
phi = 2.0*PI * (double)j/hp->np; |
397 |
< |
cosp = cos(phi); sinp = sin(phi); |
397 |
> |
cosp = tcos(phi); sinp = tsin(phi); |
398 |
|
xd += mag0*cosp - mag1*sinp; |
399 |
|
yd += mag0*sinp + mag1*cosp; |
400 |
|
} |
401 |
|
for (i = 0; i < 3; i++) |
402 |
< |
gv[i] = (xd*hp->ux[i] + yd*hp->uy[i])/PI; |
402 |
> |
gv[i] = (xd*hp->ux[i] + yd*hp->uy[i])*(hp->nt*hp->np)/PI; |
403 |
|
} |
404 |
|
|
405 |
|
|
406 |
< |
dirgradient(gv, da, hp) /* compute direction gradient */ |
407 |
< |
FVECT gv; |
408 |
< |
AMBSAMP *da; /* assumes standard ordering */ |
409 |
< |
AMBHEMI *hp; |
406 |
> |
void |
407 |
> |
dirgradient( /* compute direction gradient */ |
408 |
> |
FVECT gv, |
409 |
> |
AMBSAMP *da, /* assumes standard ordering */ |
410 |
> |
AMBHEMI *hp |
411 |
> |
) |
412 |
|
{ |
413 |
< |
register int i, j; |
413 |
> |
int i, j; |
414 |
|
double mag; |
415 |
|
double phi, xd, yd; |
416 |
< |
register AMBSAMP *dp; |
416 |
> |
AMBSAMP *dp; |
417 |
|
|
418 |
|
xd = yd = 0.0; |
419 |
|
for (j = 0; j < hp->np; j++) { |
425 |
|
error(CONSISTENCY, |
426 |
|
"division order in dirgradient"); |
427 |
|
#endif |
428 |
< |
mag += sqrt((i+.5)/hp->nt)*bright(dp->v); |
428 |
> |
/* tan(t) */ |
429 |
> |
mag += bright(dp->v)/sqrt(hp->nt/(i+.5) - 1.0); |
430 |
|
dp += hp->np; |
431 |
|
} |
432 |
|
phi = 2.0*PI * (j+.5)/hp->np + PI/2.0; |
433 |
< |
xd += mag * cos(phi); |
434 |
< |
yd += mag * sin(phi); |
433 |
> |
xd += mag * tcos(phi); |
434 |
> |
yd += mag * tsin(phi); |
435 |
|
} |
436 |
|
for (i = 0; i < 3; i++) |
437 |
< |
gv[i] = (xd*hp->ux[i] + yd*hp->uy[i])*PI/(hp->nt*hp->np); |
437 |
> |
gv[i] = xd*hp->ux[i] + yd*hp->uy[i]; |
438 |
|
} |
439 |
+ |
|
440 |
+ |
#endif /* ! NEWAMB */ |