16 |
|
#include "rtprocess.h" |
17 |
|
|
18 |
|
#ifndef NSAMPLES |
19 |
< |
#define NSAMPLES 100000 /* number of samples to use */ |
19 |
> |
#define NSAMPLES 80000 /* number of samples to use */ |
20 |
|
#endif |
21 |
|
|
22 |
|
char *progname; /* global argv[0] */ |
23 |
|
|
24 |
< |
char temp_octree[128]; /* temporary octree */ |
24 |
> |
char temp_octree[128]; /* temporary octree */ |
25 |
|
|
26 |
|
const char UVF_PNAME[] = |
27 |
|
"ZoneProperty:UserViewFactor:bySurfaceName"; |
28 |
|
|
29 |
|
const char ADD_HEADER[] = |
30 |
< |
"!+++ User View Factors computed by Radiance +++!\n"; |
30 |
> |
"\n!+++ User View Factors computed by Radiance +++!\n\n"; |
31 |
|
|
32 |
|
#define NAME_FLD 1 /* name field always first? */ |
33 |
|
|
39 |
|
|
40 |
|
const SURF_PTYPE surf_type[] = { |
41 |
|
{"BuildingSurface:Detailed", 4, 10}, |
42 |
+ |
{"Floor:Detailed", 3, 9}, |
43 |
+ |
{"RoofCeiling:Detailed", 3, 9}, |
44 |
+ |
{"Wall:Detailed", 3, 9}, |
45 |
|
{NULL} |
46 |
|
}; |
47 |
|
|
146 |
|
static int |
147 |
|
start_rcontrib(SUBPROC *pd, ZONE *zp) |
148 |
|
{ |
149 |
< |
#define BASE_AC 3 |
149 |
> |
#define BASE_AC 5 |
150 |
|
static char *base_av[BASE_AC] = { |
151 |
< |
"rcontrib", "-ff", "-h" |
151 |
> |
"rcontrib", "-ff", "-h", "-x", "1" |
152 |
|
}; |
153 |
|
char cbuf[300]; |
154 |
|
char **av; |
224 |
|
vl3 = (FVECT *)malloc(sizeof(FVECT)*nv); |
225 |
|
if (vl3 == NULL) |
226 |
|
return(NULL); |
227 |
< |
for (i = 0; i < nv; i++) |
227 |
> |
for (i = nv; i--; ) /* reverse vertex ordering */ |
228 |
|
for (j = 0; j < 3; j++) { |
229 |
|
if (fptr == NULL) { |
230 |
|
fputs(progname, stderr); |
231 |
< |
fputs(": bad vertex in init_poly()\n", stderr); |
231 |
> |
fputs(": missing vertex in init_poly()\n", stderr); |
232 |
|
return(NULL); |
233 |
|
} |
234 |
|
vl3[i][j] = atof(fptr->val); |
235 |
+ |
fptr = fptr->next; |
236 |
|
} |
237 |
|
/* compute area and normal */ |
238 |
|
ps->sdir[2][0] = ps->sdir[2][1] = ps->sdir[2][2] = 0; |
256 |
|
normalize(ps->sdir[0]); |
257 |
|
fcross(ps->sdir[1], ps->sdir[2], ps->sdir[0]); |
258 |
|
/* compute plane offset */ |
259 |
< |
ps->poff = DOT(vl3[0], ps->sdir[2]) + FTINY; |
259 |
> |
ps->poff = DOT(vl3[0], ps->sdir[2]); |
260 |
|
/* assign 2-D vertices */ |
261 |
|
for (i = 0; i < nv; i++) { |
262 |
|
vl2->v[i].mX = DOT(vl3[i], ps->sdir[0]); |
280 |
|
for (i = 3; i--; ) { |
281 |
|
orig[i] = vl2->v[a].mX*ps->sdir[0][i] + |
282 |
|
vl2->v[a].mY*ps->sdir[1][i] + |
283 |
< |
ps->poff*ps->sdir[2][i]; |
283 |
> |
(ps->poff+.001)*ps->sdir[2][i]; |
284 |
|
ab[i] = (vl2->v[b].mX - vl2->v[a].mX)*ps->sdir[0][i] + |
285 |
|
(vl2->v[b].mY - vl2->v[a].mY)*ps->sdir[1][i]; |
286 |
|
ac[i] = (vl2->v[c].mX - vl2->v[a].mX)*ps->sdir[0][i] + |
309 |
|
samp = (float *)malloc(sizeof(float)*6*ns); |
310 |
|
if (samp == NULL) |
311 |
|
return(0); |
312 |
< |
for (i = ns; i--; ) { |
312 |
> |
for (i = ns; i--; ) { /* stratified Monte Carlo sampling */ |
313 |
|
double sv[4]; |
314 |
+ |
FVECT dv; |
315 |
|
multisamp(sv, 4, (i+frandom())/(double)ns); |
316 |
|
sv[0] *= sv[1] = sqrt(sv[1]); |
317 |
|
sv[1] = 1. - sv[1]; |
318 |
|
for (j = 3; j--; ) |
319 |
< |
samp[ns*6 + j] = orig[j] + sv[0]*ab[j] + sv[1]*ac[j]; |
320 |
< |
sv[3] = sqrt(sv[3]); |
321 |
< |
sv[4] *= 2.*PI; |
322 |
< |
samp[ns*6 + 3] = tcos(sv[4]) * sv[3]; |
323 |
< |
samp[ns*6 + 4] = tsin(sv[4]) * sv[3]; |
324 |
< |
samp[ns*6 + 5] = sqrt(1. - sv[3]*sv[3]); |
319 |
> |
samp[i*6 + j] = orig[j] + sv[0]*ab[j] + sv[1]*ac[j]; |
320 |
> |
sv[2] = sqrt(sv[2]); |
321 |
> |
sv[3] *= 2.*PI; |
322 |
> |
dv[0] = tcos(sv[3]) * sv[2]; |
323 |
> |
dv[1] = tsin(sv[3]) * sv[2]; |
324 |
> |
dv[2] = sqrt(1. - sv[2]*sv[2]); |
325 |
> |
for (j = 3; j--; ) |
326 |
> |
samp[i*6 + 3 + j] = dv[0]*ps->sdir[0][j] + |
327 |
> |
dv[1]*ps->sdir[1][j] + |
328 |
> |
dv[2]*ps->sdir[2][j] ; |
329 |
|
} |
330 |
|
/* send to our process */ |
331 |
|
writebuf(ps->wd, (char *)samp, sizeof(float)*6*ns); |
342 |
|
int nv; |
343 |
|
Vert2_list *vlist2; |
344 |
|
/* set up our polygon sampler */ |
345 |
< |
if (fptr == NULL || (nv = atoi(fptr->val)) < 3) { |
346 |
< |
fprintf(stderr, "%s: error in %s '%s'\n", |
345 |
> |
if (fptr == NULL || (nv = atoi(fptr->val)) < 3 || |
346 |
> |
(vlist2 = init_poly(&psamp, fptr->next, nv)) == NULL) { |
347 |
> |
fprintf(stderr, "%s: bad polygon %s '%s'\n", |
348 |
|
progname, param->pname, |
349 |
|
idf_getfield(param,NAME_FLD)->val); |
350 |
|
return(0); |
351 |
|
} |
342 |
– |
vlist2 = init_poly(&psamp, fptr->next, nv); |
343 |
– |
if (vlist2 == NULL) |
344 |
– |
return(0); |
352 |
|
psamp.samp_left = NSAMPLES; /* assign samples & destination */ |
353 |
|
psamp.wd = wd; |
354 |
|
/* sample each subtriangle */ |
386 |
|
return(0); |
387 |
|
/* UVFs from each surface */ |
388 |
|
for (n = zp->nsurf, pptr = zp->pfirst; n--; pptr = pptr->dnext) { |
389 |
+ |
double vfsum = 0; |
390 |
|
/* send samples to rcontrib */ |
391 |
|
if (!sample_surface(pptr, pd->w)) |
392 |
|
return(0); |
400 |
|
/* append UVF fields */ |
401 |
|
for (m = 0, pptr1 = zp->pfirst; |
402 |
|
m < zp->nsurf; m++, pptr1 = pptr1->dnext) { |
403 |
+ |
vfsum += uvfa[3*m + 1]; |
404 |
|
if (pptr1 == pptr) { |
405 |
|
if (uvfa[3*m + 1] > .001) |
406 |
|
fprintf(stderr, |
407 |
< |
"%s: warning - non-zero self-VF (%.3e) for surface '%s'\n", |
408 |
< |
progname, uvfa[3*m + 1], |
407 |
> |
"%s: warning - non-zero self-VF (%.1f%%) for surface '%s'\n", |
408 |
> |
progname, 100.*uvfa[3*m + 1], |
409 |
|
idf_getfield(pptr,NAME_FLD)->val); |
410 |
|
continue; /* don't record self-factor */ |
411 |
|
} |
412 |
< |
sprintf(uvfbuf, "%.6f", uvfa[3*m + 1]); |
412 |
> |
sprintf(uvfbuf, "%.4f", uvfa[3*m + 1]); |
413 |
|
if (!idf_addfield(pout, |
414 |
|
idf_getfield(pptr,NAME_FLD)->val, NULL) || |
415 |
|
!idf_addfield(pout, |
422 |
|
return(0); |
423 |
|
} |
424 |
|
} |
425 |
+ |
if (vfsum < 0.95) |
426 |
+ |
fprintf(stderr, |
427 |
+ |
"%s: warning - missing %.1f%% of energy from surface '%s'\n", |
428 |
+ |
progname, 100.*(1.-vfsum), |
429 |
+ |
idf_getfield(pptr,NAME_FLD)->val); |
430 |
|
} |
431 |
|
free(uvfa); /* clean up and return */ |
432 |
|
return(1); |
438 |
|
{ |
439 |
|
ZONE *zptr; |
440 |
|
/* temporary octree name */ |
441 |
< |
if (temp_filename(temp_octree, sizeof(temp_octree), TEMPLATE) == NULL) { |
428 |
< |
fputs(progname, stderr); |
429 |
< |
fputs(": cannot create temporary octree\n", stderr); |
430 |
< |
return(0); |
431 |
< |
} |
441 |
> |
mktemp(strcpy(temp_octree, TEMPLATE)); |
442 |
|
/* compute each zone */ |
443 |
|
for (zptr = zone_list; zptr != NULL; zptr = zptr->next) { |
444 |
|
SUBPROC rcproc; |