38 |
|
CMATRIX *cm; |
39 |
|
|
40 |
|
if ((nrows <= 0) | (ncols <= 0)) |
41 |
< |
return(NULL); |
41 |
> |
error(USER, "attempt to create empty matrix"); |
42 |
|
cm = (CMATRIX *)malloc(sizeof(CMATRIX) + |
43 |
|
3*sizeof(COLORV)*(nrows*ncols - 1)); |
44 |
|
if (cm == NULL) |
160 |
|
int maxrow = (nrows > 0 ? nrows : 32000); |
161 |
|
int r, c; |
162 |
|
for (r = 0; r < maxrow; r++) { |
163 |
< |
if (r >= cm->nrows) /* need more space? */ |
163 |
> |
if (r >= cm->nrows) /* need more space? */ |
164 |
|
cm = cm_resize(cm, 2*cm->nrows); |
165 |
|
for (c = 0; c < ncols; c++) { |
166 |
|
COLORV *cv = cm_lval(cm,r,c); |
167 |
|
if (fscanf(fp, COLSPEC, cv, cv+1, cv+2) != 3) |
168 |
< |
if ((nrows <= 0) & (r > 0) & (c == 0)) { |
168 |
> |
if ((nrows <= 0) & (r > 0) & !c) { |
169 |
|
cm = cm_resize(cm, maxrow=r); |
170 |
|
break; |
171 |
|
} else |
193 |
|
if (nread == cm->nrows*cm->ncols) |
194 |
|
/* need more space? */ |
195 |
|
cm = cm_resize(cm, 2*cm->nrows); |
196 |
< |
else if (nread % cm->ncols == 0) |
196 |
> |
else if (nread && !(nread % cm->ncols)) |
197 |
|
/* seem to be done */ |
198 |
|
cm = cm_resize(cm, nread/cm->ncols); |
199 |
|
else /* ended mid-row */ |
294 |
|
cm_bsdf(const struct BSDF_data *bsdf) |
295 |
|
{ |
296 |
|
CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); |
297 |
– |
COLORV *mp = cm->cmem; |
297 |
|
int nbadohm = 0; |
298 |
|
int nneg = 0; |
299 |
|
int r, c; |
300 |
|
|
301 |
< |
for (r = 0; r < cm->nrows; r++) |
302 |
< |
for (c = 0; c < cm->ncols; c++, mp += 3) { |
301 |
> |
for (c = 0; c < cm->ncols; c++) { |
302 |
> |
float dom = getBSDF_incohm(bsdf,c); |
303 |
> |
FVECT v; |
304 |
> |
|
305 |
> |
if (dom <= .0) { |
306 |
> |
nbadohm++; |
307 |
> |
continue; |
308 |
> |
} |
309 |
> |
if (!getBSDF_incvec(v,bsdf,c) || v[2] > FTINY) |
310 |
> |
error(USER, "illegal incoming BTDF direction"); |
311 |
> |
dom *= -v[2]; |
312 |
> |
|
313 |
> |
for (r = 0; r < cm->nrows; r++) { |
314 |
|
float f = BSDF_value(bsdf,c,r); |
315 |
< |
float dom = getBSDF_incohm(bsdf,c); |
316 |
< |
FVECT v; |
307 |
< |
|
315 |
> |
COLORV *mp = cm_lval(cm,r,c); |
316 |
> |
|
317 |
|
if (f <= .0) { |
318 |
|
nneg += (f < -FTINY); |
319 |
< |
continue; |
319 |
> |
f = .0f; |
320 |
|
} |
321 |
< |
if (dom <= .0) { |
313 |
< |
nbadohm++; |
314 |
< |
continue; |
315 |
< |
} |
316 |
< |
if (!getBSDF_incvec(v,bsdf,c) || v[2] > FTINY) |
317 |
< |
error(USER, "illegal incoming BTDF direction"); |
318 |
< |
|
319 |
< |
mp[0] = mp[1] = mp[2] = f * dom * -v[2]; |
321 |
> |
mp[0] = mp[1] = mp[2] = f * dom; |
322 |
|
} |
323 |
+ |
} |
324 |
|
if (nneg || nbadohm) { |
325 |
|
sprintf(errmsg, |
326 |
|
"BTDF has %d negatives and %d bad incoming solid angles", |
404 |
|
return(fflush(stdout) == 0); |
405 |
|
} |
406 |
|
|
407 |
< |
/* check to see if a string contains a %d specification */ |
408 |
< |
int |
409 |
< |
hasDecimalSpec(const char *s) |
407 |
> |
/* check to see if a string contains a %d or %o specification */ |
408 |
> |
static int |
409 |
> |
hasNumberFormat(const char *s) |
410 |
|
{ |
411 |
|
while (*s && *s != '%') |
412 |
|
s++; |
416 |
|
++s; |
417 |
|
while (isdigit(*s)); |
418 |
|
|
419 |
< |
return(*s == 'd'); |
419 |
> |
return(*s == 'd' | *s == 'i' | *s == 'o' | *s == 'x' | *s == 'X'); |
420 |
|
} |
421 |
|
|
422 |
|
int |
432 |
|
progname); |
433 |
|
return(1); |
434 |
|
} |
435 |
+ |
/* load Tregenza vector */ |
436 |
|
tvec = cm_load(argv[4], 0, 1, DTascii); /* argv[4]==NULL iff argc==4 */ |
437 |
< |
Dmat = cm_load(argv[3], 0, tvec->nrows, DTfromHeader); |
437 |
> |
/* load BTDF */ |
438 |
|
btdf = load_BSDF(argv[2]); |
439 |
|
if (btdf == NULL) |
440 |
|
return(1); |
441 |
< |
if (btdf->ninc != Dmat->nrows) { |
442 |
< |
sprintf(errmsg, "Incoming BTDF dir (%d) mismatch to D (%d)", |
439 |
< |
btdf->ninc, Dmat->nrows); |
440 |
< |
error(USER, errmsg); |
441 |
< |
} |
441 |
> |
/* load Daylight matrix */ |
442 |
> |
Dmat = cm_load(argv[3], btdf->ninc, tvec->nrows, DTfromHeader); |
443 |
|
/* multiply vector through */ |
444 |
|
ivec = cm_multiply(Dmat, tvec); |
445 |
|
cm_free(Dmat); cm_free(tvec); |
447 |
|
free_BSDF(btdf); |
448 |
|
cvec = cm_multiply(Tmat, ivec); /* cvec = component vector */ |
449 |
|
cm_free(Tmat); cm_free(ivec); |
450 |
< |
if (hasDecimalSpec(argv[1])) { /* generating image */ |
450 |
> |
if (hasNumberFormat(argv[1])) { /* generating image */ |
451 |
|
SET_FILE_BINARY(stdout); |
452 |
|
newheader("RADIANCE", stdout); |
453 |
|
printargs(argc, argv, stdout); |