45 |
|
SDError |
46 |
|
SDreportEnglish(SDError ec, FILE *fp) |
47 |
|
{ |
48 |
– |
if (fp == NULL) |
49 |
– |
return ec; |
48 |
|
if (!ec) |
49 |
|
return SDEnone; |
50 |
+ |
if ((ec < SDEnone) | (ec > SDEunknown)) { |
51 |
+ |
SDerrorDetail[0] = '\0'; |
52 |
+ |
ec = SDEunknown; |
53 |
+ |
} |
54 |
+ |
if (fp == NULL) |
55 |
+ |
return ec; |
56 |
|
fputs(SDerrorEnglish[ec], fp); |
57 |
|
if (SDerrorDetail[0]) { |
58 |
|
fputs(": ", fp); |
89 |
|
|
90 |
|
if (wdb == NULL) /* no geometry section? */ |
91 |
|
return SDEnone; |
88 |
– |
sprintf(SDerrorDetail, "Negative size in \"%s\"", sd->name); |
92 |
|
sd->dim[0] = sd->dim[1] = sd->dim[2] = .0; |
93 |
|
if ((geom = ezxml_child(wdb, "Width")) != NULL) |
94 |
|
sd->dim[0] = atof(ezxml_txt(geom)) * |
99 |
|
if ((geom = ezxml_child(wdb, "Thickness")) != NULL) |
100 |
|
sd->dim[2] = atof(ezxml_txt(geom)) * |
101 |
|
to_meters(ezxml_attr(geom, "unit")); |
102 |
< |
if ((sd->dim[0] < .0) | (sd->dim[1] < .0) | (sd->dim[2] < .0)) |
102 |
> |
if ((sd->dim[0] < .0) | (sd->dim[1] < .0) | (sd->dim[2] < .0)) { |
103 |
> |
sprintf(SDerrorDetail, "Negative size in \"%s\"", sd->name); |
104 |
|
return SDEdata; |
105 |
+ |
} |
106 |
|
if ((geom = ezxml_child(wdb, "Geometry")) == NULL || |
107 |
|
(mgfstr = ezxml_txt(geom)) == NULL) |
108 |
|
return SDEnone; |
273 |
|
|
274 |
|
/* Initialize an unused BSDF struct (simply clears to zeroes) */ |
275 |
|
void |
276 |
< |
SDclearBSDF(SDData *sd) |
276 |
> |
SDclearBSDF(SDData *sd, const char *fname) |
277 |
|
{ |
278 |
< |
if (sd != NULL) |
279 |
< |
memset(sd, 0, sizeof(SDData)); |
278 |
> |
if (sd == NULL) |
279 |
> |
return; |
280 |
> |
memset(sd, 0, sizeof(SDData)); |
281 |
> |
if (fname == NULL) |
282 |
> |
return; |
283 |
> |
SDclipName(sd->name, fname); |
284 |
|
} |
285 |
|
|
286 |
|
/* Free data associated with BSDF struct */ |
338 |
|
sdl->next = SDcacheList; |
339 |
|
SDcacheList = sdl; |
340 |
|
|
341 |
< |
sdl->refcnt++; |
341 |
> |
sdl->refcnt = 1; |
342 |
|
return &sdl->bsdf; |
343 |
|
} |
344 |
|
|
382 |
|
for (sdl = SDcacheList; sdl != NULL; sdl = (sdLast=sdl)->next) |
383 |
|
if (&sdl->bsdf == sd) |
384 |
|
break; |
385 |
< |
if (sdl == NULL || --sdl->refcnt) |
385 |
> |
if (sdl == NULL || (sdl->refcnt -= (sdl->refcnt > 0))) |
386 |
|
return; /* missing or still in use */ |
387 |
|
/* keep unreferenced data? */ |
388 |
|
if (SDisLoaded(sd) && SDretainSet) { |
459 |
|
bitmask_t ndx, coord[MS_MAXDIM]; |
460 |
|
|
461 |
|
while (n > MS_MAXDIM) /* punt for higher dimensions */ |
462 |
< |
t[--n] = drand48(); |
462 |
> |
t[--n] = rand()*(1./(RAND_MAX+.5)); |
463 |
|
nBits = (8*sizeof(bitmask_t) - 1) / n; |
464 |
|
ndx = randX * (double)((bitmask_t)1 << (nBits*n)); |
465 |
|
/* get coordinate on Hilbert curve */ |
467 |
|
/* convert back to [0,1) range */ |
468 |
|
scale = 1. / (double)((bitmask_t)1 << nBits); |
469 |
|
while (n--) |
470 |
< |
t[n] = scale * ((double)coord[n] + drand48()); |
470 |
> |
t[n] = scale * ((double)coord[n] + rand()*(1./(RAND_MAX+.5))); |
471 |
|
} |
472 |
|
|
473 |
|
#undef MS_MAXDIM |
497 |
|
if ((projSA == NULL) | (vec == NULL) | (sd == NULL)) |
498 |
|
return SDEargument; |
499 |
|
/* initialize extrema */ |
500 |
< |
switch (qflags & SDqueryMin+SDqueryMax) { |
500 |
> |
switch (qflags) { |
501 |
|
case SDqueryMax: |
502 |
|
projSA[0] = .0; |
503 |
|
break; |
527 |
|
if (ec) |
528 |
|
return ec; |
529 |
|
} |
530 |
< |
return ec; |
530 |
> |
if (ec) { /* all diffuse? */ |
531 |
> |
projSA[0] = M_PI; |
532 |
> |
if (qflags == SDqueryMin+SDqueryMax) |
533 |
> |
projSA[1] = M_PI; |
534 |
> |
} |
535 |
> |
return SDEnone; |
536 |
|
} |
537 |
|
|
538 |
|
/* Return BSDF for the given incident and scattered ray vectors */ |